imu rev1
Fork of AIviate by
Revision 3:f9e18a9cd9af, committed 2013-11-01
- Comitter:
- teamgoat
- Date:
- Fri Nov 01 01:23:04 2013 +0000
- Parent:
- 2:452dd766d212
- Child:
- 4:44a5b1e8fd27
- Commit message:
- Gyro is working; note: need to implement zero-level canceling on gyro (zero-level is result of stress on sensor being mounted on PCB)
Changed in this revision
--- a/sensor.cpp Fri Nov 01 00:48:06 2013 +0000 +++ b/sensor.cpp Fri Nov 01 01:23:04 2013 +0000 @@ -136,7 +136,7 @@ if (ret == 0) { if (DEBUG) - pc.printf("Error putting accelerometer in measure mode (accelerometer_measure)\r\n"); + pc.printf("Error turning on gyro (gyro_turnon)\r\n"); return 0; } power_ctl |= 0x8 ; @@ -144,7 +144,7 @@ if (ret == 0) { if (DEBUG) - pc.printf("Error putting accelerometer in measure mode (accelerometer_measure)\r\n"); + pc.printf("Error turning on gyro (gyro_turnon)\r\n"); return 0; } return 1; @@ -157,7 +157,7 @@ if (ret == 0) { if (DEBUG) - pc.printf("Error putting accelerometer in standby (accelerometer_standby)\r\n"); + pc.printf("Error turning off gyro (gyro_turnoff)\r\n"); return 0; } power_ctl &= 0xF7 ; @@ -165,7 +165,7 @@ if (ret == 0) { if (DEBUG) - pc.printf("Error putting accelerometer in standby (accelerometer_standby)\r\n"); + pc.printf("Error turning off gyro (gyro_turnoff)\r\n"); return 0; } return 1; @@ -202,9 +202,9 @@ { if (DEBUG) pc.printf("Error starting up accelerometer\r\n"); - return 1; + return 0; } - return ret; + return 8; } int config_gyro(void) { @@ -214,17 +214,21 @@ { if (DEBUG) pc.printf("Error starting up gyro\r\n"); - return 1; + return 0; } - return ret; + return 4; } -void config_compass(void){} -void config_barometer(void){} +int config_compass(void){return 2;} +int config_barometer(void){return 1;} int config_gy80(struct config *c) { + // return value is a 4-bit number: AGCB, indicating + // the return values of accel, gyro, compass, and barometer i2c.frequency(c->frequency); - return config_accelerometer(); - /*config_gyro(); - config_compass()*/; + int ret = config_accelerometer(); + ret |= config_gyro(); + ret |= config_compass(); + ret |= config_barometer(); + return ret; } \ No newline at end of file
--- a/sensor.h Fri Nov 01 00:48:06 2013 +0000 +++ b/sensor.h Fri Nov 01 01:23:04 2013 +0000 @@ -10,7 +10,7 @@ #define accel_w 0xA6 #define ACCEL_X 0x32 // x: 0x32,0x33 y: 0x34,0x35 z: 0x36,0x37 Little Endian!!! (x = 0x33<<8|0x22). 2's complement 16bit #define ACCEL_POWER_CTL 0x2D -#define gyro_w 0xD0 +#define gyro_w 0xD2 #define GYRO_X 0x28 // x: 0x28,0x29 y: 0x2A,0x2B z: 0x2C,0x2D Little Endian! (x = 0x28<<8|0x22). 2's complement 16bit #define GYRO_CTRL_REG1 0x20 #define compass_w 0x3C @@ -51,8 +51,8 @@ int config_accelerometer(void); int config_gyro(void); -void config_compass(void); -void config_barometer(void); +int config_compass(void); +int config_barometer(void); int config_gy80(struct config *c);
--- a/steps.cpp Fri Nov 01 00:48:06 2013 +0000 +++ b/steps.cpp Fri Nov 01 01:23:04 2013 +0000 @@ -11,8 +11,12 @@ pc.printf("Error in get_sensor_data while reading from accel!\r\n"); return; } - - pc.printf("Ax: %i Ay: %i Az: %i;\r\n", s.ax, s.ay, s.az); + if (read_gyro(&s) == 0) + { + pc.printf("Error in get_sensor_data while reading from gyro!\r\n"); + return; + } + pc.printf("Ax: %i Ay: %i Az: %i Gx: %i Gy: %i Gz: %i\r\n", s.ax, s.ay, s.az, s.gx, s.gy, s.gz); return; }