YUTO WATANABE / JY901_os6
Committer:
DarkFlame
Date:
Mon Apr 12 01:47:17 2021 +0000
Revision:
7:a06925c41956
Parent:
6:7e7dd6184774
Child:
9:899168e14871
DFM.;

Who changed what in which revision?

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