New version of quadcopter software written to OO principles
Dependencies: mbed MODSERIAL filter mbed-rtos ConfigFile PID PPM FreeIMU_external_magnetometer TinyGPS
Sensors/Sensors.h@3:4823d6750629, 2015-04-24 (annotated)
- Committer:
- joe4465
- Date:
- Fri Apr 24 16:50:20 2015 +0000
- Revision:
- 3:4823d6750629
- Parent:
- 2:969dfa4f2436
- Child:
- 4:9ffbf9101992
Altitude mode working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joe4465 | 2:969dfa4f2436 | 1 | #include "mbed.h" |
joe4465 | 2:969dfa4f2436 | 2 | #include "Global.h" |
joe4465 | 2:969dfa4f2436 | 3 | #include "rtos.h" |
joe4465 | 2:969dfa4f2436 | 4 | #include "Gps.h" |
joe4465 | 2:969dfa4f2436 | 5 | #include "Imu.h" |
joe4465 | 2:969dfa4f2436 | 6 | #include "Status.h" |
joe4465 | 2:969dfa4f2436 | 7 | #include "LidarLitePwm.h" |
joe4465 | 2:969dfa4f2436 | 8 | #include "Kalman.h" |
joe4465 | 3:4823d6750629 | 9 | #include <math.h> |
joe4465 | 2:969dfa4f2436 | 10 | |
joe4465 | 2:969dfa4f2436 | 11 | #ifndef Sensors_H |
joe4465 | 2:969dfa4f2436 | 12 | #define Sensors_H |
joe4465 | 2:969dfa4f2436 | 13 | |
joe4465 | 3:4823d6750629 | 14 | //#define PI 3.14159265 |
joe4465 | 3:4823d6750629 | 15 | |
joe4465 | 3:4823d6750629 | 16 | using namespace std; |
joe4465 | 2:969dfa4f2436 | 17 | |
joe4465 | 2:969dfa4f2436 | 18 | class Sensors |
joe4465 | 2:969dfa4f2436 | 19 | { |
joe4465 | 2:969dfa4f2436 | 20 | public: |
joe4465 | 2:969dfa4f2436 | 21 | Sensors(Status& status, ConfigFileWrapper& configFileWrapper, PinName gpsPinTx, PinName gpsPinRx, PinName i2cSda, PinName i2cScl, PinName lidarInterrupt); |
joe4465 | 2:969dfa4f2436 | 22 | ~Sensors(); |
joe4465 | 2:969dfa4f2436 | 23 | |
joe4465 | 2:969dfa4f2436 | 24 | struct Position |
joe4465 | 2:969dfa4f2436 | 25 | { |
joe4465 | 3:4823d6750629 | 26 | Gps::Value gpsPosition; |
joe4465 | 2:969dfa4f2436 | 27 | double computedX; |
joe4465 | 2:969dfa4f2436 | 28 | double computedY; |
joe4465 | 2:969dfa4f2436 | 29 | }; |
joe4465 | 2:969dfa4f2436 | 30 | |
joe4465 | 2:969dfa4f2436 | 31 | struct Altitude |
joe4465 | 2:969dfa4f2436 | 32 | { |
joe4465 | 2:969dfa4f2436 | 33 | double lidar; |
joe4465 | 2:969dfa4f2436 | 34 | double barometer; |
joe4465 | 2:969dfa4f2436 | 35 | double gps; |
joe4465 | 2:969dfa4f2436 | 36 | double computed; |
joe4465 | 2:969dfa4f2436 | 37 | }; |
joe4465 | 2:969dfa4f2436 | 38 | |
joe4465 | 2:969dfa4f2436 | 39 | void update(); |
joe4465 | 2:969dfa4f2436 | 40 | Imu::Rate getRate(); |
joe4465 | 2:969dfa4f2436 | 41 | Imu::Angle getAngle(); |
joe4465 | 2:969dfa4f2436 | 42 | Gps::Value getGpsValues(); |
joe4465 | 3:4823d6750629 | 43 | Imu::Velocity getImuVelocity(); |
joe4465 | 2:969dfa4f2436 | 44 | Sensors::Altitude getAltitude(); |
joe4465 | 2:969dfa4f2436 | 45 | Sensors::Position getPosition(); |
joe4465 | 2:969dfa4f2436 | 46 | void enable(bool enable); |
joe4465 | 2:969dfa4f2436 | 47 | void zeroBarometer(); |
joe4465 | 2:969dfa4f2436 | 48 | void updateImu(); |
joe4465 | 2:969dfa4f2436 | 49 | void zeroAccel(); |
joe4465 | 3:4823d6750629 | 50 | void zeroPos(); |
joe4465 | 2:969dfa4f2436 | 51 | |
joe4465 | 2:969dfa4f2436 | 52 | private: |
joe4465 | 2:969dfa4f2436 | 53 | void zeroGyro(); |
joe4465 | 2:969dfa4f2436 | 54 | void updateGpsValues(); |
joe4465 | 2:969dfa4f2436 | 55 | void updateAltitude(); |
joe4465 | 2:969dfa4f2436 | 56 | void updateVelocity(); |
joe4465 | 2:969dfa4f2436 | 57 | void updatePosition(); |
joe4465 | 2:969dfa4f2436 | 58 | int getLidarAltitude(); |
joe4465 | 3:4823d6750629 | 59 | double toRadian(double deg); |
joe4465 | 2:969dfa4f2436 | 60 | |
joe4465 | 2:969dfa4f2436 | 61 | Status& _status; |
joe4465 | 2:969dfa4f2436 | 62 | Imu::Rate _rate; |
joe4465 | 2:969dfa4f2436 | 63 | Imu::Angle _angle; |
joe4465 | 2:969dfa4f2436 | 64 | Position _position; |
joe4465 | 3:4823d6750629 | 65 | Position _startingPosition; |
joe4465 | 2:969dfa4f2436 | 66 | Altitude _altitude; |
joe4465 | 2:969dfa4f2436 | 67 | Gps::Value _gpsValues; |
joe4465 | 2:969dfa4f2436 | 68 | Imu* _imu; |
joe4465 | 2:969dfa4f2436 | 69 | Gps* _gps; |
joe4465 | 2:969dfa4f2436 | 70 | LidarLitePwm* _lidar; |
joe4465 | 2:969dfa4f2436 | 71 | Kalman* _altitudeKalmanFilter; |
joe4465 | 3:4823d6750629 | 72 | Kalman* _xPosKalmanFilter; |
joe4465 | 3:4823d6750629 | 73 | Kalman* _yPosKalmanFilter; |
joe4465 | 2:969dfa4f2436 | 74 | }; |
joe4465 | 2:969dfa4f2436 | 75 | |
joe4465 | 2:969dfa4f2436 | 76 | #endif |