code of robot bike
Dependencies: SDFileSystem mbed
Fork of Robot_Bicycle by
SPI_9dSensor.h@1:709be64ca63c, 2016-06-21 (annotated)
- Committer:
- YCTung
- Date:
- Tue Jun 21 18:11:46 2016 +0000
- Revision:
- 1:709be64ca63c
- Parent:
- 0:830ddddc129f
- Child:
- 4:b0967990e390
update
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 | |
YCTung | 0:830ddddc129f | 25 | #define GX_offset 35 |
YCTung | 0:830ddddc129f | 26 | #define GY_offset -28 |
YCTung | 0:830ddddc129f | 27 | #define GZ_offset 151 |
YCTung | 0:830ddddc129f | 28 | #define AX_offset -715///-908 |
YCTung | 0:830ddddc129f | 29 | #define AY_offset -501 |
YCTung | 0:830ddddc129f | 30 | #define AZ_offset 215 |
YCTung | 0:830ddddc129f | 31 | #define MX_offset 136 |
YCTung | 0:830ddddc129f | 32 | #define MY_offset -108 |
YCTung | 0:830ddddc129f | 33 | #define MZ_offset -102 |
YCTung | 0:830ddddc129f | 34 | |
YCTung | 0:830ddddc129f | 35 | #define Mag_backgnd 0.36435f ///gauss, Magnetic field in Hsinchu |
YCTung | 0:830ddddc129f | 36 | #define Gyro_gainx 0.001065f///2000dps/2^15 = 61 miliDegree/s = 0.001065rad/s |
YCTung | 0:830ddddc129f | 37 | #define Gyro_gainy 0.001065f///0.001212716 |
YCTung | 0:830ddddc129f | 38 | #define Gyro_gainz 0.001065f///0.0012375596 |
YCTung | 0:830ddddc129f | 39 | #define Acce_gainx -0.002394f///=8*9.81/2^15 |
YCTung | 0:830ddddc129f | 40 | #define Acce_gainy -0.002394f///=8*9.81/2^15 |
YCTung | 0:830ddddc129f | 41 | #define Acce_gainz -0.002394f///=8*9.81/2^15 |
YCTung | 0:830ddddc129f | 42 | #define Magn_gain 0.000244f ///8gauss/2^15 = 0.000244gauss |
YCTung | 0:830ddddc129f | 43 | |
YCTung | 1:709be64ca63c | 44 | extern SPI spi2; |
YCTung | 1:709be64ca63c | 45 | extern DigitalOut sensor_CSG; |
YCTung | 1:709be64ca63c | 46 | extern DigitalOut sensor_CSXM; |
YCTung | 1:709be64ca63c | 47 | |
YCTung | 0:830ddddc129f | 48 | extern Serial pc; |
YCTung | 0:830ddddc129f | 49 | |
YCTung | 0:830ddddc129f | 50 | extern int volatile interrupt; |
YCTung | 0:830ddddc129f | 51 | |
YCTung | 0:830ddddc129f | 52 | extern const int speed; |
YCTung | 0:830ddddc129f | 53 | |
YCTung | 0:830ddddc129f | 54 | extern unsigned char sensorG_CTRL_REG[6], sensorXM_CTRL_REG[9]; |
YCTung | 0:830ddddc129f | 55 | |
YCTung | 0:830ddddc129f | 56 | extern short int Gyro_axis_data[3], Gyro_axis_zero[3]; |
YCTung | 0:830ddddc129f | 57 | extern float Gyro_scale[3]; |
YCTung | 0:830ddddc129f | 58 | |
YCTung | 0:830ddddc129f | 59 | extern short int Acce_axis_data[3], Acce_axis_zero[3]; |
YCTung | 0:830ddddc129f | 60 | extern float Acce_scale[3]; |
YCTung | 0:830ddddc129f | 61 | |
YCTung | 0:830ddddc129f | 62 | extern short int Magn_axis_data[3], Magn_axis_zero[3]; |
YCTung | 0:830ddddc129f | 63 | extern float Magn_scale[3]; |
YCTung | 0:830ddddc129f | 64 | |
YCTung | 0:830ddddc129f | 65 | extern float B_x, B_y, B_z, B_total; |
YCTung | 0:830ddddc129f | 66 | extern float u_cali[9], u_old[9]; |
YCTung | 0:830ddddc129f | 67 | |
YCTung | 0:830ddddc129f | 68 | extern void sig_handler(int signo); |
YCTung | 0:830ddddc129f | 69 | extern void setup_spi(void); |
YCTung | 0:830ddddc129f | 70 | void close(int fd); |
YCTung | 0:830ddddc129f | 71 | |
YCTung | 0:830ddddc129f | 72 | extern void init_Sensors(void); |
YCTung | 0:830ddddc129f | 73 | extern void sensorG_setup(void); |
YCTung | 0:830ddddc129f | 74 | extern void sensorXM_setup(void); |
YCTung | 0:830ddddc129f | 75 | extern void sensorG_read_3axis(void); |
YCTung | 0:830ddddc129f | 76 | extern void sensorX_read_3axis(void); |
YCTung | 0:830ddddc129f | 77 | extern void sensorM_read_3axis(void); |
YCTung | 0:830ddddc129f | 78 | |
YCTung | 0:830ddddc129f | 79 | extern short int filted_sensor_data(unsigned char axis_index, float freq); |
YCTung | 0:830ddddc129f | 80 | extern void reset_gyro_offset(void); |
YCTung | 0:830ddddc129f | 81 | extern void reset_acceX_offset(void); |
YCTung | 0:830ddddc129f | 82 | |
YCTung | 0:830ddddc129f | 83 | extern void get_9axis_scale(void); |
YCTung | 0:830ddddc129f | 84 | |
YCTung | 0:830ddddc129f | 85 | #endif // SPI_9DSENSOR_H_INCLUDED |