code of robot bike
Dependencies: SDFileSystem mbed
Fork of Robot_Bicycle by
SPI_9dSensor.h@12:60593247555d, 2017-02-22 (annotated)
- Committer:
- cpul5338
- Date:
- Wed Feb 22 09:49:44 2017 +0000
- Revision:
- 12:60593247555d
- Parent:
- 10:3b952ea7fad4
robot bike
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YCTung | 0:830ddddc129f | 1 | #ifndef SPI_9DSENSOR_H_INCLUDED |
YCTung | 0:830ddddc129f | 2 | #define SPI_9DSENSOR_H_INCLUDED |
YCTung | 0:830ddddc129f | 3 | |
YCTung | 0:830ddddc129f | 4 | #include "mbed.h" // GPIO |
YCTung | 0:830ddddc129f | 5 | |
YCTung | 0:830ddddc129f | 6 | #define sensorG_CTRL_REG1_address 0x20 |
YCTung | 0:830ddddc129f | 7 | #define sensorXM_CTRL_REG0_address 0x1F |
YCTung | 0:830ddddc129f | 8 | #define sensorG_OUT_X_L_address 0x28 |
YCTung | 0:830ddddc129f | 9 | #define sensorXM_OUT_X_L_A_address 0x28 |
YCTung | 0:830ddddc129f | 10 | #define sensorXM_OUT_X_L_M_address 0x08 |
YCTung | 0:830ddddc129f | 11 | |
YCTung | 0:830ddddc129f | 12 | #define CSG 0 |
YCTung | 0:830ddddc129f | 13 | #define CSXM 1 |
YCTung | 0:830ddddc129f | 14 | |
YCTung | 0:830ddddc129f | 15 | #define INDEX_GYRO_X 1 |
YCTung | 0:830ddddc129f | 16 | #define INDEX_GYRO_Y 2 |
YCTung | 0:830ddddc129f | 17 | #define INDEX_GYRO_Z 3 |
YCTung | 0:830ddddc129f | 18 | #define INDEX_ACCE_X 4 |
YCTung | 0:830ddddc129f | 19 | #define INDEX_ACCE_Y 5 |
YCTung | 0:830ddddc129f | 20 | #define INDEX_ACCE_Z 6 |
YCTung | 0:830ddddc129f | 21 | #define INDEX_MAGN_X 7 |
YCTung | 0:830ddddc129f | 22 | #define INDEX_MAGN_Y 8 |
YCTung | 0:830ddddc129f | 23 | #define INDEX_MAGN_Z 9 |
YCTung | 0:830ddddc129f | 24 | |
cpul5338 | 12:60593247555d | 25 | // sensor correction |
cpul5338 | 12:60593247555d | 26 | #define GX_offset 50.095//35 |
cpul5338 | 12:60593247555d | 27 | #define GY_offset 56.249//same |
cpul5338 | 12:60593247555d | 28 | #define GZ_offset 1.862//151 |
cpul5338 | 12:60593247555d | 29 | #define AX_offset -651.6106//-715///-908 |
cpul5338 | 12:60593247555d | 30 | #define AY_offset -697.9139//-501 |
cpul5338 | 12:60593247555d | 31 | #define AZ_offset 218.8919//215 |
YCTung | 0:830ddddc129f | 32 | #define MX_offset 136 |
YCTung | 0:830ddddc129f | 33 | #define MY_offset -108 |
YCTung | 0:830ddddc129f | 34 | #define MZ_offset -102 |
YCTung | 0:830ddddc129f | 35 | |
cpul5338 | 12:60593247555d | 36 | // Gain of Gyro and Acce |
YCTung | 0:830ddddc129f | 37 | #define Mag_backgnd 0.36435f ///gauss, Magnetic field in Hsinchu |
cpul5338 | 12:60593247555d | 38 | #define Gyro_gainx 0.002422966362920f///2000dps/2^15 = 61 miliDegree/s = 0.001065rad/s |
cpul5338 | 12:60593247555d | 39 | #define Gyro_gainy 0.002422966362920f///0.001212716 |
cpul5338 | 12:60593247555d | 40 | #define Gyro_gainz 0.002422966362920f///0.0012375596 |
cpul5338 | 12:60593247555d | 41 | #define Acce_gainx -0.002404245422390f///=8*9.81/2^15 |
cpul5338 | 12:60593247555d | 42 | #define Acce_gainy -0.002344293490135f///=8*9.81/2^15 |
cpul5338 | 12:60593247555d | 43 | #define Acce_gainz -0.002307390759185f///=8*9.81/2^15 |
YCTung | 0:830ddddc129f | 44 | #define Magn_gain 0.000244f ///8gauss/2^15 = 0.000244gauss |
YCTung | 0:830ddddc129f | 45 | |
YCTung | 4:b0967990e390 | 46 | extern SPI sensor_LSM9D; |
YCTung | 1:709be64ca63c | 47 | extern DigitalOut sensor_CSG; |
YCTung | 1:709be64ca63c | 48 | extern DigitalOut sensor_CSXM; |
YCTung | 1:709be64ca63c | 49 | |
YCTung | 0:830ddddc129f | 50 | extern unsigned char sensorG_CTRL_REG[6], sensorXM_CTRL_REG[9]; |
YCTung | 0:830ddddc129f | 51 | |
YCTung | 0:830ddddc129f | 52 | extern short int Gyro_axis_data[3], Gyro_axis_zero[3]; |
YCTung | 0:830ddddc129f | 53 | extern float Gyro_scale[3]; |
YCTung | 0:830ddddc129f | 54 | |
YCTung | 0:830ddddc129f | 55 | extern short int Acce_axis_data[3], Acce_axis_zero[3]; |
YCTung | 0:830ddddc129f | 56 | extern float Acce_scale[3]; |
YCTung | 0:830ddddc129f | 57 | |
YCTung | 0:830ddddc129f | 58 | extern short int Magn_axis_data[3], Magn_axis_zero[3]; |
YCTung | 0:830ddddc129f | 59 | extern float Magn_scale[3]; |
YCTung | 0:830ddddc129f | 60 | |
YCTung | 0:830ddddc129f | 61 | extern float B_x, B_y, B_z, B_total; |
YCTung | 0:830ddddc129f | 62 | extern float u_cali[9], u_old[9]; |
YCTung | 0:830ddddc129f | 63 | |
YCTung | 10:3b952ea7fad4 | 64 | extern bool setup_spi_sensor(void); |
YCTung | 0:830ddddc129f | 65 | |
YCTung | 0:830ddddc129f | 66 | extern void init_Sensors(void); |
YCTung | 0:830ddddc129f | 67 | extern void sensorG_setup(void); |
YCTung | 0:830ddddc129f | 68 | extern void sensorXM_setup(void); |
YCTung | 0:830ddddc129f | 69 | extern void sensorG_read_3axis(void); |
YCTung | 0:830ddddc129f | 70 | extern void sensorX_read_3axis(void); |
YCTung | 0:830ddddc129f | 71 | extern void sensorM_read_3axis(void); |
YCTung | 0:830ddddc129f | 72 | |
YCTung | 0:830ddddc129f | 73 | extern short int filted_sensor_data(unsigned char axis_index, float freq); |
YCTung | 0:830ddddc129f | 74 | extern void reset_gyro_offset(void); |
YCTung | 0:830ddddc129f | 75 | extern void reset_acceX_offset(void); |
YCTung | 0:830ddddc129f | 76 | |
YCTung | 0:830ddddc129f | 77 | extern void get_9axis_scale(void); |
YCTung | 0:830ddddc129f | 78 | |
YCTung | 10:3b952ea7fad4 | 79 | extern unsigned char get_WhoAmI_G(void); |
YCTung | 10:3b952ea7fad4 | 80 | extern unsigned char get_WhoAmI_XM(void); |
YCTung | 4:b0967990e390 | 81 | |
YCTung | 0:830ddddc129f | 82 | #endif // SPI_9DSENSOR_H_INCLUDED |