imu impl
This commit is contained in:
parent
aeea35cce0
commit
86549f3093
3 changed files with 23 additions and 4 deletions
|
@ -29,7 +29,7 @@ LSM6::LSM6(void)
|
|||
bool LSM6::checkForNewData(void)
|
||||
{
|
||||
bool retVal = false;
|
||||
if(getStatus() & 0x01)
|
||||
if(getStatus() & 0x02)
|
||||
{
|
||||
read();
|
||||
|
||||
|
@ -228,7 +228,7 @@ void LSM6::enableDefault(void)
|
|||
{
|
||||
// Set the gyro full scale and data rate
|
||||
setFullScaleGyro(GYRO_FS245);
|
||||
setGyroDataOutputRate(ODR13);
|
||||
setGyroDataOutputRate(ODR104);
|
||||
|
||||
// Set the accelerometer full scale and data rate
|
||||
setFullScaleAcc(ACC_FS2);
|
||||
|
|
|
@ -141,6 +141,12 @@ public:
|
|||
|
||||
vector<float> updateGyroBias(void)
|
||||
{
|
||||
if (initialMeasurement) {
|
||||
gyroBias.z = g.z;
|
||||
initialMeasurement = false;
|
||||
}
|
||||
float retain = (0.98);
|
||||
gyroBias.z = g.z * (1- retain) + gyroBias.z * retain;
|
||||
/**
|
||||
* TODO: add a low-pass filter to update the bias
|
||||
*/
|
||||
|
@ -169,6 +175,7 @@ public:
|
|||
// float estimatedPitchAngle = 0;
|
||||
// vector<float> eulerAngles;
|
||||
vector<float> gyroBias;
|
||||
bool initialMeasurement = true;
|
||||
|
||||
/* We make Robot a friend to avoid all the setters and getters. */
|
||||
friend class Robot;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "robot.h"
|
||||
#include <IRdecoder.h>
|
||||
#include <limits.h>
|
||||
|
||||
void Robot::InitializeRobot(void)
|
||||
{
|
||||
|
@ -79,11 +80,22 @@ void Robot::HandleOrientationUpdate(void)
|
|||
|
||||
else // update orientation
|
||||
{
|
||||
// TODO: update the orientation
|
||||
float z_rot = ((float)imu.g.z - imu.gyroBias.z) / (float) INT_MAX;
|
||||
z_rot /= 104;
|
||||
z_rot *= 245;
|
||||
eulerAngles.z += z_rot;
|
||||
}
|
||||
|
||||
#ifdef __IMU_DEBUG__
|
||||
Serial.println(eulerAngles.z);
|
||||
Serial.print(imu.gyroBias.z);
|
||||
Serial.print('\t');
|
||||
Serial.print(eulerAngles.z);
|
||||
Serial.print('\t');
|
||||
//Serial.print(imu.g.x);
|
||||
//Serial.print('\t');
|
||||
//Serial.print(imu.g.y);
|
||||
//Serial.print('\t');
|
||||
Serial.println(imu.g.z);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue