Skip to content

Commit

Permalink
Fix rest detection timescale
Browse files Browse the repository at this point in the history
Sensor fusion expects the time to be in seconds while rest detection expects it to be in microseconds. This makes is so when the update sensor fusion is called the rest detection now gets the time in micros
  • Loading branch information
wigwagwent committed Dec 1, 2023
1 parent 14f2752 commit 9ae0021
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/sensors/SensorFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ namespace SlimeVR

void SensorFusion::calcLinearAcc(const sensor_real_t accin[3], const sensor_real_t gravVec[3], sensor_real_t accout[3])
{
accout[0] = accin[0] - gravVec[0] * CONST_EARTH_GRAVITY;
accout[1] = accin[1] - gravVec[1] * CONST_EARTH_GRAVITY;
accout[2] = accin[2] - gravVec[2] * CONST_EARTH_GRAVITY;
accout[0] = (accin[0] - gravVec[0]) * CONST_EARTH_GRAVITY;
accout[1] = (accin[1] - gravVec[1]) * CONST_EARTH_GRAVITY;
accout[2] = (accin[2] - gravVec[2]) * CONST_EARTH_GRAVITY;
}
}
}
4 changes: 2 additions & 2 deletions src/sensors/SensorFusionRestDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace SlimeVR
void SensorFusionRestDetect::updateAcc(sensor_real_t Axyz[3], sensor_real_t deltat)
{
if (deltat < 0) deltat = accTs;
restDetection.updateAcc(deltat, Axyz);
restDetection.updateAcc(deltat * 1e6, Axyz);
SensorFusion::updateAcc(Axyz, deltat);
}

void SensorFusionRestDetect::updateGyro(sensor_real_t Gxyz[3], sensor_real_t deltat)
{
if (deltat < 0) deltat = gyrTs;
restDetection.updateGyr(deltat, Gxyz);
restDetection.updateGyr(deltat * 1e6, Gxyz);
SensorFusion::updateGyro(Gxyz, deltat);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/sensors/bmi160sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ void BMI160Sensor::onGyroRawSample(uint32_t dtMicros, int16_t x, int16_t y, int1
}
remapGyroAccel(&Gxyz[0], &Gxyz[1], &Gxyz[2]);

sfusion.updateGyro(Gxyz, (double)dtMicros * 1.0e-6);
sfusion.updateGyro(Gxyz, (float)dtMicros * 1.0e-6);

optimistic_yield(100);
}
Expand All @@ -548,7 +548,7 @@ void BMI160Sensor::onAccelRawSample(uint32_t dtMicros, int16_t x, int16_t y, int
lastAxyz[1] = Axyz[1];
lastAxyz[2] = Axyz[2];

sfusion.updateAcc(Axyz, dtMicros);
sfusion.updateAcc(Axyz, (float)dtMicros * 1.0e-6);

optimistic_yield(100);
}
Expand Down

0 comments on commit 9ae0021

Please sign in to comment.