pylon:
What exactly is the "first one", "second one" and "third one" in this context?
One IMU to another one. So having 3 IMUs i'll get 2 Relative motion.
pylon:
Forget that, the relative error sums up to complete uselessness within no time. You might get a rough direction but forget a useful distance value.
Using something like Magdwick filter? (or similar)
pylon:
The time needed to transfer the values from one IMU is below 4ms. How did you measure the 30ms? There is no measuring code in the posted sketch. You can increase the I2C speed to 400kHz but your circuit design might not allow that (overall capacitance of the bus).
This is the code i'm using. I'm getting 9-axis measaurements from these 3 IMUs connected through multiplex I2C.
I fixed the ODR (output data rate) for the IMUs at 400Hz, but i see (with millis() function) the temporal distance from one reading and the next one is roughly 20ms, so 55Hz. I've already setted up setClock to 400KHz.
// Including Libraries
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_FXOS8700.h>
#include <Adafruit_FXAS21002C.h>
// Definition Multiplex's address
#define TCAADDR 0x70
// Assignation Sensors' ID
Adafruit_FXOS8700 accelmag = Adafruit_FXOS8700(0x8700A, 0x8700B);
Adafruit_FXAS21002C gyro = Adafruit_FXAS21002C(0x0021002C);
Adafruit_FXOS8700 accelmag1 = Adafruit_FXOS8700(0x8700A, 0x8700B);
Adafruit_FXAS21002C gyro1 = Adafruit_FXAS21002C(0x0021002C);
Adafruit_FXOS8700 accelmag2 = Adafruit_FXOS8700(0x8700A, 0x8700B);
Adafruit_FXAS21002C gyro2 = Adafruit_FXAS21002C(0x0021002C);
// definition of the variables
float accx, accy, accz;
float gyrox, gyroy, gyroz;
float magx, magy, magz;
float accx1, accy1, accz1;
float gyrox1, gyroy1, gyroz1;
float magx1, magy1, magz1;
float accx2, accy2, accz2;
float gyrox2, gyroy2, gyroz2;
float magx2, magy2, magz2;
// tcaselect to choose which channel has to work
void tcaselect (uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup() {
delay(5000);
//SerialUSB.println("TEST With Matlab!");
Wire.begin();
Wire.setClock(400000);
SerialUSB.begin(115200);
tcaselect(7);
if(!gyro.begin())
{
/* There was a problem detecting the FXAS21002C ... check your connections */
SerialUSB.println("Ooops, no FXAS21002C detected ... Check your wiring!");
while(1);
}
/* Initialise Accelerometer and Magnetometer */
if(!accelmag.begin())
{
/* There was a problem detecting the FXOS8700 ... check your connections */
SerialUSB.println("Ooops, no FXOS8700 detected ... Check your wiring!");
while(1);
}
/* SECOND IMU */
tcaselect(2);
if(!gyro1.begin())
{
/* There was a problem detecting the FXAS21002C ... check your connections */
SerialUSB.println("Ooops, no FXAS21002C detected ... Check your wiring!");
while(1);
}
/* Initialise Accelerometer and Magnetometer */
if(!accelmag1.begin())
{
/* There was a problem detecting the FXOS8700 ... check your connections */
SerialUSB.println("Ooops, no FXOS8700 detected ... Check your wiring!");
while(1);
}
/* THIRD IMU */
tcaselect(4);
if(!gyro2.begin())
{
/* There was a problem detecting the FXAS21002C ... check your connections */
SerialUSB.println("Ooops, no FXAS21002C detected ... Check your wiring!");
while(1);
}
/* Initialise Accelerometer and Magnetometer */
if(!accelmag2.begin())
{
/* There was a problem detecting the FXOS8700 ... check your connections */
SerialUSB.println("Ooops, no FXOS8700 detected ... Check your wiring!");
while(1);
}
}
void loop() {
if(SerialUSB.available()>0) {
if(SerialUSB.read() == 'a') {
//SerialUSB.println("1000");
/* READING FROM 1° IMU */
sensors_event_t aevent, mevent;
/* Get first sensor event */
tcaselect(7);
accelmag.getEvent(&aevent, &mevent);
sensors_event_t event;
// tcaselect(7);
gyro.getEvent(&event);
// FIRST IMU
/* Display the accel results (acceleration is measured in m/s^2) */
SerialUSB.print(aevent.acceleration.x, 3); SerialUSB.print(",");
SerialUSB.print(aevent.acceleration.y, 3); SerialUSB.print(",");
SerialUSB.print(aevent.acceleration.z, 3); SerialUSB.print(",");
/* Display the mag results (mag data is in uTesla) */
SerialUSB.print(mevent.magnetic.x, 3); SerialUSB.print(",");
SerialUSB.print(mevent.magnetic.y, 3); SerialUSB.print(",");
SerialUSB.print(mevent.magnetic.z, 3); SerialUSB.print(",");
/* Display the gyro results (speed is measured in rad/s) */
SerialUSB.print(event.gyro.x, 3); SerialUSB.print(",");
SerialUSB.print(event.gyro.y, 3); SerialUSB.print(",");
SerialUSB.print(event.gyro.z, 3); SerialUSB.print(",");
/* READING FROM 2° IMU */
sensors_event_t aevent1, mevent1;
tcaselect(2);
accelmag.getEvent(&aevent1, &mevent1);
/* Get second sensor event */
sensors_event_t event1;
// tcaselect(2);
gyro.getEvent(&event1);
// SECOND IMU
/* Display the accel results (acceleration is measured in m/s^2) */
SerialUSB.print(aevent1.acceleration.x, 3); SerialUSB.print(",");
SerialUSB.print(aevent1.acceleration.y, 3); SerialUSB.print(",");
SerialUSB.print(aevent1.acceleration.z, 3); SerialUSB.print(",");
/* Display the mag results (mag data is in uTesla) */
SerialUSB.print(mevent1.magnetic.x, 3); SerialUSB.print(",");
SerialUSB.print(mevent1.magnetic.y, 3); SerialUSB.print(",");
SerialUSB.print(mevent1.magnetic.z, 3); SerialUSB.print(",");
/* Display the gyro results (speed is measured in rad/s) */
SerialUSB.print(event1.gyro.x, 3); SerialUSB.print(",");
SerialUSB.print(event1.gyro.y, 3); SerialUSB.print(",");
SerialUSB.print(event1.gyro.z, 3); SerialUSB.print(",");
//SerialUSB.println("Time");SerialUSB.println(millis());
/* READING FROM 3° IMU */
sensors_event_t aevent2, mevent2;
/* Get first sensor event */
tcaselect(4);
accelmag.getEvent(&aevent2, &mevent2);
sensors_event_t event2;
// tcaselect(4);
gyro.getEvent(&event2);
// THIRD IMU
SerialUSB.print(aevent2.acceleration.x, 3); SerialUSB.print(",");
SerialUSB.print(aevent2.acceleration.y, 3); SerialUSB.print(",");
SerialUSB.print(aevent2.acceleration.z, 3); SerialUSB.print(",");
/* Display the mag results (mag data is in uTesla) */
SerialUSB.print(mevent2.magnetic.x, 3); SerialUSB.print(",");
SerialUSB.print(mevent2.magnetic.y, 3); SerialUSB.print(",");
SerialUSB.print(mevent2.magnetic.z, 3); SerialUSB.print(",");
/* Display the gyro results (speed is measured in rad/s) */
SerialUSB.print(event2.gyro.x, 3); SerialUSB.print(",");
SerialUSB.print(event2.gyro.y, 3); SerialUSB.print(",");
SerialUSB.print(event2.gyro.z, 3); SerialUSB.print(",");
SerialUSB.println(millis());
}
}
}
[code]
How could I speed up the communication?
[/code]