From aa966946d5d9af8216a3a2102c356383f26cc474 Mon Sep 17 00:00:00 2001 From: Serban Waltter Date: Tue, 2 Oct 2018 14:06:17 +0300 Subject: [PATCH] Added iGyroscope interface Signed-off-by: Serban Waltter Signed-off-by: Mihai Tudor Panu --- examples/java/BMG160_Example.java | 1 + examples/java/BMI160_Example.java | 19 ++++++------ examples/java/CMakeLists.txt | 4 +-- include/interfaces/iGyroscope.hpp | 48 +++++++++++++++++++++++++++++++ include/interfaces/interfaces.cxx | 1 + include/interfaces/interfaces.i | 3 ++ src/CMakeLists.txt | 5 +++- src/adxrs610/CMakeLists.txt | 1 + src/adxrs610/adxrs610.cxx | 21 ++++++++++++++ src/adxrs610/adxrs610.hpp | 17 +++++++++-- src/bmg160/CMakeLists.txt | 1 + src/bmg160/bmg160.cxx | 1 + src/bmg160/bmg160.hpp | 4 ++- src/bmg160/bmg160.i | 24 +++++++--------- src/bmi160/CMakeLists.txt | 2 +- src/bmi160/bmi160.cxx | 4 +-- src/bmi160/bmi160.hpp | 5 ++-- src/bmx055/CMakeLists.txt | 2 +- src/bmx055/bmi055.hpp | 3 +- src/bmx055/bmx055.hpp | 3 +- src/bno055/bno055.hpp | 1 + src/itg3200/CMakeLists.txt | 1 + src/itg3200/itg3200.cxx | 8 ++++++ src/itg3200/itg3200.hpp | 14 ++++++++- src/itg3200/itg3200.i | 13 +++++++++ src/l3gd20/CMakeLists.txt | 1 + src/l3gd20/l3gd20.cxx | 10 +++++++ src/l3gd20/l3gd20.hpp | 14 ++++++++- src/lsm6ds3h/CMakeLists.txt | 2 +- src/lsm6ds3h/lsm6ds3h.cxx | 1 + src/lsm6ds3h/lsm6ds3h.hpp | 3 +- src/lsm6dsl/CMakeLists.txt | 2 +- src/lsm6dsl/lsm6dsl.cxx | 1 + src/lsm6dsl/lsm6dsl.hpp | 3 +- src/lsm9ds0/CMakeLists.txt | 2 +- src/lsm9ds0/lsm9ds0.hpp | 5 ++-- src/mpu9150/CMakeLists.txt | 2 +- src/mpu9150/mpu60x0.cxx | 7 +++++ src/mpu9150/mpu60x0.hpp | 10 ++++++- 39 files changed, 222 insertions(+), 47 deletions(-) create mode 100644 include/interfaces/iGyroscope.hpp diff --git a/examples/java/BMG160_Example.java b/examples/java/BMG160_Example.java index a50f5435..ac5d110d 100644 --- a/examples/java/BMG160_Example.java +++ b/examples/java/BMG160_Example.java @@ -23,6 +23,7 @@ */ import upm_bmg160.BMG160; +import upm_interfaces.*; import java.util.AbstractList; import java.lang.Float; diff --git a/examples/java/BMI160_Example.java b/examples/java/BMI160_Example.java index 6d83e2e2..b7f1b34b 100644 --- a/examples/java/BMI160_Example.java +++ b/examples/java/BMI160_Example.java @@ -22,6 +22,9 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import java.util.AbstractList; +import upm_interfaces.*; + import upm_bmi160.BMI160; public class BMI160_Example @@ -39,25 +42,25 @@ public class BMI160_Example // update our values from the sensor sensor.update(); - float dataA[] = sensor.getAccelerometer(); + AbstractList dataA = sensor.getAcceleration(); System.out.println("Accelerometer: " + "AX: " - + dataA[0] + + dataA.get(0) + " AY: " - + dataA[1] + + dataA.get(1) + " AZ: " - + dataA[2]); + + dataA.get(2)); - float dataG[] = sensor.getGyroscope(); + AbstractList dataG = sensor.getGyroscope(); System.out.println("Gryoscope: " + "GX: " - + dataG[0] + + dataG.get(0) + " GY: " - + dataG[1] + + dataG.get(1) + " GZ: " - + dataG[2]); + + dataG.get(2)); float dataM[] = sensor.getMagnetometer(); diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index bd684115..9f276e46 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -79,7 +79,7 @@ add_example(BISS0001_Example "biss0001;interfaces") add_example(BMA250E_Example "bma250e;interfaces") add_example(BMC150_Example "bmx055;interfaces") add_example(BME280_Example "bmp280;interfaces") -add_example(BMG160_Example bmg160) +add_example(BMG160_Example "bmg160;interfaces") add_example(BMI055_Example "bmx055;interfaces") add_example(BMI160_Example "bmi160;interfaces") add_example(BMM150_Example bmm150) @@ -139,7 +139,7 @@ add_example(Hmc5883l_Example hmc5883l) add_example(HMTRP_Example hmtrp) add_example(HP20x_Example "hp20x;interfaces") add_example(HTU21D_Example "htu21d;interfaces") -add_example(Itg3200_Example itg3200) +add_example(Itg3200_Example "itg3200;interfaces") add_example(Jhd1313m1_Example jhd1313m1) add_example(Jhd1313m1_lcd_Example jhd1313m1) add_example(Joystick12_Example joystick12) diff --git a/include/interfaces/iGyroscope.hpp b/include/interfaces/iGyroscope.hpp new file mode 100644 index 00000000..8661dfc3 --- /dev/null +++ b/include/interfaces/iGyroscope.hpp @@ -0,0 +1,48 @@ +/* + * 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 iGyroscope + { + public: + virtual ~iGyroscope() {} + + /** + * Return gyroscope data in degrees per second in the form of + * a floating point vector. + * + * @return A floating point vector containing x, y, and z in + * that order in degrees/second. + */ + virtual std::vector getGyroscope() = 0; + }; +} // upm diff --git a/include/interfaces/interfaces.cxx b/include/interfaces/interfaces.cxx index 768667a6..96ecf300 100644 --- a/include/interfaces/interfaces.cxx +++ b/include/interfaces/interfaces.cxx @@ -9,6 +9,7 @@ #include "iElectromagnet.hpp" #include "iEmg.hpp" #include "iGps.hpp" +#include "iGyroscope.hpp" #include "iHallEffect.hpp" #include "iHeartRate.hpp" #include "iHumidity.hpp" diff --git a/include/interfaces/interfaces.i b/include/interfaces/interfaces.i index b4bf7f7c..cf2390e5 100644 --- a/include/interfaces/interfaces.i +++ b/include/interfaces/interfaces.i @@ -50,6 +50,7 @@ import java.lang.Float; %interface_impl (upm::iElectromagnet); %interface_impl (upm::iEmg); %interface_impl (upm::iGps); + %interface_impl (upm::iGyroscope); %interface_impl (upm::iHallEffect); %interface_impl (upm::iHeartRate); %interface_impl (upm::iHumidity); @@ -78,6 +79,7 @@ import java.lang.Float; #include "iElectromagnet.hpp" #include "iEmg.hpp" #include "iGps.hpp" + #include "iGyroscope.hpp" #include "iHallEffect.hpp" #include "iHeartRate.hpp" #include "iHumidity.hpp" @@ -105,6 +107,7 @@ import java.lang.Float; %include "iElectromagnet.hpp" %include "iEmg.hpp" %include "iGps.hpp" +%include "iGyroscope.hpp" %include "iHallEffect.hpp" %include "iHeartRate.hpp" %include "iHumidity.hpp" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ddb082d7..b81efeb8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -267,10 +267,13 @@ function (_get_current_dot_i_file filePrefix varDotIFile) list (FIND module_iface "iAcceleration.hpp" _index) if (${_index} GREATER -1) set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") + list (FIND module_iface "iGyroscope.hpp" _index) + elseif(${_index} GREATER -1) + set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") endif() else() cmake_policy(SET CMP0057 NEW) - if ("iAcceleration.hpp" IN_LIST module_iface) + if (("iAcceleration.hpp" IN_LIST module_iface) OR ("iGyroscope.hpp" IN_LIST module_iface)) set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") endif() endif() diff --git a/src/adxrs610/CMakeLists.txt b/src/adxrs610/CMakeLists.txt index 57c8b99d..168aed9a 100644 --- a/src/adxrs610/CMakeLists.txt +++ b/src/adxrs610/CMakeLists.txt @@ -2,4 +2,5 @@ set (libname "adxrs610") set (libdescription "Gyro Breakout Board (300 Degrees/second)") set (module_src ${libname}.cxx) set (module_hpp ${libname}.hpp) +set (module_iface iGyroscope.hpp iTemperature.hpp) upm_module_init(mraa) diff --git a/src/adxrs610/adxrs610.cxx b/src/adxrs610/adxrs610.cxx index c5d3f175..98d78ae1 100644 --- a/src/adxrs610/adxrs610.cxx +++ b/src/adxrs610/adxrs610.cxx @@ -97,3 +97,24 @@ float ADXRS610::getAngularVelocity() else return -((m_zeroPoint - dataV) / m_degreeCoeff); } + +std::vector ADXRS610::getGyroscope() +{ + float dataV = getDataVolts(); + + // check the deadband + if (dataV < (m_zeroPoint + m_deadband) && + dataV > (m_zeroPoint - m_deadband)) + return std::vector{0 ,0 ,0}; + + if (dataV > m_zeroPoint) + { + float v = ((dataV - m_zeroPoint) / m_degreeCoeff); + return std::vector{0 ,0 , v}; + } + else + { + float v = -((m_zeroPoint - dataV) / m_degreeCoeff); + return std::vector{0 ,0 , v}; + } +} diff --git a/src/adxrs610/adxrs610.hpp b/src/adxrs610/adxrs610.hpp index 81021b01..4807eb16 100644 --- a/src/adxrs610/adxrs610.hpp +++ b/src/adxrs610/adxrs610.hpp @@ -27,6 +27,9 @@ #include #include +#include +#include + // volts per degree / second (typ) #define m_degreeCoeff 0.006 @@ -69,7 +72,7 @@ namespace upm { * @snippet adxrs610.cxx Interesting */ - class ADXRS610 { + class ADXRS610: virtual public iGyroscope, virtual public iTemperature { public: /** @@ -84,7 +87,7 @@ namespace upm { /** * ADXRS610 destructor */ - ~ADXRS610(); + virtual ~ADXRS610(); /** * Returns the voltage detected on the DATA analog pin @@ -153,6 +156,16 @@ namespace upm { */ float getAngularVelocity(); + /** + * Return gyroscope data in degrees per second in the form of + * a floating point vector. update() must have been called + * prior to calling this method. + * + * @return A floating point vector containing x, y, and z in + * that order. + */ + std::vector getGyroscope(); + protected: mraa::Aio m_aioData; mraa::Aio m_aioTemp; diff --git a/src/bmg160/CMakeLists.txt b/src/bmg160/CMakeLists.txt index eee87db3..d91b1723 100644 --- a/src/bmg160/CMakeLists.txt +++ b/src/bmg160/CMakeLists.txt @@ -5,5 +5,6 @@ upm_mixed_module_init (NAME bmg160 CPP_HDR bmg160.hpp CPP_SRC bmg160.cxx FTI_SRC bmg160_fti.c + IFACE_HDR iGyroscope.hpp CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/bmg160/bmg160.cxx b/src/bmg160/bmg160.cxx index 342dee53..b281bece 100644 --- a/src/bmg160/bmg160.cxx +++ b/src/bmg160/bmg160.cxx @@ -108,6 +108,7 @@ void BMG160::getGyroscope(float *x, float *y, float *z) std::vector BMG160::getGyroscope() { + update(); float v[3]; getGyroscope(&v[0], &v[1], &v[2]); diff --git a/src/bmg160/bmg160.hpp b/src/bmg160/bmg160.hpp index b7fcf42b..ac799e57 100644 --- a/src/bmg160/bmg160.hpp +++ b/src/bmg160/bmg160.hpp @@ -31,6 +31,8 @@ #include #include "bmg160.h" +#include + namespace upm { /** @@ -71,7 +73,7 @@ namespace upm { * @snippet bmg160.cxx Interesting */ - class BMG160 { + class BMG160: virtual public iGyroscope { public: /** * BMG160 constructor. diff --git a/src/bmg160/bmg160.i b/src/bmg160/bmg160.i index 5b7c1a9c..f979cfad 100644 --- a/src/bmg160/bmg160.i +++ b/src/bmg160/bmg160.i @@ -1,26 +1,22 @@ +#ifdef SWIGPYTHON +%module (package="upm") a110x +#endif + +%import "interfaces/interfaces.i" + %include "../common_top.i" /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%include "../upm_javastdvector.i" - -%ignore installISR (BMG160_INTERRUPT_PINS_T , int mraa::Edge , void *, void *); -%ignore getGyroscope(float *, float *, float *); - %typemap(javaimports) SWIGTYPE %{ +import upm_interfaces.*; + import java.util.AbstractList; import java.lang.Float; %} -%typemap(javaout) SWIGTYPE { - return new $&javaclassname($jnicall, true); -} -%typemap(javaout) std::vector { - return (AbstractList)(new $&javaclassname($jnicall, true)); -} -%typemap(jstype) std::vector "AbstractList" - -%template(floatVector) std::vector; +%ignore installISR (BMG160_INTERRUPT_PINS_T , int mraa::Edge , void *, void *); +%ignore getGyroscope(float *, float *, float *); %define INTERRUPT BMG160_INTERRUPT_PINS_T %enddef diff --git a/src/bmi160/CMakeLists.txt b/src/bmi160/CMakeLists.txt index 78cfb434..2d702958 100644 --- a/src/bmi160/CMakeLists.txt +++ b/src/bmi160/CMakeLists.txt @@ -4,7 +4,7 @@ upm_mixed_module_init (NAME bmi160 C_SRC bmi160.c bosch_bmi160.c CPP_HDR bmi160.hpp CPP_SRC bmi160.cxx - IFACE_HDR iAcceleration.hpp + IFACE_HDR iAcceleration.hpp iGyroscope.hpp # FTI_SRC bmi160_fti.c CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/bmi160/bmi160.cxx b/src/bmi160/bmi160.cxx index 257c218e..af224729 100644 --- a/src/bmi160/bmi160.cxx +++ b/src/bmi160/bmi160.cxx @@ -92,13 +92,13 @@ std::vector BMI160::getAcceleration() return v; } -float *BMI160::getGyroscope() +std::vector BMI160::getGyroscope() { static float values[3]; // x, y, and then z getGyroscope(&values[0], &values[1], &values[2]); - return values; + return std::vector(values, values + 3); } float *BMI160::getMagnetometer() diff --git a/src/bmi160/bmi160.hpp b/src/bmi160/bmi160.hpp index f3ebdee9..044d935b 100644 --- a/src/bmi160/bmi160.hpp +++ b/src/bmi160/bmi160.hpp @@ -26,6 +26,7 @@ #include "bmi160.h" #include +#include #define BMI160_I2C_BUS 0 #define BMI160_DEFAULT_I2C_ADDR 0x69 @@ -74,7 +75,7 @@ namespace upm { * * @snippet bmi160.cxx Interesting */ - class BMI160: virtual public iAcceleration { + class BMI160: virtual public iAcceleration, virtual public iGyroscope { public: /** @@ -162,7 +163,7 @@ namespace upm { * @return Pointer to 3 floating point values: X, Y, and Z in * degrees per second. */ - float *getGyroscope(); + virtual std::vector getGyroscope(); /** * Get the Gyroscope values. The values returned are in degrees diff --git a/src/bmx055/CMakeLists.txt b/src/bmx055/CMakeLists.txt index 22137f18..b9b2ffb1 100644 --- a/src/bmx055/CMakeLists.txt +++ b/src/bmx055/CMakeLists.txt @@ -2,5 +2,5 @@ upm_mixed_module_init (NAME bmx055 DESCRIPTION "Bosch IMU Sensor Library" CPP_HDR bmx055.hpp bmc150.hpp bmi055.hpp CPP_SRC bmx055.cxx bmc150.cxx bmi055.cxx - IFACE_HDR iAcceleration.hpp + IFACE_HDR iAcceleration.hpp iGyroscope.hpp REQUIRES mraa bmg160 bma250e bmm150) diff --git a/src/bmx055/bmi055.hpp b/src/bmx055/bmi055.hpp index 751246dc..8e02d992 100644 --- a/src/bmx055/bmi055.hpp +++ b/src/bmx055/bmi055.hpp @@ -32,6 +32,7 @@ #include "bmg160.hpp" #include +#include namespace upm { @@ -66,7 +67,7 @@ namespace upm { * @snippet bmx055-bmi055.cxx Interesting */ - class BMI055: virtual public iAcceleration { + class BMI055: virtual public iAcceleration, virtual public iGyroscope { public: /** * BMI055 constructor. diff --git a/src/bmx055/bmx055.hpp b/src/bmx055/bmx055.hpp index 19674516..5947cb4f 100644 --- a/src/bmx055/bmx055.hpp +++ b/src/bmx055/bmx055.hpp @@ -33,6 +33,7 @@ #include "bmm150.hpp" #include +#include #define BMX055_DEFAULT_MAG_I2C_ADDR 0x12 @@ -78,7 +79,7 @@ namespace upm { * @snippet bmx055.cxx Interesting */ - class BMX055: virtual public iAcceleration { + class BMX055: virtual public iAcceleration, virtual public iGyroscope { public: /** * BMX055 constructor. diff --git a/src/bno055/bno055.hpp b/src/bno055/bno055.hpp index d430b007..275cff46 100644 --- a/src/bno055/bno055.hpp +++ b/src/bno055/bno055.hpp @@ -29,6 +29,7 @@ #include "bno055.h" #include +#include namespace upm { diff --git a/src/itg3200/CMakeLists.txt b/src/itg3200/CMakeLists.txt index c92d51ca..779f1cb6 100644 --- a/src/itg3200/CMakeLists.txt +++ b/src/itg3200/CMakeLists.txt @@ -2,4 +2,5 @@ set (libname "itg3200") set (libdescription "3-axis Digital Gyroscope") set (module_src ${libname}.cxx) set (module_hpp ${libname}.hpp) +set (module_iface iGyroscope.hpp) upm_module_init(mraa) diff --git a/src/itg3200/itg3200.cxx b/src/itg3200/itg3200.cxx index 3533c02c..9ba8edec 100644 --- a/src/itg3200/itg3200.cxx +++ b/src/itg3200/itg3200.cxx @@ -114,6 +114,14 @@ Itg3200::getRotation() return &m_angle[0]; } +std::vector Itg3200::getGyroscope() +{ + for(int i = 0; i < 3; i++){ + m_angle[i] = m_rotation[i]/14.375; + } + return std::vector(m_angle, m_angle + 3); +} + int16_t* Itg3200::getRawValues() { diff --git a/src/itg3200/itg3200.hpp b/src/itg3200/itg3200.hpp index a5468d4f..bc7bd16e 100644 --- a/src/itg3200/itg3200.hpp +++ b/src/itg3200/itg3200.hpp @@ -25,6 +25,8 @@ #include +#include + #define READ_BUFFER_LENGTH 8 namespace upm { @@ -56,7 +58,7 @@ namespace upm { * @image html itg3200.jpeg * @snippet itg3200.cxx Interesting */ -class Itg3200 { +class Itg3200: virtual public iGyroscope { public: /** * Creates an Itg3200 object @@ -86,6 +88,16 @@ public: */ float* getRotation(); + /** + * Return gyroscope data in degrees per second in the form of + * a floating point vector. update() must have been called + * prior to calling this method. + * + * @return A floating point vector containing x, y, and z in + * that order. + */ + std::vector getGyroscope(); + /** * Returns a pointer to an int[3] that contains raw register values for X, Y, and Z * diff --git a/src/itg3200/itg3200.i b/src/itg3200/itg3200.i index 1e5d7d14..58f985bb 100644 --- a/src/itg3200/itg3200.i +++ b/src/itg3200/itg3200.i @@ -1,7 +1,20 @@ +#ifdef SWIGPYTHON +%module (package="upm") a110x +#endif + +%import "interfaces/interfaces.i" + %include "../common_top.i" /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA +%typemap(javaimports) SWIGTYPE %{ +import upm_interfaces.*; + +import java.util.AbstractList; +import java.lang.Float; +%} + %typemap(jni) float* "jfloatArray" %typemap(jstype) float* "float[]" %typemap(jtype) float* "float[]" diff --git a/src/l3gd20/CMakeLists.txt b/src/l3gd20/CMakeLists.txt index a91a1f14..91e42634 100644 --- a/src/l3gd20/CMakeLists.txt +++ b/src/l3gd20/CMakeLists.txt @@ -3,5 +3,6 @@ if (MRAA_IIO_FOUND) set (libdescription "Tri-axis Digital Gyroscope") set (module_src ${libname}.cxx) set (module_hpp ${libname}.hpp) + set (module_iface iGyroscope.hpp) upm_module_init(mraa) endif (MRAA_IIO_FOUND) diff --git a/src/l3gd20/l3gd20.cxx b/src/l3gd20/l3gd20.cxx index 091a7908..537854f4 100644 --- a/src/l3gd20/l3gd20.cxx +++ b/src/l3gd20/l3gd20.cxx @@ -273,6 +273,16 @@ void L3GD20::getGyroscope(float *x, float *y, float *z) *z = m_gyrZ; } +std::vector L3GD20::getGyroscope() +{ + update(); + std::vector values(3); + values[0] = m_gyrX; + values[1] = m_gyrY; + values[2] = m_gyrZ; + return values; +} + void L3GD20::update() { int bufLen = 6; diff --git a/src/l3gd20/l3gd20.hpp b/src/l3gd20/l3gd20.hpp index ef90e9a0..96a20d46 100644 --- a/src/l3gd20/l3gd20.hpp +++ b/src/l3gd20/l3gd20.hpp @@ -31,6 +31,8 @@ #include #include +#include + #define L3GD20_DEFAULT_I2C_BUS 0 // if SDO tied to GND #define L3GD20_DEFAULT_I2C_ADDR 0x6a @@ -74,7 +76,7 @@ namespace upm * @snippet l3gd20-i2c.cxx Interesting */ -class L3GD20 +class L3GD20: virtual public iGyroscope { public: typedef struct { @@ -479,6 +481,16 @@ class L3GD20 */ void getGyroscope(float *x, float *y, float *z); + /** + * Return gyroscope data in degrees per second in the form of + * a floating point vector. update() must have been called + * prior to calling this method. + * + * @return A floating point vector containing x, y, and z in + * that order. + */ + std::vector getGyroscope(); + /** * Set the power mode of the device. I2C only. * diff --git a/src/lsm6ds3h/CMakeLists.txt b/src/lsm6ds3h/CMakeLists.txt index aff9bbec..3de4be7b 100644 --- a/src/lsm6ds3h/CMakeLists.txt +++ b/src/lsm6ds3h/CMakeLists.txt @@ -5,6 +5,6 @@ upm_mixed_module_init (NAME lsm6ds3h CPP_HDR lsm6ds3h.hpp CPP_SRC lsm6ds3h.cxx FTI_SRC lsm6ds3h_fti.c - IFACE_HDR iAcceleration.hpp + IFACE_HDR iAcceleration.hpp iGyroscope.hpp CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/lsm6ds3h/lsm6ds3h.cxx b/src/lsm6ds3h/lsm6ds3h.cxx index 6598706b..b77d8a7b 100644 --- a/src/lsm6ds3h/lsm6ds3h.cxx +++ b/src/lsm6ds3h/lsm6ds3h.cxx @@ -124,6 +124,7 @@ void LSM6DS3H::getGyroscope(float *x, float *y, float *z) std::vector LSM6DS3H::getGyroscope() { + update(); float v[3]; getGyroscope(&v[0], &v[1], &v[2]); diff --git a/src/lsm6ds3h/lsm6ds3h.hpp b/src/lsm6ds3h/lsm6ds3h.hpp index ee3ce100..7861a66e 100644 --- a/src/lsm6ds3h/lsm6ds3h.hpp +++ b/src/lsm6ds3h/lsm6ds3h.hpp @@ -32,6 +32,7 @@ #include "lsm6ds3h.h" #include +#include namespace upm { @@ -66,7 +67,7 @@ namespace upm { * @snippet lsm6ds3h.cxx Interesting */ - class LSM6DS3H: virtual public iAcceleration { + class LSM6DS3H: virtual public iAcceleration, virtual public iGyroscope { public: /** diff --git a/src/lsm6dsl/CMakeLists.txt b/src/lsm6dsl/CMakeLists.txt index f5c85e9a..0067d072 100644 --- a/src/lsm6dsl/CMakeLists.txt +++ b/src/lsm6dsl/CMakeLists.txt @@ -4,7 +4,7 @@ upm_mixed_module_init (NAME lsm6dsl C_SRC lsm6dsl.c CPP_HDR lsm6dsl.hpp CPP_SRC lsm6dsl.cxx - IFACE_HDR iAcceleration.hpp + IFACE_HDR iAcceleration.hpp iGyroscope.hpp FTI_SRC lsm6dsl_fti.c CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/lsm6dsl/lsm6dsl.cxx b/src/lsm6dsl/lsm6dsl.cxx index d141bbf1..1612849b 100644 --- a/src/lsm6dsl/lsm6dsl.cxx +++ b/src/lsm6dsl/lsm6dsl.cxx @@ -125,6 +125,7 @@ void LSM6DSL::getGyroscope(float *x, float *y, float *z) std::vector LSM6DSL::getGyroscope() { + update(); float v[3]; getGyroscope(&v[0], &v[1], &v[2]); diff --git a/src/lsm6dsl/lsm6dsl.hpp b/src/lsm6dsl/lsm6dsl.hpp index baa917f7..cc3e79e3 100644 --- a/src/lsm6dsl/lsm6dsl.hpp +++ b/src/lsm6dsl/lsm6dsl.hpp @@ -32,6 +32,7 @@ #include "lsm6dsl.h" #include +#include namespace upm { @@ -65,7 +66,7 @@ namespace upm { * @snippet lsm6dsl.cxx Interesting */ - class LSM6DSL: virtual public iAcceleration { + class LSM6DSL: virtual public iAcceleration, virtual public iGyroscope { public: /** diff --git a/src/lsm9ds0/CMakeLists.txt b/src/lsm9ds0/CMakeLists.txt index ff70596f..feab915c 100644 --- a/src/lsm9ds0/CMakeLists.txt +++ b/src/lsm9ds0/CMakeLists.txt @@ -2,5 +2,5 @@ set (libname "lsm9ds0") set (libdescription "Triaxial Gyroscope/accelerometer/magnetometer Sensor") set (module_src ${libname}.cxx) set (module_hpp ${libname}.hpp) -set (module_iface iAcceleration.hpp) +set (module_iface iAcceleration.hpp iGyroscope.hpp) upm_module_init(mraa) diff --git a/src/lsm9ds0/lsm9ds0.hpp b/src/lsm9ds0/lsm9ds0.hpp index a5f26739..dc18e5ce 100644 --- a/src/lsm9ds0/lsm9ds0.hpp +++ b/src/lsm9ds0/lsm9ds0.hpp @@ -31,6 +31,7 @@ #include #include +#include #define LSM9DS0_I2C_BUS 1 #define LSM9DS0_DEFAULT_XM_ADDR 0x1d @@ -79,7 +80,7 @@ namespace upm { * @snippet lsm9ds0.cxx Interesting */ - class LSM9DS0: virtual public iAcceleration { + class LSM9DS0: virtual public iAcceleration, virtual public iGyroscope { public: // NOTE: reserved registers must not be written into or permanent @@ -1074,7 +1075,7 @@ namespace upm { /** * LSM9DS0 Destructor */ - ~LSM9DS0(); + virtual ~LSM9DS0(); /** * set up initial values and start operation diff --git a/src/mpu9150/CMakeLists.txt b/src/mpu9150/CMakeLists.txt index c80e75c8..d4948835 100644 --- a/src/mpu9150/CMakeLists.txt +++ b/src/mpu9150/CMakeLists.txt @@ -2,5 +2,5 @@ set (libname "mpu9150") set (libdescription "IMU Sensor Library Based On the Mpu9150") set (module_src ${libname}.cxx ak8975.cxx mpu60x0.cxx mpu9250.cxx) set (module_hpp ${libname}.hpp ak8975.hpp mpu60x0.hpp mpu9250.hpp) -set (module_iface iAcceleration.hpp) +set (module_iface iAcceleration.hpp iGyroscope.hpp) upm_module_init(mraa) diff --git a/src/mpu9150/mpu60x0.cxx b/src/mpu9150/mpu60x0.cxx index a672dc20..063a212e 100644 --- a/src/mpu9150/mpu60x0.cxx +++ b/src/mpu9150/mpu60x0.cxx @@ -325,6 +325,13 @@ void MPU60X0::getGyroscope(float *x, float *y, float *z) *z = m_gyroZ / m_gyroScale; } +std::vector MPU60X0::getGyroscope() +{ + update(); + return std::vector {m_gyroX / m_gyroScale, m_gyroY / m_gyroScale, m_gyroZ / m_gyroScale}; +} + + float MPU60X0::getTemperature() { // this equation is taken from the datasheet diff --git a/src/mpu9150/mpu60x0.hpp b/src/mpu9150/mpu60x0.hpp index 001fdd17..31647b7d 100644 --- a/src/mpu9150/mpu60x0.hpp +++ b/src/mpu9150/mpu60x0.hpp @@ -31,6 +31,7 @@ #include #include +#include #define MPU60X0_I2C_BUS 0 #define MPU60X0_DEFAULT_I2C_ADDR 0x68 @@ -62,7 +63,7 @@ namespace upm { * @image html mpu60x0.jpg * @snippet mpu9150-mpu60x0.cxx Interesting */ - class MPU60X0: virtual public iAcceleration { + class MPU60X0: virtual public iAcceleration, virtual public iGyroscope { public: // NOTE: These enums were composed from both the mpu6050 and @@ -811,6 +812,13 @@ namespace upm { */ void getGyroscope(float *x, float *y, float *z); + /** + * get the gyroscope values in degrees per second + * + * @return std::vector containing X, Y, Z gyroscope values + */ + std::vector getGyroscope(); + /** * get the temperature value *