YUTO WATANABE / JY901_os6
Committer:
DarkFlame
Date:
Tue Apr 12 00:39:26 2022 +0000
Revision:
9:899168e14871
Parent:
7:a06925c41956
fit os6.

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