ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Committer:
ivo_david_michelle
Date:
Sat Apr 02 21:40:37 2016 +0000
Revision:
12:422963993df5
Parent:
11:5c54826d23a7
Child:
13:291ba30c7806
working stand with x axis control and quadcopter class

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 6:6f3ffd97d808 7
ivo_david_michelle 7:f3f94eadc5b5 8
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 10:e7d1801e966a 26 // do one struct called "vector", or use standart template library
ivo_david_michelle 7:f3f94eadc5b5 27 struct offset {
ivo_david_michelle 10:e7d1801e966a 28 double x;
ivo_david_michelle 10:e7d1801e966a 29 double y;
ivo_david_michelle 10:e7d1801e966a 30 double z;
ivo_david_michelle 7:f3f94eadc5b5 31 };
ivo_david_michelle 7:f3f94eadc5b5 32
ivo_david_michelle 11:5c54826d23a7 33 struct motors {
ivo_david_michelle 11:5c54826d23a7 34 double m1;
ivo_david_michelle 11:5c54826d23a7 35 double m2;
ivo_david_michelle 11:5c54826d23a7 36 double m3;
ivo_david_michelle 11:5c54826d23a7 37 double m4;
ivo_david_michelle 11:5c54826d23a7 38 };
ivo_david_michelle 10:e7d1801e966a 39
ivo_david_michelle 10:e7d1801e966a 40
ivo_david_michelle 6:6f3ffd97d808 41 class Quadcopter
ivo_david_michelle 6:6f3ffd97d808 42 {
ivo_david_michelle 6:6f3ffd97d808 43 private:
ivo_david_michelle 8:326e7009ce0c 44 state state_;
ivo_david_michelle 10:e7d1801e966a 45 state desiredState_;
ivo_david_michelle 10:e7d1801e966a 46 controlInput controlInput_;
ivo_david_michelle 10:e7d1801e966a 47 //pwmOut * _pwmOut; // give address to constructor, than change this value
ivo_david_michelle 11:5c54826d23a7 48 motors motorPwm_;
ivo_david_michelle 7:f3f94eadc5b5 49
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 7:f3f94eadc5b5 54
ivo_david_michelle 10:e7d1801e966a 55 sensors_event_t accel_event_;
ivo_david_michelle 9:f1bd96708a21 56 sensors_event_t mag_event_;
ivo_david_michelle 9:f1bd96708a21 57 sensors_event_t gyro_event_;
ivo_david_michelle 9:f1bd96708a21 58 sensors_vec_t orientation_;
ivo_david_michelle 9:f1bd96708a21 59
ivo_david_michelle 10:e7d1801e966a 60 offset offsetAngRate_;
ivo_david_michelle 10:e7d1801e966a 61 offset offsetAttitude_; // used later to compensate tilt of IMU
ivo_david_michelle 10:e7d1801e966a 62
ivo_david_michelle 10:e7d1801e966a 63 Serial *pcPntr_; // used to access serial communication
ivo_david_michelle 10:e7d1801e966a 64
ivo_david_michelle 10:e7d1801e966a 65 double g_; // gravity [m/s^2]
ivo_david_michelle 10:e7d1801e966a 66 double m_; // mass [kg]
ivo_david_michelle 10:e7d1801e966a 67 // proportional attitude control gains
ivo_david_michelle 10:e7d1801e966a 68 double kp_phi_;
ivo_david_michelle 10:e7d1801e966a 69 double kp_theta_;
ivo_david_michelle 10:e7d1801e966a 70 double kp_psi_;
ivo_david_michelle 10:e7d1801e966a 71
ivo_david_michelle 10:e7d1801e966a 72 // derivative attitude control gains
ivo_david_michelle 10:e7d1801e966a 73 double kd_phi_;
ivo_david_michelle 10:e7d1801e966a 74 double kd_theta_;
ivo_david_michelle 10:e7d1801e966a 75 double kd_psi_;
ivo_david_michelle 10:e7d1801e966a 76
ivo_david_michelle 10:e7d1801e966a 77 // desired force (will come from joystick)
ivo_david_michelle 10:e7d1801e966a 78 double F_des_; // desired thrust force (excluding weight compensation)
ivo_david_michelle 7:f3f94eadc5b5 79
ivo_david_michelle 7:f3f94eadc5b5 80
ivo_david_michelle 6:6f3ffd97d808 81 public:
ivo_david_michelle 10:e7d1801e966a 82 Quadcopter(); // constructor
ivo_david_michelle 10:e7d1801e966a 83 void setState(state *source, state *goal);
ivo_david_michelle 8:326e7009ce0c 84 void controller();
ivo_david_michelle 8:326e7009ce0c 85 void readSensorValues();
ivo_david_michelle 9:f1bd96708a21 86 void initAllSensors();
ivo_david_michelle 10:e7d1801e966a 87 void setSerial(Serial *pcPntr) {
ivo_david_michelle 10:e7d1801e966a 88 pcPntr_=pcPntr;
ivo_david_michelle 10:e7d1801e966a 89 };
ivo_david_michelle 10:e7d1801e966a 90 void print(char * myString); // overload in order to print numbers
ivo_david_michelle 11:5c54826d23a7 91 motors getPwm();
ivo_david_michelle 10:e7d1801e966a 92
ivo_david_michelle 10:e7d1801e966a 93 // not implemented yet
ivo_david_michelle 10:e7d1801e966a 94 void setGains();
ivo_david_michelle 10:e7d1801e966a 95 //void setPwm();
ivo_david_michelle 10:e7d1801e966a 96 //void initializePwm();
ivo_david_michelle 6:6f3ffd97d808 97 };
ivo_david_michelle 7:f3f94eadc5b5 98
ivo_david_michelle 6:6f3ffd97d808 99 #endif