IMU Operation:

The IMU uses a Microchip DSPIC33FJ64MC202 to implement the algorithm and to communicate with the gyro chip (L3G4200D) and the accelerometer/magnetometer chip (LSM303DLHC). These sensors use an I2C bus to communicate with the DSPIC. The algorithm internal computations use an update rate of 250 Hz. The algorithm uses a sequential quadratic programming approach in which quaternion parameters that define the displacement of the IMU from the home position are the unknown variables. These variables are adjusted recursively in order to minimize the difference between the predicted measurements and the actual measurements in a least squares sense.

Communication with the Arduino (or other microcontrollers) is achieved using the DSPIC’s built in DMA data transfer to SPI or UART function. This enables the Arduino to request data asynchronously from the internal DSPIC algorithm. Data transfer occurs in less than 0.1 millisecond, depending on the clock speeds of the master device.

The SPI lines used by the DSPIC are 5 V tolerant so the Arduino can be operated at 5 V with the same wiring as for 3.3 V operation. However, be sure not to apply more than 3.3 V at the power input to the IMU since this will overload all of the devices on the IMU (DSPIC, L3G4200D, LSM303DLHC). The IMU consumes a current of about 75 ma, and does not have a sleep state. The DSPIC can be rebooted by pulling the RES pin low for a short time. However, it is best to reboot the entire IMU by removing the supply voltage since this will also reboot the gyro and accelerometer chips.
Coordinate Frames and Output Data:

The IMU uses the coordinate frames shown in the figures. The "inertial" frame is defined by the red axes, with x in the magnetic north direction, z down, and y defined such that the cross product of x and y gives z. The IMU algorithm assumes that this frame is translating at constant velocity. Accelerations of the frame will create errors in estimation, but the algorithm has been tuned to minimize these errors. The moving "body fixed" frame is defined by the blue axes. The motion of the body fixed frame is defined relative to the inertial frame by three Euler angles: roll φ, pitch θ, and yaw ψ angles as shown.
1) Home position
2) Rotation about z by yaw angle ψ = 30 °
3) Rotation about body-fixed (blue) y axis by pitch angle θ = 30 °
4) Rotation about body-fixed (blue) x axis by roll angle φ = 30 °

The x, y, and z axes of the IMU are labelled on the circuit board as shown. If these axes are initially aligned with the red axes in home position, labelled 1) in the figure, the first three outputs of the IMU will read 0.0. When the IMU orientation is not in the home position, the IMU algorithm outputs its best estimate of the current roll φ, pitch θ, and yaw ψ angles. Depending on how it is wired (see wiring diagrams), the IMU returns these angles alone continuously at 50Hz, or if the Serial Peripheral Interface (SPI) is used, the IMU returns the angles, their time derivatives, and the acceleration of the moving body. The acceleration is projected to a frame that has its x-y axis horizontal, with the horizontal x axis aligned with the body-fixed x axis. Using the Arduino as the SPI master and the IMU as the SPI slave, the time needed to transmit these 9 integers (2 bytes each) is around 800 microseconds. Your Arduino can request the data as often as it likes, but internally, the IMU updates its data at 250 Hz.

Vectors in the body fixed (blue) frame are related to vectors in the inertial (red) frame by the relation:

p i = R (ψ, θ, φ) p b

where p i is a 3-dimensional vector in the inertial frame, p b is a 3-dimensional vector in the body-fixed frame, and the 3x3 rotation matrix (also called direction cosine matrix) R (ψ, θ, φ) is given by:

This rotation matrix is used to relate vectors in the body-fixed IMU frame to vectors in the inertial frame. The acceleration of the body is output by the IMU when the SPI interface is used. This rotation transformation breaks down when the pitch
θ ≈ ± 90 ° since it is impossible to distinguish the roll φ angle from the yaw ψ when the x axis is pointing straight up or down. Internally, the IMU uses quaternions rather than roll, pitch, and yaw, so there is no problem with computations in this “singular configuration” (R (ψ, θ, φ) is not invertible in this configuration).