ESE350 project, Spring 2016, University of Pennsylvania
Dependencies: Adafruit9-DOf Receiver mbed-rtos mbed
quadcopter.h@13:291ba30c7806, 2016-04-02 (annotated)
- Committer:
- ivo_david_michelle
- Date:
- Sat Apr 02 22:06:46 2016 +0000
- Revision:
- 13:291ba30c7806
- Parent:
- 12:422963993df5
- Child:
- 14:64b06476d943
cleaned up a bit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ivo_david_michelle | 6:6f3ffd97d808 | 1 | #ifndef QUADCOPTER_H |
ivo_david_michelle | 6:6f3ffd97d808 | 2 | #define QUADCOPTER_H |
ivo_david_michelle | 6:6f3ffd97d808 | 3 | |
ivo_david_michelle | 7:f3f94eadc5b5 | 4 | #include "mbed.h" |
ivo_david_michelle | 7:f3f94eadc5b5 | 5 | #include "Adafruit_9DOF.h" |
ivo_david_michelle | 9:f1bd96708a21 | 6 | #include "Serial_base.h" |
ivo_david_michelle | 6:6f3ffd97d808 | 7 | |
ivo_david_michelle | 13:291ba30c7806 | 8 | // a few struct declarations. Can possibly eliminated using the vector class in STL |
ivo_david_michelle | 7:f3f94eadc5b5 | 9 | struct state { |
ivo_david_michelle | 10:e7d1801e966a | 10 | double phi; // roll |
ivo_david_michelle | 10:e7d1801e966a | 11 | double theta; // pitch |
ivo_david_michelle | 10:e7d1801e966a | 12 | double psi; // yaw |
ivo_david_michelle | 10:e7d1801e966a | 13 | double p; // omega x |
ivo_david_michelle | 10:e7d1801e966a | 14 | double q; // omega y |
ivo_david_michelle | 10:e7d1801e966a | 15 | double r; // omega z |
ivo_david_michelle | 10:e7d1801e966a | 16 | |
ivo_david_michelle | 6:6f3ffd97d808 | 17 | }; |
ivo_david_michelle | 7:f3f94eadc5b5 | 18 | |
ivo_david_michelle | 10:e7d1801e966a | 19 | struct controlInput { |
ivo_david_michelle | 10:e7d1801e966a | 20 | double f; |
ivo_david_michelle | 10:e7d1801e966a | 21 | double mx; |
ivo_david_michelle | 10:e7d1801e966a | 22 | double my; |
ivo_david_michelle | 10:e7d1801e966a | 23 | double mz; |
ivo_david_michelle | 7:f3f94eadc5b5 | 24 | }; |
ivo_david_michelle | 7:f3f94eadc5b5 | 25 | |
ivo_david_michelle | 7:f3f94eadc5b5 | 26 | struct offset { |
ivo_david_michelle | 10:e7d1801e966a | 27 | double x; |
ivo_david_michelle | 10:e7d1801e966a | 28 | double y; |
ivo_david_michelle | 10:e7d1801e966a | 29 | double z; |
ivo_david_michelle | 7:f3f94eadc5b5 | 30 | }; |
ivo_david_michelle | 7:f3f94eadc5b5 | 31 | |
ivo_david_michelle | 11:5c54826d23a7 | 32 | struct motors { |
ivo_david_michelle | 11:5c54826d23a7 | 33 | double m1; |
ivo_david_michelle | 11:5c54826d23a7 | 34 | double m2; |
ivo_david_michelle | 11:5c54826d23a7 | 35 | double m3; |
ivo_david_michelle | 11:5c54826d23a7 | 36 | double m4; |
ivo_david_michelle | 13:291ba30c7806 | 37 | }; |
ivo_david_michelle | 10:e7d1801e966a | 38 | |
ivo_david_michelle | 10:e7d1801e966a | 39 | |
ivo_david_michelle | 6:6f3ffd97d808 | 40 | class Quadcopter |
ivo_david_michelle | 6:6f3ffd97d808 | 41 | { |
ivo_david_michelle | 6:6f3ffd97d808 | 42 | private: |
ivo_david_michelle | 8:326e7009ce0c | 43 | state state_; |
ivo_david_michelle | 10:e7d1801e966a | 44 | state desiredState_; |
ivo_david_michelle | 10:e7d1801e966a | 45 | controlInput controlInput_; |
ivo_david_michelle | 10:e7d1801e966a | 46 | //pwmOut * _pwmOut; // give address to constructor, than change this value |
ivo_david_michelle | 11:5c54826d23a7 | 47 | motors motorPwm_; |
ivo_david_michelle | 13:291ba30c7806 | 48 | |
ivo_david_michelle | 13:291ba30c7806 | 49 | // declarations for IMU use |
ivo_david_michelle | 10:e7d1801e966a | 50 | Adafruit_9DOF dof_; |
ivo_david_michelle | 10:e7d1801e966a | 51 | Adafruit_LSM303_Accel_Unified accel_; |
ivo_david_michelle | 10:e7d1801e966a | 52 | Adafruit_LSM303_Mag_Unified mag_; |
ivo_david_michelle | 10:e7d1801e966a | 53 | Adafruit_L3GD20_Unified gyro_; |
ivo_david_michelle | 10:e7d1801e966a | 54 | sensors_event_t accel_event_; |
ivo_david_michelle | 9:f1bd96708a21 | 55 | sensors_event_t mag_event_; |
ivo_david_michelle | 9:f1bd96708a21 | 56 | sensors_event_t gyro_event_; |
ivo_david_michelle | 9:f1bd96708a21 | 57 | sensors_vec_t orientation_; |
ivo_david_michelle | 13:291ba30c7806 | 58 | offset offsetAngRate_; |
ivo_david_michelle | 13:291ba30c7806 | 59 | offset offsetAttitude_; // used later to compensate default tilt of IMU |
ivo_david_michelle | 9:f1bd96708a21 | 60 | |
ivo_david_michelle | 10:e7d1801e966a | 61 | Serial *pcPntr_; // used to access serial communication |
ivo_david_michelle | 10:e7d1801e966a | 62 | |
ivo_david_michelle | 10:e7d1801e966a | 63 | double g_; // gravity [m/s^2] |
ivo_david_michelle | 10:e7d1801e966a | 64 | double m_; // mass [kg] |
ivo_david_michelle | 13:291ba30c7806 | 65 | |
ivo_david_michelle | 10:e7d1801e966a | 66 | // proportional attitude control gains |
ivo_david_michelle | 10:e7d1801e966a | 67 | double kp_phi_; |
ivo_david_michelle | 10:e7d1801e966a | 68 | double kp_theta_; |
ivo_david_michelle | 10:e7d1801e966a | 69 | double kp_psi_; |
ivo_david_michelle | 10:e7d1801e966a | 70 | |
ivo_david_michelle | 10:e7d1801e966a | 71 | // derivative attitude control gains |
ivo_david_michelle | 10:e7d1801e966a | 72 | double kd_phi_; |
ivo_david_michelle | 10:e7d1801e966a | 73 | double kd_theta_; |
ivo_david_michelle | 10:e7d1801e966a | 74 | double kd_psi_; |
ivo_david_michelle | 10:e7d1801e966a | 75 | |
ivo_david_michelle | 10:e7d1801e966a | 76 | // desired force (will come from joystick) |
ivo_david_michelle | 10:e7d1801e966a | 77 | double F_des_; // desired thrust force (excluding weight compensation) |
ivo_david_michelle | 7:f3f94eadc5b5 | 78 | |
ivo_david_michelle | 7:f3f94eadc5b5 | 79 | |
ivo_david_michelle | 6:6f3ffd97d808 | 80 | public: |
ivo_david_michelle | 10:e7d1801e966a | 81 | Quadcopter(); // constructor |
ivo_david_michelle | 10:e7d1801e966a | 82 | void setState(state *source, state *goal); |
ivo_david_michelle | 8:326e7009ce0c | 83 | void controller(); |
ivo_david_michelle | 8:326e7009ce0c | 84 | void readSensorValues(); |
ivo_david_michelle | 9:f1bd96708a21 | 85 | void initAllSensors(); |
ivo_david_michelle | 10:e7d1801e966a | 86 | void setSerial(Serial *pcPntr) { |
ivo_david_michelle | 10:e7d1801e966a | 87 | pcPntr_=pcPntr; |
ivo_david_michelle | 10:e7d1801e966a | 88 | }; |
ivo_david_michelle | 10:e7d1801e966a | 89 | void print(char * myString); // overload in order to print numbers |
ivo_david_michelle | 11:5c54826d23a7 | 90 | motors getPwm(); |
ivo_david_michelle | 10:e7d1801e966a | 91 | |
ivo_david_michelle | 10:e7d1801e966a | 92 | // not implemented yet |
ivo_david_michelle | 13:291ba30c7806 | 93 | //void setGains(); |
ivo_david_michelle | 10:e7d1801e966a | 94 | //void setPwm(); |
ivo_david_michelle | 10:e7d1801e966a | 95 | //void initializePwm(); |
ivo_david_michelle | 6:6f3ffd97d808 | 96 | }; |
ivo_david_michelle | 7:f3f94eadc5b5 | 97 | |
ivo_david_michelle | 6:6f3ffd97d808 | 98 | #endif |