Sheila Pham
/
IMU6050Ver1
Added for gyro and testing
IMU6050/IMUWheelchair.h@14:365c1c1bf6ee, 2019-07-04 (annotated)
- Committer:
- sepham
- Date:
- Thu Jul 04 18:25:35 2019 +0000
- Revision:
- 14:365c1c1bf6ee
- Parent:
- 13:d66766523196
IMU tof more gyro and testing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jahutchi | 13:d66766523196 | 1 | #ifndef IMUWheelchair_H |
jahutchi | 13:d66766523196 | 2 | #define IMUWheelchair_H |
jahutchi | 13:d66766523196 | 3 | |
jahutchi | 13:d66766523196 | 4 | #include "filter.h" |
jahutchi | 13:d66766523196 | 5 | //#include "mbed.h" |
jahutchi | 13:d66766523196 | 6 | #include "math.h" |
jahutchi | 13:d66766523196 | 7 | #include <MPU6050.h> |
jahutchi | 13:d66766523196 | 8 | |
jahutchi | 13:d66766523196 | 9 | #define PI 3.141593 |
jahutchi | 13:d66766523196 | 10 | |
jahutchi | 13:d66766523196 | 11 | /*#define SDA D14 |
jahutchi | 13:d66766523196 | 12 | #define SCL D15*/ |
jahutchi | 13:d66766523196 | 13 | #define SDA PB_9 |
jahutchi | 13:d66766523196 | 14 | #define SCL PB_8 |
jahutchi | 13:d66766523196 | 15 | #define SAMPLEFREQ 50 |
jahutchi | 13:d66766523196 | 16 | #define CAL_TIME 3 |
jahutchi | 13:d66766523196 | 17 | |
jahutchi | 13:d66766523196 | 18 | class IMUWheelchair { |
jahutchi | 13:d66766523196 | 19 | public: |
jahutchi | 13:d66766523196 | 20 | //The constructor for this class |
jahutchi | 13:d66766523196 | 21 | IMUWheelchair(Serial* out, Timer* time); |
jahutchi | 13:d66766523196 | 22 | IMUWheelchair(PinName sda_pin, PinName scl_pin, Serial* out, Timer* time); |
jahutchi | 13:d66766523196 | 23 | |
jahutchi | 13:d66766523196 | 24 | //Set up the IMU, check if it connects |
jahutchi | 13:d66766523196 | 25 | void setup(); |
jahutchi | 13:d66766523196 | 26 | |
jahutchi | 13:d66766523196 | 27 | //Get the x-component of the angular acceleration |
jahutchi | 13:d66766523196 | 28 | double accel_x(); |
jahutchi | 13:d66766523196 | 29 | |
jahutchi | 13:d66766523196 | 30 | //Get the y-component of the angular acceleration |
jahutchi | 13:d66766523196 | 31 | double accel_y(); |
jahutchi | 13:d66766523196 | 32 | |
jahutchi | 13:d66766523196 | 33 | //Get the z-component of the angular acceleration |
jahutchi | 13:d66766523196 | 34 | double accel_z(); |
jahutchi | 13:d66766523196 | 35 | |
jahutchi | 13:d66766523196 | 36 | //Get the x-component of gyro, angular velocity |
jahutchi | 13:d66766523196 | 37 | double gyro_x(); |
jahutchi | 13:d66766523196 | 38 | |
jahutchi | 13:d66766523196 | 39 | //Get the y-component of gyro, angular velocity |
jahutchi | 13:d66766523196 | 40 | double gyro_y(); |
jahutchi | 13:d66766523196 | 41 | |
jahutchi | 13:d66766523196 | 42 | //Get the z-component of gyro, angular velocity |
jahutchi | 13:d66766523196 | 43 | double gyro_z(); |
jahutchi | 13:d66766523196 | 44 | |
jahutchi | 13:d66766523196 | 45 | //Magnometer to find angle relative to North to compare to gyroscope |
jahutchi | 13:d66766523196 | 46 | //double angle_north(); |
jahutchi | 13:d66766523196 | 47 | |
jahutchi | 13:d66766523196 | 48 | //Get the YAW, or angle (theta), direction facing |
jahutchi | 13:d66766523196 | 49 | double yaw(); |
jahutchi | 13:d66766523196 | 50 | |
jahutchi | 13:d66766523196 | 51 | //Get the pitch, (Up and down component) |
jahutchi | 13:d66766523196 | 52 | double pitch(); |
jahutchi | 13:d66766523196 | 53 | |
jahutchi | 13:d66766523196 | 54 | //Get the roll, the tilt |
jahutchi | 13:d66766523196 | 55 | double roll(); |
jahutchi | 13:d66766523196 | 56 | |
jahutchi | 13:d66766523196 | 57 | MPU6050* imu; //The IMU we're testing from, MPU6050 |
jahutchi | 13:d66766523196 | 58 | |
jahutchi | 13:d66766523196 | 59 | private: |
jahutchi | 13:d66766523196 | 60 | Serial* usb; //the connection port |
jahutchi | 13:d66766523196 | 61 | Timer* t;//to calculate the time |
jahutchi | 13:d66766523196 | 62 | float accelData[3]; // stores the angular acceleration component |
jahutchi | 13:d66766523196 | 63 | float gyroData[3]; //stores the gyro data x,y,z |
jahutchi | 13:d66766523196 | 64 | float* accelD; //Pointer that points to either accelData |
jahutchi | 13:d66766523196 | 65 | float* gyroD; //Ptr to the gyroData array |
jahutchi | 13:d66766523196 | 66 | |
jahutchi | 13:d66766523196 | 67 | float angleData[3]; //Contains the pitch, roll, yaw angle |
jahutchi | 13:d66766523196 | 68 | float* angleD;//Ptr to angleData array |
jahutchi | 13:d66766523196 | 69 | |
jahutchi | 13:d66766523196 | 70 | void calibrate_yaw(); |
jahutchi | 13:d66766523196 | 71 | |
jahutchi | 13:d66766523196 | 72 | bool start; |
jahutchi | 13:d66766523196 | 73 | |
jahutchi | 13:d66766523196 | 74 | }; |
jahutchi | 13:d66766523196 | 75 | |
jahutchi | 13:d66766523196 | 76 | #endif |