imu: replace all floats by doubles to avoid warning in printf
authorOlivier Matz <zer0@droids-corp.org>
Thu, 26 Jun 2014 18:23:22 +0000 (20:23 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 26 Jun 2014 18:23:22 +0000 (20:23 +0200)
imu.c
mpu6050.c
mpu6050.h

diff --git a/imu.c b/imu.c
index 8486960..745df11 100644 (file)
--- a/imu.c
+++ b/imu.c
@@ -81,18 +81,18 @@ void do_led_blink(void *dummy)
 //uint8_t command_buf[I2C_SEND_BUFFER_SIZE];
 
 
-float Accel_Vector[3]= {0,0,0}; //Store the acceleration in a vector
-float Gyro_Vector[3]= {0,0,0};//Store the gyros rutn rate in a vector
-float Magnet_Vector[3]= {0,0,0}; //Store the acceleration in a vector
+double Accel_Vector[3]= {0,0,0}; //Store the acceleration in a vector
+double Gyro_Vector[3]= {0,0,0};//Store the gyros rutn rate in a vector
+double Magnet_Vector[3]= {0,0,0}; //Store the acceleration in a vector
 
-float Omega_Vector[3]= {0,0,0}; //Corrected Gyro_Vector data
-float Omega_P[3]= {0,0,0};//Omega Proportional correction
-float Omega_I[3]= {0,0,0};//Omega Integrator
-float Omega[3]= {0,0,0};
+double Omega_Vector[3]= {0,0,0}; //Corrected Gyro_Vector data
+double Omega_P[3]= {0,0,0};//Omega Proportional correction
+double Omega_I[3]= {0,0,0};//Omega Integrator
+double Omega[3]= {0,0,0};
 
-float Update_Matrix[3][3]={{0,1,2},{3,4,5},{6,7,8}}; //Gyros here
+double Update_Matrix[3][3]={{0,1,2},{3,4,5},{6,7,8}}; //Gyros here
 
-float DCM_Matrix[3][3]= {
+double DCM_Matrix[3][3]= {
   {
     1,0,0  }
   ,{
@@ -101,7 +101,7 @@ float DCM_Matrix[3][3]= {
     0,0,1  }
 };
 
-float Temporary_Matrix[3][3]={
+double Temporary_Matrix[3][3]={
   {
     0,0,0  }
   ,{
@@ -110,11 +110,11 @@ float Temporary_Matrix[3][3]={
     0,0,0  }
 };
 
-float errorRollPitch[3]= {0,0,0};
-float errorYaw[3]= {0,0,0};
-float errorCourse=180;
-float COGX=0; //Course overground X axis
-float COGY=1; //Course overground Y axis
+double errorRollPitch[3]= {0,0,0};
+double errorYaw[3]= {0,0,0};
+double errorCourse=180;
+double COGX=0; //Course overground X axis
+double COGY=1; //Course overground Y axis
 
 
 
@@ -136,7 +136,7 @@ float COGY=1; //Course overground Y axis
 #define Gyro_Scaled_Y(x) ((x)*ToRad(Gyro_Gain_Y)) //Return the scaled ADC raw data of the gyro in radians for second
 #define Gyro_Scaled_Z(x) ((x)*ToRad(Gyro_Gain_Z)) //Return the scaled ADC raw data of the gyro in radians for second
 
-float G_Dt=0.02;    // Integration time (DCM algorithm)
+double G_Dt=0.02;    // Integration time (DCM algorithm)
 
 #define GRAVITY 1.01 //this equivalent to 1G in the raw data coming from the accelerometer
 #define Accel_Scale(x) x*(GRAVITY/9.81)//Scaling the raw data of the accel to actual acceleration in meters for seconds square
@@ -155,15 +155,15 @@ float G_Dt=0.02;    // Integration time (DCM algorithm)
 
 
 int mag_offset[3];
-float Heading;
-float Heading_X;
-float Heading_Y;
+double Heading;
+double Heading_X;
+double Heading_Y;
 
 
 // Euler angles
-float roll;
-float pitch;
-float yaw;
+double roll;
+double pitch;
+double yaw;
 
 int SENSOR_SIGN[]= {
        1,1,1,   // GYROX, GYROY, GYROZ,
@@ -173,29 +173,29 @@ int SENSOR_SIGN[]= {
 
 #if 0
 
-float read_adc(uint8_t index)
+double read_adc(uint8_t index)
 {
        int16_t value;
 
        switch(index) {
                case 0:
                        itg3200_read_axe(0, &value);
-                       return (float) (SENSOR_SIGN[index] * value);
+                       return (double) (SENSOR_SIGN[index] * value);
                case 1:
                        itg3200_read_axe(1, &value);
-                       return (float) (SENSOR_SIGN[index] * value);
+                       return (double) (SENSOR_SIGN[index] * value);
                case 2:
                        itg3200_read_axe(2, &value);
-                       return (float) (SENSOR_SIGN[index] * value);
+                       return (double) (SENSOR_SIGN[index] * value);
                case 3:
                        bma150_read_axe(0, &value);
-                       return (float) (SENSOR_SIGN[index] * bma15_axe2g(value));
+                       return (double) (SENSOR_SIGN[index] * bma15_axe2g(value));
                case 4:
                        bma150_read_axe(1, &value);
-                       return (float) (SENSOR_SIGN[index] * bma15_axe2g(value));
+                       return (double) (SENSOR_SIGN[index] * bma15_axe2g(value));
                case 5:
                        bma150_read_axe(2, &value);
-                       return (float) (SENSOR_SIGN[index] * bma15_axe2g(value));
+                       return (double) (SENSOR_SIGN[index] * bma15_axe2g(value));
        }
        return 0.0;
 }
@@ -221,9 +221,9 @@ void read_sensors(void)
                err = ak8500_read_all_axes(&axes);
                if (err == 0) {
                        /*
-                       Magnet_Vector[0] = (float)SENSOR_SIGN[6] * (float)axes[0];
-                       Magnet_Vector[1] = (float)SENSOR_SIGN[7] * (float)axes[1];
-                       Magnet_Vector[2] = (float)SENSOR_SIGN[8] * (float)axes[2];
+                       Magnet_Vector[0] = (double)SENSOR_SIGN[6] * (double)axes[0];
+                       Magnet_Vector[1] = (double)SENSOR_SIGN[7] * (double)axes[1];
+                       Magnet_Vector[2] = (double)SENSOR_SIGN[8] * (double)axes[2];
                        */
                        /*
                        */
index 4f1ab81..5ffa100 100644 (file)
--- a/mpu6050.c
+++ b/mpu6050.c
 
 #define SWAP_16(a) ((( (a) & 0xff)<<8) | (( (a) >> 8) & 0xff))
 
-float mpu6050_gx;
-float mpu6050_gy;
-float mpu6050_gz;
+double mpu6050_gx;
+double mpu6050_gy;
+double mpu6050_gz;
 
-float mpu6050_ax;
-float mpu6050_ay;
-float mpu6050_az;
+double mpu6050_ax;
+double mpu6050_ay;
+double mpu6050_az;
 
-float mpu6050_mx;
-float mpu6050_my;
-float mpu6050_mz;
+double mpu6050_mx;
+double mpu6050_my;
+double mpu6050_mz;
 
-float mpu6050_temp;
+double mpu6050_temp;
 
 int16_t drift_g[3] = {0, 0, 0};
 
@@ -81,19 +81,19 @@ uint8_t mpu6050_read_all_axes(int16_t *values)
                values[i] = SWAP_16(values[i]);
        }
 
-       mpu6050_ax = 9.81 * (float)values[0] / accel_x_resolution ;
-       mpu6050_ay = 9.81 * (float)values[1] / accel_y_resolution ;
-       mpu6050_az = 9.81 * (float)values[2] / accel_z_resolution ;
+       mpu6050_ax = 9.81 * (double)values[0] / accel_x_resolution ;
+       mpu6050_ay = 9.81 * (double)values[1] / accel_y_resolution ;
+       mpu6050_az = 9.81 * (double)values[2] / accel_z_resolution ;
 
-       mpu6050_temp = (float)values[3]/340. + 36.5;
+       mpu6050_temp = (double)values[3]/340. + 36.5;
 
-       mpu6050_gx = ToRad((float)(values[4] - drift_g[0]) / gyro_x_resolution );
-       mpu6050_gy = ToRad((float)(values[5] - drift_g[1]) / gyro_y_resolution );
-       mpu6050_gz = ToRad((float)(values[6] - drift_g[2]) / gyro_z_resolution );
+       mpu6050_gx = ToRad((double)(values[4] - drift_g[0]) / gyro_x_resolution );
+       mpu6050_gy = ToRad((double)(values[5] - drift_g[1]) / gyro_y_resolution );
+       mpu6050_gz = ToRad((double)(values[6] - drift_g[2]) / gyro_z_resolution );
 
-       mpu6050_mx = (float) values[7] * 0.3;
-       mpu6050_my = (float) values[8] * 0.3;
-       mpu6050_mz = (float) values[9] * 0.3;
+       mpu6050_mx = (double) values[7] * 0.3;
+       mpu6050_my = (double) values[8] * 0.3;
+       mpu6050_mz = (double) values[9] * 0.3;
 
 
        return err;
index 5113b0d..b04c67c 100644 (file)
--- a/mpu6050.h
+++ b/mpu6050.h
@@ -119,19 +119,19 @@ uint8_t mpu6050_init(void);
 uint8_t mpu6050_read_all_axes(int16_t *values);
 
 
-extern float mpu6050_gx;
-extern float mpu6050_gy;
-extern float mpu6050_gz;
+extern double mpu6050_gx;
+extern double mpu6050_gy;
+extern double mpu6050_gz;
 
-extern float mpu6050_ax;
-extern float mpu6050_ay;
-extern float mpu6050_az;
+extern double mpu6050_ax;
+extern double mpu6050_ay;
+extern double mpu6050_az;
 
 
-extern float mpu6050_mx;
-extern float mpu6050_my;
-extern float mpu6050_mz;
+extern double mpu6050_mx;
+extern double mpu6050_my;
+extern double mpu6050_mz;
 
-extern float mpu6050_temp;
+extern double mpu6050_temp;
 
 #endif // _MPU6050_H_