diff --git a/include/interfaces/CMakeLists.txt b/include/interfaces/CMakeLists.txt index 9e314723..f0b93892 100644 --- a/include/interfaces/CMakeLists.txt +++ b/include/interfaces/CMakeLists.txt @@ -24,6 +24,7 @@ set (module_hpp iClock.hpp iMotion.hpp iPressure.hpp iTemperature.hpp + iAcceleration.hpp ) # Install interfaces headers a bit differently install (FILES ${module_hpp} DESTINATION include/upm/interfaces COMPONENT ${libname}) diff --git a/include/interfaces/iAcceleration.hpp b/include/interfaces/iAcceleration.hpp new file mode 100644 index 00000000..dd95e460 --- /dev/null +++ b/include/interfaces/iAcceleration.hpp @@ -0,0 +1,47 @@ +/* + * Author: Serban Waltter + * Copyright (c) 2018 Intel Corporation. + * + * 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. + */ + +#pragma once + +#include + +namespace upm +{ + /** + * @brief Interface for acceleration sensors + */ + class iAcceleration + { + public: + virtual ~iAcceleration() {} + + /** + * Get acceleration values on X, Y and Z axis. + * v[0] = X, v[1] = Y, v[2] = Z + * + * @return vector of 3 floats containing acceleration on each axis + */ + virtual std::vector getAcceleration() = 0; + }; +} // upm diff --git a/include/interfaces/new_interfaces.cxx b/include/interfaces/new_interfaces.cxx index d9310b7e..72b0defb 100644 --- a/include/interfaces/new_interfaces.cxx +++ b/include/interfaces/new_interfaces.cxx @@ -13,3 +13,4 @@ #include "iMotion.hpp" #include "iPressure.hpp" #include "iTemperature.hpp" +#include "iAcceleration.hpp" diff --git a/include/interfaces/new_interfaces.i b/include/interfaces/new_interfaces.i index e53dba8f..4c8e2d59 100644 --- a/include/interfaces/new_interfaces.i +++ b/include/interfaces/new_interfaces.i @@ -20,6 +20,7 @@ %interface_impl (upm::iMotion); %interface_impl (upm::iPressure); %interface_impl (upm::iTemperature); + %interface_impl (upm::iAcceleration); #endif %{ @@ -37,6 +38,7 @@ #include "iMotion.hpp" #include "iPressure.hpp" #include "iTemperature.hpp" + #include "iAcceleration.hpp" %} %include "iClock.hpp" @@ -53,6 +55,7 @@ %include "iMotion.hpp" %include "iPressure.hpp" %include "iTemperature.hpp" +%include "iAcceleration.hpp" /* Java-specific SWIG syntax */ #ifdef SWIGJAVA diff --git a/src/adxl335/adxl335.cxx b/src/adxl335/adxl335.cxx index 3a564c9e..7b3a2429 100644 --- a/src/adxl335/adxl335.cxx +++ b/src/adxl335/adxl335.cxx @@ -106,6 +106,28 @@ std::vector ADXL335::acceleration() return v; } +std::vector ADXL335::getAcceleration() +{ + std::vector v(3); + + int x, y, z; + float xVolts, yVolts, zVolts; + + x = mraa_aio_read(m_aioX); + y = mraa_aio_read(m_aioY); + z = mraa_aio_read(m_aioZ); + + xVolts = float(x) * m_aref / 1024.0; + yVolts = float(y) * m_aref / 1024.0; + zVolts = float(z) * m_aref / 1024.0; + + v[0] = (xVolts - m_zeroX) / ADXL335_SENSITIVITY; + v[1] = (yVolts - m_zeroY) / ADXL335_SENSITIVITY; + v[2] = (zVolts - m_zeroZ) / ADXL335_SENSITIVITY; + + return v; +} + void ADXL335::calibrate() { // make sure the sensor is still before running calibration. diff --git a/src/adxl335/adxl335.hpp b/src/adxl335/adxl335.hpp index 9a840211..f7657457 100644 --- a/src/adxl335/adxl335.hpp +++ b/src/adxl335/adxl335.hpp @@ -30,6 +30,8 @@ #include #include +#include + #define ADXL335_DEFAULT_AREF 5.0 #define ADXL335_SENSITIVITY 0.25 // 0.25v/g @@ -60,7 +62,7 @@ namespace upm { * @image html adxl335.jpg * @snippet adxl335.cxx Interesting */ - class ADXL335 { + class ADXL335: virtual public iAcceleration { public: /** * ADXL335 constructor @@ -130,6 +132,13 @@ namespace upm { */ std::vector acceleration(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * While the sensor is still, measures the X-axis, Y-axis, and Z-axis * values and uses those values as the zero values. diff --git a/src/adxl345/adxl345.cxx b/src/adxl345/adxl345.cxx index 878683ea..c4868a6e 100644 --- a/src/adxl345/adxl345.cxx +++ b/src/adxl345/adxl345.cxx @@ -131,6 +131,21 @@ Adxl345::getAcceleration() return &m_accel[0]; } +// std::vector +// Adxl345::getAcceleration() +// { +// update(); + +// std::vector v(3); + +// for(int i = 0; i < 3; i++) +// { +// v[i] = m_rawaccel[i] * m_offsets[i]; +// } + +// return v; +// } + int16_t* Adxl345::getRawValues() { diff --git a/src/adxl345/adxl345.hpp b/src/adxl345/adxl345.hpp index 8ff243f6..6bbd6661 100644 --- a/src/adxl345/adxl345.hpp +++ b/src/adxl345/adxl345.hpp @@ -25,6 +25,8 @@ #include +// #include + #define READ_BUFFER_LENGTH 6 namespace upm { @@ -57,6 +59,7 @@ namespace upm { * @image html adxl345.jpeg * @snippet adxl345.cxx Interesting */ +// class Adxl345: virtual public iAcceleration { class Adxl345 { public: /** @@ -78,6 +81,13 @@ public: */ float* getAcceleration(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + // virtual std::vector getAcceleration(); + /** * Returns a pointer to an int[3] that contains the raw register values * for X, Y, and Z diff --git a/src/bma220/bma220.cxx b/src/bma220/bma220.cxx index 113fc39f..57bdbcd8 100644 --- a/src/bma220/bma220.cxx +++ b/src/bma220/bma220.cxx @@ -174,6 +174,18 @@ std::vector BMA220::getAccelerometer() return v; } +std::vector BMA220::getAcceleration() +{ + std::vector v(3); + + update(); + v[0] = m_accelX / m_accelScale; + v[1] = m_accelY / m_accelScale; + v[2] = m_accelZ / m_accelScale; + + return v; +} + uint8_t BMA220::getChipID() { return readReg(REG_CHIPID); diff --git a/src/bma220/bma220.hpp b/src/bma220/bma220.hpp index a188f6e2..094c3f62 100644 --- a/src/bma220/bma220.hpp +++ b/src/bma220/bma220.hpp @@ -29,6 +29,8 @@ #include #include +#include + #define BMA220_I2C_BUS 0 #define BMA220_DEFAULT_ADDR 0x0a @@ -68,7 +70,7 @@ namespace upm { * @snippet bma220.cxx Interesting */ - class BMA220 { + class BMA220: virtual public iAcceleration { public: // NOTE: reserved registers must not be written into or read from. @@ -547,6 +549,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * set the filtering configuration * diff --git a/src/bma250e/bma250e.cxx b/src/bma250e/bma250e.cxx index 9575d5cc..e219dbe9 100644 --- a/src/bma250e/bma250e.cxx +++ b/src/bma250e/bma250e.cxx @@ -114,6 +114,14 @@ std::vector BMA250E::getAccelerometer() return std::vector(v, v+3); } +std::vector BMA250E::getAcceleration() +{ + std::vector v(3); + + bma250e_get_accelerometer(m_bma250e, &v[0], &v[1], &v[2]); + return v; +} + float BMA250E::getTemperature(bool fahrenheit) { float temperature = bma250e_get_temperature(m_bma250e); diff --git a/src/bma250e/bma250e.hpp b/src/bma250e/bma250e.hpp index 5ebaba71..fb4e6b21 100644 --- a/src/bma250e/bma250e.hpp +++ b/src/bma250e/bma250e.hpp @@ -31,6 +31,8 @@ #include #include "bma250e.h" +#include + namespace upm { /** @@ -73,7 +75,7 @@ namespace upm { * @snippet bma250e.cxx Interesting */ - class BMA250E { + class BMA250E: virtual public iAcceleration { public: /** @@ -138,6 +140,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return the current measured temperature. Note, this is not * ambient temperature. update() must have been called prior to diff --git a/src/bmi160/bmi160.cxx b/src/bmi160/bmi160.cxx index 79426e8e..257c218e 100644 --- a/src/bmi160/bmi160.cxx +++ b/src/bmi160/bmi160.cxx @@ -84,6 +84,14 @@ float *BMI160::getAccelerometer() return values; } +std::vector BMI160::getAcceleration() +{ + std::vector v(3); + + bmi160_get_accelerometer(m_bmi160, &v[0], &v[1], &v[2]); + return v; +} + float *BMI160::getGyroscope() { static float values[3]; // x, y, and then z diff --git a/src/bmi160/bmi160.hpp b/src/bmi160/bmi160.hpp index ad135845..f3ebdee9 100644 --- a/src/bmi160/bmi160.hpp +++ b/src/bmi160/bmi160.hpp @@ -25,6 +25,8 @@ #include #include "bmi160.h" +#include + #define BMI160_I2C_BUS 0 #define BMI160_DEFAULT_I2C_ADDR 0x69 @@ -72,7 +74,7 @@ namespace upm { * * @snippet bmi160.cxx Interesting */ - class BMI160 { + class BMI160: virtual public iAcceleration { public: /** @@ -142,6 +144,13 @@ namespace upm { */ void getAccelerometer(float *x, float *y, float *z); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Get the Gyroscope values. This function returns a pointer to 3 * floating point values: X, Y, and Z, in that order. The values diff --git a/src/bmx055/bmc150.cxx b/src/bmx055/bmc150.cxx index 8b8af2e6..ca5d36eb 100644 --- a/src/bmx055/bmc150.cxx +++ b/src/bmx055/bmc150.cxx @@ -101,6 +101,14 @@ std::vector BMC150::getAccelerometer() return {0, 0, 0}; } +std::vector BMC150::getAcceleration() +{ + if (m_accel) + return m_accel->getAcceleration(); + else + return {0, 0, 0}; +} + void BMC150::getMagnetometer(float *x, float *y, float *z) { if (m_mag) diff --git a/src/bmx055/bmc150.hpp b/src/bmx055/bmc150.hpp index 1f9233d0..8a084883 100644 --- a/src/bmx055/bmc150.hpp +++ b/src/bmx055/bmc150.hpp @@ -29,6 +29,8 @@ #include "bma250e.hpp" #include "bmm150.hpp" +#include + #define BMC150_DEFAULT_BUS 0 #define BMC150_DEFAULT_ACC_ADDR 0x10 #define BMC150_DEFAULT_MAG_ADDR 0x12 @@ -70,7 +72,7 @@ namespace upm { * @snippet bmx055-bmc150.cxx Interesting */ - class BMC150 { + class BMC150: virtual public iAcceleration { public: /** * BMC150 constructor. @@ -164,6 +166,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return magnetometer data in micro-Teslas (uT). update() must * have been called prior to calling this method. diff --git a/src/bmx055/bmi055.cxx b/src/bmx055/bmi055.cxx index f8edd973..0a65e2ce 100644 --- a/src/bmx055/bmi055.cxx +++ b/src/bmx055/bmi055.cxx @@ -103,6 +103,14 @@ std::vector BMI055::getAccelerometer() return {0, 0, 0}; } +std::vector BMI055::getAcceleration() +{ + if (m_accel) + return m_accel->getAcceleration(); + else + return {0, 0, 0}; +} + void BMI055::getGyroscope(float *x, float *y, float *z) { if (m_gyro) diff --git a/src/bmx055/bmi055.hpp b/src/bmx055/bmi055.hpp index e2c50952..751246dc 100644 --- a/src/bmx055/bmi055.hpp +++ b/src/bmx055/bmi055.hpp @@ -31,6 +31,8 @@ #include "bma250e.hpp" #include "bmg160.hpp" +#include + namespace upm { /** @@ -64,7 +66,7 @@ namespace upm { * @snippet bmx055-bmi055.cxx Interesting */ - class BMI055 { + class BMI055: virtual public iAcceleration { public: /** * BMI055 constructor. @@ -152,6 +154,13 @@ namespace upm { */ void getAccelerometer(float *x, float *y, float *z); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return accelerometer data in gravities in the form of a * floating point vector. update() must have been called prior to diff --git a/src/bmx055/bmx055.cxx b/src/bmx055/bmx055.cxx index 4fbc5c70..79bca090 100644 --- a/src/bmx055/bmx055.cxx +++ b/src/bmx055/bmx055.cxx @@ -121,6 +121,14 @@ std::vector BMX055::getAccelerometer() return {0, 0, 0}; } +std::vector BMX055::getAcceleration() +{ + if (m_accel) + return m_accel->getAcceleration(); + else + return {0, 0, 0}; +} + void BMX055::getGyroscope(float *x, float *y, float *z) { if (m_gyro) diff --git a/src/bmx055/bmx055.hpp b/src/bmx055/bmx055.hpp index 333cd44a..19674516 100644 --- a/src/bmx055/bmx055.hpp +++ b/src/bmx055/bmx055.hpp @@ -32,6 +32,8 @@ #include "bmg160.hpp" #include "bmm150.hpp" +#include + #define BMX055_DEFAULT_MAG_I2C_ADDR 0x12 namespace upm { @@ -76,7 +78,7 @@ namespace upm { * @snippet bmx055.cxx Interesting */ - class BMX055 { + class BMX055: virtual public iAcceleration { public: /** * BMX055 constructor. @@ -195,6 +197,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return gyroscope data in degrees per second. update() must * have been called prior to calling this method. diff --git a/src/bno055/bno055.cxx b/src/bno055/bno055.cxx index 2f9a53f8..510067a2 100644 --- a/src/bno055/bno055.cxx +++ b/src/bno055/bno055.cxx @@ -388,6 +388,14 @@ vector BNO055::getAccelerometer() return vector(v, v+3); } +std::vector BNO055::getAcceleration() +{ + std::vector v(3); + + bno055_get_accelerometer(m_bno055, &v[0], &v[1], &v[2]); + return v; +} + void BNO055::getMagnetometer(float *x, float *y, float *z) { bno055_get_magnetometer(m_bno055, x, y, z); diff --git a/src/bno055/bno055.hpp b/src/bno055/bno055.hpp index 744523d8..d430b007 100644 --- a/src/bno055/bno055.hpp +++ b/src/bno055/bno055.hpp @@ -28,6 +28,8 @@ #include #include "bno055.h" +#include + namespace upm { /** @@ -100,7 +102,7 @@ namespace upm { * @snippet bno055.cxx Interesting */ - class BNO055 { + class BNO055: virtual public iAcceleration { public: /** @@ -420,6 +422,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return uncompensated magnetometer data (non-fusion). In fusion * modes, this data will be of little value. The returned values diff --git a/src/h3lis331dl/h3lis331dl.cxx b/src/h3lis331dl/h3lis331dl.cxx index 58a1f01d..b9ef83b3 100644 --- a/src/h3lis331dl/h3lis331dl.cxx +++ b/src/h3lis331dl/h3lis331dl.cxx @@ -602,8 +602,14 @@ void H3LIS331DL::getXYZ(int *x, int *y, int*z) std::vector H3LIS331DL::getAcceleration() { + update(); std::vector v(3); - getAcceleration(&v[0], &v[1], &v[2]); + + const float gains = 0.003; // Seeed magic number? + + v[0] = float(m_rawX - m_adjX) * gains; + v[1] = float(m_rawY - m_adjY) * gains; + v[2] = float(m_rawZ - m_adjZ) * gains; return v; } diff --git a/src/h3lis331dl/h3lis331dl.hpp b/src/h3lis331dl/h3lis331dl.hpp index 903a4889..e4461031 100644 --- a/src/h3lis331dl/h3lis331dl.hpp +++ b/src/h3lis331dl/h3lis331dl.hpp @@ -28,6 +28,8 @@ #include #include +#include + #define H3LIS331DL_I2C_BUS 0 #define H3LIS331DL_DEFAULT_I2C_ADDR 0x18 @@ -56,7 +58,7 @@ namespace upm { * @image html h3lis331dl.jpg * @snippet h3lis331dl.cxx Interesting */ - class H3LIS331DL { + class H3LIS331DL: virtual public iAcceleration { public: /** diff --git a/src/lis2ds12/lis2ds12.cxx b/src/lis2ds12/lis2ds12.cxx index 086df551..6c1383ac 100644 --- a/src/lis2ds12/lis2ds12.cxx +++ b/src/lis2ds12/lis2ds12.cxx @@ -108,6 +108,14 @@ std::vector LIS2DS12::getAccelerometer() return std::vector(v, v+3); } +std::vector LIS2DS12::getAcceleration() +{ + std::vector v(3); + + lis2ds12_get_accelerometer(m_lis2ds12, &v[0], &v[1], &v[2]); + return v; +} + float LIS2DS12::getTemperature(bool fahrenheit) { float temperature = lis2ds12_get_temperature(m_lis2ds12); diff --git a/src/lis2ds12/lis2ds12.hpp b/src/lis2ds12/lis2ds12.hpp index 4534695c..77666523 100644 --- a/src/lis2ds12/lis2ds12.hpp +++ b/src/lis2ds12/lis2ds12.hpp @@ -31,6 +31,8 @@ #include #include "lis2ds12.h" +#include + namespace upm { /** @@ -70,7 +72,7 @@ namespace upm { * @snippet lis2ds12.cxx Interesting */ - class LIS2DS12 { + class LIS2DS12: virtual public iAcceleration { public: /** @@ -135,6 +137,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return the current measured temperature. Note, this is not * ambient temperature. update() must have been called prior to diff --git a/src/lis3dh/lis3dh.cxx b/src/lis3dh/lis3dh.cxx index 64049ce4..c90b348f 100644 --- a/src/lis3dh/lis3dh.cxx +++ b/src/lis3dh/lis3dh.cxx @@ -234,6 +234,15 @@ LIS3DH::getAccelerometer() return std::vector(v, v + 3); } +std::vector +LIS3DH::getAcceleration() +{ + std::vector v(3); + + lis3dh_get_accelerometer(m_lis3dh, &v[0], &v[1], &v[2]); + return v; +} + float LIS3DH::getTemperature(bool fahrenheit) { diff --git a/src/lis3dh/lis3dh.hpp b/src/lis3dh/lis3dh.hpp index 4e311586..21000f6b 100644 --- a/src/lis3dh/lis3dh.hpp +++ b/src/lis3dh/lis3dh.hpp @@ -35,6 +35,8 @@ #include "lis3dh.h" #include +#include + namespace upm { /** @@ -72,7 +74,7 @@ namespace upm * @snippet lis3dh.cxx Interesting */ -class LIS3DH +class LIS3DH: virtual public iAcceleration { public: /** @@ -304,6 +306,13 @@ class LIS3DH */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return the current measured temperature. Note, this is not * ambient temperature. update() must have been called prior to diff --git a/src/lsm303agr/lsm303agr.cxx b/src/lsm303agr/lsm303agr.cxx index 74b0cbdf..b9e3bb6e 100644 --- a/src/lsm303agr/lsm303agr.cxx +++ b/src/lsm303agr/lsm303agr.cxx @@ -109,6 +109,14 @@ std::vector LSM303AGR::getAccelerometer() return std::vector(v, v+3); } +std::vector LSM303AGR::getAcceleration() +{ + std::vector v(3); + + lsm303agr_get_accelerometer(m_lsm303agr, &v[0], &v[1], &v[2]); + return v; +} + float LSM303AGR::getTemperature() { return lsm303agr_get_temperature(m_lsm303agr); diff --git a/src/lsm303agr/lsm303agr.hpp b/src/lsm303agr/lsm303agr.hpp index 35bd43ab..11dd9637 100644 --- a/src/lsm303agr/lsm303agr.hpp +++ b/src/lsm303agr/lsm303agr.hpp @@ -31,6 +31,8 @@ #include #include "lsm303agr.h" +#include + namespace upm { /** @@ -65,7 +67,7 @@ namespace upm { * @snippet lsm303agr.cxx Interesting */ - class LSM303AGR { + class LSM303AGR: virtual public iAcceleration { public: /** * LSM303AGR constructor @@ -149,6 +151,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return temperature data in degrees Celsius. NOTE: This is * not the ambient room temperature. update() must have been diff --git a/src/lsm303d/lsm303d.cxx b/src/lsm303d/lsm303d.cxx index 13639e57..37fcb33f 100644 --- a/src/lsm303d/lsm303d.cxx +++ b/src/lsm303d/lsm303d.cxx @@ -109,6 +109,15 @@ std::vector LSM303D::getAccelerometer() return std::vector(v, v+3); } +std::vector LSM303D::getAcceleration() +{ + std::vector v(3); + + lsm303d_get_accelerometer(m_lsm303d, &v[0], &v[1], &v[2]); + + return v; +} + float LSM303D::getTemperature() { return lsm303d_get_temperature(m_lsm303d); diff --git a/src/lsm303d/lsm303d.hpp b/src/lsm303d/lsm303d.hpp index 1ae36f89..c24c6269 100644 --- a/src/lsm303d/lsm303d.hpp +++ b/src/lsm303d/lsm303d.hpp @@ -31,6 +31,8 @@ #include #include "lsm303d.h" +#include + namespace upm { /** @@ -65,7 +67,7 @@ namespace upm { * @snippet lsm303d.cxx Interesting */ - class LSM303D { + class LSM303D: virtual public iAcceleration { public: /** * LSM303D constructor @@ -142,6 +144,13 @@ namespace upm { * that order */ std::vector getAccelerometer(); + + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); /** * Return temperature data in degrees Celsius. NOTE: This is diff --git a/src/lsm6ds3h/lsm6ds3h.cxx b/src/lsm6ds3h/lsm6ds3h.cxx index 150abaa8..6598706b 100644 --- a/src/lsm6ds3h/lsm6ds3h.cxx +++ b/src/lsm6ds3h/lsm6ds3h.cxx @@ -109,6 +109,14 @@ std::vector LSM6DS3H::getAccelerometer() return std::vector(v, v+3); } +std::vector LSM6DS3H::getAcceleration() +{ + std::vector v(3); + + lsm6ds3h_get_accelerometer(m_lsm6ds3h, &v[0], &v[1], &v[2]); + return v; +} + void LSM6DS3H::getGyroscope(float *x, float *y, float *z) { lsm6ds3h_get_gyroscope(m_lsm6ds3h, x, y, z); diff --git a/src/lsm6ds3h/lsm6ds3h.hpp b/src/lsm6ds3h/lsm6ds3h.hpp index 299282d9..ee3ce100 100644 --- a/src/lsm6ds3h/lsm6ds3h.hpp +++ b/src/lsm6ds3h/lsm6ds3h.hpp @@ -31,6 +31,8 @@ #include #include "lsm6ds3h.h" +#include + namespace upm { /** @@ -64,7 +66,7 @@ namespace upm { * @snippet lsm6ds3h.cxx Interesting */ - class LSM6DS3H { + class LSM6DS3H: virtual public iAcceleration { public: /** @@ -129,6 +131,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return gyroscope data in degrees per second (DPS). * update() must have been called prior to calling this diff --git a/src/lsm6dsl/lsm6dsl.cxx b/src/lsm6dsl/lsm6dsl.cxx index 63d2bd12..d141bbf1 100644 --- a/src/lsm6dsl/lsm6dsl.cxx +++ b/src/lsm6dsl/lsm6dsl.cxx @@ -109,6 +109,15 @@ std::vector LSM6DSL::getAccelerometer() return std::vector(v, v+3); } +std::vector LSM6DSL::getAcceleration() +{ + std::vector v(3); + + lsm6dsl_get_accelerometer(m_lsm6dsl, &v[0], &v[1], &v[2]); + + return v; +} + void LSM6DSL::getGyroscope(float *x, float *y, float *z) { lsm6dsl_get_gyroscope(m_lsm6dsl, x, y, z); diff --git a/src/lsm6dsl/lsm6dsl.hpp b/src/lsm6dsl/lsm6dsl.hpp index cdebeea1..baa917f7 100644 --- a/src/lsm6dsl/lsm6dsl.hpp +++ b/src/lsm6dsl/lsm6dsl.hpp @@ -31,6 +31,8 @@ #include #include "lsm6dsl.h" +#include + namespace upm { /** @@ -63,7 +65,7 @@ namespace upm { * @snippet lsm6dsl.cxx Interesting */ - class LSM6DSL { + class LSM6DSL: virtual public iAcceleration { public: /** @@ -128,6 +130,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Return gyroscope data in degrees per second (DPS). * update() must have been called prior to calling this diff --git a/src/lsm9ds0/lsm9ds0.cxx b/src/lsm9ds0/lsm9ds0.cxx index d4aa85fa..a110bf62 100644 --- a/src/lsm9ds0/lsm9ds0.cxx +++ b/src/lsm9ds0/lsm9ds0.cxx @@ -629,6 +629,13 @@ std::vector LSM9DS0::getAccelerometer() return v; } +std::vector LSM9DS0::getAcceleration() +{ + std::vector v(3); + getAccelerometer(&v[0], &v[1], &v[2]); + return v; +} + std::vector LSM9DS0::getGyroscope() { std::vector v(3); diff --git a/src/lsm9ds0/lsm9ds0.hpp b/src/lsm9ds0/lsm9ds0.hpp index fe10e104..a5f26739 100644 --- a/src/lsm9ds0/lsm9ds0.hpp +++ b/src/lsm9ds0/lsm9ds0.hpp @@ -30,6 +30,8 @@ #include +#include + #define LSM9DS0_I2C_BUS 1 #define LSM9DS0_DEFAULT_XM_ADDR 0x1d #define LSM9DS0_DEFAULT_GYRO_ADDR 0x6b @@ -77,7 +79,7 @@ namespace upm { * @snippet lsm9ds0.cxx Interesting */ - class LSM9DS0 { + class LSM9DS0: virtual public iAcceleration { public: // NOTE: reserved registers must not be written into or permanent @@ -1274,6 +1276,13 @@ namespace upm { */ std::vector getAccelerometer(); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * get the gyroscope values in degrees per second * diff --git a/src/mma7361/mma7361.cxx b/src/mma7361/mma7361.cxx index f80d5e82..275d734e 100644 --- a/src/mma7361/mma7361.cxx +++ b/src/mma7361/mma7361.cxx @@ -112,6 +112,15 @@ void MMA7361::getAcceleration(float *x, float *y, float *z) mma7361_get_acceleration(m_mma7361, x, y, z); } +// std::vector MMA7361::getAcceleration() +// { +// std::vector v(3); + +// mma7361_get_acceleration(m_mma7361, &v[0], &v[1], &v[2]); + +// return v; +// } + float *MMA7361::getAcceleration() { static float data[3]; diff --git a/src/mma7361/mma7361.hpp b/src/mma7361/mma7361.hpp index 7db3aeef..77440243 100644 --- a/src/mma7361/mma7361.hpp +++ b/src/mma7361/mma7361.hpp @@ -32,6 +32,8 @@ #include "mma7361.h" +// #include + namespace upm { /** * @brief MMA7361 Analog Accelerometer @@ -57,6 +59,7 @@ namespace upm { * @snippet mma7361.cxx Interesting */ + // class MMA7361: virtual public iAcceleration { class MMA7361 { public: @@ -150,6 +153,13 @@ namespace upm { */ void getAcceleration(float *x, float *y, float *z); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + // virtual std::vector getAcceleration(); + /** * Get computed acceleration from the sensor. update() must have * been called prior to calling this function. diff --git a/src/mma7455/mma7455.cxx b/src/mma7455/mma7455.cxx index 4b8e5ecd..8b5647c2 100644 --- a/src/mma7455/mma7455.cxx +++ b/src/mma7455/mma7455.cxx @@ -140,6 +140,46 @@ std::vector MMA7455::readData() { return v; } +std::vector MMA7455::getAcceleration() { + std::vector v(3); + accelData xyz; + int nBytes = 0; + + /*do { + nBytes = i2cReadReg (MMA7455_STATUS, &data, 0x1); + } while ( !(data & MMA7455_DRDY) && nBytes == mraa::SUCCESS); + + if (nBytes == mraa::SUCCESS) { + std::cout << "NO_GDB :: 1" << std::endl; + return mraa::SUCCESS; + }*/ + + nBytes = i2cReadReg (MMA7455_XOUTL, (unsigned char *) &xyz, 0x6); + if (nBytes == 0) { + std::cout << "NO_GDB :: 2" << std::endl; + //return mraa::ERROR_UNSPECIFIED; + } + + if (xyz.reg.x_msb & 0x02) { + xyz.reg.x_msb |= 0xFC; + } + + if (xyz.reg.y_msb & 0x02) { + xyz.reg.y_msb |= 0xFC; + } + + if (xyz.reg.z_msb & 0x02) { + xyz.reg.z_msb |= 0xFC; + } + + // The result is the g-force in units of 64 per 'g'. + v[0] = (float)xyz.value.x; + v[1] = (float)xyz.value.y; + v[2] = (float)xyz.value.z; + + return v; +} + int MMA7455::i2cReadReg (unsigned char reg, uint8_t *buffer, int len) { if (mraa::SUCCESS != m_i2ControlCtx.writeByte(reg)) { diff --git a/src/mma7455/mma7455.hpp b/src/mma7455/mma7455.hpp index ce9bae92..c8abb806 100644 --- a/src/mma7455/mma7455.hpp +++ b/src/mma7455/mma7455.hpp @@ -27,6 +27,8 @@ #include #include +#include + #define ADDR 0x1D // device address // Register names according to the datasheet. @@ -171,7 +173,7 @@ typedef union { * @image html mma7455.jpg * @snippet mma7455.cxx Interesting */ -class MMA7455 { +class MMA7455: virtual public iAcceleration { public: /** * Instantiates an MMA7455 object @@ -216,6 +218,13 @@ class MMA7455 { */ std::vector readData (); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Internal function for reading I2C data * diff --git a/src/mma7660/mma7660.cxx b/src/mma7660/mma7660.cxx index 38df355e..560bcb7e 100644 --- a/src/mma7660/mma7660.cxx +++ b/src/mma7660/mma7660.cxx @@ -190,3 +190,14 @@ void MMA7660::getAcceleration(float *ax, float *ay, float *az) ": mma7660_get_acceleration() failed"); } +std::vector MMA7660::getAcceleration() +{ + std::vector v(3); + + if (mma7660_get_acceleration(m_mma7660, &v[0], &v[1], &v[2])) + throw std::runtime_error(std::string(__FUNCTION__) + + ": mma7660_get_acceleration() failed"); + + return v; +} + diff --git a/src/mma7660/mma7660.hpp b/src/mma7660/mma7660.hpp index ec260dde..96491026 100644 --- a/src/mma7660/mma7660.hpp +++ b/src/mma7660/mma7660.hpp @@ -26,6 +26,7 @@ #include #include "mma7660.h" +#include namespace upm { @@ -58,7 +59,7 @@ namespace upm { * @image html mma7660.jpg * @snippet mma7660.cxx Interesting */ - class MMA7660 { + class MMA7660: virtual public iAcceleration { public: /** @@ -109,6 +110,13 @@ namespace upm { */ void getAcceleration(float *ax, float *ay, float *az); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Reads an axis, verifying its validity. The value passed must * be one of REG_XOUT, REG_YOUT, or REG_ZOUT. @@ -199,20 +207,6 @@ namespace upm { */ bool setSampleRate(MMA7660_AUTOSLEEP_T sr); - /** - * Reads the current acceleration values. The returned memory - * is statically allocated and will be overwritten on each - * call. - * - * @return std::vector containing x, y, z. - */ - std::vector getAcceleration() - { - std::vector values(3); - getAcceleration(&values[0], &values[1], &values[2]); - return values; - } - /** * Reads the current value of conversion. The returned memory * is statically allocated and will be overwritten on each diff --git a/src/mma8x5x/mma8x5x.cpp b/src/mma8x5x/mma8x5x.cpp index a1a5d7b7..18ab0504 100644 --- a/src/mma8x5x/mma8x5x.cpp +++ b/src/mma8x5x/mma8x5x.cpp @@ -328,6 +328,19 @@ MMA8X5X::getZ(int bSampleData) return s_data->z; } +std::vector +MMA8X5X::getAcceleration() +{ + sampleData(); + + std::vector v(3); + v[0] = s_data->x; + v[1] = s_data->y; + v[2] = s_data->z; + + return v; +} + int MMA8X5X::getData(mma8x5x_data_t* data, int bSampleData) { diff --git a/src/mma8x5x/mma8x5x.hpp b/src/mma8x5x/mma8x5x.hpp index aa5f9e05..45566711 100644 --- a/src/mma8x5x/mma8x5x.hpp +++ b/src/mma8x5x/mma8x5x.hpp @@ -31,6 +31,8 @@ #include #include +#include + /* Supported devices by this driver */ #define MMA8X5X_DEVICE_ID_MMA8652 0x4a #define MMA8X5X_DEVICE_ID_MMA8653 0x5a @@ -341,7 +343,7 @@ typedef struct { * * @snippet mma8x5x.cxx Interesting */ -class MMA8X5X { +class MMA8X5X: virtual public iAcceleration { public: /** * @@ -448,6 +450,13 @@ class MMA8X5X { */ int16_t getZ(int bSampleData = 0); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * Get sensor values * diff --git a/src/mpu9150/mpu60x0.cxx b/src/mpu9150/mpu60x0.cxx index 9ccde924..a672dc20 100644 --- a/src/mpu9150/mpu60x0.cxx +++ b/src/mpu9150/mpu60x0.cxx @@ -301,6 +301,18 @@ void MPU60X0::getAccelerometer(float *x, float *y, float *z) *z = m_accelZ / m_accelScale; } +std::vector MPU60X0::getAcceleration() +{ + update(); + + std::vector v(3); + v[0] = m_accelX / m_accelScale; + v[1] = m_accelY / m_accelScale; + v[2] = m_accelZ / m_accelScale; + + return v; +} + void MPU60X0::getGyroscope(float *x, float *y, float *z) { if (x) diff --git a/src/mpu9150/mpu60x0.hpp b/src/mpu9150/mpu60x0.hpp index 91d7aa03..001fdd17 100644 --- a/src/mpu9150/mpu60x0.hpp +++ b/src/mpu9150/mpu60x0.hpp @@ -24,11 +24,14 @@ #pragma once #include +#include #include #include #include +#include + #define MPU60X0_I2C_BUS 0 #define MPU60X0_DEFAULT_I2C_ADDR 0x68 @@ -59,7 +62,7 @@ namespace upm { * @image html mpu60x0.jpg * @snippet mpu9150-mpu60x0.cxx Interesting */ - class MPU60X0 { + class MPU60X0: virtual public iAcceleration { public: // NOTE: These enums were composed from both the mpu6050 and @@ -791,6 +794,13 @@ namespace upm { */ void getAccelerometer(float *x, float *y, float *z); + /** + * get acceleration values + * + * @return stl vector of size 3 representing the 3 axis + */ + virtual std::vector getAcceleration(); + /** * get the gyroscope values *