Make sure that ICM20948 is only updated once per loop when needed

This commit is contained in:
Niklas Jensen
2025-12-26 22:33:16 +01:00
parent ee571ed0ff
commit 32966a3430
2 changed files with 18 additions and 9 deletions
+7 -3
View File
@@ -82,13 +82,17 @@ class IMU : public SensorBase<IMUAnglesMsg> {
_msg.temperature = _imu.getTemperature(); _msg.temperature = _imu.getTemperature();
#endif #endif
#if FT_ENABLED(USE_ICM20948) #if FT_ENABLED(USE_ICM20948)
#ifndef ICM20948_GET_AGMT_UPDATED_ONCE_PER_LOOP
#define ICM20948_GET_AGMT_UPDATED_ONCE_PER_LOOP
if (_imu->dataReady()) if (_imu->dataReady())
{ {
_imu->getAGMT(); _imu->getAGMT();
_msg.rpy[0] = _imu->gyrX();
_msg.rpy[1] = _imu->gyrY();
_msg.rpy[2] = _imu->gyrZ();
} }
#endif
_msg.rpy[0] = _imu->accX();
_msg.rpy[1] = _imu->accY();
_msg.rpy[2] = _imu->accZ();
#endif #endif
#if FT_ENABLED(USE_BNO055) #if FT_ENABLED(USE_BNO055)
#endif #endif
+7 -2
View File
@@ -43,8 +43,13 @@ class Magnetometer : public SensorBase<MagnetometerMsg> {
bool update() override { bool update() override {
if (!_msg.success) return false; if (!_msg.success) return false;
#if FT_ENABLED(USE_ICM20948) #if FT_ENABLED(USE_ICM20948)
_mag->getAGMT(); #ifndef ICM20948_GET_AGMT_UPDATED_ONCE_PER_LOOP
if (_mag->status != ICM_20948_Stat_Ok){ return false; } #define ICM20948_GET_AGMT_UPDATED_ONCE_PER_LOOP
if (_imu->dataReady())
{
_imu->getAGMT();
}
#endif
_msg.rpy[0] = _mag->magX(); _msg.rpy[0] = _mag->magX();
_msg.rpy[1] = _mag->magY(); _msg.rpy[1] = _mag->magY();
_msg.rpy[2] = _mag->magZ(); _msg.rpy[2] = _mag->magZ();