![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
gy
Dependencies: mbed
main.cpp@0:ad7593dc27a6, 2015-12-07 (annotated)
- Committer:
- palmdotax
- Date:
- Mon Dec 07 09:20:21 2015 +0000
- Revision:
- 0:ad7593dc27a6
gy
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
palmdotax | 0:ad7593dc27a6 | 1 | /***** |
palmdotax | 0:ad7593dc27a6 | 2 | Algorithm based on MPU-9250_Snowda program. It has been modified by Josu? Olmeda Castell? for imasD Tecnolog?a. |
palmdotax | 0:ad7593dc27a6 | 3 | |
palmdotax | 0:ad7593dc27a6 | 4 | This algorithm calibrates and reads data from accelerometer, gyroscope, magnetometer and the |
palmdotax | 0:ad7593dc27a6 | 5 | internal temperature sensor. The lecture is made each time has a new mesured value (both gyro and accel data). |
palmdotax | 0:ad7593dc27a6 | 6 | A comunication with a computer is made using serial interface. The user can see the data measured with 1 second update rate. |
palmdotax | 0:ad7593dc27a6 | 7 | |
palmdotax | 0:ad7593dc27a6 | 8 | This algorithm uses the STM32L152 development board and the MPU-9250 9-axis InvenSense movement sensor. The communication |
palmdotax | 0:ad7593dc27a6 | 9 | between both devices is made through I2C serial interface. |
palmdotax | 0:ad7593dc27a6 | 10 | |
palmdotax | 0:ad7593dc27a6 | 11 | AD0 should be connected to GND. |
palmdotax | 0:ad7593dc27a6 | 12 | |
palmdotax | 0:ad7593dc27a6 | 13 | 04/05/2015 |
palmdotax | 0:ad7593dc27a6 | 14 | *****/ |
palmdotax | 0:ad7593dc27a6 | 15 | |
palmdotax | 0:ad7593dc27a6 | 16 | #include "mbed.h" |
palmdotax | 0:ad7593dc27a6 | 17 | #include "mpu9250.h" |
palmdotax | 0:ad7593dc27a6 | 18 | void timer(); |
palmdotax | 0:ad7593dc27a6 | 19 | |
palmdotax | 0:ad7593dc27a6 | 20 | |
palmdotax | 0:ad7593dc27a6 | 21 | Serial pc(USBTX, USBRX); // Huyperterminal default config: 9600 bauds, 8-bit data, 1 stop bit, no parity |
palmdotax | 0:ad7593dc27a6 | 22 | Serial bell(PA_11,PA_12); |
palmdotax | 0:ad7593dc27a6 | 23 | MPU9250 mpu9250; |
palmdotax | 0:ad7593dc27a6 | 24 | Timer t; |
palmdotax | 0:ad7593dc27a6 | 25 | //DigitalOut myled(LED1); |
palmdotax | 0:ad7593dc27a6 | 26 | |
palmdotax | 0:ad7593dc27a6 | 27 | float sum = 0; |
palmdotax | 0:ad7593dc27a6 | 28 | uint32_t sumCount = 0; |
palmdotax | 0:ad7593dc27a6 | 29 | char buffer[14]; |
palmdotax | 0:ad7593dc27a6 | 30 | uint8_t dato_leido[2]; |
palmdotax | 0:ad7593dc27a6 | 31 | uint8_t whoami; |
palmdotax | 0:ad7593dc27a6 | 32 | char showtimez[10]; |
palmdotax | 0:ad7593dc27a6 | 33 | int timez=0; |
palmdotax | 0:ad7593dc27a6 | 34 | |
palmdotax | 0:ad7593dc27a6 | 35 | int main() { |
palmdotax | 0:ad7593dc27a6 | 36 | |
palmdotax | 0:ad7593dc27a6 | 37 | //___ Set up I2C: use fast (400 kHz) I2C ___ |
palmdotax | 0:ad7593dc27a6 | 38 | i2c.frequency(400000); |
palmdotax | 0:ad7593dc27a6 | 39 | |
palmdotax | 0:ad7593dc27a6 | 40 | pc.printf("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); |
palmdotax | 0:ad7593dc27a6 | 41 | |
palmdotax | 0:ad7593dc27a6 | 42 | t.start(); // Timer ON |
palmdotax | 0:ad7593dc27a6 | 43 | |
palmdotax | 0:ad7593dc27a6 | 44 | // Read the WHO_AM_I register, this is a good test of communication |
palmdotax | 0:ad7593dc27a6 | 45 | whoami = mpu9250.readByte(MPU9250_ADDRESS, WHO_AM_I_MPU9250); |
palmdotax | 0:ad7593dc27a6 | 46 | |
palmdotax | 0:ad7593dc27a6 | 47 | pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x71\n\r"); |
palmdotax | 0:ad7593dc27a6 | 48 | if (I2Cstate != 0) // error on I2C |
palmdotax | 0:ad7593dc27a6 | 49 | pc.printf("I2C failure while reading WHO_AM_I register"); |
palmdotax | 0:ad7593dc27a6 | 50 | |
palmdotax | 0:ad7593dc27a6 | 51 | if (whoami == 0x71) // WHO_AM_I should always be 0x71 |
palmdotax | 0:ad7593dc27a6 | 52 | { |
palmdotax | 0:ad7593dc27a6 | 53 | pc.printf("MPU9250 WHO_AM_I is 0x%x\n\r", whoami); |
palmdotax | 0:ad7593dc27a6 | 54 | pc.printf("MPU9250 is online...\n\r"); |
palmdotax | 0:ad7593dc27a6 | 55 | sprintf(buffer, "0x%x", whoami); |
palmdotax | 0:ad7593dc27a6 | 56 | wait(1); |
palmdotax | 0:ad7593dc27a6 | 57 | |
palmdotax | 0:ad7593dc27a6 | 58 | mpu9250.resetMPU9250(); // Reset registers to default in preparation for device calibration |
palmdotax | 0:ad7593dc27a6 | 59 | |
palmdotax | 0:ad7593dc27a6 | 60 | mpu9250.MPU9250SelfTest(SelfTest); // Start by performing self test and reporting values (accelerometer and gyroscope self test) |
palmdotax | 0:ad7593dc27a6 | 61 | pc.printf("x-axis self test: acceleration trim within : %f % of factory value\n\r", SelfTest[0]); |
palmdotax | 0:ad7593dc27a6 | 62 | pc.printf("y-axis self test: acceleration trim within : %f % of factory value\n\r", SelfTest[1]); |
palmdotax | 0:ad7593dc27a6 | 63 | pc.printf("z-axis self test: acceleration trim within : %f % of factory value\n\r", SelfTest[2]); |
palmdotax | 0:ad7593dc27a6 | 64 | pc.printf("x-axis self test: gyration trim within : %f % of factory value\n\r", SelfTest[3]); |
palmdotax | 0:ad7593dc27a6 | 65 | pc.printf("y-axis self test: gyration trim within : %f % of factory value\n\r", SelfTest[4]); |
palmdotax | 0:ad7593dc27a6 | 66 | pc.printf("z-axis self test: gyration trim within : %f % of factory value\n\r", SelfTest[5]); |
palmdotax | 0:ad7593dc27a6 | 67 | |
palmdotax | 0:ad7593dc27a6 | 68 | mpu9250.calibrateMPU9250(gyroBias, accelBias); // Calibrate gyro and accelerometer, load biases in bias registers |
palmdotax | 0:ad7593dc27a6 | 69 | pc.printf("x gyro bias = %f\n\r", gyroBias[0]); |
palmdotax | 0:ad7593dc27a6 | 70 | pc.printf("y gyro bias = %f\n\r", gyroBias[1]); |
palmdotax | 0:ad7593dc27a6 | 71 | pc.printf("z gyro bias = %f\n\r", gyroBias[2]); |
palmdotax | 0:ad7593dc27a6 | 72 | pc.printf("x accel bias = %f\n\r", accelBias[0]); |
palmdotax | 0:ad7593dc27a6 | 73 | pc.printf("y accel bias = %f\n\r", accelBias[1]); |
palmdotax | 0:ad7593dc27a6 | 74 | pc.printf("z accel bias = %f\n\r", accelBias[2]); |
palmdotax | 0:ad7593dc27a6 | 75 | wait(2); |
palmdotax | 0:ad7593dc27a6 | 76 | |
palmdotax | 0:ad7593dc27a6 | 77 | // Initialize device for active mode read of acclerometer, gyroscope, and temperature |
palmdotax | 0:ad7593dc27a6 | 78 | mpu9250.initMPU9250(); |
palmdotax | 0:ad7593dc27a6 | 79 | pc.printf("MPU9250 initialized for active data mode....\n\r"); |
palmdotax | 0:ad7593dc27a6 | 80 | |
palmdotax | 0:ad7593dc27a6 | 81 | // Initialize device for active mode read of magnetometer, 16 bit resolution, 100Hz. |
palmdotax | 0:ad7593dc27a6 | 82 | mpu9250.initAK8963(magCalibration); |
palmdotax | 0:ad7593dc27a6 | 83 | pc.printf("AK8963 initialized for active data mode....\n\r"); |
palmdotax | 0:ad7593dc27a6 | 84 | pc.printf("Accelerometer full-scale range = %f g\n\r", 2.0f*(float)(1<<Ascale)); |
palmdotax | 0:ad7593dc27a6 | 85 | pc.printf("Gyroscope full-scale range = %f deg/s\n\r", 250.0f*(float)(1<<Gscale)); |
palmdotax | 0:ad7593dc27a6 | 86 | if(Mscale == 0) pc.printf("Magnetometer resolution = 14 bits\n\r"); |
palmdotax | 0:ad7593dc27a6 | 87 | if(Mscale == 1) pc.printf("Magnetometer resolution = 16 bits\n\r"); |
palmdotax | 0:ad7593dc27a6 | 88 | if(Mmode == 2) pc.printf("Magnetometer ODR = 8 Hz\n\r"); |
palmdotax | 0:ad7593dc27a6 | 89 | if(Mmode == 6) pc.printf("Magnetometer ODR = 100 Hz\n\r"); |
palmdotax | 0:ad7593dc27a6 | 90 | wait(1); |
palmdotax | 0:ad7593dc27a6 | 91 | } |
palmdotax | 0:ad7593dc27a6 | 92 | |
palmdotax | 0:ad7593dc27a6 | 93 | else // Connection failure |
palmdotax | 0:ad7593dc27a6 | 94 | { |
palmdotax | 0:ad7593dc27a6 | 95 | pc.printf("Could not connect to MPU9250: \n\r"); |
palmdotax | 0:ad7593dc27a6 | 96 | pc.printf("%#x \n", whoami); |
palmdotax | 0:ad7593dc27a6 | 97 | sprintf(buffer, "WHO_AM_I 0x%x", whoami); |
palmdotax | 0:ad7593dc27a6 | 98 | while(1) ; // Loop forever if communication doesn't happen |
palmdotax | 0:ad7593dc27a6 | 99 | } |
palmdotax | 0:ad7593dc27a6 | 100 | |
palmdotax | 0:ad7593dc27a6 | 101 | mpu9250.getAres(); // Get accelerometer sensitivity |
palmdotax | 0:ad7593dc27a6 | 102 | mpu9250.getGres(); // Get gyro sensitivity |
palmdotax | 0:ad7593dc27a6 | 103 | mpu9250.getMres(); // Get magnetometer sensitivity |
palmdotax | 0:ad7593dc27a6 | 104 | pc.printf("Accelerometer sensitivity is %f LSB/g \n\r", 1.0f/aRes); |
palmdotax | 0:ad7593dc27a6 | 105 | pc.printf("Gyroscope sensitivity is %f LSB/deg/s \n\r", 1.0f/gRes); |
palmdotax | 0:ad7593dc27a6 | 106 | pc.printf("Magnetometer sensitivity is %f LSB/G \n\r", 1.0f/mRes); |
palmdotax | 0:ad7593dc27a6 | 107 | magbias[0] = +470.; // User environmental x-axis correction in milliGauss, should be automatically calculated |
palmdotax | 0:ad7593dc27a6 | 108 | magbias[1] = +120.; // User environmental x-axis correction in milliGauss |
palmdotax | 0:ad7593dc27a6 | 109 | magbias[2] = +125.; // User environmental x-axis correction in milliGauss |
palmdotax | 0:ad7593dc27a6 | 110 | |
palmdotax | 0:ad7593dc27a6 | 111 | while(1) { |
palmdotax | 0:ad7593dc27a6 | 112 | |
palmdotax | 0:ad7593dc27a6 | 113 | // If intPin goes high, all data registers have new data |
palmdotax | 0:ad7593dc27a6 | 114 | if(mpu9250.readByte(MPU9250_ADDRESS, INT_STATUS) & 0x01) { // On interrupt, check if data ready interrupt |
palmdotax | 0:ad7593dc27a6 | 115 | |
palmdotax | 0:ad7593dc27a6 | 116 | mpu9250.readAccelData(accelCount); // Read the x/y/z adc values |
palmdotax | 0:ad7593dc27a6 | 117 | // Now we'll calculate the accleration value into actual g's |
palmdotax | 0:ad7593dc27a6 | 118 | if (I2Cstate != 0) //error on I2C |
palmdotax | 0:ad7593dc27a6 | 119 | pc.printf("I2C error ocurred while reading accelerometer data. I2Cstate = %d \n\r", I2Cstate); |
palmdotax | 0:ad7593dc27a6 | 120 | else{ // I2C read or write ok |
palmdotax | 0:ad7593dc27a6 | 121 | I2Cstate = 1; |
palmdotax | 0:ad7593dc27a6 | 122 | ax = (float)accelCount[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set |
palmdotax | 0:ad7593dc27a6 | 123 | ay = (float)accelCount[1]*aRes - accelBias[1]; |
palmdotax | 0:ad7593dc27a6 | 124 | az = (float)accelCount[2]*aRes - accelBias[2]; |
palmdotax | 0:ad7593dc27a6 | 125 | } |
palmdotax | 0:ad7593dc27a6 | 126 | |
palmdotax | 0:ad7593dc27a6 | 127 | mpu9250.readGyroData(gyroCount); // Read the x/y/z adc values |
palmdotax | 0:ad7593dc27a6 | 128 | // Calculate the gyro value into actual degrees per second |
palmdotax | 0:ad7593dc27a6 | 129 | if (I2Cstate != 0) //error on I2C |
palmdotax | 0:ad7593dc27a6 | 130 | pc.printf("I2C error ocurred while reading gyrometer data. I2Cstate = %d \n\r", I2Cstate); |
palmdotax | 0:ad7593dc27a6 | 131 | else{ // I2C read or write ok |
palmdotax | 0:ad7593dc27a6 | 132 | I2Cstate = 1; |
palmdotax | 0:ad7593dc27a6 | 133 | gx = (float)gyroCount[0]*gRes - gyroBias[0]; // get actual gyro value, this depends on scale being set |
palmdotax | 0:ad7593dc27a6 | 134 | gy = (float)gyroCount[1]*gRes - gyroBias[1]; |
palmdotax | 0:ad7593dc27a6 | 135 | gz = (float)gyroCount[2]*gRes - gyroBias[2]; |
palmdotax | 0:ad7593dc27a6 | 136 | } |
palmdotax | 0:ad7593dc27a6 | 137 | |
palmdotax | 0:ad7593dc27a6 | 138 | mpu9250.readMagData(magCount); // Read the x/y/z adc values |
palmdotax | 0:ad7593dc27a6 | 139 | // Calculate the magnetometer values in milliGauss |
palmdotax | 0:ad7593dc27a6 | 140 | // Include factory calibration per data sheet and user environmental corrections |
palmdotax | 0:ad7593dc27a6 | 141 | if (I2Cstate != 0) //error on I2C |
palmdotax | 0:ad7593dc27a6 | 142 | pc.printf("I2C error ocurred while reading magnetometer data. I2Cstate = %d \n\r", I2Cstate); |
palmdotax | 0:ad7593dc27a6 | 143 | else{ // I2C read or write ok |
palmdotax | 0:ad7593dc27a6 | 144 | I2Cstate = 1; |
palmdotax | 0:ad7593dc27a6 | 145 | mx = (float)magCount[0]*mRes*magCalibration[0] - magbias[0]; // get actual magnetometer value, this depends on scale being set |
palmdotax | 0:ad7593dc27a6 | 146 | my = (float)magCount[1]*mRes*magCalibration[1] - magbias[1]; |
palmdotax | 0:ad7593dc27a6 | 147 | mz = (float)magCount[2]*mRes*magCalibration[2] - magbias[2]; |
palmdotax | 0:ad7593dc27a6 | 148 | } |
palmdotax | 0:ad7593dc27a6 | 149 | |
palmdotax | 0:ad7593dc27a6 | 150 | mpu9250.getCompassOrientation(orientation); |
palmdotax | 0:ad7593dc27a6 | 151 | } |
palmdotax | 0:ad7593dc27a6 | 152 | |
palmdotax | 0:ad7593dc27a6 | 153 | Now = t.read_us(); |
palmdotax | 0:ad7593dc27a6 | 154 | deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update |
palmdotax | 0:ad7593dc27a6 | 155 | lastUpdate = Now; |
palmdotax | 0:ad7593dc27a6 | 156 | sum += deltat; |
palmdotax | 0:ad7593dc27a6 | 157 | sumCount++; |
palmdotax | 0:ad7593dc27a6 | 158 | |
palmdotax | 0:ad7593dc27a6 | 159 | // Pass gyro rate as rad/s |
palmdotax | 0:ad7593dc27a6 | 160 | // mpu9250.MadgwickQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz); |
palmdotax | 0:ad7593dc27a6 | 161 | mpu9250.MahonyQuaternionUpdate(ax, ay, az, gx*PI/180.0f, gy*PI/180.0f, gz*PI/180.0f, my, mx, mz); |
palmdotax | 0:ad7593dc27a6 | 162 | |
palmdotax | 0:ad7593dc27a6 | 163 | |
palmdotax | 0:ad7593dc27a6 | 164 | // Serial print and/or display at 1.5 s rate independent of data rates |
palmdotax | 0:ad7593dc27a6 | 165 | delt_t = t.read_ms() - count; |
palmdotax | 0:ad7593dc27a6 | 166 | if (delt_t > 100) { // update LCD once per half-second independent of read rate |
palmdotax | 0:ad7593dc27a6 | 167 | // pc.printf("ax = %f", 1000*ax); |
palmdotax | 0:ad7593dc27a6 | 168 | // pc.printf(" ay = %f", 1000*ay); |
palmdotax | 0:ad7593dc27a6 | 169 | // pc.printf(" az = %f mg\n\r", 1000*az); |
palmdotax | 0:ad7593dc27a6 | 170 | // pc.printf("gx = %f", gx); |
palmdotax | 0:ad7593dc27a6 | 171 | // pc.printf(" gy = %f", gy); |
palmdotax | 0:ad7593dc27a6 | 172 | // pc.printf(" gz = %f deg/s\n\r", gz); |
palmdotax | 0:ad7593dc27a6 | 173 | // pc.printf("mx = %f", mx); |
palmdotax | 0:ad7593dc27a6 | 174 | // pc.printf(" my = %f", my); |
palmdotax | 0:ad7593dc27a6 | 175 | // pc.printf(" mz = %f mG\n\r", mz); |
palmdotax | 0:ad7593dc27a6 | 176 | |
palmdotax | 0:ad7593dc27a6 | 177 | |
palmdotax | 0:ad7593dc27a6 | 178 | tempCount = mpu9250.readTempData(); // Read the adc values |
palmdotax | 0:ad7593dc27a6 | 179 | if (I2Cstate != 0) //error on I2C |
palmdotax | 0:ad7593dc27a6 | 180 | pc.printf("I2C error ocurred while reading sensor temp. I2Cstate = %d \n\r", I2Cstate); |
palmdotax | 0:ad7593dc27a6 | 181 | else{ // I2C read or write ok |
palmdotax | 0:ad7593dc27a6 | 182 | I2Cstate = 1; |
palmdotax | 0:ad7593dc27a6 | 183 | temperature = ((float) tempCount) / 333.87f + 21.0f; // Temperature in degrees Centigrade |
palmdotax | 0:ad7593dc27a6 | 184 | // pc.printf(" temperature = %f C\n\r", temperature); |
palmdotax | 0:ad7593dc27a6 | 185 | } |
palmdotax | 0:ad7593dc27a6 | 186 | // pc.printf("q0 = %f\n\r", q[0]); |
palmdotax | 0:ad7593dc27a6 | 187 | // pc.printf("q1 = %f\n\r", q[1]); |
palmdotax | 0:ad7593dc27a6 | 188 | // pc.printf("q2 = %f\n\r", q[2]); |
palmdotax | 0:ad7593dc27a6 | 189 | // pc.printf("q3 = %f\n\r", q[3]); |
palmdotax | 0:ad7593dc27a6 | 190 | |
palmdotax | 0:ad7593dc27a6 | 191 | // pc.printf("Compass orientation: %f\n", orientation[0]); |
palmdotax | 0:ad7593dc27a6 | 192 | |
palmdotax | 0:ad7593dc27a6 | 193 | |
palmdotax | 0:ad7593dc27a6 | 194 | |
palmdotax | 0:ad7593dc27a6 | 195 | |
palmdotax | 0:ad7593dc27a6 | 196 | // Define output variables from updated quaternion---these are Tait-Bryan angles, commonly used in aircraft orientation. |
palmdotax | 0:ad7593dc27a6 | 197 | // In this coordinate system, the positive z-axis is down toward Earth. |
palmdotax | 0:ad7593dc27a6 | 198 | // Yaw is the angle between Sensor x-axis and Earth magnetic North (or true North if corrected for local declination, looking down on the sensor positive yaw is counterclockwise. |
palmdotax | 0:ad7593dc27a6 | 199 | // Pitch is angle between sensor x-axis and Earth ground plane, toward the Earth is positive, up toward the sky is negative. |
palmdotax | 0:ad7593dc27a6 | 200 | // Roll is angle between sensor y-axis and Earth ground plane, y-axis up is positive roll. |
palmdotax | 0:ad7593dc27a6 | 201 | // These arise from the definition of the homogeneous rotation matrix constructed from quaternions. |
palmdotax | 0:ad7593dc27a6 | 202 | // Tait-Bryan angles as well as Euler angles are non-commutative; that is, the get the correct orientation the rotations must be |
palmdotax | 0:ad7593dc27a6 | 203 | // applied in the correct order which for this configuration is yaw, pitch, and then roll. |
palmdotax | 0:ad7593dc27a6 | 204 | // For more see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles which has additional links. |
palmdotax | 0:ad7593dc27a6 | 205 | |
palmdotax | 0:ad7593dc27a6 | 206 | yaw = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]); |
palmdotax | 0:ad7593dc27a6 | 207 | pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2])); |
palmdotax | 0:ad7593dc27a6 | 208 | roll = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]); |
palmdotax | 0:ad7593dc27a6 | 209 | pitch *= 180.0f / PI; |
palmdotax | 0:ad7593dc27a6 | 210 | yaw *= 180.0f / PI; |
palmdotax | 0:ad7593dc27a6 | 211 | yaw -= 13.8f; // Declination at Danville, California is 13 degrees 48 minutes and 47 seconds on 2014-04-04 |
palmdotax | 0:ad7593dc27a6 | 212 | roll *= 180.0f / PI; |
palmdotax | 0:ad7593dc27a6 | 213 | |
palmdotax | 0:ad7593dc27a6 | 214 | |
palmdotax | 0:ad7593dc27a6 | 215 | pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll); |
palmdotax | 0:ad7593dc27a6 | 216 | pc.printf("Pitch, Roll: %f %f\n\r", pitch, roll); |
palmdotax | 0:ad7593dc27a6 | 217 | /* if(pitch>40&&pitch<80){ |
palmdotax | 0:ad7593dc27a6 | 218 | pc.printf("VV\n");} |
palmdotax | 0:ad7593dc27a6 | 219 | else if(pitch>10&&pitch<40){ |
palmdotax | 0:ad7593dc27a6 | 220 | pc.printf("V\n");} |
palmdotax | 0:ad7593dc27a6 | 221 | else if(pitch>-80&&pitch<-40){ |
palmdotax | 0:ad7593dc27a6 | 222 | pc.printf("^^\n");} |
palmdotax | 0:ad7593dc27a6 | 223 | else if(pitch>-40&&pitch<-10){ |
palmdotax | 0:ad7593dc27a6 | 224 | pc.printf("^\n");} |
palmdotax | 0:ad7593dc27a6 | 225 | |
palmdotax | 0:ad7593dc27a6 | 226 | else if(roll>40&&roll<80){ |
palmdotax | 0:ad7593dc27a6 | 227 | pc.printf("<<\n");} |
palmdotax | 0:ad7593dc27a6 | 228 | else if(roll>10&&roll<40){ |
palmdotax | 0:ad7593dc27a6 | 229 | pc.printf("<\n");} |
palmdotax | 0:ad7593dc27a6 | 230 | else if(roll>-80&&roll<-40){ |
palmdotax | 0:ad7593dc27a6 | 231 | pc.printf(">>\n");} |
palmdotax | 0:ad7593dc27a6 | 232 | else if(roll>-40&&roll<-10){ |
palmdotax | 0:ad7593dc27a6 | 233 | pc.printf(">\n");} |
palmdotax | 0:ad7593dc27a6 | 234 | else {pc.printf("No move\n"); |
palmdotax | 0:ad7593dc27a6 | 235 | //showtimez=timer(); |
palmdotax | 0:ad7593dc27a6 | 236 | timer; |
palmdotax | 0:ad7593dc27a6 | 237 | bell.printf("time\n");} |
palmdotax | 0:ad7593dc27a6 | 238 | // pc.printf("average rate = %f\n\r", (float) sumCount/sum); |
palmdotax | 0:ad7593dc27a6 | 239 | |
palmdotax | 0:ad7593dc27a6 | 240 | |
palmdotax | 0:ad7593dc27a6 | 241 | |
palmdotax | 0:ad7593dc27a6 | 242 | myled= !myled; |
palmdotax | 0:ad7593dc27a6 | 243 | count = t.read_ms(); |
palmdotax | 0:ad7593dc27a6 | 244 | |
palmdotax | 0:ad7593dc27a6 | 245 | if(count > 1<<21) { |
palmdotax | 0:ad7593dc27a6 | 246 | t.start(); // start the timer over again if ~30 minutes has passed |
palmdotax | 0:ad7593dc27a6 | 247 | count = 0; |
palmdotax | 0:ad7593dc27a6 | 248 | deltat= 0; |
palmdotax | 0:ad7593dc27a6 | 249 | lastUpdate = t.read_us(); |
palmdotax | 0:ad7593dc27a6 | 250 | } |
palmdotax | 0:ad7593dc27a6 | 251 | sum = 0; |
palmdotax | 0:ad7593dc27a6 | 252 | sumCount = 0; |
palmdotax | 0:ad7593dc27a6 | 253 | } |
palmdotax | 0:ad7593dc27a6 | 254 | } |
palmdotax | 0:ad7593dc27a6 | 255 | } |
palmdotax | 0:ad7593dc27a6 | 256 | |
palmdotax | 0:ad7593dc27a6 | 257 | |
palmdotax | 0:ad7593dc27a6 | 258 | void timer() |
palmdotax | 0:ad7593dc27a6 | 259 | { |
palmdotax | 0:ad7593dc27a6 | 260 | timez=timez+100; |
palmdotax | 0:ad7593dc27a6 | 261 | //bell.printf(timez); |
palmdotax | 0:ad7593dc27a6 | 262 | }*/ |
palmdotax | 0:ad7593dc27a6 | 263 | } |
palmdotax | 0:ad7593dc27a6 | 264 | } |
palmdotax | 0:ad7593dc27a6 | 265 | } |