ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Committer:
ivo_david_michelle
Date:
Wed Apr 13 00:57:15 2016 +0000
Revision:
24:e220fbb70ded
Parent:
22:92401a4fec13
Child:
25:d44610851105
after integration

Who changed what in which revision?

UserRevisionLine numberNew 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 14:64b06476d943 7 #include "MRF24J40.h"
ivo_david_michelle 14:64b06476d943 8
ivo_david_michelle 6:6f3ffd97d808 9
ivo_david_michelle 13:291ba30c7806 10 // a few struct declarations. Can possibly eliminated using the vector class in STL
ivo_david_michelle 7:f3f94eadc5b5 11 struct state {
ivo_david_michelle 10:e7d1801e966a 12 double phi; // roll
ivo_david_michelle 10:e7d1801e966a 13 double theta; // pitch
ivo_david_michelle 10:e7d1801e966a 14 double psi; // yaw
ivo_david_michelle 10:e7d1801e966a 15 double p; // omega x
ivo_david_michelle 10:e7d1801e966a 16 double q; // omega y
ivo_david_michelle 10:e7d1801e966a 17 double r; // omega z
ivo_david_michelle 10:e7d1801e966a 18
ivo_david_michelle 6:6f3ffd97d808 19 };
ivo_david_michelle 7:f3f94eadc5b5 20
ivo_david_michelle 10:e7d1801e966a 21 struct controlInput {
ivo_david_michelle 10:e7d1801e966a 22 double f;
ivo_david_michelle 10:e7d1801e966a 23 double mx;
ivo_david_michelle 10:e7d1801e966a 24 double my;
ivo_david_michelle 10:e7d1801e966a 25 double mz;
ivo_david_michelle 7:f3f94eadc5b5 26 };
ivo_david_michelle 7:f3f94eadc5b5 27
ivo_david_michelle 14:64b06476d943 28 typedef struct {
ivo_david_michelle 24:e220fbb70ded 29 double gyro_x;
ivo_david_michelle 24:e220fbb70ded 30 double gyro_y;
ivo_david_michelle 24:e220fbb70ded 31 double gyro_z;
ivo_david_michelle 24:e220fbb70ded 32 double roll;
ivo_david_michelle 24:e220fbb70ded 33 double pitch;
ivo_david_michelle 24:e220fbb70ded 34 double heading;
ivo_david_michelle 14:64b06476d943 35 } offset;
ivo_david_michelle 7:f3f94eadc5b5 36
ivo_david_michelle 11:5c54826d23a7 37 struct motors {
ivo_david_michelle 11:5c54826d23a7 38 double m1;
ivo_david_michelle 11:5c54826d23a7 39 double m2;
ivo_david_michelle 11:5c54826d23a7 40 double m3;
ivo_david_michelle 11:5c54826d23a7 41 double m4;
ivo_david_michelle 13:291ba30c7806 42 };
ivo_david_michelle 10:e7d1801e966a 43
ivo_david_michelle 10:e7d1801e966a 44
ivo_david_michelle 24:e220fbb70ded 45 class Quadcopter
ivo_david_michelle 24:e220fbb70ded 46 {
ivo_david_michelle 6:6f3ffd97d808 47 private:
ivo_david_michelle 14:64b06476d943 48 Serial *pc_; // use for printing
ivo_david_michelle 24:e220fbb70ded 49
ivo_david_michelle 14:64b06476d943 50 // allow for remote communication
ivo_david_michelle 14:64b06476d943 51 MRF24J40 *mrf_;
ivo_david_michelle 14:64b06476d943 52 int rcIterations_;
ivo_david_michelle 14:64b06476d943 53 int rcLength_;
ivo_david_michelle 14:64b06476d943 54 Timer rcTimer_;
ivo_david_michelle 14:64b06476d943 55
ivo_david_michelle 8:326e7009ce0c 56 state state_;
ivo_david_michelle 10:e7d1801e966a 57 state desiredState_;
ivo_david_michelle 10:e7d1801e966a 58 controlInput controlInput_;
ivo_david_michelle 10:e7d1801e966a 59 //pwmOut * _pwmOut; // give address to constructor, than change this value
ivo_david_michelle 11:5c54826d23a7 60 motors motorPwm_;
ivo_david_michelle 14:64b06476d943 61 PwmOut *motor1_;
ivo_david_michelle 24:e220fbb70ded 62
ivo_david_michelle 13:291ba30c7806 63 // declarations for IMU use
ivo_david_michelle 10:e7d1801e966a 64 Adafruit_9DOF dof_;
ivo_david_michelle 10:e7d1801e966a 65 Adafruit_LSM303_Accel_Unified accel_;
ivo_david_michelle 10:e7d1801e966a 66 Adafruit_LSM303_Mag_Unified mag_;
ivo_david_michelle 10:e7d1801e966a 67 Adafruit_L3GD20_Unified gyro_;
ivo_david_michelle 10:e7d1801e966a 68 sensors_event_t accel_event_;
ivo_david_michelle 9:f1bd96708a21 69 sensors_event_t mag_event_;
ivo_david_michelle 9:f1bd96708a21 70 sensors_event_t gyro_event_;
ivo_david_michelle 9:f1bd96708a21 71 sensors_vec_t orientation_;
ivo_david_michelle 24:e220fbb70ded 72 offset* initial_offsets_;
ivo_david_michelle 9:f1bd96708a21 73
ivo_david_michelle 10:e7d1801e966a 74 Serial *pcPntr_; // used to access serial communication
ivo_david_michelle 24:e220fbb70ded 75
ivo_david_michelle 10:e7d1801e966a 76
ivo_david_michelle 10:e7d1801e966a 77 double g_; // gravity [m/s^2]
ivo_david_michelle 10:e7d1801e966a 78 double m_; // mass [kg]
ivo_david_michelle 20:efa15ed008b4 79 double l_; // arm lenght [m]
ivo_david_michelle 20:efa15ed008b4 80 double gamma_; // relation between moment coefficient and force coefficient.
ivo_david_michelle 24:e220fbb70ded 81
ivo_david_michelle 10:e7d1801e966a 82 // proportional attitude control gains
ivo_david_michelle 21:336faf452989 83 double kp_f_; // gain converting radio input to thrust.
ivo_david_michelle 10:e7d1801e966a 84 double kp_phi_;
ivo_david_michelle 10:e7d1801e966a 85 double kp_theta_;
ivo_david_michelle 10:e7d1801e966a 86 double kp_psi_;
ivo_david_michelle 10:e7d1801e966a 87
ivo_david_michelle 10:e7d1801e966a 88 // derivative attitude control gains
ivo_david_michelle 10:e7d1801e966a 89 double kd_phi_;
ivo_david_michelle 10:e7d1801e966a 90 double kd_theta_;
ivo_david_michelle 10:e7d1801e966a 91 double kd_psi_;
ivo_david_michelle 10:e7d1801e966a 92
ivo_david_michelle 10:e7d1801e966a 93 // desired force (will come from joystick)
ivo_david_michelle 10:e7d1801e966a 94 double F_des_; // desired thrust force (excluding weight compensation)
ivo_david_michelle 7:f3f94eadc5b5 95
ivo_david_michelle 14:64b06476d943 96 public:
ivo_david_michelle 15:90e07946186f 97 Quadcopter(Serial *pcPntr, MRF24J40 *mrfPntr); // constructor
ivo_david_michelle 7:f3f94eadc5b5 98
ivo_david_michelle 14:64b06476d943 99 void setState(state *source, state *goal); // not sure if needed
ivo_david_michelle 8:326e7009ce0c 100 void controller();
ivo_david_michelle 8:326e7009ce0c 101 void readSensorValues();
ivo_david_michelle 14:64b06476d943 102
ivo_david_michelle 14:64b06476d943 103 void readRc();
ivo_david_michelle 14:64b06476d943 104
ivo_david_michelle 11:5c54826d23a7 105 motors getPwm();
ivo_david_michelle 24:e220fbb70ded 106 state getState();
ivo_david_michelle 24:e220fbb70ded 107 Adafruit_LSM303_Accel_Unified getAccel();
ivo_david_michelle 24:e220fbb70ded 108 Adafruit_LSM303_Mag_Unified getMag();
ivo_david_michelle 24:e220fbb70ded 109 Adafruit_L3GD20_Unified getGyro();
ivo_david_michelle 24:e220fbb70ded 110 Adafruit_9DOF getIMU();
ivo_david_michelle 24:e220fbb70ded 111 offset* getOffset();
ivo_david_michelle 22:92401a4fec13 112
ivo_david_michelle 17:96d0c72e413e 113 float thrust;
ivo_david_michelle 17:96d0c72e413e 114 float yaw;
ivo_david_michelle 17:96d0c72e413e 115 float pitch;
ivo_david_michelle 17:96d0c72e413e 116 float roll;
ivo_david_michelle 17:96d0c72e413e 117 long long id;
ivo_david_michelle 24:e220fbb70ded 118
ivo_david_michelle 14:64b06476d943 119 //void readJoystick();
ivo_david_michelle 10:e7d1801e966a 120 // not implemented yet
ivo_david_michelle 13:291ba30c7806 121 //void setGains();
ivo_david_michelle 10:e7d1801e966a 122 //void setPwm();
ivo_david_michelle 10:e7d1801e966a 123 //void initializePwm();
ivo_david_michelle 6:6f3ffd97d808 124 };
ivo_david_michelle 7:f3f94eadc5b5 125
ivo_david_michelle 6:6f3ffd97d808 126 #endif