Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LSM9DS0 by
Revision 10:60a176bd72b3, committed 2016-12-28
- Comitter:
- benson516
- Date:
- Wed Dec 28 16:44:09 2016 +0000
- Parent:
- 8:08932ac08cb2
- Commit message:
- Add a set of functions for vector-output capability.
Changed in this revision
| LSM9DS0.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LSM9DS0.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LSM9DS0.cpp Tue Oct 25 06:21:28 2016 +0000
+++ b/LSM9DS0.cpp Wed Dec 28 16:44:09 2016 +0000
@@ -50,6 +50,10 @@
// If we're using SPI, these variables store the chip-select pins.
gAddress = gAddr;
xmAddress = xmAddr;
+
+ // Unit transformation
+ deg2rad = PI/180.0;
+ rad2deg = 180.0/PI;
}
uint16_t LSM9DS0::begin(gyro_scale gScl, accel_scale aScl, mag_scale mScl,
@@ -343,7 +347,27 @@
gy = (temp[3] << 8) | temp[2]; // Store y-axis values into gy
gz = (temp[5] << 8) | temp[4]; // Store z-axis values into gz
}
+void LSM9DS0::readGyroFloatVector_degPs(vector<float> &v_out) // Read to float array v_out[]
+{
+ readGyro(); // get gx, gy, gz
+ v_out[0] = calcGyro(gx - gyroOffset[0]);
+ v_out[1] = calcGyro(gy - gyroOffset[1]);
+ v_out[2] = calcGyro(gz - gyroOffset[2]);
+}
+void LSM9DS0::readGyroFloatVector_radPs(vector<float> &v_out) // Read to float array v_out[]
+{
+ readGyro(); // get gx, gy, gz
+ v_out[0] = calcGyro(gx - gyroOffset[0])*deg2rad;
+ v_out[1] = calcGyro(gy - gyroOffset[1])*deg2rad;
+ v_out[2] = calcGyro(gz - gyroOffset[2])*deg2rad;
+}
+void LSM9DS0::readGyroRawVector(vector<int16_t> &v_out){ // Raw data in int16_t
+ readGyro(); // get gx, gy, gz
+ v_out[0] = gx;
+ v_out[1] = gy;
+ v_out[2] = gz;
+}
void LSM9DS0::setGyroOffset(int16_t _gx, int16_t _gy, int16_t _gz)
{
gyroOffset[0] = _gx;
@@ -404,7 +428,20 @@
ay = (temp[3] << 8) | temp[2]; // Store y-axis values into ay
az = (temp[5] << 8) | temp[4]; // Store z-axis values into az
}
+void LSM9DS0::readAccelFloatVector(vector<float> &v_out) // Read to float array v_out[]
+{
+ readAccel(); // get ax, ay, az
+ v_out[0] = calcAccel(ax - accelOffset[0]);
+ v_out[1] = calcAccel(ay - accelOffset[1]);
+ v_out[2] = calcAccel(az - accelOffset[2]);
+}
+void LSM9DS0::readAccelRawVector(vector<int16_t> &v_out){ // Raw data in int16_t
+ readAccel(); // get ax, ay, az
+ v_out[0] = ax;
+ v_out[1] = ay;
+ v_out[2] = az;
+}
void LSM9DS0::setAccelOffset(int16_t _ax, int16_t _ay, int16_t _az)
{
accelOffset[0] = _ax;
@@ -465,7 +502,20 @@
my = (temp[3] << 8) | temp[2]; // Store y-axis values into my
mz = (temp[5] << 8) | temp[4]; // Store z-axis values into mz
}
+void LSM9DS0::readMagFloatVector(vector<float> &v_out) // Read to float array v_out[]
+{
+ readMag(); // get mx, my, mz
+ v_out[0] = calcMag(mx - magOffset[0]);
+ v_out[1] = calcMag(my - magOffset[1]);
+ v_out[2] = calcMag(mz - magOffset[2]);
+}
+void LSM9DS0::readMagRawVector(vector<int16_t> &v_out){ // Raw data in int16_t
+ readMag(); // get mx, my, mz
+ v_out[0] = mx;
+ v_out[1] = my;
+ v_out[2] = mz;
+}
void LSM9DS0::setMagOffset(int16_t _mx, int16_t _my, int16_t _mz)
{
magOffset[0] = _mx;
--- a/LSM9DS0.h Tue Oct 25 06:21:28 2016 +0000
+++ b/LSM9DS0.h Wed Dec 28 16:44:09 2016 +0000
@@ -20,6 +20,8 @@
#define __SFE_LSM9DS0_H__
#include "mbed.h"
+#include <vector>
+using std::vector;
#define PI 3.14159
@@ -203,6 +205,10 @@
M_ODR_50 = 0x04, // 50 (0x04)
M_ODR_100 = 0x05, // 100 Hz (0x05)
};
+
+ // Unit transformation
+ float deg2rad; // = 3.1415926/180.0;
+ float rad2deg; // = 180.0/3.1415926;
// We'll store the gyro, accel, and magnetometer readings in a series of
// public class variables. Each sensor gets three variables -- one for each
@@ -262,6 +268,9 @@
// The readings are stored in the class' gx, gy, and gz variables. Read
// those _after_ calling readGyro().
void readGyro();
+ void readGyroFloatVector_degPs(vector<float> &v_out); // Read to float array v_out[]
+ void readGyroFloatVector_radPs(vector<float> &v_out); // Read to float array v_out[]
+ void readGyroRawVector(vector<int16_t> &v_out); // Raw data in int16_t
int16_t readRawGyroX( void );
int16_t readRawGyroY( void );
int16_t readRawGyroZ( void );
@@ -274,6 +283,8 @@
// The readings are stored in the class' ax, ay, and az variables. Read
// those _after_ calling readAccel().
void readAccel();
+ void readAccelFloatVector(vector<float> &v_out); // Read to float array v_out[]
+ void readAccelRawVector(vector<int16_t> &v_out); // Raw data in int16_t
int16_t readRawAccelX( void );
int16_t readRawAccelY( void );
int16_t readRawAccelZ( void );
@@ -286,6 +297,8 @@
// The readings are stored in the class' mx, my, and mz variables. Read
// those _after_ calling readMag().
void readMag();
+ void readMagFloatVector(vector<float> &v_out); // Read to float array v_out[]
+ void readMagRawVector(vector<int16_t> &v_out); // Raw data in int16_t
int16_t readRawMagX( void );
int16_t readRawMagY( void );
int16_t readRawMagZ( void );
