### Calibrate IMU Sensor with Arduino Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt The calibrateImu() function removes accelerometer and gyroscope offsets. The sensor must be stationary during calibration. This example demonstrates synchronous calibration, which blocks until complete. Asynchronous calibration is also possible. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } Serial.println("Keep sensor stationary during calibration..."); // Synchronous calibration (blocking, waits until complete) myOtos.calibrateImu(); // Uses default 255 samples Serial.println("Calibration complete!"); // Alternative: Asynchronous calibration (non-blocking) // myOtos.calibrateImu(255, false); // uint8_t samplesRemaining; // do { // myOtos.getImuCalibrationProgress(samplesRemaining); // Serial.print("Samples remaining: "); // Serial.println(samplesRemaining); // delay(10); // } while (samplesRemaining > 0); myOtos.resetTracking(); } void loop() { // Position tracking code here } // Expected output: // Keep sensor stationary during calibration... // Calibration complete! ``` -------------------------------- ### Get Position Data Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Retrieves the current 2D pose from the sensor, including x and y coordinates plus heading angle. The values are returned in the currently configured units. ```APIDOC ## Get Position Data ### Description Retrieves the current 2D pose from the sensor, including x and y coordinates plus heading angle. The values are returned in the currently configured units (default: inches and degrees). ### Method `getPosition(sfe_otos_pose2d_t &pose)` ### Parameters #### Request Body - **pose** (sfe_otos_pose2d_t) - Required - A structure to store the returned pose data (x, y, h). ### Request Example ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { Serial.println("OTOS not connected!"); delay(1000); } myOtos.calibrateImu(); myOtos.resetTracking(); } void loop() { sfe_otos_pose2d_t myPosition; myOtos.getPosition(myPosition); Serial.println("Position:"); Serial.print("X (Inches): "); Serial.println(myPosition.x); Serial.print("Y (Inches): "); Serial.println(myPosition.y); Serial.print("Heading (Degrees): "); Serial.println(myPosition.h); delay(500); } ``` ### Response #### Success Response (200) - **x** (float) - The current X coordinate in the configured linear unit. - **y** (float) - The current Y coordinate in the configured linear unit. - **h** (float) - The current heading angle in the configured angular unit. #### Response Example ```json { "x": 0.00, "y": 0.00, "h": 0.00 } ``` ``` -------------------------------- ### Get Hardware and Firmware Version from OTOS Sensor Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Retrieves the hardware and firmware version numbers from the OTOS sensor. This is useful for checking compatibility and diagnostics. Requires the SparkFun Qwiic OTOS Arduino Library and Wire library. Prints version information to the serial monitor. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { Serial.println("OTOS not connected!"); delay(1000); } Serial.println("OTOS connected!"); sfe_otos_version_t hwVersion; sfe_otos_version_t fwVersion; myOtos.getVersionInfo(hwVersion, fwVersion); Serial.print("OTOS Hardware Version: v"); Serial.print(hwVersion.major); Serial.print("."); Serial.println(hwVersion.minor); Serial.print("OTOS Firmware Version: v"); Serial.print(fwVersion.major); Serial.print("."); Serial.println(fwVersion.minor); } void loop() { // Nothing to do } // Expected output: // OTOS connected! // OTOS Hardware Version: v1.0 // OTOS Firmware Version: v1.0 ``` -------------------------------- ### Reset Tracking to Origin Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Resets the tracking algorithm to return the position to the origin (0,0). This function can also recover from rare tracking errors. It can be used after calibration or to set a custom starting position. Requires SparkFun_Qwiic_OTOS_Arduino_Library.h and Wire.h. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); // Reset to origin after calibration myOtos.resetTracking(); Serial.println("Tracking reset to origin"); // Optionally set a custom starting position after reset sfe_otos_pose2d_t startPos = {12.0, 24.0, 90.0}; myOtos.setPosition(startPos); Serial.println("Starting position set to (12, 24) at 90 degrees"); } void loop() { sfe_otos_pose2d_t pos; myOtos.getPosition(pos); Serial.print("X: "); Serial.print(pos.x); Serial.print(" Y: "); Serial.print(pos.y); Serial.print(" H: "); Serial.println(pos.h); delay(500); } // Expected output (initial): // Tracking reset to origin // Starting position set to (12, 24) at 90 degrees // X: 12.00 Y: 24.00 H: 90.00 ``` -------------------------------- ### Set Sensor Offset for Robot Center Position in Arduino Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt The setOffset() function allows specifying the sensor's position relative to the robot's center. When set, the OTOS library returns the robot's center position instead of the sensor's raw position. These offset values are lost after a power cycle. This example demonstrates setting and verifying an offset. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); // Configure offset for off-center mounted sensor // Sensor is 5 inches left (negative X), 10 inches forward (positive Y), // and rotated 90 degrees clockwise (negative rotation) sfe_otos_pose2d_t offset = {-5, 10, -90}; myOtos.setOffset(offset); // Verify offset was set sfe_otos_pose2d_t currentOffset; myOtos.getOffset(currentOffset); Serial.print("Offset X: "); Serial.println(currentOffset.x); Serial.print("Offset Y: "); Serial.println(currentOffset.y); Serial.print("Offset H: "); Serial.println(currentOffset.h); myOtos.resetTracking(); // Optionally set a starting position sfe_otos_pose2d_t startPosition = {10, 20, 45}; myOtos.setPosition(startPosition); } void loop() { sfe_otos_pose2d_t myPosition; myOtos.getPosition(myPosition); // Position now reflects robot center, not sensor location Serial.print("Robot X: "); Serial.println(myPosition.x); Serial.print("Robot Y: "); Serial.println(myPosition.y); Serial.print("Robot Heading: "); Serial.println(myPosition.h); delay(500); } // Expected output: // Offset X: -5.00 // Offset Y: 10.00 // Offset H: -90.00 ``` -------------------------------- ### Get Velocity and Acceleration from OTOS Sensor Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Demonstrates how to retrieve velocity and acceleration data from the OTOS sensor using individual function calls or a more efficient burst read. Requires the SparkFun Qwiic OTOS Arduino Library and Wire library. Outputs position, velocity, and acceleration values to the serial monitor. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); myOtos.resetTracking(); } void loop() { sfe_otos_pose2d_t pos, vel, acc; // Individual reads myOtos.getPosition(pos); myOtos.getVelocity(vel); myOtos.getAcceleration(acc); // Alternative: burst read all at once (more efficient) // myOtos.getPosVelAcc(pos, vel, acc); Serial.println("Position:"); Serial.print("X: "); Serial.print(pos.x); Serial.print(" Y: "); Serial.print(pos.y); Serial.print(" H: "); Serial.println(pos.h); Serial.println("Velocity:"); Serial.print("X: "); Serial.print(vel.x); Serial.print(" in/s "); Serial.print("Y: "); Serial.print(vel.y); Serial.print(" in/s "); Serial.print("H: "); Serial.print(vel.h); Serial.println(" deg/s"); Serial.println("Acceleration:"); Serial.print("X: "); Serial.print(acc.x); Serial.print(" in/s^2 "); Serial.print("Y: "); Serial.print(acc.y); Serial.print(" in/s^2 "); Serial.print("H: "); Serial.print(acc.h); Serial.println(" deg/s^2"); delay(500); } // Expected output (when stationary): // Position: // X: 0.00 Y: 0.00 H: 0.00 // Velocity: // X: 0.00 in/s Y: 0.00 in/s H: 0.00 deg/s // Acceleration: // X: 0.00 in/s^2 Y: 0.00 in/s^2 H: 0.00 deg/s^2 ``` -------------------------------- ### Get OTOS Sensor Position Data (Arduino) Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Retrieves the current 2D pose from the sensor, including x and y coordinates plus heading angle. The values are returned in the currently configured units (default: inches and degrees). Requires sensor initialization, IMU calibration, and tracking reset before use. Outputs are printed to the Serial monitor. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { Serial.println("OTOS not connected!"); delay(1000); } myOtos.calibrateImu(); myOtos.resetTracking(); } void loop() { sfe_otos_pose2d_t myPosition; myOtos.getPosition(myPosition); Serial.println("Position:"); Serial.print("X (Inches): "); Serial.println(myPosition.x); Serial.print("Y (Inches): "); Serial.println(myPosition.y); Serial.print("Heading (Degrees): "); Serial.println(myPosition.h); delay(500); } // Expected output: // Position: // X (Inches): 0.00 // Y (Inches): 0.00 // Heading (Degrees): 0.00 ``` -------------------------------- ### Get Sensor Status Flags Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Retrieves warning and error flags from the sensor, including tilt angle warnings, optical tracking warnings, and fatal sensor errors. This function is crucial for monitoring sensor health and identifying potential issues that may affect tracking accuracy. Requires SparkFun_Qwiic_OTOS_Arduino_Library.h and Wire.h. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); myOtos.resetTracking(); } void loop() { sfe_otos_status_t status; myOtos.getStatus(status); if (status.warnTiltAngle) { Serial.println("Warning: Tilt angle exceeded - accelerometer data ignored"); } if (status.warnOpticalTracking) { Serial.println("Warning: Optical tracking unreliable - using IMU only"); } if (status.errorPaa) { Serial.println("Error: Optical sensor fatal error!"); } if (status.errorLsm) { Serial.println("Error: IMU fatal error!"); } sfe_otos_pose2d_t pos; myOtos.getPosition(pos); Serial.print("X: "); Serial.print(pos.x); Serial.print(" Y: "); Serial.print(pos.y); Serial.print(" H: "); Serial.println(pos.h); delay(500); } // Expected output (normal operation - no warnings printed): // X: 0.00 Y: 0.00 H: 0.00 ``` -------------------------------- ### Set Linear and Angular Scalars for Sensor Compensation in Arduino Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt The setLinearScalar() and setAngularScalar() functions compensate for scaling issues in sensor measurements. Valid values range from 0.872 to 1.127. It's recommended to calibrate the angular scalar first. This example shows setting scalars to default and then reading them back. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); // Set scalars to default values first myOtos.setLinearScalar(1.0); myOtos.setAngularScalar(1.0); // Example calibration calculation: // After 10 rotations (3600 degrees), sensor reports -15 degrees // Angular scalar = 3600 / 3585 = 1.004 // myOtos.setAngularScalar(1.004); // After moving 100 inches, sensor reports 103 inches // Linear scalar = 100 / 103 = 0.971 // myOtos.setLinearScalar(0.971); // Read back current scalars float linearScalar, angularScalar; myOtos.getLinearScalar(linearScalar); myOtos.getAngularScalar(angularScalar); Serial.print("Linear scalar: "); Serial.println(linearScalar, 3); Serial.print("Angular scalar: "); Serial.println(angularScalar, 3); myOtos.resetTracking(); } void loop() { // Position tracking code here } // Expected output: // Linear scalar: 1.000 // Angular scalar: 1.000 ``` -------------------------------- ### Get Standard Deviation of Motion Data from OTOS Sensor Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Retrieves statistical uncertainty values for position, velocity, and acceleration from the OTOS sensor's Kalman filter. This is useful for sensor fusion. Requires the SparkFun Qwiic OTOS Arduino Library and Wire library. Outputs position data with its standard deviation. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); myOtos.resetTracking(); } void loop() { sfe_otos_pose2d_t pos, posStdDev; sfe_otos_pose2d_t vel, velStdDev; sfe_otos_pose2d_t acc, accStdDev; // Individual reads myOtos.getPosition(pos); myOtos.getPositionStdDev(posStdDev); // Alternative: burst read all measurements and standard deviations // myOtos.getPosVelAccAndStdDev(pos, vel, acc, posStdDev, velStdDev, accStdDev); Serial.println("Position with Standard Deviation:"); Serial.print("X: "); Serial.print(pos.x); Serial.print(" +/- "); Serial.println(posStdDev.x); Serial.print("Y: "); Serial.print(pos.y); Serial.print(" +/- "); Serial.println(posStdDev.y); Serial.print("H: "); Serial.print(pos.h); Serial.print(" +/- "); Serial.println(posStdDev.h); delay(500); } // Expected output: // Position with Standard Deviation: // X: 0.00 +/- 0.01 // Y: 0.00 +/- 0.01 // H: 0.00 +/- 0.05 ``` -------------------------------- ### Initialize OTOS Sensor Connection (Arduino) Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Initializes I2C communication with the OTOS sensor and verifies the connection by checking the product ID register. It returns true if the sensor is successfully connected and ready for use. Requires the 'SparkFun_Qwiic_OTOS_Arduino_Library.h' and 'Wire.h' headers. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); // Attempt to begin the sensor with retry logic while (myOtos.begin() == false) { Serial.println("OTOS not connected, check your wiring and I2C address!"); delay(1000); } Serial.println("OTOS connected!"); } // Expected output: "OTOS connected!" when sensor is properly wired ``` -------------------------------- ### Initialize Sensor Connection Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Initializes I2C communication with the OTOS sensor and verifies the connection by checking the product ID register. Returns `true` if the sensor is successfully connected. ```APIDOC ## Initialize Sensor Connection ### Description Initializes I2C communication with the OTOS sensor and verifies the connection by checking the product ID register. Returns `true` if the sensor is successfully connected and ready for use. ### Method `begin()` ### Parameters None ### Request Example ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); // Attempt to begin the sensor with retry logic while (myOtos.begin() == false) { Serial.println("OTOS not connected, check your wiring and I2C address!"); delay(1000); } Serial.println("OTOS connected!"); } ``` ### Response #### Success Response `true` (boolean) - Indicates successful sensor initialization. #### Response Example `true` ``` -------------------------------- ### Perform Self Test Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Triggers internal diagnostics to verify sensor functionality. The sensor must be stationary during the test. Returns ksfTkErrOk on success. Requires SparkFun_Qwiic_OTOS_Arduino_Library.h and Wire.h. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { Serial.println("OTOS not connected!"); delay(1000); } Serial.println("OTOS connected!"); Serial.println("Keep sensor stationary during self test..."); sfTkError_t result = myOtos.selfTest(); if (result == ksfTkErrOk) { Serial.println("Self test passed!"); } else { Serial.println("Self test failed! Check sensor hardware."); } } void loop() { // Nothing to do } // Expected output: // OTOS connected! // Keep sensor stationary during self test... // Self test passed! ``` -------------------------------- ### Configure Measurement Units Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Configures the measurement units for all pose-related functions. Linear units can be meters or inches; angular units can be radians or degrees. ```APIDOC ## Configure Measurement Units ### Description Configures the measurement units for all pose-related functions. Linear units can be meters or inches; angular units can be radians or degrees. These settings are stored in the library, not the sensor, so they must be set at program startup. ### Method `setLinearUnit(uint8_t unit)` `setAngularUnit(uint8_t unit)` ### Parameters #### Path Parameters - **unit** (uint8_t) - Required - Specifies the desired unit. Use `kSfeOtosLinearUnitMeters`, `kSfeOtosLinearUnitInches`, `kSfeOtosAngularUnitRadians`, or `kSfeOtosAngularUnitDegrees`. ### Request Example ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); // Set units to metric (meters and radians) myOtos.setLinearUnit(kSfeOtosLinearUnitMeters); myOtos.setAngularUnit(kSfeOtosAngularUnitRadians); // Alternative: imperial units (default) // myOtos.setLinearUnit(kSfeOtosLinearUnitInches); // myOtos.setAngularUnit(kSfeOtosAngularUnitDegrees); myOtos.resetTracking(); } void loop() { sfe_otos_pose2d_t myPosition; myOtos.getPosition(myPosition); Serial.print("X (Meters): "); Serial.println(myPosition.x, 4); Serial.print("Y (Meters): "); Serial.println(myPosition.y, 4); Serial.print("Heading (Radians): "); Serial.println(myPosition.h, 4); delay(500); } ``` ### Response #### Success Response (200) No direct response, but subsequent calls to `getPosition()` will return values in the configured units. #### Response Example (No direct response body for configuration functions) ``` -------------------------------- ### Configure OTOS Measurement Units (Arduino) Source: https://context7.com/sparkfun/sparkfun_qwiic_otos_arduino_library/llms.txt Configures the measurement units for all pose-related functions using `setLinearUnit()` and `setAngularUnit()`. Linear units can be meters or inches; angular units can be radians or degrees. These settings are stored in the library and must be set at program startup. Requires sensor initialization and IMU calibration. ```cpp #include "SparkFun_Qwiic_OTOS_Arduino_Library.h" #include "Wire.h" QwiicOTOS myOtos; void setup() { Serial.begin(115200); Wire.begin(); while (myOtos.begin() == false) { delay(1000); } myOtos.calibrateImu(); // Set units to metric (meters and radians) myOtos.setLinearUnit(kSfeOtosLinearUnitMeters); myOtos.setAngularUnit(kSfeOtosAngularUnitRadians); // Alternative: imperial units (default) // myOtos.setLinearUnit(kSfeOtosLinearUnitInches); // myOtos.setAngularUnit(kSfeOtosAngularUnitDegrees); myOtos.resetTracking(); } void loop() { sfe_otos_pose2d_t myPosition; myOtos.getPosition(myPosition); Serial.print("X (Meters): "); Serial.println(myPosition.x, 4); Serial.print("Y (Meters): "); Serial.println(myPosition.y, 4); Serial.print("Heading (Radians): "); Serial.println(myPosition.h, 4); delay(500); } // Expected output (metric): // X (Meters): 0.0000 // Y (Meters): 0.0000 // Heading (Radians): 0.0000 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.