testing gyro get orientation,acceleration states get difference in two states of the device
Dependencies: mbed
Fork of testing_gyro by
Diff: main.cpp
- Revision:
- 3:95fecaa76b4a
- Parent:
- 2:2ef63ab235bf
- Child:
- 4:e89d74a1d9f5
--- a/main.cpp Tue Mar 18 17:29:44 2014 +0000 +++ b/main.cpp Sun Mar 22 16:17:19 2015 +0000 @@ -18,6 +18,7 @@ Serial pc(USBTX, USBRX); // tx, rx for USB debug printf to terminal console I2C i2c(p28, p27); // LPC1768 I2C pin allocation + // Globals int16_t const Offset_mX=-40.0; int16_t const Offset_mY=-115.0; @@ -88,16 +89,14 @@ #endif pc.printf("--------------------------------------\n \n"); - wait(1); // Wait for settings to stabilize + wait(2); // Wait for settings to stabilize } void LPS331(SensorState_t state) // Read the pressure sensor { - uint8_t tempL,tempH,pressXL,pressL,pressH; + uint8_t tempL,tempH; int16_t temp; - int32_t press24; - float pressure; // Measure temperature tempL=readByte(LPS331addr,pTEMP_OUT_L); @@ -107,19 +106,7 @@ state.tempC=((float) temp / 480.0) + 42.5; // per equation on page 29 of the spec pc.printf("Pressure sensor temperature %.1f degreesC \n",state.tempC); - - // Pressure test - pressXL=readByte(LPS331addr,pPRESS_OUT_XL); - pressL=readByte(LPS331addr,pPRESS_OUT_L); - pressH=readByte(LPS331addr,pPRESS_OUT_H); - - press24=(pressH << 16) | (pressL << 8) | pressXL ; // 24-bit 2's complement data - pressure = (float)press24/4096.0; // Sensitivity is 4096 LSB per milibar - - pc.printf("Pressure %.1f mbars or %.1f inches Hg\n", pressure, (pressure*0.0295)+0.029); - - } - +} void LSM303 (SensorState_t * state) // Magnetometer and accelerometer { @@ -175,9 +162,9 @@ state->heading=heading; state->pitch=pitch; state->roll=roll; - - pc.printf("Orientation (deg): Pitch: %5.1f Roll: %5.1f Heading: %5.1f \n",pitch*RadtoDeg,roll*RadtoDeg,heading); - pc.printf("Acceleration (mg): Forward: %5hd Left: %5hd Up: %5hd \n",aX,aY,aZ); + //5.1f + pc.printf("Orientation (deg): Rot_X: %0.0f Rot_Y: %0.0f Rot_Z: %0.0f \n",roll*RadtoDeg,pitch*RadtoDeg,heading); + pc.printf("Acceleration (mg): X: %5hd Y: %5hd Z: %5hd \n",aX,aY,aZ); } @@ -211,12 +198,12 @@ { SensorState_t state; initSensors(); - + pc.baud(115200); while(1) { - + #ifdef LPS331_on - LPS331(state); + //LPS331(state); #endif #ifdef LSM303_on @@ -224,13 +211,10 @@ #endif #ifdef L3GD20_on - L3GD20(); + //L3GD20(); #endif pc.printf("\n"); - wait(.5); + wait(.1); } -} - - - +} \ No newline at end of file