The communication with IMU
The dsPID4W MPLABX project is the same for both master and slave board. The board addressed by the IMU is elected as master at startup and performs a different behavior.
The master part of the code is designed to accept also commands on UART1 port with the original, unmodified, hardware. All the command recognized are explained on parser part of the description file attached to the project. In Lino version it is connected instead to the IMU through I2C bus. The I2C slave ISR, as aforementioned, is a porting of the PIC18F version.
The
I2C buffers on dsNav are the slave counterparts of the master
TX and
RX buffers on
UDB4 code.They are also created as struct and union in order to rebuild in the correct way the different variables divided as bytes on transmission.
On the I2C bus the dsNav master sends to the IMU data computed by odometry (position coordinates), values measured in the master board itself (motors current and speed for front wheels) and data received by the slave dsNav board (motors current and speed for rear wheels).
The values received by IMU are both the navigation indication sent by
HLS (desired speed and direction) and current heading computed by IMU. Two flags set the addressed board as dsNav master and say to it that a new data packet arrived. The heading is computed and sent by the IMU every 25ms. The odometry is computed by the dsNav every 10ms. The odometry heading is used when IMU one is not present and the value is reset when the most reliable one is received.
Some more words must be spent on stasis values computed inside dsNav master. According to
David Anderson studies, the dead-reckoning obtained by odometry on motors encoders, is good enough for distance but not for orientation. The position is computed therefore with the fusion of odometry on front wheels while the heading is received by the IMU. The heading is computed anymore by odometry at every cycle. I
f no data are received by the IMU (NewFlag not set), that is the value used for dead-reckoning.
If data are received from IMU, the
two values are compared. When IMU said for a time long enough that the rover is not turning but the encoders said it is turning, it means that the wheels are slipping, maybe because of an obstacle in the rover path. In this case the
HLS, receiving this information via the IMU, must decide the right behavior, moving backward or changing orientation.
For dsNav, the serial ports are dedicated only to the master-slave communication. The elected master sends to the slave speed setting for each single wheel and receives motors current and real speed for telemetry.