Thursday, June 2, 2011

IMU Design

Dear all,

I have developed an IMU using two breakout boards available in Sparkfun electronics,which are ITG3200 and ADXL345, the prototype is really working good. The code for my prototype is attached below.

references for the sensors: http://www.sparkfun.com/products/9694
: http://www.sparkfun.com/products/9836

sample code and example programs are also available from the above links. Infact i used those sample programs to develop this code.


#include "mbed.h"
#include "ADXL345.h"
#include "ITG3200.h"

Serial pc(USBTX, USBRX);
ITG3200 gyro(p28, p27);


ADXL345 accelerometer(p11, p12, p13, p14);


int main() {
int readings[3] = {0, 0, 0};
pc.printf("Now starting ITG-3200 test...\n");

//Set highest bandwidth.
gyro.setLpBandwidth(LPFBW_42HZ);

pc.printf("Starting ADXL345 test...\n");
pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId());

//Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);

//Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);

//3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);

//Measurement mode.
accelerometer.setPowerControl(0x08);
while (1) {

wait(0.1);
accelerometer.getOutput(readings);
unsigned int j,k,l,m,n,o,p,q,r,s,t,u;
//13-bit, sign extended values.
// pc.printf("LeftACC1:%i , LeftACC2:%i , LeftACC3:%i ", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]);

// pc.printf(" LeftGyroX:%d , LeftGyroY:%d , LeftGyroZ%d \n\r", gyro.getGyroX(),gyro.getGyroY(), gyro.getGyroZ());

j = (int16_t)readings[0];
k = (int16_t)readings[1];
l = (int16_t)readings[2];
m = gyro.getGyroX();
n = gyro.getGyroY();
o = gyro.getGyroZ();


Serial pc(USBTX, USBRX);
ITG3200 gyro(p28, p27);



ADXL345 accelerometer(p11, p12, p13, p14);

accelerometer.getOutput(readings);
gyro.setLpBandwidth(LPFBW_42HZ);

p = (int16_t)readings[0];
q = (int16_t)readings[1];
r = (int16_t)readings[2];
s = gyro.getGyroX();
t = gyro.getGyroY();
u = gyro.getGyroZ();


pc.printf("%i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i\n", j,k,l,p,q,r,m,n,o,s,t,u);

}
}



Here pc.printf will directly prints the output on ouput console. we can use either windows hyperterminal or any other serial data acquision softwares like real-term or tera term etc..