From 0b57d5eea31457d9bef2bf4df76a8c1dcc0b92da Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 15:34:02 -0500 Subject: [PATCH 01/18] Add Arduino style API's for IMU, rename CurieImu to CurieIMU --- libraries/CurieImu/src/CurieImu.cpp | 648 +++++++++++++++++++++++++++- libraries/CurieImu/src/CurieImu.h | 107 ++++- 2 files changed, 749 insertions(+), 6 deletions(-) diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieImu/src/CurieImu.cpp index 82eae2e2..c036676e 100644 --- a/libraries/CurieImu/src/CurieImu.cpp +++ b/libraries/CurieImu/src/CurieImu.cpp @@ -21,6 +21,8 @@ #include "internal/ss_spi.h" #include "interrupt.h" +#define CURIE_IMU_CHIP_ID 0xD1 + #define BMI160_GPIN_AON_PIN 4 /******************************************************************************/ @@ -30,7 +32,7 @@ * on the Curie module, before calling BMI160::initialize() to activate the * BMI160 accelerometer and gyroscpoe with default settings. */ -void CurieImuClass::initialize() +bool CurieImuClass::begin() { /* Configure pin-mux settings on the Intel Curie module to * enable SPI mode usage */ @@ -47,6 +49,644 @@ void CurieImuClass::initialize() /* The SPI interface is ready - now invoke the base class initialization */ BMI160Class::initialize(); + + /** Verify the SPI connection. + * MakgetGyroRatee sure the device is connected and responds as expected. + * @return True if connection is valid, false otherwise + */ + return (CURIE_IMU_CHIP_ID == getDeviceID()); +} + +int CurieImuClass::getGyroRange() +{ + uint8_t fullScaleGyroRange = getFullScaleGyroRange(); + + switch (fullScaleGyroRange) { + case BMI160_GYRO_RANGE_2000: + return 2000; + + case BMI160_GYRO_RANGE_1000: + return 1000; + + case BMI160_GYRO_RANGE_500: + return 500; + + case BMI160_GYRO_RANGE_250: + return 250; + + case BMI160_GYRO_RANGE_125: + return 125; + + default: + return -1; + } +} + +void CurieImuClass::setGyroRange(int range) +{ + uint8_t fullScaleGyroRange; + + if (range >= 2000) { + fullScaleGyroRange = BMI160_GYRO_RANGE_2000; + } else if (range >= 1000) { + fullScaleGyroRange = BMI160_GYRO_RANGE_1000; + } else if (range >= 500) { + fullScaleGyroRange = BMI160_GYRO_RANGE_500; + } else if (range >= 250) { + fullScaleGyroRange = BMI160_GYRO_RANGE_250; + } else { + fullScaleGyroRange = BMI160_GYRO_RANGE_125; + } + + setFullScaleGyroRange(fullScaleGyroRange); +} + +int CurieImuClass::getAccelerometerRange() +{ + uint8_t fullScaleAccelRange = getFullScaleAccelRange(); + + switch (fullScaleAccelRange) { + case BMI160_ACCEL_RANGE_2G: + return 2; + + case BMI160_ACCEL_RANGE_4G: + return 4; + + case BMI160_ACCEL_RANGE_8G: + return 8; + + case BMI160_ACCEL_RANGE_16G: + return 16; + + default: + return -1; + } +} + +void CurieImuClass::setAccelerometerRange(int range) +{ + uint8_t fullScaleAccelRange; + + if (range >= 16) { + fullScaleAccelRange = BMI160_ACCEL_RANGE_16G; + } else if (range >= 8) { + fullScaleAccelRange = BMI160_ACCEL_RANGE_8G; + } else if (range >= 4) { + fullScaleAccelRange = BMI160_ACCEL_RANGE_4G; + } else { + fullScaleAccelRange = BMI160_ACCEL_RANGE_2G; + } + + setFullScaleAccelRange(fullScaleAccelRange); +} + +void CurieImuClass::autoCalibrateGyroOffset() +{ + BMI160Class::autoCalibrateGyroOffset(); +} + +void CurieImuClass::autoCalibrateAccelerometerOffset(int axis, int target) +{ + switch (axis) { + case X_AXIS: + autoCalibrateXAccelOffset(target); + break; + + case Y_AXIS: + autoCalibrateYAccelOffset(target); + break; + + case Z_AXIS: + autoCalibrateZAccelOffset(target); + break; + + default: + break; + } +} + +void CurieImuClass::enableGyroOffset(bool state) +{ + setGyroOffsetEnabled(state); +} + +void CurieImuClass::enableAccelerometerOffset(bool state) +{ + setAccelOffsetEnabled(state); +} + +bool CurieImuClass::gyroOffsetEnabled() +{ + return getGyroOffsetEnabled(); +} + +bool CurieImuClass::accelerometerOffsetEnabled() +{ + return getAccelOffsetEnabled(); +} + +int CurieImuClass::getGyroOffset(int axis) +{ + switch (axis) { + case X_AXIS: + return getXGyroOffset(); + + case Y_AXIS: + return getYGyroOffset(); + + case Z_AXIS: + return getZGyroOffset(); + + default: + return -1; + } +} + +int CurieImuClass::getAccelerometerOffset(int axis) +{ + switch (axis) { + case X_AXIS: + return getXAccelOffset(); + + case Y_AXIS: + return getYAccelOffset(); + + case Z_AXIS: + return getZAccelOffset(); + + default: + return -1; + } +} + +void CurieImuClass::setGyroOffset(int axis, int offset) +{ + switch (axis) { + case X_AXIS: + setXGyroOffset(axis); + break; + + case Y_AXIS: + setYGyroOffset(axis); + break; + + case Z_AXIS: + setZGyroOffset(axis); + break; + + default: + break; + } +} + +void CurieImuClass::setAccelerometerOffset(int axis, int offset) +{ + switch (axis) { + case X_AXIS: + setXAccelOffset(axis); + break; + + case Y_AXIS: + setYAccelOffset(axis); + break; + + case Z_AXIS: + setZAccelOffset(axis); + break; + + default: + break; + } +} + +int CurieImuClass::getDetectionThreshold(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getFreefallDetectionThreshold(); + + case CURIE_IMU_SHOCK: + return getShockDetectionThreshold(); + + case CURIE_IMU_MOTION: + return getMotionDetectionThreshold(); + + case CURIE_IMU_ZERO_MOTION: + return getZeroMotionDetectionThreshold(); + + case CURIE_IMU_TAP: + return getTapDetectionThreshold(); + + case CURIE_IMU_STEP: + case CURIE_IMU_TAP_SHOCK: + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_DOUBLE_TAP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + return -1; + } +} + +void CurieImuClass::setDetectionThreshold(int feature, int threshold) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + setFreefallDetectionThreshold(threshold); + break; + + case CURIE_IMU_SHOCK: + setShockDetectionThreshold(threshold); + break; + + case CURIE_IMU_MOTION: + setMotionDetectionThreshold(threshold); + break; + + case CURIE_IMU_ZERO_MOTION: + setZeroMotionDetectionThreshold(threshold); + break; + + case CURIE_IMU_TAP: + setTapDetectionThreshold(threshold); + break; + + case CURIE_IMU_STEP: + case CURIE_IMU_TAP_SHOCK: + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_DOUBLE_TAP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + break; + } +} + +int CurieImuClass::getDetectionDuration(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getFreefallDetectionDuration(); + + case CURIE_IMU_SHOCK: + return getShockDetectionDuration(); + + case CURIE_IMU_MOTION: + return getMotionDetectionDuration(); + + case CURIE_IMU_TAP_SHOCK: + return getTapShockDuration(); + + case CURIE_IMU_ZERO_MOTION: + return getZeroMotionDetectionThreshold(); + + case CURIE_IMU_TAP_QUIET: + return getTapQuietDuration(); + + case CURIE_IMU_DOUBLE_TAP: + return getDoubleTapDetectionDuration(); + + case CURIE_IMU_TAP: + case CURIE_IMU_STEP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + return -1; + } +} + +void CurieImuClass::setDetectionDuration(int feature, int value) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + setFreefallDetectionDuration(value); + break; + + case CURIE_IMU_SHOCK: + setShockDetectionDuration(value); + break; + + case CURIE_IMU_MOTION: + setMotionDetectionDuration(value); + break; + + case CURIE_IMU_TAP_SHOCK: + setTapShockDuration(value); + break; + + case CURIE_IMU_ZERO_MOTION: + setZeroMotionDetectionThreshold(value); + break; + + case CURIE_IMU_TAP_QUIET: + setTapQuietDuration(value); + break; + + case CURIE_IMU_DOUBLE_TAP: + setDoubleTapDetectionDuration(value); + break; + + case CURIE_IMU_TAP: + case CURIE_IMU_STEP: + case CURIE_IMU_FIFO_FULL: + case CURIE_IMU_DATA_READY: + default: + break; + } +} + +void CurieImuClass::enableInterrupt(int feature, bool enabled) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + setIntFreefallEnabled(enabled); + break; + + case CURIE_IMU_SHOCK: + setIntShockEnabled(enabled); + break; + + case CURIE_IMU_STEP: + setIntStepEnabled(enabled); + break; + + case CURIE_IMU_MOTION: + setIntMotionEnabled(enabled); + break; + + case CURIE_IMU_ZERO_MOTION: + setIntZeroMotionEnabled(enabled); + break; + + case CURIE_IMU_TAP: + setIntTapEnabled(enabled); + break; + + case CURIE_IMU_DOUBLE_TAP: + setIntDoubleTapEnabled(enabled); + break; + + case CURIE_IMU_FIFO_FULL: + setIntFIFOBufferFullEnabled(enabled); + break; + + case CURIE_IMU_DATA_READY: + setIntDataReadyEnabled(enabled); + break; + + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_TAP_SHOCK: + default: + break; + } +} + +bool CurieImuClass::interruptEnabled(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getIntFreefallEnabled(); + + case CURIE_IMU_SHOCK: + return getIntShockEnabled(); + + case CURIE_IMU_STEP: + return getIntStepEnabled(); + + case CURIE_IMU_MOTION: + return getIntMotionEnabled(); + + case CURIE_IMU_ZERO_MOTION: + return getIntZeroMotionEnabled(); + + case CURIE_IMU_TAP: + return getIntTapEnabled(); + + case CURIE_IMU_DOUBLE_TAP: + return getIntDoubleTapEnabled(); + + case CURIE_IMU_FIFO_FULL: + return getIntFIFOBufferFullEnabled(); + + case CURIE_IMU_DATA_READY: + return getIntDataReadyEnabled(); + + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_TAP_SHOCK: + default: + return -1; + } +} + +int CurieImuClass::getInterruptStatus(int feature) +{ + switch (feature) { + case CURIE_IMU_FREEFALL: + return getIntFreefallStatus(); + + case CURIE_IMU_SHOCK: + return getIntShockStatus(); + + case CURIE_IMU_STEP: + return getIntStepStatus(); + + case CURIE_IMU_MOTION: + return getIntMotionStatus(); + + case CURIE_IMU_ZERO_MOTION: + return getIntZeroMotionStatus(); + + case CURIE_IMU_TAP: + return getIntTapStatus(); + + case CURIE_IMU_DOUBLE_TAP: + return getIntDoubleTapStatus(); + + case CURIE_IMU_FIFO_FULL: + return getIntFIFOBufferFullStatus(); + + case CURIE_IMU_DATA_READY: + return getIntDataReadyStatus(); + + case CURIE_IMU_TAP_QUIET: + case CURIE_IMU_TAP_SHOCK: + default: + return -1; + } +} + +CurieIMUStepMode CurieImuClass::getStepDetectionMode() +{ + return (CurieIMUStepMode)BMI160Class::getStepDetectionMode(); +} + +void CurieImuClass::setStepDetectionMode(int mode) +{ + BMI160Class::setStepDetectionMode((BMI160StepMode)mode); +} + +void CurieImuClass::readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz) +{ + getMotion6(&ax, &ay, &az, &gx, &gy, &gz); +} + +void CurieImuClass::readAcceleration(short& x, short& y, short& z) +{ + getAcceleration(&x, &y, &z); +} + +void CurieImuClass::readRotation(short& x, short& y, short& z) +{ + getRotation(&x, &y, &z); +} + +short CurieImuClass::readAccelerometer(int axis) +{ + switch (axis) { + case X_AXIS: + return getAccelerationX(); + + case Y_AXIS: + return getAccelerationY(); + + case Z_AXIS: + return getAccelerationZ(); + + default: + return -1; + } +} + +short CurieImuClass::readGyro(int axis) +{ + switch (axis) { + case X_AXIS: + return getRotationX(); + + case Y_AXIS: + return getRotationY(); + + case Z_AXIS: + return getRotationZ(); + + default: + return -1; + } +} + +short CurieImuClass::readTemperature() +{ + return getTemperature(); +} + +bool CurieImuClass::shockDetected(int axis, int direction) +{ + if (direction == POSITIVE) { + switch (axis) { + case X_AXIS: + return getXPosShockDetected(); + + case Y_AXIS: + return getYPosShockDetected(); + + case Z_AXIS: + return getZPosShockDetected(); + + default: + return -1; + } + } else if (direction == NEGATIVE) { + switch (axis) { + case X_AXIS: + return getXNegShockDetected(); + + case Y_AXIS: + return getYNegShockDetected(); + + case Z_AXIS: + return getZNegShockDetected(); + + default: + return -1; + } + } else { + return -1; + } +} + +bool CurieImuClass::motionDetected(int axis, int direction) +{ + if (direction == POSITIVE) { + switch (axis) { + case X_AXIS: + return getXPosMotionDetected(); + + case Y_AXIS: + return getYPosMotionDetected(); + + case Z_AXIS: + return getZPosMotionDetected(); + + default: + return -1; + } + } else if (direction == NEGATIVE) { + switch (axis) { + case X_AXIS: + return getXNegMotionDetected(); + + case Y_AXIS: + return getYNegMotionDetected(); + + case Z_AXIS: + return getZNegMotionDetected(); + + default: + return -1; + } + } else { + return -1; + } +} + +bool CurieImuClass::tapDetected(int axis, int direction) +{ + if (direction == POSITIVE) { + switch (axis) { + case X_AXIS: + return getXPosTapDetected(); + + case Y_AXIS: + return getYPosTapDetected(); + + case Z_AXIS: + return getZPosTapDetected(); + + default: + return -1; + } + } else if (direction == NEGATIVE) { + switch (axis) { + case X_AXIS: + return getXNegTapDetected(); + + case Y_AXIS: + return getYNegTapDetected(); + + case Z_AXIS: + return getZNegTapDetected(); + + default: + return -1; + } + } else { + return -1; + } +} + +bool CurieImuClass::stepsDetected() +{ + return getIntStepStatus(); } /** Provides a serial buffer transfer implementation for the BMI160 base class @@ -79,8 +719,8 @@ int CurieImuClass::serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigne void bmi160_pin1_isr(void) { soc_gpio_mask_interrupt(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); - if (CurieImu._user_callback) - CurieImu._user_callback(); + if (CurieIMU._user_callback) + CurieIMU._user_callback(); soc_gpio_unmask_interrupt(SOC_GPIO_AON, BMI160_GPIN_AON_PIN); } @@ -117,4 +757,4 @@ void CurieImuClass::detachInterrupt(void) } /* Pre-instantiated Object for this class */ -CurieImuClass CurieImu; +CurieImuClass CurieIMU; diff --git a/libraries/CurieImu/src/CurieImu.h b/libraries/CurieImu/src/CurieImu.h index a6db053a..034db277 100644 --- a/libraries/CurieImu/src/CurieImu.h +++ b/libraries/CurieImu/src/CurieImu.h @@ -24,6 +24,62 @@ #include "BMI160.h" +/** + * axis options + *@see autoCalibrateAccelerometerOffset() + *@see get/setGyroOffset() + *@see get/setAccelerometerOffset() + *@see readAcceleration() + *@see readRotation() + *@see shockDetected() + *@see tapDetected() + *@see motionDetected() + */ +typedef enum{ + X_AXIS = 0, + Y_AXIS, + Z_AXIS, +} CurieIMUAxis; + +/** + *direction options + *@see shockDetected() + *@see tapDetected() + *@see motionDetected() + */ +typedef enum{ + POSITIVE, + NEGATIVE, +} CurieIMUDirection; + + /** + * Features for getThreshold(), getDuration() functions, + */ +typedef enum { + CURIE_IMU_FREEFALL = 0, + CURIE_IMU_SHOCK, + CURIE_IMU_MOTION, + CURIE_IMU_ZERO_MOTION, + CURIE_IMU_STEP, + CURIE_IMU_TAP, + CURIE_IMU_TAP_SHOCK, + CURIE_IMU_TAP_QUIET, + CURIE_IMU_DOUBLE_TAP, + CURIE_IMU_FIFO_FULL, + CURIE_IMU_DATA_READY, +} CurieIMUFeature; + +/** + * Step Detection Mode options + * @see setStepDetectionMode() + */ +typedef enum { + CURIE_IMU_STEP_MODE_NORMAL = BMI160_STEP_MODE_NORMAL, + CURIE_IMU_STEP_MODE_SENSITIVE = BMI160_STEP_MODE_SENSITIVE, + CURIE_IMU_STEP_MODE_ROBUST = BMI160_STEP_MODE_ROBUST, + CURIE_IMU_STEP_MODE_UNKNOWN = BMI160_STEP_MODE_UNKNOWN, +} CurieIMUStepMode; + /* Note that this CurieImuClass class inherits methods from the BMI160Class which * is defined in BMI160.h. BMI160Class provides methods for configuring and * accessing features of the BMI160 IMU device. This CurieImuClass extends that @@ -38,7 +94,54 @@ class CurieImuClass : public BMI160Class { friend void bmi160_pin1_isr(void); public: - void initialize(void); + bool begin(void); + + int getGyroRange(); + void setGyroRange(int range); + int getAccelerometerRange(); + void setAccelerometerRange(int range); + + void autoCalibrateGyroOffset(); + void autoCalibrateAccelerometerOffset(int axis, int target); + + void enableGyroOffset(bool state); + void enableAccelerometerOffset(bool state); + bool gyroOffsetEnabled(); + bool accelerometerOffsetEnabled(); + + int getGyroOffset(int axis); + int getAccelerometerOffset(int axis); + + void setGyroOffset(int axis, int offset); + void setAccelerometerOffset(int axis, int offset); + + int getDetectionThreshold(int feature); + void setDetectionThreshold(int feature, int threshold); + + int getDetectionDuration(int feature); + void setDetectionDuration(int feature, int value); //value (bool) duration or samples + + void enableInterrupt(int feature, bool enabled); + bool interruptEnabled(int feature); + + int getInterruptStatus(int feature); + + CurieIMUStepMode getStepDetectionMode(); + void setStepDetectionMode(int mode); + + void readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz); + void readAcceleration(short& x, short& y, short& z); + void readRotation(short& x, short& y, short& z); + + short readAccelerometer(int axis); + short readGyro(int axis); + short readTemperature(); + + bool shockDetected(int axis, int direction); + bool motionDetected(int axis, int direction); + bool tapDetected(int axis, int direction); + bool stepsDetected(); + void attachInterrupt(void (*callback)(void)); void detachInterrupt(void); @@ -48,6 +151,6 @@ class CurieImuClass : public BMI160Class { void (*_user_callback)(void); }; -extern CurieImuClass CurieImu; +extern CurieImuClass CurieIMU; #endif /* _CURIEIMU_H_ */ From e5a1c21005d0f6049008e8856481c4642b5227ef Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 15:34:39 -0500 Subject: [PATCH 02/18] Example updates from Helena --- .../RawImuDataSerial/RawImuDataSerial.ino | 147 ++++++++++-------- .../examples/ShockDetect/ShockDetect.ino | 28 ++-- .../CurieImu/examples/StepCount/StepCount.ino | 16 +- .../CurieImu/examples/TapDetect/TapDetect.ino | 28 ++-- 4 files changed, 117 insertions(+), 102 deletions(-) diff --git a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino index 48cc278b..9f22d22b 100644 --- a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino +++ b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino @@ -1,6 +1,6 @@ /* =============================================== - Example sketch for CurieImu library for Intel(R) Curie(TM) devices. + Example sketch for CurieIMU library for Intel(R) Curie(TM) devices. Copyright (c) 2015 Intel Corporation. All rights reserved. Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 @@ -31,98 +31,113 @@ */ #include "CurieImu.h" - -int16_t ax, ay, az; // accelerometer values -int16_t gx, gy, gz; // gyrometer values +short int ax, ay, az; // accelerometer values +short int gx, gy, gz; // gyrometer values const int ledPin = 13; // activity LED pin boolean blinkState = false; // state of the LED +int calibrateOffsets = 1; // int to determine whether calibration takes place or not + void setup() { Serial.begin(9600); // initialize Serial communication while (!Serial); // wait for the serial port to open // initialize device Serial.println("Initializing IMU device..."); - CurieImu.initialize(); + CurieIMU.begin(); // verify connection Serial.println("Testing device connections..."); - if (CurieImu.testConnection()) { - Serial.println("CurieImu connection successful"); + if (CurieIMU.begin()) { + Serial.println("CurieIMU connection successful"); } else { - Serial.println("CurieImu connection failed"); + Serial.println("CurieIMU connection failed"); } - + // use the code below to calibrate accel/gyro offset values - Serial.println("Internal sensor offsets BEFORE calibration..."); - Serial.print(CurieImu.getXAccelOffset()); - Serial.print("\t"); // -76 - Serial.print(CurieImu.getYAccelOffset()); - Serial.print("\t"); // -235 - Serial.print(CurieImu.getZAccelOffset()); - Serial.print("\t"); // 168 - Serial.print(CurieImu.getXGyroOffset()); - Serial.print("\t"); // 0 - Serial.print(CurieImu.getYGyroOffset()); - Serial.print("\t"); // 0 - Serial.println(CurieImu.getZGyroOffset()); - - // To manually configure offset compensation values, - // use the following methods instead of the autoCalibrate...() methods below - // CurieImu.setXGyroOffset(220); - // CurieImu.setYGyroOffset(76); - // CurieImu.setZGyroOffset(-85); - // CurieImu.setXAccelOffset(-76); - // CurieImu.setYAccelOffset(-235); - // CurieImu.setZAccelOffset(168); - - Serial.println("About to calibrate. Make sure your board is stable and upright"); - delay(5000); + if (calibrateOffsets == 1) { + Serial.println("Internal sensor offsets BEFORE calibration..."); + Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS)); + Serial.print("\t"); // -76 + Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS)); + Serial.print("\t"); // -235 + Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS)); + Serial.print("\t"); // 168 + Serial.print(CurieIMU.getGyroOffset(X_AXIS)); + Serial.print("\t"); // 0 + Serial.print(CurieIMU.getGyroOffset(Y_AXIS)); + Serial.print("\t"); // 0 + Serial.println(CurieIMU.getGyroOffset(Z_AXIS)); + + // To manually configure offset compensation values, + // use the following methods instead of the autoCalibrate...() methods below + //CurieIMU.setAccelerometerOffset(X_AXIS,128); + //CurieIMU.setAccelerometerOffset(Y_AXIS,-4); + //CurieIMU.setAccelerometerOffset(Z_AXIS,127); + //CurieIMU.setGyroOffset(X_AXIS,129); + //CurieIMU.setGyroOffset(Y_AXIS,-1); + //CurieIMU.setGyroOffset(Z_AXIS, 254); + + Serial.println("About to calibrate. Make sure your board is stable and upright"); + delay(5000); + + // The board must be resting in a horizontal position for + // the following calibration procedure to work correctly! + Serial.print("Starting Gyroscope calibration..."); + CurieIMU.autoCalibrateGyroOffset(); + Serial.println(" Done"); + + Serial.print("Starting Acceleration calibration..."); + CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0); + CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0); + CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1); + Serial.println(" Done"); + + Serial.println("Internal sensor offsets AFTER calibration..."); + Serial.print(CurieIMU.getAccelerometerOffset(X_AXIS)); + Serial.print("\t"); // -76 + Serial.print(CurieIMU.getAccelerometerOffset(Y_AXIS)); + Serial.print("\t"); // -2359 + Serial.print(CurieIMU.getAccelerometerOffset(Z_AXIS)); + Serial.print("\t"); // 1688 + Serial.print(CurieIMU.getGyroOffset(X_AXIS)); + Serial.print("\t"); // 0 + Serial.print(CurieIMU.getGyroOffset(Y_AXIS)); + Serial.print("\t"); // 0 + Serial.println(CurieIMU.getGyroOffset(Z_AXIS)); + + Serial.println("Enabling Gyroscope/Acceleration offset compensation"); + CurieIMU.enableGyroOffset(false); + CurieIMU.enableAccelerometerOffset(true); + + Serial.println(CurieIMU.accelerometerOffsetEnabled()); + Serial.println(CurieIMU.gyroOffsetEnabled()); + } - // The board must be resting in a horizontal position for - // the following calibration procedure to work correctly! - Serial.print("Starting Gyroscope calibration..."); - CurieImu.autoCalibrateGyroOffset(); - Serial.println(" Done"); - Serial.print("Starting Acceleration calibration..."); - CurieImu.autoCalibrateXAccelOffset(0); - CurieImu.autoCalibrateYAccelOffset(0); - CurieImu.autoCalibrateZAccelOffset(1); - Serial.println(" Done"); - - Serial.println("Internal sensor offsets AFTER calibration..."); - Serial.print(CurieImu.getXAccelOffset()); - Serial.print("\t"); // -76 - Serial.print(CurieImu.getYAccelOffset()); - Serial.print("\t"); // -2359 - Serial.print(CurieImu.getZAccelOffset()); - Serial.print("\t"); // 1688 - Serial.print(CurieImu.getXGyroOffset()); - Serial.print("\t"); // 0 - Serial.print(CurieImu.getYGyroOffset()); - Serial.print("\t"); // 0 - Serial.println(CurieImu.getZGyroOffset()); - - Serial.println("Enabling Gyroscope/Acceleration offset compensation"); - CurieImu.setGyroOffsetEnabled(true); - CurieImu.setAccelOffsetEnabled(true); - // configure Arduino LED for activity indicator pinMode(ledPin, OUTPUT); } void loop() { // read raw accel/gyro measurements from device - CurieImu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); + CurieIMU.readMotionSensor(ax, ay, az, gx, gy, gz); // these methods (and a few others) are also available - //CurieImu.getAcceleration(&ax, &ay, &az); - //CurieImu.getRotation(&gx, &gy, &gz); + + //CurieIMU.readAcceleration(ax, ay, az); + //CurieIMU.readRotation(gx, gy, gz); + + //ax = CurieIMU.readAccelerometer(X_AXIS); + //ay = CurieIMU.readAccelerometer(Y_AXIS); + //az = CurieIMU.readAccelerometer(Z_AXIS); + //gx = CurieIMU.readGyro(X_AXIS); + //gy = CurieIMU.readGyro(Y_AXIS); + //gz = CurieIMU.readGyro(Z_AXIS); // display tab-separated accel/gyro x/y/z values Serial.print("a/g:\t"); - Serial.print(ax); + Serial.print(az); Serial.print("\t"); Serial.print(ay); Serial.print("\t"); @@ -137,4 +152,4 @@ void loop() { // blink LED to indicate activity blinkState = !blinkState; digitalWrite(ledPin, blinkState); -} +} \ No newline at end of file diff --git a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino b/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino index 9e7e352e..816e530e 100644 --- a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino +++ b/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino @@ -30,16 +30,16 @@ void setup() { Serial.begin(9600); /* Initialise the IMU */ - CurieImu.initialize(); - CurieImu.attachInterrupt(eventCallback); + CurieIMU.begin(); + CurieIMU.attachInterrupt(eventCallback); /* Enable Shock Detection */ - CurieImu.setShockDetectionThreshold(192); // 1.5g - CurieImu.setShockDetectionDuration(11); // 30ms - CurieImu.setIntShockEnabled(true); + CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 192); // 1.5g + CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK,11); // 30ms + CurieIMU.enableInterrupt(CURIE_IMU_SHOCK,true); /* Enable Interrupts Notifications */ - CurieImu.setIntEnabled(true); + CurieIMU.setIntEnabled(true); Serial.println("IMU initialisation complete, waiting for events..."); } @@ -54,18 +54,18 @@ void loop() { static void eventCallback(void) { - if (CurieImu.getIntShockStatus()) { - if (CurieImu.getXNegShockDetected()) + if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) { + if (CurieIMU.shockDetected(X_AXIS,POSITIVE)) Serial.println("Negative shock detected on X-axis"); - if (CurieImu.getXPosShockDetected()) + if (CurieIMU.shockDetected(X_AXIS,NEGATIVE)) Serial.println("Positive shock detected on X-axis"); - if (CurieImu.getYNegShockDetected()) + if (CurieIMU.shockDetected(Y_AXIS,POSITIVE)) Serial.println("Negative shock detected on Y-axis"); - if (CurieImu.getYPosShockDetected()) + if (CurieIMU.shockDetected(Y_AXIS,NEGATIVE)) Serial.println("Positive shock detected on Y-axis"); - if (CurieImu.getZNegShockDetected()) + if (CurieIMU.shockDetected(Z_AXIS,POSITIVE)) Serial.println("Negative shock detected on Z-axis"); - if (CurieImu.getZPosShockDetected()) + if (CurieIMU.shockDetected(Z_AXIS,NEGATIVE)) Serial.println("Positive shock detected on Z-axis"); } -} +} \ No newline at end of file diff --git a/libraries/CurieImu/examples/StepCount/StepCount.ino b/libraries/CurieImu/examples/StepCount/StepCount.ino index 9686d6b6..f9bb71a9 100644 --- a/libraries/CurieImu/examples/StepCount/StepCount.ino +++ b/libraries/CurieImu/examples/StepCount/StepCount.ino @@ -42,18 +42,18 @@ void setup() { Serial.begin(9600); // pinMode(13, OUTPUT); // intialize the sensor: - CurieImu.initialize(); + CurieIMU.begin(); // turn on step detection mode: - CurieImu.setStepDetectionMode(BMI160_STEP_MODE_NORMAL); + CurieIMU.setStepDetectionMode(CURIE_IMU_STEP_MODE_NORMAL); // enable step counting: - CurieImu.setStepCountEnabled(true); + CurieIMU.setStepCountEnabled(true); if (stepEventsEnabeled) { // attach the eventCallback function as the // step event handler: - CurieImu.attachInterrupt(eventCallback); - CurieImu.setIntStepEnabled(true); // turn on step detection - CurieImu.setIntEnabled(true); // enable interrupts + CurieIMU.attachInterrupt(eventCallback); + CurieIMU.enableInterrupt(CURIE_IMU_STEP,true); // turn on step detection + CurieIMU.setIntEnabled(true); // enable interrupts Serial.println("IMU initialisation complete, waiting for events..."); } @@ -72,7 +72,7 @@ void loop() { static void updateStepCount() { // get the step count: - int stepCount = CurieImu.getStepCount(); + int stepCount = CurieIMU.getStepCount(); // if the step count has changed, print it: if (stepCount != lastStepCount) { @@ -84,6 +84,6 @@ static void updateStepCount() { } static void eventCallback(void) { - if (CurieImu.getIntStepStatus()) + if (CurieIMU.stepsDetected()) updateStepCount(); } diff --git a/libraries/CurieImu/examples/TapDetect/TapDetect.ino b/libraries/CurieImu/examples/TapDetect/TapDetect.ino index ce56ea0b..ed7be3d8 100644 --- a/libraries/CurieImu/examples/TapDetect/TapDetect.ino +++ b/libraries/CurieImu/examples/TapDetect/TapDetect.ino @@ -28,23 +28,23 @@ void setup() { Serial.begin(9600); // Initialise the IMU - CurieImu.initialize(); - CurieImu.attachInterrupt(eventCallback); + CurieIMU.begin(); + CurieIMU.attachInterrupt(eventCallback); // Increase Accelerometer range to allow detection of stronger taps (< 4g) - CurieImu.setFullScaleAccelRange(BMI160_ACCEL_RANGE_4G); + CurieIMU.setAccelerometerRange(4); // Reduce threshold to allow detection of weaker taps (>= 750mg) - CurieImu.setTapDetectionThreshold(6); // (6 x 125mg) + CurieIMU.setDetectionThreshold(CURIE_IMU_TAP,6); // (6 x 125mg) // Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds) - CurieImu.setDoubleTapDetectionDuration(BMI160_DOUBLE_TAP_DURATION_250MS); + CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP,250); // Enable Double-Tap detection - CurieImu.setIntDoubleTapEnabled(true); + CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP,true); // Enable Interrupts Notifications - CurieImu.setIntEnabled(true); + CurieIMU.setIntEnabled(true); Serial.println("IMU initialisation complete, waiting for events..."); } @@ -56,18 +56,18 @@ void loop() { static void eventCallback() { - if (CurieImu.getIntDoubleTapStatus()) { - if (CurieImu.getXNegTapDetected()) + if (CurieIMU.getInterruptStatus(CURIE_IMU_DOUBLE_TAP)) { + if (CurieIMU.tapDetected(X_AXIS,NEGATIVE)) Serial.println("Double Tap detected on negative X-axis"); - if (CurieImu.getXPosTapDetected()) + if (CurieIMU.tapDetected(X_AXIS,POSITIVE)) Serial.println("Double Tap detected on positive X-axis"); - if (CurieImu.getYNegTapDetected()) + if (CurieIMU.tapDetected(Y_AXIS,NEGATIVE)) Serial.println("Double Tap detected on negative Y-axis"); - if (CurieImu.getYPosTapDetected()) + if (CurieIMU.tapDetected(Y_AXIS,POSITIVE)) Serial.println("Double Tap detected on positive Y-axis"); - if (CurieImu.getZNegTapDetected()) + if (CurieIMU.tapDetected(Z_AXIS,NEGATIVE)) Serial.println("Double Tap detected on negative Z-axis"); - if (CurieImu.getZPosTapDetected()) + if (CurieIMU.tapDetected(Z_AXIS,POSITIVE)) Serial.println("Double Tap detected on positive Z-axis"); } } From 38f928fff483abfba10927610f889e022779f52a Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 16:33:34 -0500 Subject: [PATCH 03/18] Use enums for accelerometer and gyro ranges --- libraries/CurieImu/src/CurieImu.cpp | 71 ++--------------------------- libraries/CurieImu/src/CurieImu.h | 23 ++++++++++ 2 files changed, 27 insertions(+), 67 deletions(-) diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieImu/src/CurieImu.cpp index c036676e..c3bcc93d 100644 --- a/libraries/CurieImu/src/CurieImu.cpp +++ b/libraries/CurieImu/src/CurieImu.cpp @@ -59,85 +59,22 @@ bool CurieImuClass::begin() int CurieImuClass::getGyroRange() { - uint8_t fullScaleGyroRange = getFullScaleGyroRange(); - - switch (fullScaleGyroRange) { - case BMI160_GYRO_RANGE_2000: - return 2000; - - case BMI160_GYRO_RANGE_1000: - return 1000; - - case BMI160_GYRO_RANGE_500: - return 500; - - case BMI160_GYRO_RANGE_250: - return 250; - - case BMI160_GYRO_RANGE_125: - return 125; - - default: - return -1; - } + return getFullScaleGyroRange(); } void CurieImuClass::setGyroRange(int range) { - uint8_t fullScaleGyroRange; - - if (range >= 2000) { - fullScaleGyroRange = BMI160_GYRO_RANGE_2000; - } else if (range >= 1000) { - fullScaleGyroRange = BMI160_GYRO_RANGE_1000; - } else if (range >= 500) { - fullScaleGyroRange = BMI160_GYRO_RANGE_500; - } else if (range >= 250) { - fullScaleGyroRange = BMI160_GYRO_RANGE_250; - } else { - fullScaleGyroRange = BMI160_GYRO_RANGE_125; - } - - setFullScaleGyroRange(fullScaleGyroRange); + setFullScaleGyroRange(range); } int CurieImuClass::getAccelerometerRange() { - uint8_t fullScaleAccelRange = getFullScaleAccelRange(); - - switch (fullScaleAccelRange) { - case BMI160_ACCEL_RANGE_2G: - return 2; - - case BMI160_ACCEL_RANGE_4G: - return 4; - - case BMI160_ACCEL_RANGE_8G: - return 8; - - case BMI160_ACCEL_RANGE_16G: - return 16; - - default: - return -1; - } + return getFullScaleAccelRange(); } void CurieImuClass::setAccelerometerRange(int range) { - uint8_t fullScaleAccelRange; - - if (range >= 16) { - fullScaleAccelRange = BMI160_ACCEL_RANGE_16G; - } else if (range >= 8) { - fullScaleAccelRange = BMI160_ACCEL_RANGE_8G; - } else if (range >= 4) { - fullScaleAccelRange = BMI160_ACCEL_RANGE_4G; - } else { - fullScaleAccelRange = BMI160_ACCEL_RANGE_2G; - } - - setFullScaleAccelRange(fullScaleAccelRange); + setFullScaleAccelRange(range); } void CurieImuClass::autoCalibrateGyroOffset() diff --git a/libraries/CurieImu/src/CurieImu.h b/libraries/CurieImu/src/CurieImu.h index 034db277..6d6ec764 100644 --- a/libraries/CurieImu/src/CurieImu.h +++ b/libraries/CurieImu/src/CurieImu.h @@ -69,6 +69,29 @@ typedef enum { CURIE_IMU_DATA_READY, } CurieIMUFeature; +/** + * Accelerometer Sensitivity Range options + * @see setAccelerometerRange() + */ +typedef enum { + CURIE_IMU_ACCEL_RANGE_2G = BMI160_ACCEL_RANGE_2G, + CURIE_IMU_ACCEL_RANGE_4G = BMI160_ACCEL_RANGE_4G, + CURIE_IMU_ACCEL_RANGE_8G = BMI160_ACCEL_RANGE_8G, + CURIE_IMU_ACCEL_RANGE_16G = BMI160_ACCEL_RANGE_16G +} CurieIMUAccelRange; + +/** + * Gyroscope Sensitivity Range options + * @see setGyroRange() + */ +typedef enum { + CURIE_IMU_GYRO_RANGE_2000 = BMI160_GYRO_RANGE_2000, + CURIE_IMU_GYRO_RANGE_1000 = BMI160_GYRO_RANGE_1000, + CURIE_IMU_GYRO_RANGE_500 = BMI160_GYRO_RANGE_500, + CURIE_IMU_GYRO_RANGE_250 = BMI160_GYRO_RANGE_250, + CURIE_IMU_GYRO_RANGE_125 = BMI160_GYRO_RANGE_125 +} CurieIMUGyroRange; + /** * Step Detection Mode options * @see setStepDetectionMode() From 0faeb636cda253ad2768af7db12df42b3c689aa0 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 17:09:13 -0500 Subject: [PATCH 04/18] Add set/get gyro/accelerometer rate API's, and map more BMI160 enums --- libraries/CurieImu/src/CurieImu.cpp | 20 ++++ libraries/CurieImu/src/CurieImu.h | 150 +++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 5 deletions(-) diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieImu/src/CurieImu.cpp index c3bcc93d..025ecd99 100644 --- a/libraries/CurieImu/src/CurieImu.cpp +++ b/libraries/CurieImu/src/CurieImu.cpp @@ -57,6 +57,26 @@ bool CurieImuClass::begin() return (CURIE_IMU_CHIP_ID == getDeviceID()); } +int CurieImuClass::getGyroRate() +{ + return BMI160Class::getGyroRate(); +} + +void CurieImuClass::setGyroRate(int rate) +{ + BMI160Class::setGyroRate(rate); +} + +int CurieImuClass::getAccelerometerRate() +{ + return getAccelRate(); +} + +void CurieImuClass::setAccelerometerRate(int rate) +{ + setAccelRate(rate); +} + int CurieImuClass::getGyroRange() { return getFullScaleGyroRange(); diff --git a/libraries/CurieImu/src/CurieImu.h b/libraries/CurieImu/src/CurieImu.h index 6d6ec764..a5046ae8 100644 --- a/libraries/CurieImu/src/CurieImu.h +++ b/libraries/CurieImu/src/CurieImu.h @@ -74,11 +74,11 @@ typedef enum { * @see setAccelerometerRange() */ typedef enum { - CURIE_IMU_ACCEL_RANGE_2G = BMI160_ACCEL_RANGE_2G, - CURIE_IMU_ACCEL_RANGE_4G = BMI160_ACCEL_RANGE_4G, - CURIE_IMU_ACCEL_RANGE_8G = BMI160_ACCEL_RANGE_8G, + CURIE_IMU_ACCELEROMETER_RANGE_2G = BMI160_ACCEL_RANGE_2G, + CURIE_IMU_ACCELEROMETER_RANGE_4G = BMI160_ACCEL_RANGE_4G, + CURIE_IMU_ACCELEROMETER_RANGE_8G = BMI160_ACCEL_RANGE_8G, CURIE_IMU_ACCEL_RANGE_16G = BMI160_ACCEL_RANGE_16G -} CurieIMUAccelRange; +} CurieIMUAccelerometerRange; /** * Gyroscope Sensitivity Range options @@ -92,6 +92,36 @@ typedef enum { CURIE_IMU_GYRO_RANGE_125 = BMI160_GYRO_RANGE_125 } CurieIMUGyroRange; +/** + * Accelerometer Output Data Rate options + * @see setAccelerometerRate() + */ +typedef enum { + CURIE_IMU_ACCELEROMETER_RATE_25_2HZ = BMI160_ACCEL_RATE_25_2HZ, + CURIE_IMU_ACCELEROMETER_RATE_25HZ = BMI160_ACCEL_RATE_25HZ, + CURIE_IMU_ACCELEROMETER_RATE_50HZ = BMI160_ACCEL_RATE_50HZ, + CURIE_IMU_ACCELEROMETER_RATE_100HZ = BMI160_ACCEL_RATE_100HZ, + CURIE_IMU_ACCELEROMETER_RATE_200HZ = BMI160_ACCEL_RATE_200HZ, + CURIE_IMU_ACCELEROMETER_RATE_400HZ = BMI160_ACCEL_RATE_400HZ, + CURIE_IMU_ACCELEROMETER_RATE_800HZ = BMI160_ACCEL_RATE_800HZ, + CURIE_IMU_ACCELEROMETER_RATE_1600HZ = BMI160_ACCEL_RATE_1600HZ +} CurieIMUAccelRate; + +/** + * Gyroscope Output Data Rate options + * @see setGyroRate() + */ +typedef enum { + CURIE_IMU_GYRO_RATE_25HZ = BMI160_GYRO_RATE_25HZ, + CURIE_IMU_GYRO_RATE_50HZ = BMI160_GYRO_RATE_50HZ, + CURIE_IMU_GYRO_RATE_100HZ = BMI160_GYRO_RATE_100HZ, + CURIE_IMU_GYRO_RATE_200HZ = BMI160_GYRO_RATE_200HZ, + CURIE_IMU_GYRO_RATE_400HZ = BMI160_GYRO_RATE_400HZ, + CURIE_IMU_GYRO_RATE_800HZ = BMI160_GYRO_RATE_800HZ, + CURIE_IMU_GYRO_RATE_1600HZ = BMI160_GYRO_RATE_1600HZ, + CURIE_IMU_GYRO_RATE_3200HZ = BMI160_GYRO_RATE_3200HZ +} CurieIMUGyroRate; + /** * Step Detection Mode options * @see setStepDetectionMode() @@ -100,9 +130,113 @@ typedef enum { CURIE_IMU_STEP_MODE_NORMAL = BMI160_STEP_MODE_NORMAL, CURIE_IMU_STEP_MODE_SENSITIVE = BMI160_STEP_MODE_SENSITIVE, CURIE_IMU_STEP_MODE_ROBUST = BMI160_STEP_MODE_ROBUST, - CURIE_IMU_STEP_MODE_UNKNOWN = BMI160_STEP_MODE_UNKNOWN, + CURIE_IMU_STEP_MODE_UNKNOWN = BMI160_STEP_MODE_UNKNOWN } CurieIMUStepMode; +/** + * Tap Detection Shock Duration options + * @see setDetectionThreshold(CURIE_IMU_TAP, ...) + */ +typedef enum { + CURIE_IMU_TAP_SHOCK_DURATION_50MS = BMI160_TAP_SHOCK_DURATION_50MS, + CURIE_IMU_TAP_SHOCK_DURATION_75MS = BMI160_TAP_SHOCK_DURATION_75MS +} CurieIMUTapShockDuration; + +/** + * Tap Detection Quiet Duration options + * @see setDetectionThreshold(CURIE_IMU_TAP_QUIET, ...) + */ +typedef enum { + CURIE_IMU_TAP_QUIET_DURATION_30MS = BMI160_TAP_QUIET_DURATION_30MS, + CURIE_IMU_TAP_QUIET_DURATION_20MS = BMI160_TAP_QUIET_DURATION_20MS +} CurieIMUTapQuietDuration; + +/** + * Double-Tap Detection Duration options + * @see setDetectionThreshold(CURIE_IMU_DOUBLE_TAP, ...) + */ +typedef enum { + CURIE_IMU_DOUBLE_TAP_DURATION_50MS = BMI160_DOUBLE_TAP_DURATION_50MS, + CURIE_IMU_DOUBLE_TAP_DURATION_100MS = BMI160_DOUBLE_TAP_DURATION_100MS, + CURIE_IMU_DOUBLE_TAP_DURATION_150MS = BMI160_DOUBLE_TAP_DURATION_150MS, + CURIE_IMU_DOUBLE_TAP_DURATION_200MS = BMI160_DOUBLE_TAP_DURATION_200MS, + CURIE_IMU_DOUBLE_TAP_DURATION_250MS = BMI160_DOUBLE_TAP_DURATION_250MS, + CURIE_IMU_DOUBLE_TAP_DURATION_375MS = BMI160_DOUBLE_TAP_DURATION_375MS, + CURIE_IMU_DOUBLE_TAP_DURATION_500MS = BMI160_DOUBLE_TAP_DURATION_500MS, + CURIE_IMU_DOUBLE_TAP_DURATION_700MS = BMI160_DOUBLE_TAP_DURATION_700MS +} CurieIMUDoubleTapDuration; + +/** + * Zero-Motion Detection Duration options + * @see setDetectionThreshold(CURIE_IMU_ZERO_MOTION, ...) + */ +typedef enum { + CURIE_IMU_ZERO_MOTION_DURATION_1_28S = BMI160_ZERO_MOTION_DURATION_1_28S, + CURIE_IMU_ZERO_MOTION_DURATION_2_56S = BMI160_ZERO_MOTION_DURATION_2_56S, + CURIE_IMU_ZERO_MOTION_DURATION_3_84S = BMI160_ZERO_MOTION_DURATION_3_84S, + CURIE_IMU_ZERO_MOTION_DURATION_5_12S = BMI160_ZERO_MOTION_DURATION_5_12S, + CURIE_IMU_ZERO_MOTION_DURATION_6_40S = BMI160_ZERO_MOTION_DURATION_6_40S, + CURIE_IMU_ZERO_MOTION_DURATION_7_68S = BMI160_ZERO_MOTION_DURATION_7_68S, + CURIE_IMU_ZERO_MOTION_DURATION_8_96S = BMI160_ZERO_MOTION_DURATION_8_96S, + CURIE_IMU_ZERO_MOTION_DURATION_10_24S = BMI160_ZERO_MOTION_DURATION_10_24S, + CURIE_IMU_ZERO_MOTION_DURATION_11_52S = BMI160_ZERO_MOTION_DURATION_11_52S, + CURIE_IMU_ZERO_MOTION_DURATION_12_80S = BMI160_ZERO_MOTION_DURATION_12_80S, + CURIE_IMU_ZERO_MOTION_DURATION_14_08S = BMI160_ZERO_MOTION_DURATION_14_08S, + CURIE_IMU_ZERO_MOTION_DURATION_15_36S = BMI160_ZERO_MOTION_DURATION_15_36S, + CURIE_IMU_ZERO_MOTION_DURATION_16_64S = BMI160_ZERO_MOTION_DURATION_16_64S, + CURIE_IMU_ZERO_MOTION_DURATION_17_92S = BMI160_ZERO_MOTION_DURATION_17_92S, + CURIE_IMU_ZERO_MOTION_DURATION_19_20S = BMI160_ZERO_MOTION_DURATION_19_20S, + CURIE_IMU_ZERO_MOTION_DURATION_20_48S = BMI160_ZERO_MOTION_DURATION_20_48S, + CURIE_IMU_ZERO_MOTION_DURATION_25_60S = BMI160_ZERO_MOTION_DURATION_25_60S, + CURIE_IMU_ZERO_MOTION_DURATION_30_72S = BMI160_ZERO_MOTION_DURATION_30_72S, + CURIE_IMU_ZERO_MOTION_DURATION_35_84S = BMI160_ZERO_MOTION_DURATION_35_84S, + CURIE_IMU_ZERO_MOTION_DURATION_40_96S = BMI160_ZERO_MOTION_DURATION_40_96S, + CURIE_IMU_ZERO_MOTION_DURATION_46_08S = BMI160_ZERO_MOTION_DURATION_46_08S, + CURIE_IMU_ZERO_MOTION_DURATION_51_20S = BMI160_ZERO_MOTION_DURATION_51_20S, + CURIE_IMU_ZERO_MOTION_DURATION_56_32S = BMI160_ZERO_MOTION_DURATION_56_32S, + CURIE_IMU_ZERO_MOTION_DURATION_61_44S = BMI160_ZERO_MOTION_DURATION_61_44S, + CURIE_IMU_ZERO_MOTION_DURATION_66_56S = BMI160_ZERO_MOTION_DURATION_66_56S, + CURIE_IMU_ZERO_MOTION_DURATION_71_68S = BMI160_ZERO_MOTION_DURATION_71_68S, + CURIE_IMU_ZERO_MOTION_DURATION_76_80S = BMI160_ZERO_MOTION_DURATION_76_80S, + CURIE_IMU_ZERO_MOTION_DURATION_81_92S = BMI160_ZERO_MOTION_DURATION_81_92S, + CURIE_IMU_ZERO_MOTION_DURATION_87_04S = BMI160_ZERO_MOTION_DURATION_87_04S, + CURIE_IMU_ZERO_MOTION_DURATION_92_16S = BMI160_ZERO_MOTION_DURATION_92_16S, + CURIE_IMU_ZERO_MOTION_DURATION_97_28S = BMI160_ZERO_MOTION_DURATION_97_28S, + CURIE_IMU_ZERO_MOTION_DURATION_102_40S = BMI160_ZERO_MOTION_DURATION_102_40S, + CURIE_IMU_ZERO_MOTION_DURATION_112_64S = BMI160_ZERO_MOTION_DURATION_112_64S, + CURIE_IMU_ZERO_MOTION_DURATION_122_88S = BMI160_ZERO_MOTION_DURATION_122_88S, + CURIE_IMU_ZERO_MOTION_DURATION_133_12S = BMI160_ZERO_MOTION_DURATION_133_12S, + CURIE_IMU_ZERO_MOTION_DURATION_143_36S = BMI160_ZERO_MOTION_DURATION_143_36S, + CURIE_IMU_ZERO_MOTION_DURATION_153_60S = BMI160_ZERO_MOTION_DURATION_153_60S, + CURIE_IMU_ZERO_MOTION_DURATION_163_84S = BMI160_ZERO_MOTION_DURATION_163_84S, + CURIE_IMU_ZERO_MOTION_DURATION_174_08S = BMI160_ZERO_MOTION_DURATION_174_08S, + CURIE_IMU_ZERO_MOTION_DURATION_184_32S = BMI160_ZERO_MOTION_DURATION_184_32S, + CURIE_IMU_ZERO_MOTION_DURATION_194_56S = BMI160_ZERO_MOTION_DURATION_194_56S, + CURIE_IMU_ZERO_MOTION_DURATION_204_80S = BMI160_ZERO_MOTION_DURATION_204_80S, + CURIE_IMU_ZERO_MOTION_DURATION_215_04S = BMI160_ZERO_MOTION_DURATION_215_04S, + CURIE_IMU_ZERO_MOTION_DURATION_225_28S = BMI160_ZERO_MOTION_DURATION_225_28S, + CURIE_IMU_ZERO_MOTION_DURATION_235_52S = BMI160_ZERO_MOTION_DURATION_235_52S, + CURIE_IMU_ZERO_MOTION_DURATION_245_76S = BMI160_ZERO_MOTION_DURATION_245_76S, + CURIE_IMU_ZERO_MOTION_DURATION_256_00S = BMI160_ZERO_MOTION_DURATION_256_00S, + CURIE_IMU_ZERO_MOTION_DURATION_266_24S = BMI160_ZERO_MOTION_DURATION_266_24S, + CURIE_IMU_ZERO_MOTION_DURATION_276_48S = BMI160_ZERO_MOTION_DURATION_276_48S, + CURIE_IMU_ZERO_MOTION_DURATION_286_72S = BMI160_ZERO_MOTION_DURATION_286_72S, + CURIE_IMU_ZERO_MOTION_DURATION_296_96S = BMI160_ZERO_MOTION_DURATION_296_96S, + CURIE_IMU_ZERO_MOTION_DURATION_307_20S = BMI160_ZERO_MOTION_DURATION_307_20S, + CURIE_IMU_ZERO_MOTION_DURATION_317_44S = BMI160_ZERO_MOTION_DURATION_317_44S, + CURIE_IMU_ZERO_MOTION_DURATION_327_68S = BMI160_ZERO_MOTION_DURATION_327_68S, + CURIE_IMU_ZERO_MOTION_DURATION_337_92S = BMI160_ZERO_MOTION_DURATION_337_92S, + CURIE_IMU_ZERO_MOTION_DURATION_348_16S = BMI160_ZERO_MOTION_DURATION_348_16S, + CURIE_IMU_ZERO_MOTION_DURATION_358_40S = BMI160_ZERO_MOTION_DURATION_358_40S, + CURIE_IMU_ZERO_MOTION_DURATION_368_64S = BMI160_ZERO_MOTION_DURATION_368_64S, + CURIE_IMU_ZERO_MOTION_DURATION_378_88S = BMI160_ZERO_MOTION_DURATION_378_88S, + CURIE_IMU_ZERO_MOTION_DURATION_389_12S = BMI160_ZERO_MOTION_DURATION_389_12S, + CURIE_IMU_ZERO_MOTION_DURATION_399_36S = BMI160_ZERO_MOTION_DURATION_399_36S, + CURIE_IMU_ZERO_MOTION_DURATION_409_60S = BMI160_ZERO_MOTION_DURATION_409_60S, + CURIE_IMU_ZERO_MOTION_DURATION_419_84S = BMI160_ZERO_MOTION_DURATION_419_84S, + CURIE_IMU_ZERO_MOTION_DURATION_430_08S = BMI160_ZERO_MOTION_DURATION_430_08S +} CurieImuZeroMotionDuration; + /* Note that this CurieImuClass class inherits methods from the BMI160Class which * is defined in BMI160.h. BMI160Class provides methods for configuring and * accessing features of the BMI160 IMU device. This CurieImuClass extends that @@ -119,6 +253,12 @@ class CurieImuClass : public BMI160Class { public: bool begin(void); + int getGyroRate(); + void setGyroRate(int rate); + + int getAccelerometerRate(); + void setAccelerometerRate(int rate); + int getGyroRange(); void setGyroRange(int range); int getAccelerometerRange(); From ef3ccb5aebee42c2497631b8e7b77ecd5b5c2359 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 17:10:10 -0500 Subject: [PATCH 05/18] Update example to use enums --- .../examples/RawImuDataSerial/RawImuDataSerial.ino | 4 ++-- libraries/CurieImu/examples/ShockDetect/ShockDetect.ino | 6 +++--- libraries/CurieImu/examples/StepCount/StepCount.ino | 2 +- libraries/CurieImu/examples/TapDetect/TapDetect.ino | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino index 9f22d22b..3e6a9f85 100644 --- a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino +++ b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino @@ -108,7 +108,7 @@ void setup() { Serial.println(CurieIMU.getGyroOffset(Z_AXIS)); Serial.println("Enabling Gyroscope/Acceleration offset compensation"); - CurieIMU.enableGyroOffset(false); + CurieIMU.enableGyroOffset(true); CurieIMU.enableAccelerometerOffset(true); Serial.println(CurieIMU.accelerometerOffsetEnabled()); @@ -152,4 +152,4 @@ void loop() { // blink LED to indicate activity blinkState = !blinkState; digitalWrite(ledPin, blinkState); -} \ No newline at end of file +} diff --git a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino b/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino index 816e530e..bda6fc9d 100644 --- a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino +++ b/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino @@ -35,8 +35,8 @@ void setup() { /* Enable Shock Detection */ CurieIMU.setDetectionThreshold(CURIE_IMU_SHOCK, 192); // 1.5g - CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK,11); // 30ms - CurieIMU.enableInterrupt(CURIE_IMU_SHOCK,true); + CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, CURIE_IMU_TAP_SHOCK_DURATION_50MS); // 50ms + CurieIMU.enableInterrupt(CURIE_IMU_SHOCK, true); /* Enable Interrupts Notifications */ CurieIMU.setIntEnabled(true); @@ -68,4 +68,4 @@ static void eventCallback(void) if (CurieIMU.shockDetected(Z_AXIS,NEGATIVE)) Serial.println("Positive shock detected on Z-axis"); } -} \ No newline at end of file +} diff --git a/libraries/CurieImu/examples/StepCount/StepCount.ino b/libraries/CurieImu/examples/StepCount/StepCount.ino index f9bb71a9..38314e29 100644 --- a/libraries/CurieImu/examples/StepCount/StepCount.ino +++ b/libraries/CurieImu/examples/StepCount/StepCount.ino @@ -52,7 +52,7 @@ void setup() { // attach the eventCallback function as the // step event handler: CurieIMU.attachInterrupt(eventCallback); - CurieIMU.enableInterrupt(CURIE_IMU_STEP,true); // turn on step detection + CurieIMU.enableInterrupt(CURIE_IMU_STEP, true); // turn on step detection CurieIMU.setIntEnabled(true); // enable interrupts Serial.println("IMU initialisation complete, waiting for events..."); diff --git a/libraries/CurieImu/examples/TapDetect/TapDetect.ino b/libraries/CurieImu/examples/TapDetect/TapDetect.ino index ed7be3d8..b433f588 100644 --- a/libraries/CurieImu/examples/TapDetect/TapDetect.ino +++ b/libraries/CurieImu/examples/TapDetect/TapDetect.ino @@ -32,16 +32,16 @@ void setup() { CurieIMU.attachInterrupt(eventCallback); // Increase Accelerometer range to allow detection of stronger taps (< 4g) - CurieIMU.setAccelerometerRange(4); + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_4G); // Reduce threshold to allow detection of weaker taps (>= 750mg) - CurieIMU.setDetectionThreshold(CURIE_IMU_TAP,6); // (6 x 125mg) + CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 6); // (6 x 125mg) // Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds) - CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP,250); + CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP, CURIE_IMU_DOUBLE_TAP_DURATION_250MS); // Enable Double-Tap detection - CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP,true); + CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP, true); // Enable Interrupts Notifications CurieIMU.setIntEnabled(true); From 5e3605e67ef21d1b59fc5d3d7e7f034c674d6477 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 17:15:06 -0500 Subject: [PATCH 06/18] Keyword updates from Helena --- libraries/CurieImu/keywords.txt | 409 ++++++++++++-------------------- 1 file changed, 153 insertions(+), 256 deletions(-) diff --git a/libraries/CurieImu/keywords.txt b/libraries/CurieImu/keywords.txt index 913434a1..6a3bb0ca 100644 --- a/libraries/CurieImu/keywords.txt +++ b/libraries/CurieImu/keywords.txt @@ -6,288 +6,185 @@ # Datatypes (KEYWORD1) ####################################### -CurieImuClass KEYWORD1 -BMI160Class KEYWORD1 +CurieIMUClass KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### -initialize KEYWORD2 -testConnection KEYWORD2 -getGyroRate KEYWORD2 -setGyroRate KEYWORD2 -getAccelRate KEYWORD2 -setAccelRate KEYWORD2 +begin KEYWORD1 -getGyroDLPFMode KEYWORD2 -setGyroDLPFMode KEYWORD2 +getGyroRate KEYWORD1 +setGyroRate KEYWORD1 +getAccelerometerRate KEYWORD1 +setAccelerometerRate KEYWORD1 -getAccelDLPFMode KEYWORD2 -setAccelDLPFMode KEYWORD2 +getGyroRange KEYWORD1 +setGyroRange KEYWORD1 +getAccelerometerRange KEYWORD1 +setAccelerometerRange KEYWORD1 -getFullScaleGyroRange KEYWORD2 -setFullScaleGyroRange KEYWORD2 -getFullScaleAccelRange KEYWORD2 -setFullScaleAccelRange KEYWORD2 +autoCalibrateGyroOffset KEYWORD1 +autoCalibrateAccelerometerOffset KEYWORD1 -autoCalibrateGyroOffset KEYWORD2 -getGyroOffsetEnabled KEYWORD2 -setGyroOffsetEnabled KEYWORD2 +enableGyroOffset KEYWORD1 +enableAccelerometerOffset KEYWORD1 +gyroOffsetEnabled KEYWORD1 +accelerometerOffsetEnabled KEYWORD1 -getXGyroOffset KEYWORD2 -setXGyroOffset KEYWORD2 -getYGyroOffset KEYWORD2 -setYGyroOffset KEYWORD2 -getZGyroOffset KEYWORD2 -setZGyroOffset KEYWORD2 +getGyroOffset KEYWORD1 +getAccelerometerOffset KEYWORD1 -autoCalibrateXAccelOffset KEYWORD2 -autoCalibrateYAccelOffset KEYWORD2 -autoCalibrateZAccelOffset KEYWORD2 -getAccelOffsetEnabled KEYWORD2 -setAccelOffsetEnabled KEYWORD2 +setGyroOffset KEYWORD1 +setAccelerometerOffset KEYWORD1 -getXAccelOffset KEYWORD2 -setXAccelOffset KEYWORD2 -getYAccelOffset KEYWORD2 -setYAccelOffset KEYWORD2 -getZAccelOffset KEYWORD2 -setZAccelOffset KEYWORD2 +getDetectionThreshold KEYWORD1 +setDetectionThreshold KEYWORD1 -getFreefallDetectionThreshold KEYWORD2 -setFreefallDetectionThreshold KEYWORD2 +getDetectionDuration KEYWORD1 +setDetectionDuration KEYWORD1 -getFreefallDetectionDuration KEYWORD2 -setFreefallDetectionDuration KEYWORD2 +enableInterrupt KEYWORD1 +interruptEnabled KEYWORD1 -getShockDetectionThreshold KEYWORD2 -setShockDetectionThreshold KEYWORD2 +getInterruptBits KEYWORD1 +getInterruptStatus KEYWORD1 -getShockDetectionDuration KEYWORD2 -setShockDetectionDuration KEYWORD2 +getStepDetectionMode KEYWORD1 +setStepDetectionMode KEYWORD1 +getStepCount KEYWORD1 +getStepCountEnabled KEYWORD1 +setStepCountEnabled KEYWORD1 +resetStepCount KEYWORD1 -getMotionDetectionThreshold KEYWORD2 -setMotionDetectionThreshold KEYWORD2 +readMotionSensor KEYWORD1 +readAcceleration KEYWORD1 +readRotation KEYWORD1 -getMotionDetectionDuration KEYWORD2 -setMotionDetectionDuration KEYWORD2 +readAccelerometer KEYWORD1 +readGyro KEYWORD1 +readTemperature KEYWORD1 -getZeroMotionDetectionThreshold KEYWORD2 -setZeroMotionDetectionThreshold KEYWORD2 - -getZeroMotionDetectionDuration KEYWORD2 -setZeroMotionDetectionDuration KEYWORD2 - -getTapDetectionThreshold KEYWORD2 -setTapDetectionThreshold KEYWORD2 - -getTapShockDuration KEYWORD2 -setTapShockDuration KEYWORD2 - -getTapQuietDuration KEYWORD2 -setTapQuietDuration KEYWORD2 - -getDoubleTapDetectionDuration KEYWORD2 -setDoubleTapDetectionDuration KEYWORD2 - -setStepDetectionMode KEYWORD2 -getStepCountEnabled KEYWORD2 -setStepCountEnabled KEYWORD2 -getStepCount KEYWORD2 -resetStepCount KEYWORD2 - -getIntFreefallEnabled KEYWORD2 -setIntFreefallEnabled KEYWORD2 -getIntShockEnabled KEYWORD2 -setIntShockEnabled KEYWORD2 -getIntStepEnabled KEYWORD2 -setIntStepEnabled KEYWORD2 -getIntMotionEnabled KEYWORD2 -setIntMotionEnabled KEYWORD2 -getIntZeroMotionEnabled KEYWORD2 -setIntZeroMotionEnabled KEYWORD2 -getIntTapEnabled KEYWORD2 -setIntTapEnabled KEYWORD2 -getIntDoubleTapEnabled KEYWORD2 -setIntDoubleTapEnabled KEYWORD2 - -getGyroFIFOEnabled KEYWORD2 -setGyroFIFOEnabled KEYWORD2 -getAccelFIFOEnabled KEYWORD2 -setAccelFIFOEnabled KEYWORD2 - -getIntFIFOBufferFullEnabled KEYWORD2 -setIntFIFOBufferFullEnabled KEYWORD2 -getIntDataReadyEnabled KEYWORD2 -setIntDataReadyEnabled KEYWORD2 - -getIntStatus0 KEYWORD2 -getIntStatus1 KEYWORD2 -getIntStatus2 KEYWORD2 -getIntStatus3 KEYWORD2 -getIntFreefallStatus KEYWORD2 -getIntShockStatus KEYWORD2 -getIntStepStatus KEYWORD2 -getIntMotionStatus KEYWORD2 -getIntZeroMotionStatus KEYWORD2 -getIntTapStatus KEYWORD2 -getIntDoubleTapStatus KEYWORD2 -getIntFIFOBufferFullStatus KEYWORD2 -getIntDataReadyStatus KEYWORD2 - -getMotion6 KEYWORD2 -getAcceleration KEYWORD2 -getAccelerationX KEYWORD2 -getAccelerationY KEYWORD2 -getAccelerationZ KEYWORD2 - -getTemperature KEYWORD2 -getRotation KEYWORD2 -getRotationX KEYWORD2 -getRotationY KEYWORD2 -getRotationZ KEYWORD2 - -getXNegShockDetected KEYWORD2 -getXPosShockDetected KEYWORD2 -getYNegShockDetected KEYWORD2 -getYPosShockDetected KEYWORD2 -getZNegShockDetected KEYWORD2 -getZPosShockDetected KEYWORD2 -getZeroShockDetected KEYWORD2 - -getXNegMotionDetected KEYWORD2 -getXPosMotionDetected KEYWORD2 -getYNegMotionDetected KEYWORD2 -getYPosMotionDetected KEYWORD2 -getZNegMotionDetected KEYWORD2 -getZPosMotionDetected KEYWORD2 -getZeroMotionDetected KEYWORD2 - -getXNegTapDetected KEYWORD2 -getXPosTapDetected KEYWORD2 -getYNegTapDetected KEYWORD2 -getYPosTapDetected KEYWORD2 -getZNegTapDetected KEYWORD2 -getZPosTapDetected KEYWORD2 - -getFIFOHeaderModeEnabled KEYWORD2 -setFIFOHeaderModeEnabled KEYWORD2 -resetFIFO KEYWORD2 - -getFIFOCount KEYWORD2 -getFIFOBytes KEYWORD2 -getDeviceID KEYWORD2 -getRegister KEYWORD2 -setRegister KEYWORD2 - -getIntEnabled KEYWORD2 -setIntEnabled KEYWORD2 -getInterruptMode KEYWORD2 -setInterruptMode KEYWORD2 -getInterruptDrive KEYWORD2 -setInterruptDrive KEYWORD2 -getInterruptLatch KEYWORD2 -setInterruptLatch KEYWORD2 -resetInterrupt KEYWORD2 +shockDetected KEYWORD1 +motionDetected KEYWORD1 +tapDetected KEYWORD1 +stepsDetected KEYWORD1 ####################################### # Instances (KEYWORD2) ####################################### -CurieImu KEYWORD2 -BMI160 KEYWORD2 +CurieIMU KEYWORD2 ####################################### # Constants (LITERAL1) ####################################### -BMI160_GYRO_RANGE_2000 LITERAL1 -BMI160_GYRO_RANGE_1000 LITERAL1 -BMI160_GYRO_RANGE_500 LITERAL1 -BMI160_GYRO_RANGE_250 LITERAL1 -BMI160_GYRO_RANGE_125 LITERAL1 - -BMI160_ACCEL_RANGE_2G LITERAL1 -BMI160_ACCEL_RANGE_4G LITERAL1 -BMI160_ACCEL_RANGE_8G LITERAL1 -BMI160_ACCEL_RANGE_16G LITERAL1 - -BMI160_STEP_MODE_NORMAL LITERAL1 -BMI160_STEP_MODE_SENSITIVE LITERAL1 -BMI160_STEP_MODE_ROBUST LITERAL1 - -BMI160_DOUBLE_TAP_DURATION_50MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_100MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_150MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_200MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_250MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_375MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_500MS LITERAL1 -BMI160_DOUBLE_TAP_DURATION_700MS LITERAL1 - - -BMI160_ZERO_MOTION_DURATION_1_28S LITERAL1 -BMI160_ZERO_MOTION_DURATION_2_56S LITERAL1 -BMI160_ZERO_MOTION_DURATION_3_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_5_12S LITERAL1 -BMI160_ZERO_MOTION_DURATION_6_40S LITERAL1 -BMI160_ZERO_MOTION_DURATION_7_68S LITERAL1 -BMI160_ZERO_MOTION_DURATION_8_96S LITERAL1 -BMI160_ZERO_MOTION_DURATION_10_24S LITERAL1 -BMI160_ZERO_MOTION_DURATION_11_52S LITERAL1 -BMI160_ZERO_MOTION_DURATION_12_80S LITERAL1 -BMI160_ZERO_MOTION_DURATION_14_08S LITERAL1 -BMI160_ZERO_MOTION_DURATION_15_36S LITERAL1 -BMI160_ZERO_MOTION_DURATION_16_64S LITERAL1 -BMI160_ZERO_MOTION_DURATION_17_92S LITERAL1 -BMI160_ZERO_MOTION_DURATION_19_20S LITERAL1 -BMI160_ZERO_MOTION_DURATION_20_48S LITERAL1 -BMI160_ZERO_MOTION_DURATION_25_60S LITERAL1 -BMI160_ZERO_MOTION_DURATION_30_72S LITERAL1 -BMI160_ZERO_MOTION_DURATION_35_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_40_96S LITERAL1 -BMI160_ZERO_MOTION_DURATION_46_08S LITERAL1 -BMI160_ZERO_MOTION_DURATION_51_20S LITERAL1 -BMI160_ZERO_MOTION_DURATION_56_32S LITERAL1 -BMI160_ZERO_MOTION_DURATION_61_44S LITERAL1 -BMI160_ZERO_MOTION_DURATION_66_56S LITERAL1 -BMI160_ZERO_MOTION_DURATION_71_68S LITERAL1 -BMI160_ZERO_MOTION_DURATION_76_80S LITERAL1 -BMI160_ZERO_MOTION_DURATION_81_92S LITERAL1 -BMI160_ZERO_MOTION_DURATION_87_04S LITERAL1 -BMI160_ZERO_MOTION_DURATION_92_16S LITERAL1 -BMI160_ZERO_MOTION_DURATION_97_28S LITERAL1 -BMI160_ZERO_MOTION_DURATION_102_40S LITERAL1 -BMI160_ZERO_MOTION_DURATION_112_64S LITERAL1 -BMI160_ZERO_MOTION_DURATION_122_88S LITERAL1 -BMI160_ZERO_MOTION_DURATION_133_12S LITERAL1 -BMI160_ZERO_MOTION_DURATION_143_36S LITERAL1 -BMI160_ZERO_MOTION_DURATION_153_60S LITERAL1 -BMI160_ZERO_MOTION_DURATION_163_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_174_08S LITERAL1 -BMI160_ZERO_MOTION_DURATION_184_32S LITERAL1 -BMI160_ZERO_MOTION_DURATION_194_56S LITERAL1 -BMI160_ZERO_MOTION_DURATION_204_80S LITERAL1 -BMI160_ZERO_MOTION_DURATION_215_04S LITERAL1 -BMI160_ZERO_MOTION_DURATION_225_28S LITERAL1 -BMI160_ZERO_MOTION_DURATION_235_52S LITERAL1 -BMI160_ZERO_MOTION_DURATION_245_76S LITERAL1 -BMI160_ZERO_MOTION_DURATION_256_00S LITERAL1 -BMI160_ZERO_MOTION_DURATION_266_24S LITERAL1 -BMI160_ZERO_MOTION_DURATION_276_48S LITERAL1 -BMI160_ZERO_MOTION_DURATION_286_72S LITERAL1 -BMI160_ZERO_MOTION_DURATION_296_96S LITERAL1 -BMI160_ZERO_MOTION_DURATION_307_20S LITERAL1 -BMI160_ZERO_MOTION_DURATION_317_44S LITERAL1 -BMI160_ZERO_MOTION_DURATION_327_68S LITERAL1 -BMI160_ZERO_MOTION_DURATION_337_92S LITERAL1 -BMI160_ZERO_MOTION_DURATION_348_16S LITERAL1 -BMI160_ZERO_MOTION_DURATION_358_40S LITERAL1 -BMI160_ZERO_MOTION_DURATION_368_64S LITERAL1 -BMI160_ZERO_MOTION_DURATION_378_88S LITERAL1 -BMI160_ZERO_MOTION_DURATION_389_12S LITERAL1 -BMI160_ZERO_MOTION_DURATION_399_36S LITERAL1 -BMI160_ZERO_MOTION_DURATION_409_60S LITERAL1 -BMI160_ZERO_MOTION_DURATION_419_84S LITERAL1 -BMI160_ZERO_MOTION_DURATION_430_08S LITERAL1 \ No newline at end of file +CURIE_IMU_ACCELEROMETER_RATE_25_2HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_25HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_50HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_100HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_200HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_400HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_800HZ LITERAL1 +CURIE_IMU_ACCELEROMETER_RATE_1600HZ LITERAL1 + +CURIE_IMU_GYRO_RATE_25HZ LITERAL1 +CURIE_IMU_GYRO_RATE_50HZ LITERAL1 +CURIE_IMU_GYRO_RATE_100HZ LITERAL1 +CURIE_IMU_GYRO_RATE_200HZ LITERAL1 +CURIE_IMU_GYRO_RATE_400HZ LITERAL1 +CURIE_IMU_GYRO_RATE_800HZ LITERAL1 +CURIE_IMU_GYRO_RATE_1600HZ LITERAL1 +CURIE_IMU_GYRO_RATE_3200HZ LITERAL1 + +CURIE_IMU_GYRO_RANGE_2000 LITERAL1 +CURIE_IMU_GYRO_RANGE_1000 LITERAL1 +CURIE_IMU_GYRO_RANGE_500 LITERAL1 +CURIE_IMU_GYRO_RANGE_250 LITERAL1 +CURIE_IMU_GYRO_RANGE_125 LITERAL1 + +CURIE_IMU_ACCELEROMETER_RANGE_2G LITERAL1 +CURIE_IMU_ACCELEROMETER_RANGE_4G LITERAL1 +CURIE_IMU_ACCELEROMETER_RANGE_8G LITERAL1 +CURIE_IMU_ACCELEROMETER_RANGE_16G LITERAL1 + +CURIE_IMU_STEP_MODE_NORMAL LITERAL1 +CURIE_IMU_STEP_MODE_SENSITIVE LITERAL1 +CURIE_IMU_STEP_MODE_ROBUST LITERAL1 +CURIE_IMU_STEP_MODE_UNKNOWN LITERAL1 + +CURIE_IMU_DOUBLE_TAP_DURATION_50MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_100MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_150MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_200MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_250MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_375MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_500MS LITERAL1 +CURIE_IMU_DOUBLE_TAP_DURATION_700MS LITERAL1 + + +CURIE_IMU_ZERO_MOTION_DURATION_1_28S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_2_56S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_3_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_5_12S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_6_40S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_7_68S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_8_96S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_10_24S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_11_52S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_12_80S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_14_08S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_15_36S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_16_64S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_17_92S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_19_20S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_20_48S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_25_60S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_30_72S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_35_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_40_96S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_46_08S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_51_20S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_56_32S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_61_44S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_66_56S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_71_68S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_76_80S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_81_92S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_87_04S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_92_16S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_97_28S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_102_40S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_112_64S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_122_88S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_133_12S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_143_36S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_153_60S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_163_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_174_08S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_184_32S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_194_56S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_204_80S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_215_04S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_225_28S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_235_52S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_245_76S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_256_00S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_266_24S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_276_48S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_286_72S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_296_96S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_307_20S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_317_44S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_327_68S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_337_92S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_348_16S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_358_40S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_368_64S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_378_88S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_389_12S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_399_36S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_409_60S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_419_84S LITERAL1 +CURIE_IMU_ZERO_MOTION_DURATION_430_08S LITERAL1 From f6d1516068c33085766dfa042fe843f69511277c Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 17:26:19 -0500 Subject: [PATCH 07/18] Sketch auto format --- .../examples/ShockDetect/ShockDetect.ino | 12 +-- .../CurieImu/examples/StepCount/StepCount.ino | 4 +- .../CurieImu/examples/TapDetect/TapDetect.ino | 98 +++++++++---------- 3 files changed, 57 insertions(+), 57 deletions(-) diff --git a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino b/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino index bda6fc9d..e787ce4a 100644 --- a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino +++ b/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino @@ -55,17 +55,17 @@ void loop() { static void eventCallback(void) { if (CurieIMU.getInterruptStatus(CURIE_IMU_SHOCK)) { - if (CurieIMU.shockDetected(X_AXIS,POSITIVE)) + if (CurieIMU.shockDetected(X_AXIS, POSITIVE)) Serial.println("Negative shock detected on X-axis"); - if (CurieIMU.shockDetected(X_AXIS,NEGATIVE)) + if (CurieIMU.shockDetected(X_AXIS, NEGATIVE)) Serial.println("Positive shock detected on X-axis"); - if (CurieIMU.shockDetected(Y_AXIS,POSITIVE)) + if (CurieIMU.shockDetected(Y_AXIS, POSITIVE)) Serial.println("Negative shock detected on Y-axis"); - if (CurieIMU.shockDetected(Y_AXIS,NEGATIVE)) + if (CurieIMU.shockDetected(Y_AXIS, NEGATIVE)) Serial.println("Positive shock detected on Y-axis"); - if (CurieIMU.shockDetected(Z_AXIS,POSITIVE)) + if (CurieIMU.shockDetected(Z_AXIS, POSITIVE)) Serial.println("Negative shock detected on Z-axis"); - if (CurieIMU.shockDetected(Z_AXIS,NEGATIVE)) + if (CurieIMU.shockDetected(Z_AXIS, NEGATIVE)) Serial.println("Positive shock detected on Z-axis"); } } diff --git a/libraries/CurieImu/examples/StepCount/StepCount.ino b/libraries/CurieImu/examples/StepCount/StepCount.ino index 38314e29..93041feb 100644 --- a/libraries/CurieImu/examples/StepCount/StepCount.ino +++ b/libraries/CurieImu/examples/StepCount/StepCount.ino @@ -73,10 +73,10 @@ void loop() { static void updateStepCount() { // get the step count: int stepCount = CurieIMU.getStepCount(); - + // if the step count has changed, print it: if (stepCount != lastStepCount) { - Serial.print("Step count: "); + Serial.print("Step count: "); Serial.println(stepCount); // save the current count for comparison next check: lastStepCount = stepCount; diff --git a/libraries/CurieImu/examples/TapDetect/TapDetect.ino b/libraries/CurieImu/examples/TapDetect/TapDetect.ino index b433f588..69910a7f 100644 --- a/libraries/CurieImu/examples/TapDetect/TapDetect.ino +++ b/libraries/CurieImu/examples/TapDetect/TapDetect.ino @@ -1,73 +1,73 @@ /* - * Copyright (c) 2015 Intel Corporation. All rights reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ /* - * This sketch example demonstrates how the BMI160 accelerometer on the - * Intel(R) Curie(TM) module can be used to detect tap events - */ + This sketch example demonstrates how the BMI160 accelerometer on the + Intel(R) Curie(TM) module can be used to detect tap events +*/ #include "CurieImu.h" void setup() { - Serial.begin(9600); + Serial.begin(9600); - // Initialise the IMU - CurieIMU.begin(); - CurieIMU.attachInterrupt(eventCallback); + // Initialise the IMU + CurieIMU.begin(); + CurieIMU.attachInterrupt(eventCallback); - // Increase Accelerometer range to allow detection of stronger taps (< 4g) - CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_4G); + // Increase Accelerometer range to allow detection of stronger taps (< 4g) + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_4G); - // Reduce threshold to allow detection of weaker taps (>= 750mg) - CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 6); // (6 x 125mg) + // Reduce threshold to allow detection of weaker taps (>= 750mg) + CurieIMU.setDetectionThreshold(CURIE_IMU_TAP, 6); // (6 x 125mg) - // Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds) - CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP, CURIE_IMU_DOUBLE_TAP_DURATION_250MS); + // Set the time window for 2 taps to be registered as a double-tap (<= 250 milliseconds) + CurieIMU.setDetectionDuration(CURIE_IMU_DOUBLE_TAP, CURIE_IMU_DOUBLE_TAP_DURATION_250MS); - // Enable Double-Tap detection - CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP, true); + // Enable Double-Tap detection + CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP, true); - // Enable Interrupts Notifications - CurieIMU.setIntEnabled(true); + // Enable Interrupts Notifications + CurieIMU.setIntEnabled(true); - Serial.println("IMU initialisation complete, waiting for events..."); + Serial.println("IMU initialisation complete, waiting for events..."); } void loop() { // nothing happens in the loop because all the action happens - // in the callback function. + // in the callback function. } static void eventCallback() { - if (CurieIMU.getInterruptStatus(CURIE_IMU_DOUBLE_TAP)) { - if (CurieIMU.tapDetected(X_AXIS,NEGATIVE)) - Serial.println("Double Tap detected on negative X-axis"); - if (CurieIMU.tapDetected(X_AXIS,POSITIVE)) - Serial.println("Double Tap detected on positive X-axis"); - if (CurieIMU.tapDetected(Y_AXIS,NEGATIVE)) - Serial.println("Double Tap detected on negative Y-axis"); - if (CurieIMU.tapDetected(Y_AXIS,POSITIVE)) - Serial.println("Double Tap detected on positive Y-axis"); - if (CurieIMU.tapDetected(Z_AXIS,NEGATIVE)) - Serial.println("Double Tap detected on negative Z-axis"); - if (CurieIMU.tapDetected(Z_AXIS,POSITIVE)) - Serial.println("Double Tap detected on positive Z-axis"); + if (CurieIMU.getInterruptStatus(CURIE_IMU_DOUBLE_TAP)) { + if (CurieIMU.tapDetected(X_AXIS, NEGATIVE)) + Serial.println("Double Tap detected on negative X-axis"); + if (CurieIMU.tapDetected(X_AXIS, POSITIVE)) + Serial.println("Double Tap detected on positive X-axis"); + if (CurieIMU.tapDetected(Y_AXIS, NEGATIVE)) + Serial.println("Double Tap detected on negative Y-axis"); + if (CurieIMU.tapDetected(Y_AXIS, POSITIVE)) + Serial.println("Double Tap detected on positive Y-axis"); + if (CurieIMU.tapDetected(Z_AXIS, NEGATIVE)) + Serial.println("Double Tap detected on negative Z-axis"); + if (CurieIMU.tapDetected(Z_AXIS, POSITIVE)) + Serial.println("Double Tap detected on positive Z-axis"); } } From 1e30828bac4a73ef240f1bf8df8aa5e1a2ff1ff3 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 18 Dec 2015 17:46:47 -0500 Subject: [PATCH 08/18] Use if statements instead of switch for a few API's --- libraries/CurieImu/src/CurieImu.cpp | 246 ++++++++++------------------ 1 file changed, 88 insertions(+), 158 deletions(-) diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieImu/src/CurieImu.cpp index 025ecd99..d0a2801d 100644 --- a/libraries/CurieImu/src/CurieImu.cpp +++ b/libraries/CurieImu/src/CurieImu.cpp @@ -144,75 +144,49 @@ bool CurieImuClass::accelerometerOffsetEnabled() int CurieImuClass::getGyroOffset(int axis) { - switch (axis) { - case X_AXIS: - return getXGyroOffset(); - - case Y_AXIS: - return getYGyroOffset(); - - case Z_AXIS: - return getZGyroOffset(); - - default: - return -1; + if (axis == X_AXIS) { + return getXGyroOffset(); + } else if (axis == Y_AXIS) { + return getYGyroOffset(); + } else if (axis == Z_AXIS) { + return getZGyroOffset(); } + + return -1; } int CurieImuClass::getAccelerometerOffset(int axis) { - switch (axis) { - case X_AXIS: - return getXAccelOffset(); - - case Y_AXIS: - return getYAccelOffset(); - - case Z_AXIS: - return getZAccelOffset(); - - default: - return -1; + if (axis == X_AXIS) { + return getXAccelOffset(); + } else if (axis == Y_AXIS) { + return getYAccelOffset(); + } else if (axis == Z_AXIS) { + return getZAccelOffset(); } + + return -1; } void CurieImuClass::setGyroOffset(int axis, int offset) { - switch (axis) { - case X_AXIS: - setXGyroOffset(axis); - break; - - case Y_AXIS: - setYGyroOffset(axis); - break; - - case Z_AXIS: - setZGyroOffset(axis); - break; - - default: - break; + if (axis == X_AXIS) { + setXGyroOffset(axis); + } else if (axis == Y_AXIS) { + setYGyroOffset(axis); + } else if (axis == Z_AXIS) { + setZGyroOffset(axis); } } void CurieImuClass::setAccelerometerOffset(int axis, int offset) { - switch (axis) { - case X_AXIS: - setXAccelOffset(axis); - break; - - case Y_AXIS: - setYAccelOffset(axis); - break; - - case Z_AXIS: - setZAccelOffset(axis); - break; - - default: - break; + if (axis == X_AXIS) { + setXAccelOffset(axis); + } else if (axis == Y_AXIS) { + setYAccelOffset(axis); + } else if (axis == Z_AXIS) { + setZAccelOffset(axis); } } @@ -431,7 +405,7 @@ bool CurieImuClass::interruptEnabled(int feature) case CURIE_IMU_TAP_QUIET: case CURIE_IMU_TAP_SHOCK: default: - return -1; + return false; } } @@ -468,7 +442,7 @@ int CurieImuClass::getInterruptStatus(int feature) case CURIE_IMU_TAP_QUIET: case CURIE_IMU_TAP_SHOCK: default: - return -1; + return false; } } @@ -499,36 +473,28 @@ void CurieImuClass::readRotation(short& x, short& y, short& z) short CurieImuClass::readAccelerometer(int axis) { - switch (axis) { - case X_AXIS: - return getAccelerationX(); - - case Y_AXIS: - return getAccelerationY(); - - case Z_AXIS: - return getAccelerationZ(); - - default: - return -1; + if (axis == X_AXIS) { + return getAccelerationX(); + } else if (axis == Y_AXIS) { + return getAccelerationY(); + } else if (axis == Z_AXIS) { + return getAccelerationZ(); } + + return 0; } short CurieImuClass::readGyro(int axis) { - switch (axis) { - case X_AXIS: - return getRotationX(); - - case Y_AXIS: - return getRotationY(); - - case Z_AXIS: - return getRotationZ(); - - default: - return -1; + if (axis == X_AXIS) { + return getRotationX(); + } else if (axis == Y_AXIS) { + return getRotationY(); + } else if (axis == Z_AXIS) { + return getRotationZ(); } + + return 0; } short CurieImuClass::readTemperature() @@ -539,106 +505,70 @@ short CurieImuClass::readTemperature() bool CurieImuClass::shockDetected(int axis, int direction) { if (direction == POSITIVE) { - switch (axis) { - case X_AXIS: - return getXPosShockDetected(); - - case Y_AXIS: - return getYPosShockDetected(); - - case Z_AXIS: - return getZPosShockDetected(); - - default: - return -1; + if (axis == X_AXIS) { + return getXPosShockDetected(); + } else if (axis == Y_AXIS) { + return getYPosShockDetected(); + } else if (axis == Z_AXIS) { + return getZPosShockDetected(); } } else if (direction == NEGATIVE) { - switch (axis) { - case X_AXIS: - return getXNegShockDetected(); - - case Y_AXIS: - return getYNegShockDetected(); - - case Z_AXIS: - return getZNegShockDetected(); - - default: - return -1; + if (axis == X_AXIS) { + return getXNegShockDetected(); + } else if (axis == Y_AXIS) { + return getYNegShockDetected(); + } else if (axis == Z_AXIS) { + return getZNegShockDetected(); } - } else { - return -1; } + + return false; } bool CurieImuClass::motionDetected(int axis, int direction) { if (direction == POSITIVE) { - switch (axis) { - case X_AXIS: - return getXPosMotionDetected(); - - case Y_AXIS: - return getYPosMotionDetected(); - - case Z_AXIS: - return getZPosMotionDetected(); - - default: - return -1; + if (axis == X_AXIS) { + return getXPosMotionDetected(); + } else if (axis == Y_AXIS) { + return getYPosMotionDetected(); + } else if (axis == Z_AXIS) { + return getZPosMotionDetected(); } } else if (direction == NEGATIVE) { - switch (axis) { - case X_AXIS: - return getXNegMotionDetected(); - - case Y_AXIS: - return getYNegMotionDetected(); - - case Z_AXIS: - return getZNegMotionDetected(); - - default: - return -1; + if (axis == X_AXIS) { + return getXNegMotionDetected(); + } else if (axis == Y_AXIS) { + return getYNegMotionDetected(); + } else if (axis == Z_AXIS) { + return getZNegMotionDetected(); } - } else { - return -1; } + + return false; } bool CurieImuClass::tapDetected(int axis, int direction) { if (direction == POSITIVE) { - switch (axis) { - case X_AXIS: - return getXPosTapDetected(); - - case Y_AXIS: - return getYPosTapDetected(); - - case Z_AXIS: - return getZPosTapDetected(); - - default: - return -1; + if (axis == X_AXIS) { + return getXPosTapDetected(); + } else if (axis == Y_AXIS) { + return getYPosTapDetected(); + } else if (axis == Z_AXIS) { + return getZPosTapDetected(); } } else if (direction == NEGATIVE) { - switch (axis) { - case X_AXIS: - return getXNegTapDetected(); - - case Y_AXIS: - return getYNegTapDetected(); - - case Z_AXIS: - return getZNegTapDetected(); - - default: - return -1; + if (axis == X_AXIS) { + return getXNegTapDetected(); + } else if (axis == Y_AXIS) { + return getYNegTapDetected(); + } else if (axis == Z_AXIS) { + return getZNegTapDetected(); } - } else { - return -1; } + + return false; } bool CurieImuClass::stepsDetected() From c45ece5a1392b6f0cc7cfdd202b11cc1f87e9d30 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 10:50:17 -0500 Subject: [PATCH 09/18] Rename readAcceleration and readRotation API's to readAccelerometer and readGyro --- libraries/CurieImu/src/CurieImu.cpp | 4 ++-- libraries/CurieImu/src/CurieImu.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieImu/src/CurieImu.cpp index d0a2801d..da9180a1 100644 --- a/libraries/CurieImu/src/CurieImu.cpp +++ b/libraries/CurieImu/src/CurieImu.cpp @@ -461,12 +461,12 @@ void CurieImuClass::readMotionSensor(short& ax, short& ay, short& az, short& gx, getMotion6(&ax, &ay, &az, &gx, &gy, &gz); } -void CurieImuClass::readAcceleration(short& x, short& y, short& z) +void CurieImuClass::readAccelerometer(short& x, short& y, short& z) { getAcceleration(&x, &y, &z); } -void CurieImuClass::readRotation(short& x, short& y, short& z) +void CurieImuClass::readGyro(short& x, short& y, short& z) { getRotation(&x, &y, &z); } diff --git a/libraries/CurieImu/src/CurieImu.h b/libraries/CurieImu/src/CurieImu.h index a5046ae8..a0baefe7 100644 --- a/libraries/CurieImu/src/CurieImu.h +++ b/libraries/CurieImu/src/CurieImu.h @@ -293,8 +293,8 @@ class CurieImuClass : public BMI160Class { void setStepDetectionMode(int mode); void readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz); - void readAcceleration(short& x, short& y, short& z); - void readRotation(short& x, short& y, short& z); + void readAccelerometer(short& x, short& y, short& z); + void readGyro(short& x, short& y, short& z); short readAccelerometer(int axis); short readGyro(int axis); From e8a13f7c205de09fa50e90946e9634ef0d6e1562 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 10:52:38 -0500 Subject: [PATCH 10/18] Add accelerometer only example --- .../examples/Accelerometer/Accelerometer.ino | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 libraries/CurieImu/examples/Accelerometer/Accelerometer.ino diff --git a/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino b/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino new file mode 100644 index 00000000..cb471dfc --- /dev/null +++ b/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino @@ -0,0 +1,94 @@ +/* + =============================================== + Example sketch for CurieIMU library for Intel(R) Curie(TM) devices. + Copyright (c) 2015 Intel Corporation. All rights reserved. + + Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 + class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib + + =============================================== + I2Cdev device library code is placed under the MIT license + Copyright (c) 2011 Jeff Rowberg + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + =============================================== +*/ + +#include "CurieImu.h" + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // Set the accelerometer range to 2G + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_2G); + + Serial.println("About to calibrate accelerometer. Make sure your board is stable and upright"); + delay(5000); + + // start accelerometer + Serial.print("Starting accelerometer calibration..."); + CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0); + CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0); + CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1); + Serial.println(" Done"); + + Serial.println("Enabling accelerometer offset compensation"); + CurieIMU.enableAccelerometerOffset(true); +} + +void loop() { + short int axRaw, ayRaw, azRaw; // raw accelerometer values + float ax, ay, az; + + // read raw accelerometer measurements from device + CurieIMU.readAccelerometer(axRaw, ayRaw, azRaw); + + // convert the raw accelerometer data to G's + ax = convertRawAcceleration(axRaw); + ay = convertRawAcceleration(ayRaw); + az = convertRawAcceleration(azRaw); + + // display tab-separated accelerometer x/y/z values + Serial.print("a:\t"); + Serial.print(ax); + Serial.print("\t"); + Serial.print(ay); + Serial.print("\t"); + Serial.print(az); + Serial.println(); + + // wait 5 seconds + delay(5000); +} + +float convertRawAcceleration(short aRaw) { + // since we are using 2G range + // -2g maps to a raw value of -32768 + // +2g maps to a raw value of 32767 + + float a = (aRaw * 2.0) / 32768.0; + + return a; +} + From cfd445144984d9aaaf3995f257cc5db0e14f04af Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 10:57:14 -0500 Subject: [PATCH 11/18] Correct typo in example, az was printed instead of ax --- .../CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino index 3e6a9f85..98b238ce 100644 --- a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino +++ b/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino @@ -137,7 +137,7 @@ void loop() { // display tab-separated accel/gyro x/y/z values Serial.print("a/g:\t"); - Serial.print(az); + Serial.print(ax); Serial.print("\t"); Serial.print(ay); Serial.print("\t"); From 7e628f15227d24c81c4f42bfe1f3cb351bdb8f78 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 11:12:16 -0500 Subject: [PATCH 12/18] Initial gyroscope example --- libraries/CurieImu/examples/Gyro/Gyro.ino | 84 +++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 libraries/CurieImu/examples/Gyro/Gyro.ino diff --git a/libraries/CurieImu/examples/Gyro/Gyro.ino b/libraries/CurieImu/examples/Gyro/Gyro.ino new file mode 100644 index 00000000..edea47c7 --- /dev/null +++ b/libraries/CurieImu/examples/Gyro/Gyro.ino @@ -0,0 +1,84 @@ +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 on the + Intel(R) Curie(TM) module can be used to read gyroscope data +*/ + +#include "CurieImu.h" + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // Set the accelerometer range to 250 degrees/second + CurieIMU.setGyroRange(CURIE_IMU_GYRO_RANGE_250); + + Serial.println("About to calibrate gyro. Make sure your board is stable and upright"); + delay(5000); + + // start gyro + Serial.print("Starting gyro calibration..."); + CurieIMU.autoCalibrateGyroOffset(); + Serial.println(" Done"); + + Serial.println("Enabling gyro offset compensation"); + CurieIMU.enableGyroOffset(true); +} + +void loop() { + short int gxRaw, gyRaw, gzRaw; // raw gyro values + float gx, gy, gz; + + // read raw gyro measurements from device + CurieIMU.readGyro(gxRaw, gyRaw, gzRaw); + + // convert the raw gyro data to degrees/second + gx = convertRawGyro(gxRaw); + gy = convertRawGyro(gyRaw); + gz = convertRawGyro(gzRaw); + + // display tab-separated gyro x/y/z values + Serial.print("g:\t"); + Serial.print(gx); + Serial.print("\t"); + Serial.print(gy); + Serial.print("\t"); + Serial.print(gz); + Serial.println(); + + // wait 5 seconds + delay(5000); +} + +float convertRawGyro(short gRaw) { + // since we are using 250 degrees/seconds range + // -250 maps to a raw value of -32768 + // +250 maps to a raw value of 32767 + + float g = (gRaw * 250.0) / 32768.0; + + return g; +} + From a50c6b649f093f6d5dbb19e9e376f700976b833e Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 11:12:32 -0500 Subject: [PATCH 13/18] Update example header --- .../examples/Accelerometer/Accelerometer.ino | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino b/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino index cb471dfc..cb5a47aa 100644 --- a/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino +++ b/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino @@ -1,33 +1,25 @@ /* - =============================================== - Example sketch for CurieIMU library for Intel(R) Curie(TM) devices. - Copyright (c) 2015 Intel Corporation. All rights reserved. - - Based on I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 - class by Jeff Rowberg: https://github.com/jrowberg/i2cdevlib - - =============================================== - I2Cdev device library code is placed under the MIT license - Copyright (c) 2011 Jeff Rowberg - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. - =============================================== + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 on the + Intel(R) Curie(TM) module can be used to read accelerometer data */ #include "CurieImu.h" From 6557caf258f6d4cef6048036a6cdf15c4fa2a882 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 11:37:59 -0500 Subject: [PATCH 14/18] Add accelerometer orientation example --- .../AccelerometerOrientation.ino | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino diff --git a/libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino b/libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino new file mode 100644 index 00000000..b8cdf273 --- /dev/null +++ b/libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino @@ -0,0 +1,100 @@ +/* + Copyright (c) 2015 Intel Corporation. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +/* + This sketch example demonstrates how the BMI160 on the + Intel(R) Curie(TM) module can be used to read accelerometer data + and translate it to an orientation +*/ + +#include "CurieImu.h" + +int lastOrientation = - 1; // previous orientation (for comparison) + +void setup() { + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + // initialize device + Serial.println("Initializing IMU device..."); + CurieIMU.begin(); + + // Set the accelerometer range to 2G + CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_2G); +} + +void loop() { +int orientation = - 1; // the board's orientation + String orientationString; // string for printing description of orientation + /* + The orientations of the board: + 0: flat, processor facing up + 1: flat, processor facing down + 2: landscape, analog pins down + 3: landscape, analog pins up + 4: portrait, USB connector up + 5: portrait, USB connector down + */ + // read accelerometer: + short x = CurieIMU.readAccelerometer(X_AXIS); + short y = CurieIMU.readAccelerometer(Y_AXIS); + short z = CurieIMU.readAccelerometer(Z_AXIS); + + // calculate the absolute values, to determine the largest + int absX = abs(x); + int absY = abs(y); + int absZ = abs(z); + + if ( (absZ > absX) && (absZ > absY)) { + // base orientation on Z + if (z > 0) { + orientationString = "up"; + orientation = 0; + } else { + orientationString = "down"; + orientation = 1; + } + } else if ( (absY > absX) && (absY > absZ)) { + // base orientation on Y + if (y > 0) { + orientationString = "digital pins up"; + orientation = 2; + } else { + orientationString = "analog pins up"; + orientation = 3; + } + } else { + // base orientation on X + if (x < 0) { + orientationString = "connector up"; + orientation = 4; + } else { + orientationString = "connector up"; + orientation = 4; + } + } + + // if the orientation has changed, print out a description: + if (orientation != lastOrientation) { + Serial.println(orientationString); + lastOrientation = orientation; + } +} + + From 44fe3307074cb4f5648dbba5718f893b7a4098f4 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 12:10:45 -0500 Subject: [PATCH 15/18] Rename CurieImu to CurieIMU --- .../examples/Accelerometer/Accelerometer.ino | 2 +- .../AccelerometerOrientation.ino | 2 +- .../examples/Gyro/Gyro.ino | 2 +- .../RawImuDataSerial/RawImuDataSerial.ino | 2 +- .../examples/ShockDetect/ShockDetect.ino | 2 +- .../examples/StepCount/StepCount.ino | 2 +- .../examples/TapDetect/TapDetect.ino | 2 +- libraries/{CurieImu => CurieIMU}/keywords.txt | 2 +- .../{CurieImu => CurieIMU}/library.properties | 2 +- .../{CurieImu => CurieIMU}/src/BMI160.cpp | 0 libraries/{CurieImu => CurieIMU}/src/BMI160.h | 0 .../src/CurieIMU.cpp} | 86 +++++++++---------- .../CurieImu.h => CurieIMU/src/CurieIMU.h} | 10 +-- .../src/internal/ss_spi.c | 0 .../src/internal/ss_spi.h | 0 15 files changed, 57 insertions(+), 57 deletions(-) rename libraries/{CurieImu => CurieIMU}/examples/Accelerometer/Accelerometer.ino (99%) rename libraries/{CurieImu => CurieIMU}/examples/AccelerometerOrientation/AccelerometerOrientation.ino (99%) rename libraries/{CurieImu => CurieIMU}/examples/Gyro/Gyro.ino (99%) rename libraries/{CurieImu => CurieIMU}/examples/RawImuDataSerial/RawImuDataSerial.ino (99%) rename libraries/{CurieImu => CurieIMU}/examples/ShockDetect/ShockDetect.ino (99%) rename libraries/{CurieImu => CurieIMU}/examples/StepCount/StepCount.ino (99%) rename libraries/{CurieImu => CurieIMU}/examples/TapDetect/TapDetect.ino (99%) rename libraries/{CurieImu => CurieIMU}/keywords.txt (99%) rename libraries/{CurieImu => CurieIMU}/library.properties (95%) rename libraries/{CurieImu => CurieIMU}/src/BMI160.cpp (100%) rename libraries/{CurieImu => CurieIMU}/src/BMI160.h (100%) rename libraries/{CurieImu/src/CurieImu.cpp => CurieIMU/src/CurieIMU.cpp} (87%) rename libraries/{CurieImu/src/CurieImu.h => CurieIMU/src/CurieIMU.h} (98%) rename libraries/{CurieImu => CurieIMU}/src/internal/ss_spi.c (100%) rename libraries/{CurieImu => CurieIMU}/src/internal/ss_spi.h (100%) diff --git a/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino similarity index 99% rename from libraries/CurieImu/examples/Accelerometer/Accelerometer.ino rename to libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino index cb5a47aa..ad35bc6e 100644 --- a/libraries/CurieImu/examples/Accelerometer/Accelerometer.ino +++ b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used to read accelerometer data */ -#include "CurieImu.h" +#include "CurieIMU.h" void setup() { Serial.begin(9600); // initialize Serial communication diff --git a/libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino b/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino similarity index 99% rename from libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino rename to libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino index b8cdf273..67cc6df0 100644 --- a/libraries/CurieImu/examples/AccelerometerOrientation/AccelerometerOrientation.ino +++ b/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino @@ -23,7 +23,7 @@ and translate it to an orientation */ -#include "CurieImu.h" +#include "CurieIMU.h" int lastOrientation = - 1; // previous orientation (for comparison) diff --git a/libraries/CurieImu/examples/Gyro/Gyro.ino b/libraries/CurieIMU/examples/Gyro/Gyro.ino similarity index 99% rename from libraries/CurieImu/examples/Gyro/Gyro.ino rename to libraries/CurieIMU/examples/Gyro/Gyro.ino index edea47c7..1e14cd47 100644 --- a/libraries/CurieImu/examples/Gyro/Gyro.ino +++ b/libraries/CurieIMU/examples/Gyro/Gyro.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used to read gyroscope data */ -#include "CurieImu.h" +#include "CurieIMU.h" void setup() { Serial.begin(9600); // initialize Serial communication diff --git a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino similarity index 99% rename from libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino rename to libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino index 98b238ce..43823fc2 100644 --- a/libraries/CurieImu/examples/RawImuDataSerial/RawImuDataSerial.ino +++ b/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino @@ -30,7 +30,7 @@ =============================================== */ -#include "CurieImu.h" +#include "CurieIMU.h" short int ax, ay, az; // accelerometer values short int gx, gy, gz; // gyrometer values diff --git a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino b/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino similarity index 99% rename from libraries/CurieImu/examples/ShockDetect/ShockDetect.ino rename to libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino index e787ce4a..311b9fea 100644 --- a/libraries/CurieImu/examples/ShockDetect/ShockDetect.ino +++ b/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used to detect shocks or sudden movements */ -#include "CurieImu.h" +#include "CurieIMU.h" boolean blinkState = false; // state of the LED diff --git a/libraries/CurieImu/examples/StepCount/StepCount.ino b/libraries/CurieIMU/examples/StepCount/StepCount.ino similarity index 99% rename from libraries/CurieImu/examples/StepCount/StepCount.ino rename to libraries/CurieIMU/examples/StepCount/StepCount.ino index 93041feb..5bdaed34 100644 --- a/libraries/CurieImu/examples/StepCount/StepCount.ino +++ b/libraries/CurieIMU/examples/StepCount/StepCount.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used as a Step Counter (pedometer) */ -#include "CurieImu.h" +#include "CurieIMU.h" /* To get an interrupt notification for every step detected, set stepEventsEnabeled to true. Otherwise, the main loop will diff --git a/libraries/CurieImu/examples/TapDetect/TapDetect.ino b/libraries/CurieIMU/examples/TapDetect/TapDetect.ino similarity index 99% rename from libraries/CurieImu/examples/TapDetect/TapDetect.ino rename to libraries/CurieIMU/examples/TapDetect/TapDetect.ino index 69910a7f..859876ab 100644 --- a/libraries/CurieImu/examples/TapDetect/TapDetect.ino +++ b/libraries/CurieIMU/examples/TapDetect/TapDetect.ino @@ -22,7 +22,7 @@ Intel(R) Curie(TM) module can be used to detect tap events */ -#include "CurieImu.h" +#include "CurieIMU.h" void setup() { Serial.begin(9600); diff --git a/libraries/CurieImu/keywords.txt b/libraries/CurieIMU/keywords.txt similarity index 99% rename from libraries/CurieImu/keywords.txt rename to libraries/CurieIMU/keywords.txt index 6a3bb0ca..f19f4ca8 100644 --- a/libraries/CurieImu/keywords.txt +++ b/libraries/CurieIMU/keywords.txt @@ -1,5 +1,5 @@ ####################################### -# Syntax Coloring Map For CureImu +# Syntax Coloring Map For CureIMU ####################################### ####################################### diff --git a/libraries/CurieImu/library.properties b/libraries/CurieIMU/library.properties similarity index 95% rename from libraries/CurieImu/library.properties rename to libraries/CurieIMU/library.properties index b2590fb3..9e82e98a 100644 --- a/libraries/CurieImu/library.properties +++ b/libraries/CurieIMU/library.properties @@ -1,4 +1,4 @@ -name=CurieImu +name=CurieIMU version=1.0 author=Emutex maintainer=Emutex diff --git a/libraries/CurieImu/src/BMI160.cpp b/libraries/CurieIMU/src/BMI160.cpp similarity index 100% rename from libraries/CurieImu/src/BMI160.cpp rename to libraries/CurieIMU/src/BMI160.cpp diff --git a/libraries/CurieImu/src/BMI160.h b/libraries/CurieIMU/src/BMI160.h similarity index 100% rename from libraries/CurieImu/src/BMI160.h rename to libraries/CurieIMU/src/BMI160.h diff --git a/libraries/CurieImu/src/CurieImu.cpp b/libraries/CurieIMU/src/CurieIMU.cpp similarity index 87% rename from libraries/CurieImu/src/CurieImu.cpp rename to libraries/CurieIMU/src/CurieIMU.cpp index da9180a1..cbb56cdf 100644 --- a/libraries/CurieImu/src/CurieImu.cpp +++ b/libraries/CurieIMU/src/CurieIMU.cpp @@ -17,7 +17,7 @@ * */ -#include "CurieImu.h" +#include "CurieIMU.h" #include "internal/ss_spi.h" #include "interrupt.h" @@ -32,7 +32,7 @@ * on the Curie module, before calling BMI160::initialize() to activate the * BMI160 accelerometer and gyroscpoe with default settings. */ -bool CurieImuClass::begin() +bool CurieIMUClass::begin() { /* Configure pin-mux settings on the Intel Curie module to * enable SPI mode usage */ @@ -57,52 +57,52 @@ bool CurieImuClass::begin() return (CURIE_IMU_CHIP_ID == getDeviceID()); } -int CurieImuClass::getGyroRate() +int CurieIMUClass::getGyroRate() { return BMI160Class::getGyroRate(); } -void CurieImuClass::setGyroRate(int rate) +void CurieIMUClass::setGyroRate(int rate) { BMI160Class::setGyroRate(rate); } -int CurieImuClass::getAccelerometerRate() +int CurieIMUClass::getAccelerometerRate() { return getAccelRate(); } -void CurieImuClass::setAccelerometerRate(int rate) +void CurieIMUClass::setAccelerometerRate(int rate) { setAccelRate(rate); } -int CurieImuClass::getGyroRange() +int CurieIMUClass::getGyroRange() { return getFullScaleGyroRange(); } -void CurieImuClass::setGyroRange(int range) +void CurieIMUClass::setGyroRange(int range) { setFullScaleGyroRange(range); } -int CurieImuClass::getAccelerometerRange() +int CurieIMUClass::getAccelerometerRange() { return getFullScaleAccelRange(); } -void CurieImuClass::setAccelerometerRange(int range) +void CurieIMUClass::setAccelerometerRange(int range) { setFullScaleAccelRange(range); } -void CurieImuClass::autoCalibrateGyroOffset() +void CurieIMUClass::autoCalibrateGyroOffset() { BMI160Class::autoCalibrateGyroOffset(); } -void CurieImuClass::autoCalibrateAccelerometerOffset(int axis, int target) +void CurieIMUClass::autoCalibrateAccelerometerOffset(int axis, int target) { switch (axis) { case X_AXIS: @@ -122,27 +122,27 @@ void CurieImuClass::autoCalibrateAccelerometerOffset(int axis, int target) } } -void CurieImuClass::enableGyroOffset(bool state) +void CurieIMUClass::enableGyroOffset(bool state) { setGyroOffsetEnabled(state); } -void CurieImuClass::enableAccelerometerOffset(bool state) +void CurieIMUClass::enableAccelerometerOffset(bool state) { setAccelOffsetEnabled(state); } -bool CurieImuClass::gyroOffsetEnabled() +bool CurieIMUClass::gyroOffsetEnabled() { return getGyroOffsetEnabled(); } -bool CurieImuClass::accelerometerOffsetEnabled() +bool CurieIMUClass::accelerometerOffsetEnabled() { return getAccelOffsetEnabled(); } -int CurieImuClass::getGyroOffset(int axis) +int CurieIMUClass::getGyroOffset(int axis) { if (axis == X_AXIS) { return getXGyroOffset(); @@ -155,7 +155,7 @@ int CurieImuClass::getGyroOffset(int axis) return -1; } -int CurieImuClass::getAccelerometerOffset(int axis) +int CurieIMUClass::getAccelerometerOffset(int axis) { if (axis == X_AXIS) { return getXAccelOffset(); @@ -168,7 +168,7 @@ int CurieImuClass::getAccelerometerOffset(int axis) return -1; } -void CurieImuClass::setGyroOffset(int axis, int offset) +void CurieIMUClass::setGyroOffset(int axis, int offset) { if (axis == X_AXIS) { setXGyroOffset(axis); @@ -179,7 +179,7 @@ void CurieImuClass::setGyroOffset(int axis, int offset) } } -void CurieImuClass::setAccelerometerOffset(int axis, int offset) +void CurieIMUClass::setAccelerometerOffset(int axis, int offset) { if (axis == X_AXIS) { setXAccelOffset(axis); @@ -190,7 +190,7 @@ void CurieImuClass::setAccelerometerOffset(int axis, int offset) } } -int CurieImuClass::getDetectionThreshold(int feature) +int CurieIMUClass::getDetectionThreshold(int feature) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -219,7 +219,7 @@ int CurieImuClass::getDetectionThreshold(int feature) } } -void CurieImuClass::setDetectionThreshold(int feature, int threshold) +void CurieIMUClass::setDetectionThreshold(int feature, int threshold) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -253,7 +253,7 @@ void CurieImuClass::setDetectionThreshold(int feature, int threshold) } } -int CurieImuClass::getDetectionDuration(int feature) +int CurieIMUClass::getDetectionDuration(int feature) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -286,7 +286,7 @@ int CurieImuClass::getDetectionDuration(int feature) } } -void CurieImuClass::setDetectionDuration(int feature, int value) +void CurieIMUClass::setDetectionDuration(int feature, int value) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -326,7 +326,7 @@ void CurieImuClass::setDetectionDuration(int feature, int value) } } -void CurieImuClass::enableInterrupt(int feature, bool enabled) +void CurieIMUClass::enableInterrupt(int feature, bool enabled) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -372,7 +372,7 @@ void CurieImuClass::enableInterrupt(int feature, bool enabled) } } -bool CurieImuClass::interruptEnabled(int feature) +bool CurieIMUClass::interruptEnabled(int feature) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -409,7 +409,7 @@ bool CurieImuClass::interruptEnabled(int feature) } } -int CurieImuClass::getInterruptStatus(int feature) +int CurieIMUClass::getInterruptStatus(int feature) { switch (feature) { case CURIE_IMU_FREEFALL: @@ -446,32 +446,32 @@ int CurieImuClass::getInterruptStatus(int feature) } } -CurieIMUStepMode CurieImuClass::getStepDetectionMode() +CurieIMUStepMode CurieIMUClass::getStepDetectionMode() { return (CurieIMUStepMode)BMI160Class::getStepDetectionMode(); } -void CurieImuClass::setStepDetectionMode(int mode) +void CurieIMUClass::setStepDetectionMode(int mode) { BMI160Class::setStepDetectionMode((BMI160StepMode)mode); } -void CurieImuClass::readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz) +void CurieIMUClass::readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz) { getMotion6(&ax, &ay, &az, &gx, &gy, &gz); } -void CurieImuClass::readAccelerometer(short& x, short& y, short& z) +void CurieIMUClass::readAccelerometer(short& x, short& y, short& z) { getAcceleration(&x, &y, &z); } -void CurieImuClass::readGyro(short& x, short& y, short& z) +void CurieIMUClass::readGyro(short& x, short& y, short& z) { getRotation(&x, &y, &z); } -short CurieImuClass::readAccelerometer(int axis) +short CurieIMUClass::readAccelerometer(int axis) { if (axis == X_AXIS) { return getAccelerationX(); @@ -484,7 +484,7 @@ short CurieImuClass::readAccelerometer(int axis) return 0; } -short CurieImuClass::readGyro(int axis) +short CurieIMUClass::readGyro(int axis) { if (axis == X_AXIS) { return getRotationX(); @@ -497,12 +497,12 @@ short CurieImuClass::readGyro(int axis) return 0; } -short CurieImuClass::readTemperature() +short CurieIMUClass::readTemperature() { return getTemperature(); } -bool CurieImuClass::shockDetected(int axis, int direction) +bool CurieIMUClass::shockDetected(int axis, int direction) { if (direction == POSITIVE) { if (axis == X_AXIS) { @@ -525,7 +525,7 @@ bool CurieImuClass::shockDetected(int axis, int direction) return false; } -bool CurieImuClass::motionDetected(int axis, int direction) +bool CurieIMUClass::motionDetected(int axis, int direction) { if (direction == POSITIVE) { if (axis == X_AXIS) { @@ -548,7 +548,7 @@ bool CurieImuClass::motionDetected(int axis, int direction) return false; } -bool CurieImuClass::tapDetected(int axis, int direction) +bool CurieIMUClass::tapDetected(int axis, int direction) { if (direction == POSITIVE) { if (axis == X_AXIS) { @@ -571,7 +571,7 @@ bool CurieImuClass::tapDetected(int axis, int direction) return false; } -bool CurieImuClass::stepsDetected() +bool CurieIMUClass::stepsDetected() { return getIntStepStatus(); } @@ -580,7 +580,7 @@ bool CurieImuClass::stepsDetected() * to use for accessing device registers. This implementation uses the SPI * bus on the Intel Curie module to communicate with the BMI160. */ -int CurieImuClass::serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt) +int CurieIMUClass::serial_buffer_transfer(uint8_t *buf, unsigned tx_cnt, unsigned rx_cnt) { int flags, status; @@ -614,7 +614,7 @@ void bmi160_pin1_isr(void) /** Stores a user callback, and enables PIN1 interrupts from the * BMI160 module. */ -void CurieImuClass::attachInterrupt(void (*callback)(void)) +void CurieIMUClass::attachInterrupt(void (*callback)(void)) { gpio_cfg_data_t cfg; @@ -636,7 +636,7 @@ void CurieImuClass::attachInterrupt(void (*callback)(void)) /** Disables PIN1 interrupts from the BMI160 module. */ -void CurieImuClass::detachInterrupt(void) +void CurieIMUClass::detachInterrupt(void) { setIntEnabled(false); @@ -644,4 +644,4 @@ void CurieImuClass::detachInterrupt(void) } /* Pre-instantiated Object for this class */ -CurieImuClass CurieIMU; +CurieIMUClass CurieIMU; diff --git a/libraries/CurieImu/src/CurieImu.h b/libraries/CurieIMU/src/CurieIMU.h similarity index 98% rename from libraries/CurieImu/src/CurieImu.h rename to libraries/CurieIMU/src/CurieIMU.h index a0baefe7..dbc2931b 100644 --- a/libraries/CurieImu/src/CurieImu.h +++ b/libraries/CurieIMU/src/CurieIMU.h @@ -235,11 +235,11 @@ typedef enum { CURIE_IMU_ZERO_MOTION_DURATION_409_60S = BMI160_ZERO_MOTION_DURATION_409_60S, CURIE_IMU_ZERO_MOTION_DURATION_419_84S = BMI160_ZERO_MOTION_DURATION_419_84S, CURIE_IMU_ZERO_MOTION_DURATION_430_08S = BMI160_ZERO_MOTION_DURATION_430_08S -} CurieImuZeroMotionDuration; +} CurieIMUZeroMotionDuration; -/* Note that this CurieImuClass class inherits methods from the BMI160Class which +/* Note that this CurieIMUClass class inherits methods from the BMI160Class which * is defined in BMI160.h. BMI160Class provides methods for configuring and - * accessing features of the BMI160 IMU device. This CurieImuClass extends that + * accessing features of the BMI160 IMU device. This CurieIMUClass extends that * class with implementation of details specific to the integration of the BMI160 * device on the Intel Curie module, such as the serial communication interface * and interrupt signalling. @@ -247,7 +247,7 @@ typedef enum { * Please refer to the respective .cpp files for documentation on each of the * methods provided by these classes. */ -class CurieImuClass : public BMI160Class { +class CurieIMUClass : public BMI160Class { friend void bmi160_pin1_isr(void); public: @@ -314,6 +314,6 @@ class CurieImuClass : public BMI160Class { void (*_user_callback)(void); }; -extern CurieImuClass CurieIMU; +extern CurieIMUClass CurieIMU; #endif /* _CURIEIMU_H_ */ diff --git a/libraries/CurieImu/src/internal/ss_spi.c b/libraries/CurieIMU/src/internal/ss_spi.c similarity index 100% rename from libraries/CurieImu/src/internal/ss_spi.c rename to libraries/CurieIMU/src/internal/ss_spi.c diff --git a/libraries/CurieImu/src/internal/ss_spi.h b/libraries/CurieIMU/src/internal/ss_spi.h similarity index 100% rename from libraries/CurieImu/src/internal/ss_spi.h rename to libraries/CurieIMU/src/internal/ss_spi.h From c84af94b39a1efbf3afee132ac49469935b0aa7e Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 13:32:14 -0500 Subject: [PATCH 16/18] Remove call to setIntEnabled, attachInterrupt enables interrupts --- libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino | 3 --- libraries/CurieIMU/examples/StepCount/StepCount.ino | 1 - libraries/CurieIMU/examples/TapDetect/TapDetect.ino | 3 --- 3 files changed, 7 deletions(-) diff --git a/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino b/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino index 311b9fea..fe96941c 100644 --- a/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino +++ b/libraries/CurieIMU/examples/ShockDetect/ShockDetect.ino @@ -38,9 +38,6 @@ void setup() { CurieIMU.setDetectionDuration(CURIE_IMU_SHOCK, CURIE_IMU_TAP_SHOCK_DURATION_50MS); // 50ms CurieIMU.enableInterrupt(CURIE_IMU_SHOCK, true); - /* Enable Interrupts Notifications */ - CurieIMU.setIntEnabled(true); - Serial.println("IMU initialisation complete, waiting for events..."); } diff --git a/libraries/CurieIMU/examples/StepCount/StepCount.ino b/libraries/CurieIMU/examples/StepCount/StepCount.ino index 5bdaed34..664efdb8 100644 --- a/libraries/CurieIMU/examples/StepCount/StepCount.ino +++ b/libraries/CurieIMU/examples/StepCount/StepCount.ino @@ -53,7 +53,6 @@ void setup() { // step event handler: CurieIMU.attachInterrupt(eventCallback); CurieIMU.enableInterrupt(CURIE_IMU_STEP, true); // turn on step detection - CurieIMU.setIntEnabled(true); // enable interrupts Serial.println("IMU initialisation complete, waiting for events..."); } diff --git a/libraries/CurieIMU/examples/TapDetect/TapDetect.ino b/libraries/CurieIMU/examples/TapDetect/TapDetect.ino index 859876ab..e0ffa2b4 100644 --- a/libraries/CurieIMU/examples/TapDetect/TapDetect.ino +++ b/libraries/CurieIMU/examples/TapDetect/TapDetect.ino @@ -43,9 +43,6 @@ void setup() { // Enable Double-Tap detection CurieIMU.enableInterrupt(CURIE_IMU_DOUBLE_TAP, true); - // Enable Interrupts Notifications - CurieIMU.setIntEnabled(true); - Serial.println("IMU initialisation complete, waiting for events..."); } From af28e53e5b3280f4188cc2c379bacf24cd454bb7 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 13:43:50 -0500 Subject: [PATCH 17/18] Use int for accelerometer and gyro API's instead of short --- .../examples/Accelerometer/Accelerometer.ino | 4 +- .../AccelerometerOrientation.ino | 10 ++--- libraries/CurieIMU/examples/Gyro/Gyro.ino | 4 +- .../RawImuDataSerial/RawImuDataSerial.ino | 4 +- libraries/CurieIMU/src/CurieIMU.cpp | 39 ++++++++++++++----- libraries/CurieIMU/src/CurieIMU.h | 12 +++--- 6 files changed, 47 insertions(+), 26 deletions(-) diff --git a/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino index ad35bc6e..2b70151b 100644 --- a/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino +++ b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino @@ -50,7 +50,7 @@ void setup() { } void loop() { - short int axRaw, ayRaw, azRaw; // raw accelerometer values + int axRaw, ayRaw, azRaw; // raw accelerometer values float ax, ay, az; // read raw accelerometer measurements from device @@ -74,7 +74,7 @@ void loop() { delay(5000); } -float convertRawAcceleration(short aRaw) { +float convertRawAcceleration(int aRaw) { // since we are using 2G range // -2g maps to a raw value of -32768 // +2g maps to a raw value of 32767 diff --git a/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino b/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino index 67cc6df0..a3fcf006 100644 --- a/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino +++ b/libraries/CurieIMU/examples/AccelerometerOrientation/AccelerometerOrientation.ino @@ -52,9 +52,9 @@ int orientation = - 1; // the board's orientation 5: portrait, USB connector down */ // read accelerometer: - short x = CurieIMU.readAccelerometer(X_AXIS); - short y = CurieIMU.readAccelerometer(Y_AXIS); - short z = CurieIMU.readAccelerometer(Z_AXIS); + int x = CurieIMU.readAccelerometer(X_AXIS); + int y = CurieIMU.readAccelerometer(Y_AXIS); + int z = CurieIMU.readAccelerometer(Z_AXIS); // calculate the absolute values, to determine the largest int absX = abs(x); @@ -85,8 +85,8 @@ int orientation = - 1; // the board's orientation orientationString = "connector up"; orientation = 4; } else { - orientationString = "connector up"; - orientation = 4; + orientationString = "connector down"; + orientation = 5; } } diff --git a/libraries/CurieIMU/examples/Gyro/Gyro.ino b/libraries/CurieIMU/examples/Gyro/Gyro.ino index 1e14cd47..fd0a47ac 100644 --- a/libraries/CurieIMU/examples/Gyro/Gyro.ino +++ b/libraries/CurieIMU/examples/Gyro/Gyro.ino @@ -48,7 +48,7 @@ void setup() { } void loop() { - short int gxRaw, gyRaw, gzRaw; // raw gyro values + int gxRaw, gyRaw, gzRaw; // raw gyro values float gx, gy, gz; // read raw gyro measurements from device @@ -72,7 +72,7 @@ void loop() { delay(5000); } -float convertRawGyro(short gRaw) { +float convertRawGyro(int gRaw) { // since we are using 250 degrees/seconds range // -250 maps to a raw value of -32768 // +250 maps to a raw value of 32767 diff --git a/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino b/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino index 43823fc2..3ef1ac46 100644 --- a/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino +++ b/libraries/CurieIMU/examples/RawImuDataSerial/RawImuDataSerial.ino @@ -31,8 +31,8 @@ */ #include "CurieIMU.h" -short int ax, ay, az; // accelerometer values -short int gx, gy, gz; // gyrometer values +int ax, ay, az; // accelerometer values +int gx, gy, gz; // gyrometer values const int ledPin = 13; // activity LED pin boolean blinkState = false; // state of the LED diff --git a/libraries/CurieIMU/src/CurieIMU.cpp b/libraries/CurieIMU/src/CurieIMU.cpp index cbb56cdf..39ba0c03 100644 --- a/libraries/CurieIMU/src/CurieIMU.cpp +++ b/libraries/CurieIMU/src/CurieIMU.cpp @@ -456,22 +456,43 @@ void CurieIMUClass::setStepDetectionMode(int mode) BMI160Class::setStepDetectionMode((BMI160StepMode)mode); } -void CurieIMUClass::readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz) +void CurieIMUClass::readMotionSensor(int& ax, int& ay, int& az, int& gx, int& gy, int& gz) { - getMotion6(&ax, &ay, &az, &gx, &gy, &gz); + short sax, say, saz, sgx, sgy, sgz; + + getMotion6(&sax, &say, &saz, &sgx, &sgy, &sgz); + + ax = sax; + ay = say; + az = saz; + gx = sgx; + gy = sgy; + gz = sgz; } -void CurieIMUClass::readAccelerometer(short& x, short& y, short& z) +void CurieIMUClass::readAccelerometer(int& x, int& y, int& z) { - getAcceleration(&x, &y, &z); + short sx, sy, sz; + + getAcceleration(&sx, &sy, &sz); + + x = sx; + y = sy; + z = sz; } -void CurieIMUClass::readGyro(short& x, short& y, short& z) +void CurieIMUClass::readGyro(int& x, int& y, int& z) { - getRotation(&x, &y, &z); + short sx, sy, sz; + + getRotation(&sx, &sy, &sz); + + x = sx; + y = sy; + z = sz; } -short CurieIMUClass::readAccelerometer(int axis) +int CurieIMUClass::readAccelerometer(int axis) { if (axis == X_AXIS) { return getAccelerationX(); @@ -484,7 +505,7 @@ short CurieIMUClass::readAccelerometer(int axis) return 0; } -short CurieIMUClass::readGyro(int axis) +int CurieIMUClass::readGyro(int axis) { if (axis == X_AXIS) { return getRotationX(); @@ -497,7 +518,7 @@ short CurieIMUClass::readGyro(int axis) return 0; } -short CurieIMUClass::readTemperature() +int CurieIMUClass::readTemperature() { return getTemperature(); } diff --git a/libraries/CurieIMU/src/CurieIMU.h b/libraries/CurieIMU/src/CurieIMU.h index dbc2931b..31f42e6a 100644 --- a/libraries/CurieIMU/src/CurieIMU.h +++ b/libraries/CurieIMU/src/CurieIMU.h @@ -292,13 +292,13 @@ class CurieIMUClass : public BMI160Class { CurieIMUStepMode getStepDetectionMode(); void setStepDetectionMode(int mode); - void readMotionSensor(short& ax, short& ay, short& az, short& gx, short& gy, short& gz); - void readAccelerometer(short& x, short& y, short& z); - void readGyro(short& x, short& y, short& z); + void readMotionSensor(int& ax, int& ay, int& az, int& gx, int& gy, int& gz); + void readAccelerometer(int& x, int& y, int& z); + void readGyro(int& x, int& y, int& z); - short readAccelerometer(int axis); - short readGyro(int axis); - short readTemperature(); + int readAccelerometer(int axis); + int readGyro(int axis); + int readTemperature(); bool shockDetected(int axis, int direction); bool motionDetected(int axis, int direction); From 6fc749d08dfe770992fe3f50d3073260960c98d9 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Mon, 21 Dec 2015 13:46:04 -0500 Subject: [PATCH 18/18] Remove calibration steps from accelerometer and gyro examples --- .../examples/Accelerometer/Accelerometer.ino | 13 ------------- libraries/CurieIMU/examples/Gyro/Gyro.ino | 11 ----------- 2 files changed, 24 deletions(-) diff --git a/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino index 2b70151b..87070456 100644 --- a/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino +++ b/libraries/CurieIMU/examples/Accelerometer/Accelerometer.ino @@ -34,19 +34,6 @@ void setup() { // Set the accelerometer range to 2G CurieIMU.setAccelerometerRange(CURIE_IMU_ACCELEROMETER_RANGE_2G); - - Serial.println("About to calibrate accelerometer. Make sure your board is stable and upright"); - delay(5000); - - // start accelerometer - Serial.print("Starting accelerometer calibration..."); - CurieIMU.autoCalibrateAccelerometerOffset(X_AXIS, 0); - CurieIMU.autoCalibrateAccelerometerOffset(Y_AXIS, 0); - CurieIMU.autoCalibrateAccelerometerOffset(Z_AXIS, 1); - Serial.println(" Done"); - - Serial.println("Enabling accelerometer offset compensation"); - CurieIMU.enableAccelerometerOffset(true); } void loop() { diff --git a/libraries/CurieIMU/examples/Gyro/Gyro.ino b/libraries/CurieIMU/examples/Gyro/Gyro.ino index fd0a47ac..07371f24 100644 --- a/libraries/CurieIMU/examples/Gyro/Gyro.ino +++ b/libraries/CurieIMU/examples/Gyro/Gyro.ino @@ -34,17 +34,6 @@ void setup() { // Set the accelerometer range to 250 degrees/second CurieIMU.setGyroRange(CURIE_IMU_GYRO_RANGE_250); - - Serial.println("About to calibrate gyro. Make sure your board is stable and upright"); - delay(5000); - - // start gyro - Serial.print("Starting gyro calibration..."); - CurieIMU.autoCalibrateGyroOffset(); - Serial.println(" Done"); - - Serial.println("Enabling gyro offset compensation"); - CurieIMU.enableGyroOffset(true); } void loop() {