Skip to content

Commit 548f57d

Browse files
Merge pull request #5 from InvenSenseInc/features/filter_invalid_imu_data
Filter IMU invalid data:
2 parents cd55844 + 307dc51 commit 548f57d

File tree

6 files changed

+57
-13
lines changed

6 files changed

+57
-13
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,34 @@ void loop() {
178178
}
179179
```
180180

181+
**bool isAccelDataValid(inv_imu_sensor_event_t *evt)**
182+
183+
This method checks if the accelerometer data in the FIFO sample is valid.
184+
185+
```C++
186+
void event_cb(inv_imu_sensor_event_t *evt)
187+
{
188+
if(IMU.isAccelDataValid(evt)) {
189+
...
190+
}
191+
}
192+
193+
```
194+
195+
**bool isGyroDataValid(inv_imu_sensor_event_t *evt)**
196+
197+
This method checks if the gyroscope data in the FIFO sample is valid.
198+
199+
```C++
200+
void event_cb(inv_imu_sensor_event_t *evt)
201+
{
202+
if(IMU.isGyroDataValid(evt)) {
203+
...
204+
}
205+
}
206+
207+
```
208+
181209
**inv_imu_sensor_event_t**
182210

183211
This structure is used by the ICM42670P driver to return raw sensor data. Available data is:

examples/FIFO_Interrupt_SPI/FIFO_Interrupt_SPI.ino

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ void irq_handler(void) {
1111

1212
void event_cb(inv_imu_sensor_event_t *evt) {
1313
// Format data for Serial Plotter
14-
Serial.print(evt->accel[0]);
15-
Serial.print(",");
16-
Serial.print(evt->accel[1]);
17-
Serial.print(",");
18-
Serial.print(evt->accel[2]);
19-
Serial.print(",");
20-
Serial.print(evt->gyro[0]);
21-
Serial.print(",");
22-
Serial.print(evt->gyro[1]);
23-
Serial.print(",");
24-
Serial.print(evt->gyro[2]);
25-
Serial.print(",");
26-
Serial.println(evt->temperature);
14+
if(IMU.isAccelDataValid(evt)&&IMU.isGyroDataValid(evt)) {
15+
Serial.print(evt->accel[0]);
16+
Serial.print(",");
17+
Serial.print(evt->accel[1]);
18+
Serial.print(",");
19+
Serial.print(evt->accel[2]);
20+
Serial.print(",");
21+
Serial.print(evt->gyro[0]);
22+
Serial.print(",");
23+
Serial.print(evt->gyro[1]);
24+
Serial.print(",");
25+
Serial.print(evt->gyro[2]);
26+
Serial.print(",");
27+
Serial.println(evt->temperature);
28+
}
2729
}
2830

2931
void setup() {

examples/Polling_I2C/Polling_I2C.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void setup() {
1919
IMU.startAccel(100,16);
2020
// Gyro ODR = 100 Hz and Full Scale Range = 2000 dps
2121
IMU.startGyro(100,2000);
22+
// Wait IMU to start
23+
delay(100);
2224
// Plotter axis header
2325
Serial.println("AccelX,AccelY,AccelZ,GyroX,GyroY,GyroZ,Temperature");
2426
}

examples/Polling_SPI/Polling_SPI.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void setup() {
1919
IMU.startAccel(100,16);
2020
// Gyro ODR = 100 Hz and Full Scale Range = 2000 dps
2121
IMU.startGyro(100,2000);
22+
// Wait IMU to start
23+
delay(100);
2224
// Plotter axis header
2325
Serial.println("AccelX,AccelY,AccelZ,GyroX,GyroY,GyroZ,Temperature");
2426
}

src/ICM42670P.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ int ICM42670P::getDataFromFifo(ICM42670P_sensor_event_cb event_cb) {
162162
return inv_imu_get_data_from_fifo(&icm_driver);
163163
}
164164

165+
bool ICM42670P::isAccelDataValid(inv_imu_sensor_event_t *evt) {
166+
return (evt->sensor_mask & (1<<INV_SENSOR_ACCEL));
167+
}
168+
169+
bool ICM42670P::isGyroDataValid(inv_imu_sensor_event_t *evt) {
170+
return (evt->sensor_mask & (1<<INV_SENSOR_GYRO));
171+
}
172+
165173
static int i2c_write(struct inv_imu_serif * serif, uint8_t reg, const uint8_t * wbuffer, uint32_t wlen) {
166174
i2c->beginTransmission(i2c_address);
167175
i2c->write(reg);

src/ICM42670P.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ICM42670P {
5050
int getDataFromRegisters(inv_imu_sensor_event_t* evt);
5151
int enableFifoInterrupt(uint8_t intpin, ICM42670P_irq_handler handler, uint8_t fifo_watermark);
5252
int getDataFromFifo(ICM42670P_sensor_event_cb event_cb);
53+
bool isAccelDataValid(inv_imu_sensor_event_t *evt);
54+
bool isGyroDataValid(inv_imu_sensor_event_t *evt);
5355

5456
protected:
5557
struct inv_imu_device icm_driver;

0 commit comments

Comments
 (0)