Skip to content

Commit 657c246

Browse files
committed
Add initial implementation and first example
1 parent 7a51f0a commit 657c246

File tree

8 files changed

+618
-64
lines changed

8 files changed

+618
-64
lines changed

examples/Example01_BasicUsage/Example01_BasicUsage.ino

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include "SparkFun_Qwiic_OTOS_Arduino_Library.h"
2+
#include "Wire.h"
3+
4+
// Create an OTOS object
5+
QwiicOTOS myOtos;
6+
7+
void setup()
8+
{
9+
// Start serial
10+
Serial.begin(115200);
11+
Serial.println("Qwiic OTOS Example 1 - Basic Readings");
12+
13+
Wire.begin();
14+
15+
// Attempt to begin the sensor
16+
while (myOtos.begin() == false)
17+
{
18+
Serial.println("OTOS not connected, check your wiring and I2C address!");
19+
delay(1000);
20+
}
21+
22+
Serial.println("OTOS connected!");
23+
24+
// The IMU on the OTOS includes a gyroscope and accelerometer, which could
25+
// have an offset. This needs to be calibrated out in order to get accurate
26+
// tracking, which must be done while the OTOS is stationary and flat!
27+
Serial.println("Calibrating IMU...");
28+
myOtos.calibrateImu();
29+
30+
// We'll also reset the tracking to start at the origin
31+
Serial.println("Resetting pose...");
32+
otos_pose2d_t currentPose = {0, 0, 0};
33+
myOtos.setPosition(currentPose);
34+
35+
myOtos.setLinearUnit(kOtosLinearUnitInches);
36+
myOtos.setAngularUnit(kOtosAngularUnitDegrees);
37+
}
38+
39+
void loop()
40+
{
41+
// Get latest pose from sensor, which includes the x and y coordinates, plus
42+
// the heading angle
43+
otos_pose2d_t otosPose;
44+
myOtos.getPosition(otosPose);
45+
46+
// Print measurement
47+
Serial.println();
48+
Serial.println("Current pose:");
49+
Serial.print("X (Meters): ");
50+
Serial.println(otosPose.x, 3);
51+
Serial.print("Y (Meters): ");
52+
Serial.println(otosPose.y, 3);
53+
Serial.print("Heading (Radians): ");
54+
Serial.println(otosPose.h, 3);
55+
56+
// Wait a bit so we don't spam the serial port
57+
delay(500);
58+
59+
// Alternatively, you can comment out the print and delay code above, and
60+
// instead use the following code to refresh the data more quickly
61+
// Serial.print(otosPose.x, 3);
62+
// Serial.print(", ");
63+
// Serial.print(otosPose.y, 3);
64+
// Serial.print(", ");
65+
// Serial.println(otosPose.h, 3);
66+
// delay(10);
67+
}

library.properties

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name=SparkFun Template Arduino Library
1+
name=SparkFun Qwiic OTOS Arduino Library
22
version=1.0.0
33
author=SparkFun Electronics <techsupport@sparkfun.com>
44
maintainer=SparkFun Electronics <sparkfun.com>
5-
sentence=TODO: Add short description
6-
paragraph=TODO: Add long description
7-
category=TODO: Add category (Sensors, Display, Communication, etc.)
8-
url=TODO: Add URL
9-
architectures=TODO: Add architectures (*, esp32, teensy, stm32, megaavr, etc.)
5+
sentence=A library to use the SparkFun Qwiic Optical Tracking Odometry Sensor
6+
paragraph=
7+
category=Sensors
8+
url=https://github.com/sparkfun/SparkFun_Qwiic_OTOS_Arduino_Library
9+
architectures=*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
3+
#include "Arduino.h"
4+
#include "sfeQwiicOtos.h"
5+
#include <Wire.h>
6+
7+
class QwiicOTOS : public sfeQwiicOtos
8+
{
9+
public:
10+
/// @brief Begins the Qwiic Ultrasonic sensor
11+
/// @param address I2C device address to use for the sensor
12+
/// @param wirePort Wire port to use for I2C communication
13+
/// @return True if successful, false otherwise
14+
bool begin(uint8_t address = kOtosDefaultAddress, TwoWire &wirePort = Wire)
15+
{
16+
// Setup Arduino I2C bus
17+
_theI2CBus.init(wirePort, address);
18+
19+
// Begin the sensor
20+
return sfeQwiicOtos::begin(&_theI2CBus) == kSTkErrOk;
21+
}
22+
23+
protected:
24+
void delayMs(uint32_t ms)
25+
{
26+
delay(ms);
27+
}
28+
29+
private:
30+
sfeTkArdI2C _theI2CBus;
31+
};

src/SparkFun_Template_Arduino_Library.cpp

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/SparkFun_Template_Arduino_Library.h

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)