interface class for an inertial measurement unit that uses a serial protocol.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MS3DMGX2.h"
00003 
00004 MS3DMGX2 IMU(p9, p10);
00005 DigitalOut led(LED1);
00006 DigitalOut led4(LED4);
00007 Serial PC(USBTX,USBRX);
00008 int main()
00009 {
00010 led=0;
00011 led4=0;
00012 PC.baud(9600);
00013     float data[9];
00014     bool isvalid;
00015     wait(1);
00016     isvalid = IMU.Mode(0x05);
00017     PC.printf("Data Valid: %d\r\n\r\n", isvalid);
00018     //IMU.RequestSyncRead();
00019     wait(1);
00020     
00021     while (1)
00022     {
00023         while(!IMU.Readable());
00024         isvalid = IMU.Read(data);
00025         
00026         PC.printf("IMU Accel x Reads %f\r\n",data[0]);//NOTE: the compiler will not even calculate unused variables
00027         PC.printf("IMU accel y Reads %f\r\n",data[1]);//If the data retrieved above was not used, it wouldn't even be retrieved and the validity check would not pass
00028         PC.printf("IMU accel z Reads %f\r\n",data[2]);//this is called "compiler optimization"
00029         
00030         PC.printf("IMU ang rate x Reads %f\r\n",data[3]);
00031         PC.printf("IMU ang rate y Reads %f\r\n",data[4]);
00032         PC.printf("IMU ang rate z Reads %f\r\n",data[5]); 
00033         
00034         PC.printf("IMU mag x Reads %f\r\n",data[6]);
00035         PC.printf("IMU mag y Reads %f\r\n",data[7]);
00036         PC.printf("IMU mag z Reads %f\r\n",data[8]); 
00037         PC.printf("Validity: %d\r\n\r\n", isvalid);
00038         
00039         wait_ms(1000);
00040     }
00041 }