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
Diff: LSM9DS0.cpp
- Revision:
- 10:60a176bd72b3
- Parent:
- 8:08932ac08cb2
--- 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;
