Nucleo-64 version
Dependents: particle_filter_test read_sensor_data Bike_Sensor_Fusion Encoder ... more
Diff: LSM9DS0.cpp
- Revision:
- 14:91137af62732
- Parent:
- 13:2a88692b1525
- Child:
- 15:d433a3236219
--- a/LSM9DS0.cpp Tue Jul 09 03:17:00 2019 +0000 +++ b/LSM9DS0.cpp Tue Sep 03 05:18:23 2019 +0000 @@ -870,20 +870,21 @@ /* Integrate the gyro data(deg/s) over time to get angle */ pitch += data[5] * dt; // Angle around the Z-axis roll += data[3] * dt; // Angle around the X-axis - + /* Turning around the X-axis results in a vector on the Y-axis whereas turning around the Y-axis results in a vector on the X-axis. */ pitchAcc = (float)atan2f(data[0], -data[2])*180.0f/PI; rollAcc = (float)atan2f(-data[1], -data[2])*180.0f/PI;//Let Z toggle to avoid pi to -pi transition. /* Apply Complementary Filter */ -// pitch = pitch * 0.999f + pitchAcc * 0.001f; + pitch = pitch * 0.98f + pitchAcc * 0.02f; // pitch = pitch * 0.9f + pitchAcc * 0.1f;//0.95 - pitch = pitch * 0.94f + pitchAcc * 0.06f;//0.95 +// pitch = pitch * 0.94f + pitchAcc * 0.06f;//0.95 // if(pitch < 0)// = (pitch > 0 )? pitch:pitch; // pitch = -1*pitch; // roll = roll * 0.9f + rollAcc * 0.1f; roll = roll * 0.94f + rollAcc * 0.06f; + // roll = (roll > 0 )? roll:180.0f+roll; } \ No newline at end of file