Skip to content

Commit 8c1750c

Browse files
committed
Update examples
Add IMU calibration to every example Prompt user before performing IMU calibration Update with new naming conventions
1 parent 67a1e36 commit 8c1750c

File tree

8 files changed

+156
-64
lines changed

8 files changed

+156
-64
lines changed

examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,51 @@ void setup()
2727

2828
Serial.println("OTOS connected!");
2929

30-
// Reset the tracking algorithm, making the sensor report it's at the origin
30+
Serial.println("Ensure the OTOS is flat and stationary, then enter any key to calibrate the IMU");
31+
32+
// Clear the serial buffer
33+
while (Serial.available())
34+
Serial.read();
35+
// Wait for user input
36+
while (!Serial.available())
37+
;
38+
39+
Serial.println("Calibrating IMU...");
40+
41+
// Calibrate the IMU, which removes the accelerometer and gyroscope offsets
42+
myOtos.calibrateImu();
43+
44+
// Reset the tracking algorithm - this resets the position to the origin,
45+
// but can also be used to recover from some rare tracking errors
3146
myOtos.resetTracking();
3247
}
3348

3449
void loop()
3550
{
36-
// Get the latest sensor pose, which includes the x and y coordinates, plus
37-
// the heading angle
38-
otos_pose2d_t otosPose;
39-
myOtos.getPosition(otosPose);
51+
// Get the latest position, which includes the x and y coordinates, plus the
52+
// heading angle
53+
sfe_otos_pose2d_t myPosition;
54+
myOtos.getPosition(myPosition);
4055

4156
// Print measurement
4257
Serial.println();
43-
Serial.println("Sensor pose:");
58+
Serial.println("Position:");
4459
Serial.print("X (Inches): ");
45-
Serial.println(otosPose.x);
60+
Serial.println(myPosition.x);
4661
Serial.print("Y (Inches): ");
47-
Serial.println(otosPose.y);
62+
Serial.println(myPosition.y);
4863
Serial.print("Heading (Degrees): ");
49-
Serial.println(otosPose.h);
64+
Serial.println(myPosition.h);
5065

5166
// Wait a bit so we don't spam the serial port
5267
delay(500);
5368

5469
// Alternatively, you can comment out the print and delay code above, and
5570
// instead use the following code to rapidly refresh the data
56-
// Serial.print(otosPose.x);
71+
// Serial.print(myPosition.x);
5772
// Serial.print("\t");
58-
// Serial.print(otosPose.y);
73+
// Serial.print(myPosition.y);
5974
// Serial.print("\t");
60-
// Serial.println(otosPose.h);
75+
// Serial.println(myPosition.h);
6176
// delay(10);
6277
}

examples/Example2_SetUnits/Example2_SetUnits.ino

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,52 @@ void setup()
2626
}
2727

2828
Serial.println("OTOS connected!");
29-
29+
30+
Serial.println("Ensure the OTOS is flat and stationary, then enter any key to calibrate the IMU");
31+
32+
// Clear the serial buffer
33+
while (Serial.available())
34+
Serial.read();
35+
// Wait for user input
36+
while (!Serial.available())
37+
;
38+
39+
Serial.println("Calibrating IMU...");
40+
41+
// Calibrate the IMU, which removes the accelerometer and gyroscope offsets
42+
myOtos.calibrateImu();
43+
3044
// Set the desired units for linear and angular measurements. Can be either
3145
// meters or inches for linear, and radians or degrees for angular. If not
3246
// set, the default is inches and degrees. Note that this setting is not
3347
// stored in the sensor, it's part of the library, so you need to set at the
3448
// start of all your programs.
35-
myOtos.setLinearUnit(kOtosLinearUnitMeters);
36-
// myOtos.setLinearUnit(kOtosLinearUnitInches);
37-
myOtos.setAngularUnit(kOtosAngularUnitRadians);
38-
// myOtos.setAngularUnit(kOtosAngularUnitDegrees);
49+
myOtos.setLinearUnit(kSfeOtosLinearUnitMeters);
50+
// myOtos.setLinearUnit(kSfeOtosLinearUnitInches);
51+
myOtos.setAngularUnit(kSfeOtosAngularUnitRadians);
52+
// myOtos.setAngularUnit(kSfeOtosAngularUnitDegrees);
3953

40-
// Reset the tracking algorithm, making the sensor report it's at the origin
54+
// Reset the tracking algorithm - this resets the position to the origin,
55+
// but can also be used to recover from some rare tracking errors
4156
myOtos.resetTracking();
4257
}
4358

4459
void loop()
4560
{
46-
// Get the latest sensor pose, which includes the x and y coordinates, plus
47-
// the heading angle
48-
otos_pose2d_t otosPose;
49-
myOtos.getPosition(otosPose);
61+
// Get the latest position, which includes the x and y coordinates, plus the
62+
// heading angle
63+
sfe_otos_pose2d_t myPosition;
64+
myOtos.getPosition(myPosition);
5065

5166
// Print measurement
5267
Serial.println();
53-
Serial.println("Sensor pose:");
68+
Serial.println("Position:");
5469
Serial.print("X (Meters): ");
55-
Serial.println(otosPose.x, 4);
70+
Serial.println(myPosition.x, 4);
5671
Serial.print("Y (Meters): ");
57-
Serial.println(otosPose.y, 4);
72+
Serial.println(myPosition.y, 4);
5873
Serial.print("Heading (Radians): ");
59-
Serial.println(otosPose.h, 4);
74+
Serial.println(myPosition.h, 4);
6075

6176
// Wait a bit so we don't spam the serial port
6277
delay(500);

examples/Example3_Calibration/Example3_Calibration.ino

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ void setup()
2626
}
2727

2828
Serial.println("OTOS connected!");
29+
30+
Serial.println("Ensure the OTOS is flat and stationary, then enter any key to calibrate the IMU");
31+
32+
// Clear the serial buffer
33+
while (Serial.available())
34+
Serial.read();
35+
// Wait for user input
36+
while (!Serial.available())
37+
;
38+
39+
Serial.println("Calibrating IMU...");
2940

3041
// The IMU on the OTOS includes a gyroscope and accelerometer, which could
3142
// have an offset. Note that as of firmware version 1.0, the calibration
@@ -59,27 +70,29 @@ void setup()
5970
myOtos.setLinearScalar(1.0);
6071
myOtos.setAngularScalar(1.0);
6172

62-
// Reset the tracking algorithm, making the sensor report it's at the origin
73+
// Reset the tracking algorithm - this resets the position to the origin,
74+
// but can also be used to recover from some rare tracking errors
6375
myOtos.resetTracking();
6476
}
6577

6678
void loop()
6779
{
68-
// Get the latest sensor pose, which includes the x and y coordinates, plus
69-
// the heading angle
70-
otos_pose2d_t otosPose;
71-
myOtos.getPosition(otosPose);
80+
// Get the latest position, which includes the x and y coordinates, plus the
81+
// heading angle
82+
sfe_otos_pose2d_t myPosition;
83+
myOtos.getPosition(myPosition);
7284

7385
// Print measurement
7486
Serial.println();
75-
Serial.println("Sensor pose:");
87+
Serial.println("Position:");
7688
Serial.print("X (Inches): ");
77-
Serial.println(otosPose.x);
89+
Serial.println(myPosition.x);
7890
Serial.print("Y (Inches): ");
79-
Serial.println(otosPose.y);
91+
Serial.println(myPosition.y);
8092
Serial.print("Heading (Degrees): ");
81-
Serial.println(otosPose.h);
93+
Serial.println(myPosition.h);
8294

8395
// Wait a bit so we don't spam the serial port
8496
delay(500);
97+
8598
}

examples/Example4_SetOffsetAndPosition/Example4_SetOffsetAndPosition.ino

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,23 @@ void setup()
2626
}
2727

2828
Serial.println("OTOS connected!");
29-
30-
// Here you can set the offset for the sensor relative to the center of the
29+
30+
Serial.println("Ensure the OTOS is flat and stationary, then enter any key to calibrate the IMU");
31+
32+
// Clear the serial buffer
33+
while (Serial.available())
34+
Serial.read();
35+
// Wait for user input
36+
while (!Serial.available())
37+
;
38+
39+
Serial.println("Calibrating IMU...");
40+
41+
// Calibrate the IMU, which removes the accelerometer and gyroscope offsets
42+
myOtos.calibrateImu();
43+
44+
// Assuming you've mounted your sensor to a robot and it's not centered,
45+
// you can specify the offset for the sensor relative to the center of the
3146
// robot. The units default to inches and degrees, but if you want to use
3247
// different units, specify them before setting the offset! Note that as of
3348
// firmware version 1.0, these values will be lost after a power cycle, so
@@ -37,37 +52,39 @@ void setup()
3752
// clockwise (negative rotation) from the robot's orientation, the offset
3853
// would be {-5, 10, -90}. These can be any value, even the angle can be
3954
// tweaked slightly to compensate for imperfect mounting (eg. 1.3 degrees).
40-
otos_pose2d_t offset = {-5, 10, -90};
55+
sfe_otos_pose2d_t offset = {-5, 10, -90};
4156
myOtos.setOffset(offset);
4257

43-
// Reset the tracking algorithm, making the sensor report it's at the origin
58+
// Reset the tracking algorithm - this resets the position to the origin,
59+
// but can also be used to recover from some rare tracking errors
4460
myOtos.resetTracking();
4561

4662
// After resetting the tracking, the OTOS will report that the robot is at
47-
// the origin. If you know the starting coordinates of the robot, or have
63+
// the origin. If your robot does not start at the origin, or you have
4864
// another source of location information (eg. vision odometry), you can set
4965
// the OTOS location to match and it will continue to track from there.
50-
otos_pose2d_t currentPosition = {0, 0, 0};
66+
sfe_otos_pose2d_t currentPosition = {0, 0, 0};
5167
myOtos.setPosition(currentPosition);
5268
}
5369

5470
void loop()
5571
{
56-
// Get the latest robot pose, which includes the x and y coordinates, plus
57-
// the heading angle
58-
otos_pose2d_t robotPose;
59-
myOtos.getPosition(robotPose);
72+
// Get the latest position, which includes the x and y coordinates, plus the
73+
// heading angle
74+
sfe_otos_pose2d_t myPosition;
75+
myOtos.getPosition(myPosition);
6076

6177
// Print measurement
6278
Serial.println();
63-
Serial.println("Robot pose:");
79+
Serial.println("Position:");
6480
Serial.print("X (Inches): ");
65-
Serial.println(robotPose.x);
81+
Serial.println(myPosition.x);
6682
Serial.print("Y (Inches): ");
67-
Serial.println(robotPose.y);
83+
Serial.println(myPosition.y);
6884
Serial.print("Heading (Degrees): ");
69-
Serial.println(robotPose.h);
85+
Serial.println(myPosition.h);
7086

7187
// Wait a bit so we don't spam the serial port
7288
delay(500);
89+
7390
}

examples/Example5_VelocityAndAcceleration/Example5_VelocityAndAcceleration.ino

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,32 @@ void setup()
2828
}
2929

3030
Serial.println("OTOS connected!");
31-
32-
// Reset the tracking algorithm, making the sensor report it's at the origin
31+
32+
Serial.println("Ensure the OTOS is flat and stationary, then enter any key to calibrate the IMU");
33+
34+
// Clear the serial buffer
35+
while (Serial.available())
36+
Serial.read();
37+
// Wait for user input
38+
while (!Serial.available())
39+
;
40+
41+
Serial.println("Calibrating IMU...");
42+
43+
// Calibrate the IMU, which removes the accelerometer and gyroscope offsets
44+
myOtos.calibrateImu();
45+
46+
// Reset the tracking algorithm - this resets the position to the origin,
47+
// but can also be used to recover from some rare tracking errors
3348
myOtos.resetTracking();
3449
}
3550

3651
void loop()
3752
{
3853
// Create structs for position, velocity, and acceleration
39-
otos_pose2d_t pos;
40-
otos_pose2d_t vel;
41-
otos_pose2d_t acc;
54+
sfe_otos_pose2d_t pos;
55+
sfe_otos_pose2d_t vel;
56+
sfe_otos_pose2d_t acc;
4257

4358
// These values can be read individually like so:
4459
myOtos.getPosition(pos);

examples/Example6_StandardDeviation/Example6_StandardDeviation.ino

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,23 @@ void setup()
2626
}
2727

2828
Serial.println("OTOS connected!");
29-
30-
// Reset the tracking algorithm, making the sensor report it's at the origin
29+
30+
Serial.println("Ensure the OTOS is flat and stationary, then enter any key to calibrate the IMU");
31+
32+
// Clear the serial buffer
33+
while (Serial.available())
34+
Serial.read();
35+
// Wait for user input
36+
while (!Serial.available())
37+
;
38+
39+
Serial.println("Calibrating IMU...");
40+
41+
// Calibrate the IMU, which removes the accelerometer and gyroscope offsets
42+
myOtos.calibrateImu();
43+
44+
// Reset the tracking algorithm - this resets the position to the origin,
45+
// but can also be used to recover from some rare tracking errors
3146
myOtos.resetTracking();
3247
}
3348

@@ -36,12 +51,12 @@ void loop()
3651
// Create structs for position and standard deviations. This example can be
3752
// extended to include velocity and acceleration, which have been omitted
3853
// for simplicity, but can be added by uncommenting the code below
39-
otos_pose2d_t pos;
40-
// otos_pose2d_t vel;
41-
// otos_pose2d_t acc;
42-
otos_pose2d_t posStdDev;
43-
// otos_pose2d_t velStdDev;
44-
// otos_pose2d_t accStdDev;
54+
sfe_otos_pose2d_t pos;
55+
// sfe_otos_pose2d_t vel;
56+
// sfe_otos_pose2d_t acc;
57+
sfe_otos_pose2d_t posStdDev;
58+
// sfe_otos_pose2d_t velStdDev;
59+
// sfe_otos_pose2d_t accStdDev;
4560

4661
// Read the position like normal (and velocity and acceleration if desired)
4762
myOtos.getPosition(pos);

examples/Example7_GetVersion/Example7_GetVersion.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ void setup()
2828
Serial.println("OTOS connected!");
2929

3030
// Get the hardware and firmware version
31-
otos_version_t hwVersion;
32-
otos_version_t fwVersion;
31+
sfe_otos_version_t hwVersion;
32+
sfe_otos_version_t fwVersion;
3333
myOtos.getVersionInfo(hwVersion, fwVersion);
3434

3535
// Print the hardware and firmware version

examples/Example8_SelfTest/Example8_SelfTest.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ void setup()
2727

2828
Serial.println("OTOS connected!");
2929

30+
Serial.println("The OTOS must be stationary during the self test!");
31+
3032
// Perform the self test
3133
sfeTkError_t result = myOtos.selfTest();
3234

0 commit comments

Comments
 (0)