unfinished
Dependents: WRS_mechanamu_test WRS2019_master mbed_2018 mbed_2019_rx3 ... more
JY901.h@4:cd62e2d69f62, 2018-08-23 (annotated)
- Committer:
- sgrsn
- Date:
- Thu Aug 23 05:33:30 2018 +0000
- Revision:
- 4:cd62e2d69f62
- Parent:
- 3:b0aecd9a3cc9
- Child:
- 5:a492cfb18242
saving memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sgrsn | 0:6ff4cad60b67 | 1 | #ifndef MBED_JY901_H |
sgrsn | 0:6ff4cad60b67 | 2 | #define MBED_JY901_H |
sgrsn | 0:6ff4cad60b67 | 3 | |
sgrsn | 0:6ff4cad60b67 | 4 | #include "mbed.h" |
sgrsn | 0:6ff4cad60b67 | 5 | |
sgrsn | 2:5af50b300137 | 6 | /*example************************************* |
sgrsn | 3:b0aecd9a3cc9 | 7 | #include "mbed.h" |
sgrsn | 3:b0aecd9a3cc9 | 8 | #include "JY901.h" |
sgrsn | 3:b0aecd9a3cc9 | 9 | |
sgrsn | 4:cd62e2d69f62 | 10 | I2C myi2c(p28, p27); |
sgrsn | 4:cd62e2d69f62 | 11 | JY901 jy901(&myi2c); |
sgrsn | 2:5af50b300137 | 12 | |
sgrsn | 2:5af50b300137 | 13 | int main() |
sgrsn | 2:5af50b300137 | 14 | { |
sgrsn | 2:5af50b300137 | 15 | float angle = 0; |
sgrsn | 4:cd62e2d69f62 | 16 | jy901.calibrateAll(5000); |
sgrsn | 2:5af50b300137 | 17 | while(1) |
sgrsn | 2:5af50b300137 | 18 | { |
sgrsn | 4:cd62e2d69f62 | 19 | angle = jy901.getZaxisAngle(); |
sgrsn | 2:5af50b300137 | 20 | printf("%f\r\n", angle); |
sgrsn | 2:5af50b300137 | 21 | } |
sgrsn | 2:5af50b300137 | 22 | } |
sgrsn | 2:5af50b300137 | 23 | **********************************************/ |
sgrsn | 2:5af50b300137 | 24 | |
sgrsn | 0:6ff4cad60b67 | 25 | #define IICADDR 0xa0 // IIC address |
sgrsn | 0:6ff4cad60b67 | 26 | #define g 9.8 // Acceleration of gravity |
sgrsn | 0:6ff4cad60b67 | 27 | |
sgrsn | 0:6ff4cad60b67 | 28 | #define SAVE 0x00 // Save |
sgrsn | 0:6ff4cad60b67 | 29 | #define CALSW 0x01 // Calibration |
sgrsn | 0:6ff4cad60b67 | 30 | #define RSW 0x02 // Return data content |
sgrsn | 0:6ff4cad60b67 | 31 | #define RATE 0x03 // Return data Speed |
sgrsn | 0:6ff4cad60b67 | 32 | #define BAUD 0x04 // Baud rate |
sgrsn | 0:6ff4cad60b67 | 33 | #define AXOFFSET 0x05 // X axis Acceleration bias |
sgrsn | 0:6ff4cad60b67 | 34 | #define AYOFFSET 0x06 // Y axis Acceleration bias |
sgrsn | 0:6ff4cad60b67 | 35 | #define AZOFFSET 0x07 // Z axis Acceleration bias |
sgrsn | 0:6ff4cad60b67 | 36 | #define GXOFFSET 0x08 // X axis angular velocity bias |
sgrsn | 0:6ff4cad60b67 | 37 | #define GYOFFSET 0x09 // Y axis angular velocity bias |
sgrsn | 0:6ff4cad60b67 | 38 | #define GZOFFSET 0x0a // Z axis angular velocity bias |
sgrsn | 0:6ff4cad60b67 | 39 | #define HXOFFSET 0x0b // X axis Magnetic bias |
sgrsn | 0:6ff4cad60b67 | 40 | #define HYOFFSET 0x0c // Y axis Magnetic bias |
sgrsn | 0:6ff4cad60b67 | 41 | #define HZOFFSET 0x0d // Z axis Magnetic bias |
sgrsn | 0:6ff4cad60b67 | 42 | #define D0MODE 0x0e // D0 mode |
sgrsn | 0:6ff4cad60b67 | 43 | #define D1MODE 0x0f // D1 mode |
sgrsn | 0:6ff4cad60b67 | 44 | #define D2MODE 0x10 // D2 mode |
sgrsn | 0:6ff4cad60b67 | 45 | #define D3MODE 0x11 // D3 mode |
sgrsn | 0:6ff4cad60b67 | 46 | #define D0PWMH 0x12 // D0PWM High-level width |
sgrsn | 0:6ff4cad60b67 | 47 | #define D1PWMH 0x13 // D1PWM High-level width |
sgrsn | 0:6ff4cad60b67 | 48 | #define D2PWMH 0x14 // D2PWM High-level width |
sgrsn | 0:6ff4cad60b67 | 49 | #define D3PWMH 0x15 // D3PWM High-level width |
sgrsn | 0:6ff4cad60b67 | 50 | #define D0PWMT 0x16 // D0PWM Period |
sgrsn | 0:6ff4cad60b67 | 51 | #define D1PWMT 0x17 // D1PWM Period |
sgrsn | 0:6ff4cad60b67 | 52 | #define D2PWMT 0x18 // D2PWM Period |
sgrsn | 0:6ff4cad60b67 | 53 | #define D3PWMT 0x19 // D3PWM Period |
sgrsn | 0:6ff4cad60b67 | 54 | #define LEDOFF 0x1b // Turn off LED |
sgrsn | 0:6ff4cad60b67 | 55 | #define GPSBAUD 0x1c // GPS baud rate |
sgrsn | 0:6ff4cad60b67 | 56 | |
sgrsn | 0:6ff4cad60b67 | 57 | #define YYMM 0x30 // Year、Month |
sgrsn | 0:6ff4cad60b67 | 58 | #define DDHH 0x31 // Day、Hour |
sgrsn | 0:6ff4cad60b67 | 59 | #define MMSS 0x32 // Minute、Second |
sgrsn | 0:6ff4cad60b67 | 60 | #define MS 0x33 // Millisecond |
sgrsn | 0:6ff4cad60b67 | 61 | #define AX 0x34 // X axis Acceleration |
sgrsn | 0:6ff4cad60b67 | 62 | #define AY 0x35 // Y axis Acceleration |
sgrsn | 0:6ff4cad60b67 | 63 | #define AZ 0x36 // Z axis Acceleration |
sgrsn | 0:6ff4cad60b67 | 64 | #define GX 0x37 // X axis angular velocity |
sgrsn | 0:6ff4cad60b67 | 65 | #define GY 0x38 // Y axis angular velocity |
sgrsn | 0:6ff4cad60b67 | 66 | #define GZ 0x39 // Z axis angular velocity |
sgrsn | 0:6ff4cad60b67 | 67 | #define HX 0x3a // X axis Magnetic |
sgrsn | 0:6ff4cad60b67 | 68 | #define HY 0x3b // Y axis Magnetic |
sgrsn | 0:6ff4cad60b67 | 69 | #define HZ 0x3c // Z axis Magnetic |
sgrsn | 0:6ff4cad60b67 | 70 | #define Roll 0x3d // X axis Angle |
sgrsn | 0:6ff4cad60b67 | 71 | #define Pitch 0x3e // Y axis Angle |
sgrsn | 0:6ff4cad60b67 | 72 | #define Yaw 0x3f // Z axis Angle |
sgrsn | 0:6ff4cad60b67 | 73 | #define TEMP 0x40 // Temperature |
sgrsn | 0:6ff4cad60b67 | 74 | #define D0Status 0x41 // D0Status |
sgrsn | 0:6ff4cad60b67 | 75 | #define D1Status 0x42 // D1Status |
sgrsn | 0:6ff4cad60b67 | 76 | #define D2Status 0x43 // D2Status |
sgrsn | 0:6ff4cad60b67 | 77 | #define D3Status 0x44 // D3Status |
sgrsn | 0:6ff4cad60b67 | 78 | #define PressureL 0x45 // Pressure Low Byte |
sgrsn | 0:6ff4cad60b67 | 79 | #define PressureH 0x46 // Pressure High Byte |
sgrsn | 0:6ff4cad60b67 | 80 | #define HeightL 0x47 // Height Low Byte |
sgrsn | 0:6ff4cad60b67 | 81 | #define HeightH 0x48 // Height High Byte |
sgrsn | 0:6ff4cad60b67 | 82 | #define LonL 0x49 // Longitude Low Byte |
sgrsn | 0:6ff4cad60b67 | 83 | #define LonH 0x4a // Longitude High Byte |
sgrsn | 0:6ff4cad60b67 | 84 | #define LatL 0x4b // Latitude Low Byte |
sgrsn | 0:6ff4cad60b67 | 85 | #define LatH 0x4c // Latitude High Byte |
sgrsn | 0:6ff4cad60b67 | 86 | #define GPSHeight 0x4d // GPS Height |
sgrsn | 0:6ff4cad60b67 | 87 | #define GPSYaw 0x4e // GPS Yaw |
sgrsn | 0:6ff4cad60b67 | 88 | #define GPSVL 0x4f // GPS speed Low byte |
sgrsn | 0:6ff4cad60b67 | 89 | #define GPSVH 0x50 // GPS speed High byte |
sgrsn | 0:6ff4cad60b67 | 90 | #define Q0 0x51 // Quaternion Q0 |
sgrsn | 0:6ff4cad60b67 | 91 | #define Q1 0x52 // Quaternion Q1 |
sgrsn | 0:6ff4cad60b67 | 92 | #define Q2 0x53 // Quaternion Q2 |
sgrsn | 0:6ff4cad60b67 | 93 | #define Q3 0x54 // Quaternion Q3 |
sgrsn | 0:6ff4cad60b67 | 94 | |
sgrsn | 4:cd62e2d69f62 | 95 | class JY901 |
sgrsn | 0:6ff4cad60b67 | 96 | { |
sgrsn | 0:6ff4cad60b67 | 97 | public: |
sgrsn | 4:cd62e2d69f62 | 98 | JY901(I2C *i2c); |
sgrsn | 0:6ff4cad60b67 | 99 | |
sgrsn | 1:6bcbd18a719a | 100 | void calibrateGyroAccel(); |
sgrsn | 1:6bcbd18a719a | 101 | void calibrateMagnetic(); |
sgrsn | 1:6bcbd18a719a | 102 | void calibrateHeight(); |
sgrsn | 1:6bcbd18a719a | 103 | void endCalibrate(); |
sgrsn | 1:6bcbd18a719a | 104 | void calibrateAll(int time_ms); |
sgrsn | 0:6ff4cad60b67 | 105 | int getYear(); |
sgrsn | 0:6ff4cad60b67 | 106 | int getMonth(); |
sgrsn | 0:6ff4cad60b67 | 107 | int getDay(); |
sgrsn | 0:6ff4cad60b67 | 108 | int getHour(); |
sgrsn | 0:6ff4cad60b67 | 109 | int getMinute(); |
sgrsn | 0:6ff4cad60b67 | 110 | int getSecond(); |
sgrsn | 0:6ff4cad60b67 | 111 | int getMillisecond(); |
sgrsn | 0:6ff4cad60b67 | 112 | float getXaxisAcceleration(); |
sgrsn | 0:6ff4cad60b67 | 113 | float getYaxisAcceleration(); |
sgrsn | 0:6ff4cad60b67 | 114 | float getZaxisAcceleration(); |
sgrsn | 0:6ff4cad60b67 | 115 | float getXaxisAngularVelocity(); |
sgrsn | 0:6ff4cad60b67 | 116 | float getYaxisAngularVelocity(); |
sgrsn | 0:6ff4cad60b67 | 117 | float getZaxisAngularVelocity(); |
sgrsn | 0:6ff4cad60b67 | 118 | float getXaxisMagnetic(); |
sgrsn | 0:6ff4cad60b67 | 119 | float getYaxisMagnetic(); |
sgrsn | 0:6ff4cad60b67 | 120 | float getZaxisMagnetic(); |
sgrsn | 0:6ff4cad60b67 | 121 | float getXaxisAngle(); |
sgrsn | 0:6ff4cad60b67 | 122 | float getYaxisAngle(); |
sgrsn | 0:6ff4cad60b67 | 123 | float getZaxisAngle(); |
sgrsn | 0:6ff4cad60b67 | 124 | float getTemperature(); |
sgrsn | 0:6ff4cad60b67 | 125 | float getD0Status(); |
sgrsn | 0:6ff4cad60b67 | 126 | float getD1Status(); |
sgrsn | 0:6ff4cad60b67 | 127 | float getD2Status(); |
sgrsn | 0:6ff4cad60b67 | 128 | float getD3Status(); |
sgrsn | 0:6ff4cad60b67 | 129 | |
sgrsn | 0:6ff4cad60b67 | 130 | /*dnt use I correct someday*********/ |
sgrsn | 0:6ff4cad60b67 | 131 | float getPressure(); |
sgrsn | 0:6ff4cad60b67 | 132 | float getHeight(); |
sgrsn | 0:6ff4cad60b67 | 133 | float getLongitude(); |
sgrsn | 0:6ff4cad60b67 | 134 | float getLatitude(); |
sgrsn | 0:6ff4cad60b67 | 135 | float getGPSHeight(); |
sgrsn | 0:6ff4cad60b67 | 136 | float getGPSYaw(); |
sgrsn | 0:6ff4cad60b67 | 137 | float getGPSspeed(); |
sgrsn | 0:6ff4cad60b67 | 138 | /*************************************/ |
sgrsn | 0:6ff4cad60b67 | 139 | |
sgrsn | 0:6ff4cad60b67 | 140 | private: |
sgrsn | 0:6ff4cad60b67 | 141 | char *getdata(char registar); |
sgrsn | 4:cd62e2d69f62 | 142 | |
sgrsn | 4:cd62e2d69f62 | 143 | I2C *_i2c; |
sgrsn | 0:6ff4cad60b67 | 144 | }; |
sgrsn | 0:6ff4cad60b67 | 145 | |
sgrsn | 0:6ff4cad60b67 | 146 | #endif |