Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: WRS_mechanamu_test WRS2019_master mbed_2018 mbed_2019_rx3 ... more
JY901.h
00001 #ifndef MBED_JY901_H 00002 #define MBED_JY901_H 00003 00004 #include "mbed.h" 00005 00006 /*example************************************* 00007 #include "mbed.h" 00008 #include "JY901.h" 00009 00010 I2C myi2c(p28, p27); 00011 JY901 jy901(&myi2c); 00012 00013 int main() 00014 { 00015 float angle = 0; 00016 jy901.calibrateAll(5000); 00017 while(1) 00018 { 00019 angle = jy901.getZaxisAngle(); 00020 printf("%f\r\n", angle); 00021 } 00022 } 00023 **********************************************/ 00024 00025 #define IICADDR 0xa0 // IIC address 00026 #define g 9.80665 // Acceleration of gravity 00027 00028 //#define SAVE 0x00 // Save 00029 #define CALSW 0x01 // Calibration 00030 #define RSW 0x02 // Return data content 00031 #define RATE 0x03 // Return data Speed 00032 #define BAUD 0x04 // Baud rate 00033 #define AXOFFSET 0x05 // X axis Acceleration bias 00034 #define AYOFFSET 0x06 // Y axis Acceleration bias 00035 #define AZOFFSET 0x07 // Z axis Acceleration bias 00036 #define GXOFFSET 0x08 // X axis angular velocity bias 00037 #define GYOFFSET 0x09 // Y axis angular velocity bias 00038 #define GZOFFSET 0x0a // Z axis angular velocity bias 00039 #define HXOFFSET 0x0b // X axis Magnetic bias 00040 #define HYOFFSET 0x0c // Y axis Magnetic bias 00041 #define HZOFFSET 0x0d // Z axis Magnetic bias 00042 #define D0MODE 0x0e // D0 mode 00043 #define D1MODE 0x0f // D1 mode 00044 #define D2MODE 0x10 // D2 mode 00045 #define D3MODE 0x11 // D3 mode 00046 #define D0PWMH 0x12 // D0PWM High-level width 00047 #define D1PWMH 0x13 // D1PWM High-level width 00048 #define D2PWMH 0x14 // D2PWM High-level width 00049 #define D3PWMH 0x15 // D3PWM High-level width 00050 #define D0PWMT 0x16 // D0PWM Period 00051 #define D1PWMT 0x17 // D1PWM Period 00052 #define D2PWMT 0x18 // D2PWM Period 00053 #define D3PWMT 0x19 // D3PWM Period 00054 #define LEDOFF 0x1b // Turn off LED 00055 #define GPSBAUD 0x1c // GPS baud rate 00056 00057 #define YYMM 0x30 // Year、Month 00058 #define DDHH 0x31 // Day、Hour 00059 #define MMSS 0x32 // Minute、Second 00060 #define MS 0x33 // Millisecond 00061 #define AX 0x34 // X axis Acceleration 00062 #define AY 0x35 // Y axis Acceleration 00063 #define AZ 0x36 // Z axis Acceleration 00064 #define GX 0x37 // X axis angular velocity 00065 #define GY 0x38 // Y axis angular velocity 00066 #define GZ 0x39 // Z axis angular velocity 00067 #define HX 0x3a // X axis Magnetic 00068 #define HY 0x3b // Y axis Magnetic 00069 #define HZ 0x3c // Z axis Magnetic 00070 #define Roll 0x3d // X axis Angle 00071 #define Pitch 0x3e // Y axis Angle 00072 #define Yaw 0x3f // Z axis Angle 00073 #define TEMP 0x40 // Temperature 00074 #define D0Status 0x41 // D0Status 00075 #define D1Status 0x42 // D1Status 00076 #define D2Status 0x43 // D2Status 00077 #define D3Status 0x44 // D3Status 00078 #define PressureL 0x45 // Pressure Low Byte 00079 #define PressureH 0x46 // Pressure High Byte 00080 #define HeightL 0x47 // Height Low Byte 00081 #define HeightH 0x48 // Height High Byte 00082 #define LonL 0x49 // Longitude Low Byte 00083 #define LonH 0x4a // Longitude High Byte 00084 #define LatL 0x4b // Latitude Low Byte 00085 #define LatH 0x4c // Latitude High Byte 00086 #define GPSHeight 0x4d // GPS Height 00087 #define GPSYaw 0x4e // GPS Yaw 00088 #define GPSVL 0x4f // GPS speed Low byte 00089 #define GPSVH 0x50 // GPS speed High byte 00090 #define Q0 0x51 // Quaternion Q0 00091 #define Q1 0x52 // Quaternion Q1 00092 #define Q2 0x53 // Quaternion Q2 00093 #define Q3 0x54 // Quaternion Q3 00094 00095 class JY901 00096 { 00097 public: 00098 JY901(I2C *i2c); 00099 JY901(I2C *i2c, Timer *t); 00100 00101 /****************************************/ 00102 //not recommended 00103 //used only me 00104 float calculateAngleOnlyGyro(); 00105 void reset(); 00106 /****************************************/ 00107 00108 void calibrateGyroAccel(); 00109 void calibrateMagnetic(); 00110 void calibrateHeight(); 00111 void endCalibrate(); 00112 void calibrateAll(int time_ms); 00113 int getYear(); 00114 int getMonth(); 00115 int getDay(); 00116 int getHour(); 00117 int getMinute(); 00118 int getSecond(); 00119 int getMillisecond(); 00120 float getXaxisAcceleration(); 00121 float getYaxisAcceleration(); 00122 float getZaxisAcceleration(); 00123 float getXaxisAngularVelocity(); 00124 float getYaxisAngularVelocity(); 00125 float getZaxisAngularVelocity(); 00126 float getXaxisMagnetic(); 00127 float getYaxisMagnetic(); 00128 float getZaxisMagnetic(); 00129 float getXaxisAngle(); 00130 float getYaxisAngle(); 00131 float getZaxisAngle(); 00132 float getTemperature(); 00133 float getD0Status(); 00134 float getD1Status(); 00135 float getD2Status(); 00136 float getD3Status(); 00137 00138 /*dnt use I correct someday*********/ 00139 float getPressure(); 00140 float getHeight(); 00141 float getLongitude(); 00142 float getLatitude(); 00143 float getGPSHeight(); 00144 float getGPSYaw(); 00145 float getGPSspeed(); 00146 /*************************************/ 00147 00148 private: 00149 char *getdata(char registar); 00150 float s16(int dataL, int dataH); 00151 00152 float last_time, time, dt; 00153 float gyroZ[3]; 00154 float angleZ; 00155 00156 I2C *_i2c; 00157 Timer *_timer; 00158 }; 00159 00160 #endif
Generated on Fri Jul 15 2022 03:30:25 by
