I2C interface for LG1300L IMU

Dependents:   LG1300L_Hello_World LG1300L_Hello_World_LCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LG1300L.h Source File

LG1300L.h

00001 #include "mbed.h"
00002 #ifndef MBED_LG1300L_H
00003 #define MBED_LG1300L_H
00004 /** CruizCore XG1300L IMU interface
00005  *  Used for communicating with an XG1300L IMU over I2C
00006  *  @code
00007  *#include "mbed.h"
00008  *#include "TextLCD.h"
00009  *#include "LG1300L.h"
00010  *
00011  *TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
00012  *
00013  *Serial pc(USBTX, USBRX); // tx, rx
00014  *  
00015  *I2C i2c(p28,p27);
00016  *DigitalOut LED (LED1);
00017  *
00018  *int main() {
00019  *    LG1300L IMU(i2c, 2);
00020  *
00021  *    while(1) {
00022  *        float angle = IMU.GetAngle();
00023  *        float ROT= IMU.GetROT();
00024  *        float X_ACC = IMU.GetACC_X();
00025  *        float Y_ACC = IMU. GetACC_Y();
00026  *        float Z_ACC = IMU. GetACC_Z();
00027  *        pc.printf("///////////////////////////////////\n");
00028  *        pc.printf("//ANGLE: %f\n", angle);
00029  *        pc.printf("//ROT: %f\n", ROT);
00030  *        pc.printf("//X-Axis: %f\n", X_ACC );
00031  *        pc.printf("//Y-Axis: %f\n", Y_ACC );
00032  *        pc.printf("//Z-axis: %f\n", Z_ACC );
00033  *        pc.printf("///////////////////////////////////\n");
00034  *        wait(1);
00035  *    }
00036  *}
00037  *    @endcode
00038  */
00039 
00040 
00041 
00042 
00043 class LG1300L{
00044 public:
00045 
00046     /** Create an IMU readout interface   
00047      *
00048      * @param i2c The instantiated I2C bus to be used
00049      * @param ACC_SETTING the desired initialization range for the
00050      * @note Create an IMU readout interface 
00051      accelerometers, choices are +-2G, +-4G, or +-8G
00052      */
00053 LG1300L(I2C& i2c, int ACC_SETTING);
00054 
00055     /** Returns a float containing the current Accumulated Angle  
00056      * @returns the Accumulated Angle
00057      */
00058 float GetAngle();
00059     /** Returns a float containing the current ROT  
00060      * @returns the Rate of Turn 
00061      */
00062 float GetROT();
00063     /** Returns a float containing the current acceleration on
00064      * the X axis. 
00065      * @returns the acceleration on the X_Axis   
00066      *  
00067      */
00068 float GetACC_X();
00069     /** Returns a float containing the current acceleration on
00070      *the Y axis. 
00071      * @returns the acceleration on the Y_Axis       
00072      */
00073 float GetACC_Y();
00074     /** Returns a float containing the current acceleration on
00075      *the Z axis.
00076      * @returns the acceleration on the Z_Axis       
00077      */
00078 float GetACC_Z();
00079 private:
00080 
00081 void init();
00082 
00083     char ANGLE_LSB_REG[1];
00084     char ANGLE_MSB_REG[1];
00085     char ROT_LSB_REG[1];
00086     char ROT_MSB_REG[1];  
00087     char X_ACC_LSB_REG[1];
00088     char X_ACC_MSB_REG[1];
00089     char Y_ACC_LSB_REG[1];
00090     char Y_ACC_MSB_REG[1];
00091     char Z_ACC_LSB_REG[1];
00092     char Z_ACC_MSB_REG[1];      
00093     
00094 
00095     char RESET_REG[1];
00096     char SELECT_2G_REG[1];
00097     char SELECT_4G_REG[1];
00098     char SELECT_8G_REG[1];
00099 
00100 float CALC_ANG, CALC_ROT, CALC_X, CALC_Y, CALC_Z;
00101 int ACC_RANGE;
00102 signed short ANGLE_MSB;
00103 signed short ANGLE_LSB;
00104 signed short ROT_MSB;
00105 signed short ROT_LSB;
00106 signed short ACC_X_MSB;
00107 signed short ACC_X_LSB;
00108 signed short ACC_Y_MSB;
00109 signed short ACC_Y_LSB;
00110 signed short ACC_Z_MSB;
00111 signed short ACC_Z_LSB;
00112 protected:
00113 
00114 I2C& IMU;
00115 char data[2];
00116 const int IMU_ADDR;
00117 };
00118 
00119 #endif