|
| 1 | +#include "SparkFun_Qwiic_OTOS_Arduino_Library.h" |
| 2 | +#include "Wire.h" |
| 3 | + |
| 4 | +// Create an Optical Tracking Odometry Sensor object |
| 5 | +QwiicOTOS myOtos; |
| 6 | + |
| 7 | +void setup() |
| 8 | +{ |
| 9 | + // Start serial |
| 10 | + Serial.begin(115200); |
| 11 | + Serial.println("Qwiic OTOS Example 5 - Velocity and Acceleration"); |
| 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 | + // Reset the tracking algorithm, making the sensor report it's at the origin |
| 25 | + myOtos.resetTracking(); |
| 26 | +} |
| 27 | + |
| 28 | +void loop() |
| 29 | +{ |
| 30 | + // Create structs for position and standard deviations. This example can be |
| 31 | + // extended to include velocity and acceleration, which have been omitted |
| 32 | + // for simplicity, but can be added by uncommenting the code below |
| 33 | + otos_pose2d_t pos; |
| 34 | + // otos_pose2d_t vel; |
| 35 | + // otos_pose2d_t acc; |
| 36 | + otos_pose2d_t posStdDev; |
| 37 | + // otos_pose2d_t velStdDev; |
| 38 | + // otos_pose2d_t accStdDev; |
| 39 | + |
| 40 | + // Read the position like normal (and velocity and acceleration if desired) |
| 41 | + myOtos.getPosition(pos); |
| 42 | + // myOtos.getVelocity(vel); |
| 43 | + // myOtos.getAccerlation(acc); |
| 44 | + |
| 45 | + // Read the standard deviation of the tracking. Note that these values are |
| 46 | + // just the square root of the diagonal elements of the covariance matrices |
| 47 | + // of the Kalman filters used in the firmware of the OTOS, and THEY DO NOT |
| 48 | + // REPRESENT THE ACTUAL TRACKING ERROR! These values are provided primarily |
| 49 | + // for anyone wanting to do sensor fusion with additional sensors, but they |
| 50 | + // can be used to at least get an idea of the quality of the tracking. |
| 51 | + myOtos.getPositionStdDev(posStdDev); |
| 52 | + // myOtos.getVelocityStdDev(velStdDev); |
| 53 | + // myOtos.getAccerlationStdDev(accStdDev); |
| 54 | + |
| 55 | + // These values can instead be read out in chunks: |
| 56 | + // myOtos.getPosVelAcc(pos, vel, acc); |
| 57 | + // myOtos.getPosVelAccStdDev(posStdDev, velStdDev, accStdDev); |
| 58 | + |
| 59 | + // Or all at once: |
| 60 | + // myOtos.getPosVelAccAndStdDev(pos, vel, acc, posStdDev, velStdDev, accStdDev); |
| 61 | + |
| 62 | + // Print measurements |
| 63 | + Serial.println(); |
| 64 | + Serial.println("Sensor pose:"); |
| 65 | + Serial.print("X (Inches): "); |
| 66 | + Serial.print(pos.x); |
| 67 | + Serial.print(" +/- "); |
| 68 | + Serial.println(posStdDev.x); |
| 69 | + Serial.print("Y (Inches): "); |
| 70 | + Serial.print(pos.y); |
| 71 | + Serial.print(" +/- "); |
| 72 | + Serial.println(posStdDev.y); |
| 73 | + Serial.print("Heading (Degrees): "); |
| 74 | + Serial.print(pos.h); |
| 75 | + Serial.print(" +/- "); |
| 76 | + Serial.println(posStdDev.h); |
| 77 | + |
| 78 | + // Serial.println(); |
| 79 | + // Serial.println("Sensor velocity:"); |
| 80 | + // Serial.print("X (Inches/sec): "); |
| 81 | + // Serial.print(vel.x); |
| 82 | + // Serial.print(" +/- "); |
| 83 | + // Serial.println(velStdDev.x); |
| 84 | + // Serial.print("Y (Inches/sec): "); |
| 85 | + // Serial.print(vel.y); |
| 86 | + // Serial.print(" +/- "); |
| 87 | + // Serial.println(velStdDev.y); |
| 88 | + // Serial.print("Heading (Degrees/sec): "); |
| 89 | + // Serial.print(vel.h); |
| 90 | + // Serial.print(" +/- "); |
| 91 | + // Serial.println(velStdDev.h); |
| 92 | + |
| 93 | + // Serial.println(); |
| 94 | + // Serial.println("Sensor acceleration:"); |
| 95 | + // Serial.print("X (Inches/sec^2): "); |
| 96 | + // Serial.print(acc.x); |
| 97 | + // Serial.print(" +/- "); |
| 98 | + // Serial.println(accStdDev.x); |
| 99 | + // Serial.print("Y (Inches/sec^2): "); |
| 100 | + // Serial.print(acc.y); |
| 101 | + // Serial.print(" +/- "); |
| 102 | + // Serial.println(accStdDev.y); |
| 103 | + // Serial.print("Heading (Degrees/sec^2): "); |
| 104 | + // Serial.print(acc.h); |
| 105 | + // Serial.print(" +/- "); |
| 106 | + // Serial.println(accStdDev.h); |
| 107 | + |
| 108 | + // Wait a bit so we don't spam the serial port |
| 109 | + delay(500); |
| 110 | +} |
0 commit comments