ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Committer:
ivo_david_michelle
Date:
Sun Apr 10 19:50:18 2016 +0000
Revision:
20:efa15ed008b4
Parent:
17:96d0c72e413e
Child:
21:336faf452989
implemented controll of all axis

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 10:e7d1801e966a 29 double x;
ivo_david_michelle 10:e7d1801e966a 30 double y;
ivo_david_michelle 10:e7d1801e966a 31 double z;
ivo_david_michelle 14:64b06476d943 32 } offset;
ivo_david_michelle 7:f3f94eadc5b5 33
ivo_david_michelle 11:5c54826d23a7 34 struct motors {
ivo_david_michelle 11:5c54826d23a7 35 double m1;
ivo_david_michelle 11:5c54826d23a7 36 double m2;
ivo_david_michelle 11:5c54826d23a7 37 double m3;
ivo_david_michelle 11:5c54826d23a7 38 double m4;
ivo_david_michelle 13:291ba30c7806 39 };
ivo_david_michelle 10:e7d1801e966a 40
ivo_david_michelle 10:e7d1801e966a 41
ivo_david_michelle 14:64b06476d943 42 class Quadcopter {
ivo_david_michelle 6:6f3ffd97d808 43 private:
ivo_david_michelle 14:64b06476d943 44 Serial *pc_; // use for printing
ivo_david_michelle 14:64b06476d943 45
ivo_david_michelle 14:64b06476d943 46 // allow for remote communication
ivo_david_michelle 14:64b06476d943 47 MRF24J40 *mrf_;
ivo_david_michelle 14:64b06476d943 48 int rcIterations_;
ivo_david_michelle 14:64b06476d943 49 int rcLength_;
ivo_david_michelle 14:64b06476d943 50 Timer rcTimer_;
ivo_david_michelle 14:64b06476d943 51
ivo_david_michelle 8:326e7009ce0c 52 state state_;
ivo_david_michelle 10:e7d1801e966a 53 state desiredState_;
ivo_david_michelle 10:e7d1801e966a 54 controlInput controlInput_;
ivo_david_michelle 10:e7d1801e966a 55 //pwmOut * _pwmOut; // give address to constructor, than change this value
ivo_david_michelle 11:5c54826d23a7 56 motors motorPwm_;
ivo_david_michelle 14:64b06476d943 57 PwmOut *motor1_;
ivo_david_michelle 13:291ba30c7806 58
ivo_david_michelle 13:291ba30c7806 59 // declarations for IMU use
ivo_david_michelle 10:e7d1801e966a 60 Adafruit_9DOF dof_;
ivo_david_michelle 10:e7d1801e966a 61 Adafruit_LSM303_Accel_Unified accel_;
ivo_david_michelle 10:e7d1801e966a 62 Adafruit_LSM303_Mag_Unified mag_;
ivo_david_michelle 10:e7d1801e966a 63 Adafruit_L3GD20_Unified gyro_;
ivo_david_michelle 10:e7d1801e966a 64 sensors_event_t accel_event_;
ivo_david_michelle 9:f1bd96708a21 65 sensors_event_t mag_event_;
ivo_david_michelle 9:f1bd96708a21 66 sensors_event_t gyro_event_;
ivo_david_michelle 9:f1bd96708a21 67 sensors_vec_t orientation_;
ivo_david_michelle 13:291ba30c7806 68 offset offsetAngRate_;
ivo_david_michelle 13:291ba30c7806 69 offset offsetAttitude_; // used later to compensate default tilt of IMU
ivo_david_michelle 9:f1bd96708a21 70
ivo_david_michelle 10:e7d1801e966a 71 Serial *pcPntr_; // used to access serial communication
ivo_david_michelle 14:64b06476d943 72
ivo_david_michelle 10:e7d1801e966a 73
ivo_david_michelle 10:e7d1801e966a 74 double g_; // gravity [m/s^2]
ivo_david_michelle 10:e7d1801e966a 75 double m_; // mass [kg]
ivo_david_michelle 20:efa15ed008b4 76 double l_; // arm lenght [m]
ivo_david_michelle 20:efa15ed008b4 77 double gamma_; // relation between moment coefficient and force coefficient.
ivo_david_michelle 13:291ba30c7806 78
ivo_david_michelle 10:e7d1801e966a 79 // proportional attitude control gains
ivo_david_michelle 10:e7d1801e966a 80 double kp_phi_;
ivo_david_michelle 10:e7d1801e966a 81 double kp_theta_;
ivo_david_michelle 10:e7d1801e966a 82 double kp_psi_;
ivo_david_michelle 10:e7d1801e966a 83
ivo_david_michelle 10:e7d1801e966a 84 // derivative attitude control gains
ivo_david_michelle 10:e7d1801e966a 85 double kd_phi_;
ivo_david_michelle 10:e7d1801e966a 86 double kd_theta_;
ivo_david_michelle 10:e7d1801e966a 87 double kd_psi_;
ivo_david_michelle 10:e7d1801e966a 88
ivo_david_michelle 10:e7d1801e966a 89 // desired force (will come from joystick)
ivo_david_michelle 10:e7d1801e966a 90 double F_des_; // desired thrust force (excluding weight compensation)
ivo_david_michelle 7:f3f94eadc5b5 91
ivo_david_michelle 14:64b06476d943 92 public:
ivo_david_michelle 15:90e07946186f 93 Quadcopter(Serial *pcPntr, MRF24J40 *mrfPntr); // constructor
ivo_david_michelle 7:f3f94eadc5b5 94
ivo_david_michelle 14:64b06476d943 95 void setState(state *source, state *goal); // not sure if needed
ivo_david_michelle 8:326e7009ce0c 96 void controller();
ivo_david_michelle 8:326e7009ce0c 97 void readSensorValues();
ivo_david_michelle 14:64b06476d943 98
ivo_david_michelle 14:64b06476d943 99 void readRc();
ivo_david_michelle 14:64b06476d943 100
ivo_david_michelle 11:5c54826d23a7 101 motors getPwm();
ivo_david_michelle 14:64b06476d943 102
ivo_david_michelle 17:96d0c72e413e 103 float thrust;
ivo_david_michelle 17:96d0c72e413e 104 float yaw;
ivo_david_michelle 17:96d0c72e413e 105 float pitch;
ivo_david_michelle 17:96d0c72e413e 106 float roll;
ivo_david_michelle 17:96d0c72e413e 107 long long id;
ivo_david_michelle 17:96d0c72e413e 108
ivo_david_michelle 14:64b06476d943 109 //void readJoystick();
ivo_david_michelle 10:e7d1801e966a 110 // not implemented yet
ivo_david_michelle 13:291ba30c7806 111 //void setGains();
ivo_david_michelle 10:e7d1801e966a 112 //void setPwm();
ivo_david_michelle 10:e7d1801e966a 113 //void initializePwm();
ivo_david_michelle 6:6f3ffd97d808 114 };
ivo_david_michelle 7:f3f94eadc5b5 115
ivo_david_michelle 6:6f3ffd97d808 116 #endif