ESE350 project, Spring 2016, University of Pennsylvania

Dependencies:   Adafruit9-DOf Receiver mbed-rtos mbed

Committer:
ivo_david_michelle
Date:
Thu Apr 07 21:14:27 2016 +0000
Revision:
15:90e07946186f
Parent:
14:64b06476d943
Child:
16:2be2aab63198
communication parses - april 7 17:14

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 uint8_t rcChannel_;
ivo_david_michelle 14:64b06476d943 52
ivo_david_michelle 8:326e7009ce0c 53 state state_;
ivo_david_michelle 10:e7d1801e966a 54 state desiredState_;
ivo_david_michelle 10:e7d1801e966a 55 controlInput controlInput_;
ivo_david_michelle 10:e7d1801e966a 56 //pwmOut * _pwmOut; // give address to constructor, than change this value
ivo_david_michelle 11:5c54826d23a7 57 motors motorPwm_;
ivo_david_michelle 14:64b06476d943 58 PwmOut *motor1_;
ivo_david_michelle 13:291ba30c7806 59
ivo_david_michelle 13:291ba30c7806 60 // declarations for IMU use
ivo_david_michelle 10:e7d1801e966a 61 Adafruit_9DOF dof_;
ivo_david_michelle 10:e7d1801e966a 62 Adafruit_LSM303_Accel_Unified accel_;
ivo_david_michelle 10:e7d1801e966a 63 Adafruit_LSM303_Mag_Unified mag_;
ivo_david_michelle 10:e7d1801e966a 64 Adafruit_L3GD20_Unified gyro_;
ivo_david_michelle 10:e7d1801e966a 65 sensors_event_t accel_event_;
ivo_david_michelle 9:f1bd96708a21 66 sensors_event_t mag_event_;
ivo_david_michelle 9:f1bd96708a21 67 sensors_event_t gyro_event_;
ivo_david_michelle 9:f1bd96708a21 68 sensors_vec_t orientation_;
ivo_david_michelle 13:291ba30c7806 69 offset offsetAngRate_;
ivo_david_michelle 13:291ba30c7806 70 offset offsetAttitude_; // used later to compensate default tilt of IMU
ivo_david_michelle 9:f1bd96708a21 71
ivo_david_michelle 10:e7d1801e966a 72 Serial *pcPntr_; // used to access serial communication
ivo_david_michelle 14:64b06476d943 73
ivo_david_michelle 10:e7d1801e966a 74
ivo_david_michelle 10:e7d1801e966a 75 double g_; // gravity [m/s^2]
ivo_david_michelle 10:e7d1801e966a 76 double m_; // mass [kg]
ivo_david_michelle 13:291ba30c7806 77
ivo_david_michelle 10:e7d1801e966a 78 // proportional attitude control gains
ivo_david_michelle 10:e7d1801e966a 79 double kp_phi_;
ivo_david_michelle 10:e7d1801e966a 80 double kp_theta_;
ivo_david_michelle 10:e7d1801e966a 81 double kp_psi_;
ivo_david_michelle 10:e7d1801e966a 82
ivo_david_michelle 10:e7d1801e966a 83 // derivative attitude control gains
ivo_david_michelle 10:e7d1801e966a 84 double kd_phi_;
ivo_david_michelle 10:e7d1801e966a 85 double kd_theta_;
ivo_david_michelle 10:e7d1801e966a 86 double kd_psi_;
ivo_david_michelle 10:e7d1801e966a 87
ivo_david_michelle 10:e7d1801e966a 88 // desired force (will come from joystick)
ivo_david_michelle 10:e7d1801e966a 89 double F_des_; // desired thrust force (excluding weight compensation)
ivo_david_michelle 7:f3f94eadc5b5 90
ivo_david_michelle 14:64b06476d943 91 public:
ivo_david_michelle 15:90e07946186f 92 Quadcopter(Serial *pcPntr, MRF24J40 *mrfPntr); // constructor
ivo_david_michelle 7:f3f94eadc5b5 93
ivo_david_michelle 14:64b06476d943 94 void setState(state *source, state *goal); // not sure if needed
ivo_david_michelle 8:326e7009ce0c 95 void controller();
ivo_david_michelle 8:326e7009ce0c 96 void readSensorValues();
ivo_david_michelle 14:64b06476d943 97
ivo_david_michelle 14:64b06476d943 98 void readRc();
ivo_david_michelle 14:64b06476d943 99
ivo_david_michelle 11:5c54826d23a7 100 motors getPwm();
ivo_david_michelle 14:64b06476d943 101
ivo_david_michelle 14:64b06476d943 102 //void readJoystick();
ivo_david_michelle 10:e7d1801e966a 103 // not implemented yet
ivo_david_michelle 13:291ba30c7806 104 //void setGains();
ivo_david_michelle 10:e7d1801e966a 105 //void setPwm();
ivo_david_michelle 10:e7d1801e966a 106 //void initializePwm();
ivo_david_michelle 6:6f3ffd97d808 107 };
ivo_david_michelle 7:f3f94eadc5b5 108
ivo_david_michelle 6:6f3ffd97d808 109 #endif