Quadcopter software. Flying - Contact me for more details or a copy of the PC ground station code

Dependencies:   ConfigFile PID PPM MODSERIAL mbed-rtos mbed MaxbotixDriver TinyGPS filter

Revision:
9:7b194f83e567
Parent:
7:bc5822aa8878
--- a/hardware.h	Tue Feb 10 20:58:12 2015 +0000
+++ b/hardware.h	Sun Feb 22 20:10:12 2015 +0000
@@ -4,8 +4,11 @@
 #include "PID.h"
 #include "ConfigFile.h"
 #include "PPM.h"
+#include <sstream>
+#include <TinyGPS.h>
+#include "sonar.h"
+#include "MODSERIAL.h"
 #include "filter.h"
-#include <sstream>
 
 #ifndef HARDWARE_H
 #define HARDWARE_H
@@ -30,16 +33,16 @@
 #define             RC_IN_MIN 1000
 #define             RC_OUT_MAX 1
 #define             RC_OUT_MIN 0
-#define             RC_YAW_RATE_MAX 90
-#define             RC_YAW_RATE_MIN -90
+#define             RC_YAW_RATE_MAX 180
+#define             RC_YAW_RATE_MIN -180
 #define             RC_ROLL_RATE_MAX 90
 #define             RC_ROLL_RATE_MIN -90
 #define             RC_PITCH_RATE_MAX 90
 #define             RC_PITCH_RATE_MIN -90
-#define             RC_ROLL_ANGLE_MAX 45
-#define             RC_ROLL_ANGLE_MIN -45
-#define             RC_PITCH_ANGLE_MAX 45
-#define             RC_PITCH_ANGLE_MIN -45
+#define             RC_ROLL_ANGLE_MAX 20
+#define             RC_ROLL_ANGLE_MIN -20
+#define             RC_PITCH_ANGLE_MAX 20
+#define             RC_PITCH_ANGLE_MIN -20
 #define             RC_THRUST_MAX 1
 #define             RC_THRUST_MIN 0
 
@@ -69,12 +72,12 @@
 float               _oldZeroValues[3] = {0,0,0}; //Yaw, pitch, roll
 float               _rcCommands[8] = {0,0,0,0,0,0,0,0};
 float               _rcMappedCommands[4] = {0,0,0,0}; //Yaw, pitch, roll, thrust
-float               _gpsValues[5] = {0,0,0,0,0}; //Latitude, longitude, altitude, course, speed
+double              _gpsValues[5] = {0,0,0,0,0}; //Latitude, longitude, altitude, course, speed
+bool                _gpsConnected = false;
 bool                _armed = false;
 bool                _rate = false;
 bool                _stab = true;
 bool                _initialised = false;
-bool                _gpsConnected = false;
 float               _motorPower [4] = {0,0,0,0};
 float               _gyroRate[3] = {0,0,0}; // Yaw, Pitch, Roll
 float               _ypr[3] = {0,0,0}; // Yaw, pitch, roll
@@ -83,6 +86,9 @@
 bool                _levelOffset = false;
 int                 _commsMode = 0;
 int                 _batt = 0;
+float               _yawTarget = 0;
+float               _maxBotixPingAltitude = 0;
+float               _barometerAltitude = 0;
     
 //PID controllers
 PID                 *_yawRatePIDController;
@@ -97,6 +103,7 @@
 Thread              *_serialPortMonitorThread;
 Thread              *_flightControllerThread;
 Thread              *_rcCommandMonitorThread;
+Thread              *_altitudeMonitorThread;
 
 //Config file
 LocalFileSystem     local("local");
@@ -104,12 +111,10 @@
 char*               _str = new char[1024];
 
 //RC filters
-//medianFilter        *_yawMedianFilter;
-//medianFilter        *_pitchMedianFilter;
-//medianFilter        *_rollMedianFilter;
-//medianFilter        *_thrustMedianFilter;
-//medianFilter        *_channel7MedianFilter;
-//medianFilter        *_channel8MedianFilter;
+medianFilter        *_yawMedianFilter;
+medianFilter        *_pitchMedianFilter;
+medianFilter        *_rollMedianFilter;
+medianFilter        *_thrustMedianFilter;
 
 //HARDWARE////////////////////////////////////////////////////////////////////////////////////
 // M1  M2
@@ -126,20 +131,18 @@
 PwmOut              _motor4(p24);
 
 //USB serial
-Serial              _wiredSerial(USBTX, USBRX);
+MODSERIAL           _wiredSerial(USBTX, USBRX);
 
 //Wireless Serial
-Serial              _wirelessSerial(p9, p10);
+MODSERIAL           _wirelessSerial(p9, p10);
 
 //GPS Serial
-//Serial            _gpsSerial(p28, p27);
+MODSERIAL           _gps(p13, p14);
+TinyGPS             _tinyGPS;
 
 //PPM in
-PPM *_ppm;
-InterruptIn *_interruptPin = new InterruptIn(p8);
-
-//Battery monitor
-//DigitalIn         _batteryMonitor(p8);
+PPM                 *_ppm;
+InterruptIn         *_interruptPin = new InterruptIn(p8);
 
 //Onboard LED's
 DigitalOut          _led1(LED1);
@@ -147,18 +150,22 @@
 DigitalOut          _led3(LED3);
 DigitalOut          _led4(LED4);
 
-//Outputs
-//DigitalOut          _output1(p11);
-//DigitalOut          _output2(p12);
-//DigitalOut          _output3(p5);
-//DigitalOut          _output4(p6);
-
 //IMU
 FreeIMU             _freeIMU;
 
 //Buzzer
 DigitalOut          _buzzer(p20);
 
+//MaxBotix Ping sensor
+Timer               _maxBotixTimer;
+Sonar               _maxBotixSensor(p15, _maxBotixTimer);
+
+//Unused analog pins
+DigitalOut         _spare1(p16);
+DigitalOut         _spare2(p17);
+DigitalOut         _spare3(p18);
+DigitalOut         _spare4(p19);
+
 //Functions///////////////////////////////////////////////////////////////////////////////////////////////
 //Zero gyro and arm
 void Arm()