Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICM20948 no timeout detected fix #287

Merged
merged 2 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/sensors/icm20948sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,22 @@ void ICM20948Sensor::motionLoop()
}
#endif

hasdata = false;
readFIFOToEnd();
readRotation();
checkSensorTimeout();
// Performance Test
/*
if (hasdata) cntrounds ++;

if ((lastData2 + 2000) <= millis())
{
lastData2 = millis();
printf("Data worked/2sec: %d, Dataframes: %d\n", cntrounds,cntbuf);
cntbuf = 0;
cntrounds = 0;
}
*/
}

void ICM20948Sensor::readFIFOToEnd()
Expand All @@ -82,6 +95,9 @@ void ICM20948Sensor::readFIFOToEnd()
if(readStatus == ICM_20948_Stat_Ok)
{
dmpData = dmpDataTemp;
// Performance Test
// cntbuf ++;
hasdata = true;
readFIFOToEnd();
}
}
Expand Down Expand Up @@ -127,6 +143,19 @@ void ICM20948Sensor::startCalibrationAutoSave()

void ICM20948Sensor::startDMP()
{
#ifdef ESP32
#if ESP32C3
#define ICM20948_ODRGYR 1
#define ICM20948_ODRAXL 1
#else
#define ICM20948_ODRGYR 1
#define ICM20948_ODRAXL 1
#endif
#else
#define ICM20948_ODRGYR 1
#define ICM20948_ODRAXL 1
#endif

if(imu.initializeDMP() == ICM_20948_Stat_Ok)
{
m_Logger.debug("DMP initialized");
Expand Down Expand Up @@ -181,7 +210,7 @@ void ICM20948Sensor::startDMP()

#if(USE_6_AXIS)
{
if(imu.setDMPODRrate(DMP_ODR_Reg_Quat6, 0) == ICM_20948_Stat_Ok)
if(imu.setDMPODRrate(DMP_ODR_Reg_Quat6, ICM20948_ODRGYR) == ICM_20948_Stat_Ok)
{
m_Logger.debug("Set Quat6 to 100Hz frequency");
}
Expand All @@ -193,7 +222,7 @@ void ICM20948Sensor::startDMP()
}
#else
{
if(imu.setDMPODRrate(DMP_ODR_Reg_Quat9, 0) == ICM_20948_Stat_Ok)
if(imu.setDMPODRrate(DMP_ODR_Reg_Quat9, ICM20948_ODRGYR) == ICM_20948_Stat_Ok)
{
m_Logger.debug("Set Quat9 to 100Hz frequency");
}
Expand All @@ -206,7 +235,7 @@ void ICM20948Sensor::startDMP()
#endif

#if(SEND_ACCELERATION)
if (this->imu.setDMPODRrate(DMP_ODR_Reg_Accel, 0) == ICM_20948_Stat_Ok)
if (this->imu.setDMPODRrate(DMP_ODR_Reg_Accel, ICM20948_ODRAXL) == ICM_20948_Stat_Ok)
{
this->m_Logger.debug("Set Accel to 100Hz frequency");
}
Expand Down Expand Up @@ -307,7 +336,7 @@ void ICM20948Sensor::readRotation()
{
#if(USE_6_AXIS)
{
if ((dmpData.header & DMP_header_bitmap_Quat6) > 0)
if (((dmpData.header & DMP_header_bitmap_Quat6) > 0) && hasdata)
{
// Q0 value is computed from this equation: Q0^2 + Q1^2 + Q2^2 + Q3^2 = 1.
// In case of drift, the sum will not add to 1, therefore, quaternion data need to be corrected with right bias values.
Expand All @@ -334,7 +363,7 @@ void ICM20948Sensor::readRotation()
}
#else
{
if((dmpData.header & DMP_header_bitmap_Quat9) > 0)
if(((dmpData.header & DMP_header_bitmap_Quat9) > 0) && hasdata)
{
// Q0 value is computed from this equation: Q0^2 + Q1^2 + Q2^2 + Q3^2 = 1.
// In case of drift, the sum will not add to 1, therefore, quaternion data need to be corrected with right bias values.
Expand Down
7 changes: 7 additions & 0 deletions src/sensors/icm20948sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class ICM20948Sensor : public Sensor
unsigned long lastData = 0;
unsigned long lastDataSent = 0;
int bias_save_counter = 0;
bool hasdata = false;
// Performance test
/*
uint8_t cntbuf = 0;
int32_t cntrounds = 0;
unsigned long lastData2 = 0;
*/

#define DMPNUMBERTODOUBLECONVERTER 1073741824.0;

Expand Down