明石高専ロボ研 mbedライブラリ
Dependencies: mbed
gy521.hpp@14:7ea663f79c81, 2022-03-05 (annotated)
- Committer:
- darkumatar
- Date:
- Sat Mar 05 05:00:50 2022 +0000
- Revision:
- 14:7ea663f79c81
- Parent:
- 4:39ef4d91dc34
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TanakaRobo | 0:ca84ed7518f5 | 1 | #ifndef GY521_H |
TanakaRobo | 0:ca84ed7518f5 | 2 | #define GY521_H |
TanakaRobo | 0:ca84ed7518f5 | 3 | #include "mbed.h" |
TanakaRobo | 0:ca84ed7518f5 | 4 | |
TanakaRobo | 0:ca84ed7518f5 | 5 | /*GY521を使う。 |
TanakaRobo | 0:ca84ed7518f5 | 6 | *I2Cオブジェクトを渡す |
TanakaRobo | 0:ca84ed7518f5 | 7 | *GY521(I2C &i2c,int bit = 2,int calibration = 1000,double user_reg = 1.0); |
TanakaRobo | 0:ca84ed7518f5 | 8 | *example |
TanakaRobo | 0:ca84ed7518f5 | 9 | *L432KC : SDA = PB_7 , SCL = PB_6 |
TanakaRobo | 0:ca84ed7518f5 | 10 | *F446RE : SDA = PB_3 , SCL = PB_10 |
TanakaRobo | 3:28c77df7c0b6 | 11 | *ループ内で毎回 |
TanakaRobo | 3:28c77df7c0b6 | 12 | *<obj>.update() |
TanakaRobo | 3:28c77df7c0b6 | 13 | *を呼び出してください。 |
TanakaRobo | 0:ca84ed7518f5 | 14 | */ |
TanakaRobo | 0:ca84ed7518f5 | 15 | //I2C i2c(SDA,SCL); |
TanakaRobo | 0:ca84ed7518f5 | 16 | //GY521 gyro(i2c); |
TanakaRobo | 0:ca84ed7518f5 | 17 | |
TanakaRobo | 4:39ef4d91dc34 | 18 | enum GY521RegisterMap { |
TanakaRobo | 4:39ef4d91dc34 | 19 | WHO_AM_I = 0x75, |
TanakaRobo | 4:39ef4d91dc34 | 20 | PWR_MGMT_1 = 0x6B, |
TanakaRobo | 4:39ef4d91dc34 | 21 | LPF = 0x1A, |
TanakaRobo | 4:39ef4d91dc34 | 22 | FS_SEL = 0x1B, |
TanakaRobo | 4:39ef4d91dc34 | 23 | AFS_SEL = 0x1C, |
TanakaRobo | 4:39ef4d91dc34 | 24 | ACCEL_XOUT_H = 0x3B, |
TanakaRobo | 4:39ef4d91dc34 | 25 | ACCEL_YOUT_H = 0x3D, |
TanakaRobo | 4:39ef4d91dc34 | 26 | ACCEL_ZOUT_H = 0x3F, |
TanakaRobo | 4:39ef4d91dc34 | 27 | //TEMPERATURE = 0x41, |
TanakaRobo | 4:39ef4d91dc34 | 28 | //GYRO_XOUT_H = 0x43, |
TanakaRobo | 4:39ef4d91dc34 | 29 | //GYRO_YOUT_H = 0x45, |
TanakaRobo | 4:39ef4d91dc34 | 30 | GYRO_ZOUT_H = 0x47 |
TanakaRobo | 4:39ef4d91dc34 | 31 | }; |
TanakaRobo | 4:39ef4d91dc34 | 32 | |
TanakaRobo | 0:ca84ed7518f5 | 33 | class GY521{ |
TanakaRobo | 0:ca84ed7518f5 | 34 | public: |
TanakaRobo | 0:ca84ed7518f5 | 35 | GY521(I2C &i2c,int bit = 2,int calibration = 1000,double user_reg = 1.0); |
TanakaRobo | 0:ca84ed7518f5 | 36 | double yaw; |
TanakaRobo | 0:ca84ed7518f5 | 37 | //double temp; |
TanakaRobo | 3:28c77df7c0b6 | 38 | void update(); |
TanakaRobo | 0:ca84ed7518f5 | 39 | void reset(int user); |
TanakaRobo | 0:ca84ed7518f5 | 40 | void start(double start = 0){ |
TanakaRobo | 0:ca84ed7518f5 | 41 | yaw = start; |
TanakaRobo | 0:ca84ed7518f5 | 42 | } |
TanakaRobo | 0:ca84ed7518f5 | 43 | double checkStatus(int mode); |
TanakaRobo | 0:ca84ed7518f5 | 44 | private: |
TanakaRobo | 0:ca84ed7518f5 | 45 | I2C &i2c_; |
TanakaRobo | 0:ca84ed7518f5 | 46 | Timer timer_; |
TanakaRobo | 0:ca84ed7518f5 | 47 | int16_t gyroRead2(enum GY521RegisterMap reg); |
TanakaRobo | 0:ca84ed7518f5 | 48 | double gyro_z_aver_; |
TanakaRobo | 0:ca84ed7518f5 | 49 | double gyro_z_now_; |
TanakaRobo | 0:ca84ed7518f5 | 50 | double gyro_z_prev_; |
TanakaRobo | 0:ca84ed7518f5 | 51 | double gyro_LSB_; |
TanakaRobo | 0:ca84ed7518f5 | 52 | double diff_yaw_; |
TanakaRobo | 0:ca84ed7518f5 | 53 | int bit_; |
TanakaRobo | 0:ca84ed7518f5 | 54 | int calibration_; |
TanakaRobo | 0:ca84ed7518f5 | 55 | bool flag_; |
TanakaRobo | 0:ca84ed7518f5 | 56 | }; |
TanakaRobo | 0:ca84ed7518f5 | 57 | |
TanakaRobo | 0:ca84ed7518f5 | 58 | #endif /* GY521_H */ |