ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Committer:
ivo_david_michelle
Date:
Thu Apr 07 22:04:03 2016 +0000
Revision:
16:2be2aab63198
Parent:
15:90e07946186f
Child:
17:96d0c72e413e
18:03 successful communication with no waiting

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 16:2be2aab63198 51 float thrust_;
ivo_david_michelle 16:2be2aab63198 52 float yaw_;
ivo_david_michelle 16:2be2aab63198 53 float pitch_;
ivo_david_michelle 16:2be2aab63198 54 float roll_;
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 13:291ba30c7806 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 13:291ba30c7806 72 offset offsetAngRate_;
ivo_david_michelle 13:291ba30c7806 73 offset offsetAttitude_; // used later to compensate default tilt of IMU
ivo_david_michelle 9:f1bd96708a21 74
ivo_david_michelle 10:e7d1801e966a 75 Serial *pcPntr_; // used to access serial communication
ivo_david_michelle 14:64b06476d943 76
ivo_david_michelle 10:e7d1801e966a 77
ivo_david_michelle 10:e7d1801e966a 78 double g_; // gravity [m/s^2]
ivo_david_michelle 10:e7d1801e966a 79 double m_; // mass [kg]
ivo_david_michelle 13:291ba30c7806 80
ivo_david_michelle 10:e7d1801e966a 81 // proportional attitude control gains
ivo_david_michelle 10:e7d1801e966a 82 double kp_phi_;
ivo_david_michelle 10:e7d1801e966a 83 double kp_theta_;
ivo_david_michelle 10:e7d1801e966a 84 double kp_psi_;
ivo_david_michelle 10:e7d1801e966a 85
ivo_david_michelle 10:e7d1801e966a 86 // derivative attitude control gains
ivo_david_michelle 10:e7d1801e966a 87 double kd_phi_;
ivo_david_michelle 10:e7d1801e966a 88 double kd_theta_;
ivo_david_michelle 10:e7d1801e966a 89 double kd_psi_;
ivo_david_michelle 10:e7d1801e966a 90
ivo_david_michelle 10:e7d1801e966a 91 // desired force (will come from joystick)
ivo_david_michelle 10:e7d1801e966a 92 double F_des_; // desired thrust force (excluding weight compensation)
ivo_david_michelle 7:f3f94eadc5b5 93
ivo_david_michelle 14:64b06476d943 94 public:
ivo_david_michelle 15:90e07946186f 95 Quadcopter(Serial *pcPntr, MRF24J40 *mrfPntr); // constructor
ivo_david_michelle 7:f3f94eadc5b5 96
ivo_david_michelle 14:64b06476d943 97 void setState(state *source, state *goal); // not sure if needed
ivo_david_michelle 8:326e7009ce0c 98 void controller();
ivo_david_michelle 8:326e7009ce0c 99 void readSensorValues();
ivo_david_michelle 14:64b06476d943 100
ivo_david_michelle 14:64b06476d943 101 void readRc();
ivo_david_michelle 14:64b06476d943 102
ivo_david_michelle 11:5c54826d23a7 103 motors getPwm();
ivo_david_michelle 14:64b06476d943 104
ivo_david_michelle 14:64b06476d943 105 //void readJoystick();
ivo_david_michelle 10:e7d1801e966a 106 // not implemented yet
ivo_david_michelle 13:291ba30c7806 107 //void setGains();
ivo_david_michelle 10:e7d1801e966a 108 //void setPwm();
ivo_david_michelle 10:e7d1801e966a 109 //void initializePwm();
ivo_david_michelle 6:6f3ffd97d808 110 };
ivo_david_michelle 7:f3f94eadc5b5 111
ivo_david_michelle 6:6f3ffd97d808 112 #endif