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

Files at this revision

API Documentation at this revision

Comitter:
joe4465
Date:
Tue Feb 10 20:55:44 2015 +0000
Parent:
6:4c207e7b1203
Child:
8:5a7efcd0c0dd
Commit message:
Updated software to match new PCB

Changed in this revision

flightController.h Show annotated file Show diff for this revision Revisions of this file
hardware.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
rcCommandMonitor.h Show annotated file Show diff for this revision Revisions of this file
serialPortMonitor.h Show annotated file Show diff for this revision Revisions of this file
--- a/flightController.h	Thu Jan 22 18:03:22 2015 +0000
+++ b/flightController.h	Tue Feb 10 20:55:44 2015 +0000
@@ -109,8 +109,8 @@
 
     //Calculate motor power if flying
     //RC Mapped thottle is between 0 and 1
-    //Add 0.1 to try to avoid false starts
-    if(_rcMappedCommands[3] > (RC_THRUST_MIN + 0.1) && _armed == true)
+    //Add 0.2 to try to avoid false starts
+    if(_rcMappedCommands[3] > (RC_THRUST_MIN + 0.2) && _armed == true)
     {
         //Calculate base power to apply from throttle - returns 1060 at min, 1860 at max
         float basePower = MOTORS_MIN + (_rcMappedCommands[3] * 800);
@@ -125,6 +125,7 @@
         float motorFix = 0;
         float motorMin = _motorPower[0];
         float motorMax = _motorPower[0];
+        
         for(int i=1; i<4; i++)
         {
             if(_motorPower[i] < motorMin) motorMin = _motorPower[i];
@@ -186,8 +187,8 @@
     //Use the 2 spare channels to alter the offset
     if(_levelOffset == true)
     {
-        float pitchOffset =_channel7MedianFilter->process(Map(_rcCommands[6], RC_OUT_MIN, RC_OUT_MAX, -5, 5));
-        float rollOffset =_channel8MedianFilter->process(Map(_rcCommands[7], RC_OUT_MIN, RC_OUT_MAX, -5, 5));
+        float pitchOffset = /*_channel7MedianFilter->process(*/Map(_rcCommands[6], RC_OUT_MIN, RC_OUT_MAX, -5, 5);//);
+        float rollOffset = /*_channel8MedianFilter->process(*/Map(_rcCommands[7], RC_OUT_MIN, RC_OUT_MAX, -5, 5);//);
         
         _zeroValues[1] = _oldZeroValues[1] + pitchOffset;
         _zeroValues[2] = _oldZeroValues[2] + rollOffset;
--- a/hardware.h	Thu Jan 22 18:03:22 2015 +0000
+++ b/hardware.h	Tue Feb 10 20:55:44 2015 +0000
@@ -36,10 +36,10 @@
 #define             RC_ROLL_RATE_MIN -90
 #define             RC_PITCH_RATE_MAX 90
 #define             RC_PITCH_RATE_MIN -90
-#define             RC_ROLL_ANGLE_MAX 15
-#define             RC_ROLL_ANGLE_MIN -15
-#define             RC_PITCH_ANGLE_MAX 15
-#define             RC_PITCH_ANGLE_MIN -15
+#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_THRUST_MAX 1
 #define             RC_THRUST_MIN 0
 
@@ -104,12 +104,12 @@
 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;
+//medianFilter        *_channel7MedianFilter;
+//medianFilter        *_channel8MedianFilter;
 
 //HARDWARE////////////////////////////////////////////////////////////////////////////////////
 // M1  M2
@@ -120,10 +120,10 @@
 // M3  M4
  
 //Motors
-PwmOut              _motor1(p22);
-PwmOut              _motor2(p23);
-PwmOut              _motor3(p24);
-PwmOut              _motor4(p25);
+PwmOut              _motor1(p21);
+PwmOut              _motor2(p22);
+PwmOut              _motor3(p23);
+PwmOut              _motor4(p24);
 
 //USB serial
 Serial              _wiredSerial(USBTX, USBRX);
@@ -136,7 +136,7 @@
 
 //PPM in
 PPM *_ppm;
-InterruptIn *_interruptPin = new InterruptIn(p7);
+InterruptIn *_interruptPin = new InterruptIn(p8);
 
 //Battery monitor
 //DigitalIn         _batteryMonitor(p8);
@@ -148,20 +148,23 @@
 DigitalOut          _led4(LED4);
 
 //Outputs
-DigitalOut          _output1(p11);
-DigitalOut          _output2(p12);
-DigitalOut          _output3(p5);
-DigitalOut          _output4(p6);
+//DigitalOut          _output1(p11);
+//DigitalOut          _output2(p12);
+//DigitalOut          _output3(p5);
+//DigitalOut          _output4(p6);
 
 //IMU
 FreeIMU             _freeIMU;
 
+//Buzzer
+DigitalOut          _buzzer(p20);
+
 //Functions///////////////////////////////////////////////////////////////////////////////////////////////
 //Zero gyro and arm
 void Arm()
 {
     //Don't arm unless throttle is equal to 0 and the transmitter is connected
-    if(_rcMappedCommands[3] < (RC_THRUST_MIN + 0.1) && _rcMappedCommands[3] != -1)
+    if(_rcMappedCommands[3] < (RC_THRUST_MIN + 0.2) && _rcMappedCommands[3] != -1 && _armed == false)
     {
         //Zero gyro
         _freeIMU.zeroGyro();
@@ -174,14 +177,17 @@
 //Disarm
 void Disarm()
 {   
-    //Set armed to false
-    _armed = false;  
-    
-    //Disable modes
-    _levelOffset = false; 
-    
-    //Save settings
-    WriteSettingsToConfig();
+    if(_armed == true)
+    {
+        //Set armed to false
+        _armed = false;  
+        
+        //Disable modes
+        _levelOffset = false; 
+        
+        //Save settings
+        WriteSettingsToConfig();
+    }
 }
 
 //Zero pitch and roll
--- a/main.cpp	Thu Jan 22 18:03:22 2015 +0000
+++ b/main.cpp	Tue Feb 10 20:55:44 2015 +0000
@@ -209,6 +209,8 @@
     //Setup wired serial coms
     _wiredSerial.baud(115200);
     
+    _buzzer = 0;
+    
     printf("\r\n");  
     printf("*********************************************************************************\r\n");
     printf("Starting Setup\r\n");
@@ -233,12 +235,12 @@
     printf("Setup initial RC commands\r\n");
     
     //Setup RC median filters
-    _yawMedianFilter = new medianFilter(10);
-    _pitchMedianFilter = new medianFilter(10);
-    _rollMedianFilter = new medianFilter(10);
-    _thrustMedianFilter = new medianFilter(10);
-    _channel7MedianFilter = new medianFilter(10);
-    _channel8MedianFilter = new medianFilter(10);
+    //_yawMedianFilter = new medianFilter(10);
+    //_pitchMedianFilter = new medianFilter(10);
+    //_rollMedianFilter = new medianFilter(10);
+    //_thrustMedianFilter = new medianFilter(10);
+    //_channel7MedianFilter = new medianFilter(10);
+    //_channel8MedianFilter = new medianFilter(10);
     printf("Setup RC median filters\r\n");
     
     //Initialise PPM
@@ -282,4 +284,9 @@
     
     // Wait here forever
     Thread::wait(osWaitForever); 
+    
+    /*while(true)
+    {
+        printf("%f\r\n", _ypr[1]);    
+    }*/
 }
\ No newline at end of file
--- a/rcCommandMonitor.h	Thu Jan 22 18:03:22 2015 +0000
+++ b/rcCommandMonitor.h	Tue Feb 10 20:55:44 2015 +0000
@@ -34,13 +34,13 @@
             i = 0;
             
             //Map yaw channel
-            _rcMappedCommands[0] = - _yawMedianFilter->process(Map(_rcCommands[3], RC_OUT_MIN, RC_OUT_MAX, RC_YAW_RATE_MIN, RC_YAW_RATE_MAX));
+            _rcMappedCommands[0] = - /*_yawMedianFilter->process(*/Map(_rcCommands[3], RC_OUT_MIN, RC_OUT_MAX, RC_YAW_RATE_MIN, RC_YAW_RATE_MAX);//);
         
             //Map thust channel
-            _rcMappedCommands[3] = _thrustMedianFilter->process(Map(_rcCommands[2], RC_OUT_MIN, RC_OUT_MAX, RC_THRUST_MIN, RC_THRUST_MAX));
+            _rcMappedCommands[3] = /*_thrustMedianFilter->process(*/Map(_rcCommands[2], RC_OUT_MIN, RC_OUT_MAX, RC_THRUST_MIN, RC_THRUST_MAX);//);
         
             //Map arm channel.
-            if(_rcCommands[4] > 0.5 && _initialised == true && _armed == false) Arm();
+            if(_rcCommands[4] > 0.5 && _armed == false) Arm();
             else if(_rcCommands[4] <= 0.5 && _armed == true)
             {
                 Disarm();
@@ -62,16 +62,16 @@
             if(_rate == false && _stab == true)//Stability mode
             {
                 //Roll
-                _rcMappedCommands[2] = _rollMedianFilter->process(Map(_rcCommands[0], RC_OUT_MIN, RC_OUT_MAX, RC_ROLL_ANGLE_MIN, RC_ROLL_ANGLE_MAX));
+                _rcMappedCommands[2] = /*_rollMedianFilter->process(*/Map(_rcCommands[0], RC_OUT_MIN, RC_OUT_MAX, RC_ROLL_ANGLE_MIN, RC_ROLL_ANGLE_MAX);//);
                 //Pitch
-                _rcMappedCommands[1] = _pitchMedianFilter->process(-Map(_rcCommands[1], RC_OUT_MIN, RC_OUT_MAX, RC_PITCH_ANGLE_MIN, RC_PITCH_ANGLE_MAX)); //Needs to be reverse
+                _rcMappedCommands[1] = /*_pitchMedianFilter->process(*/-Map(_rcCommands[1], RC_OUT_MIN, RC_OUT_MAX, RC_PITCH_ANGLE_MIN, RC_PITCH_ANGLE_MAX);//); //Needs to be reverse
             }
             else if(_rate == true && _stab == false)//Rate mode
             {
                 //Roll
-                _rcMappedCommands[2] = _rollMedianFilter->process(Map(_rcCommands[0], RC_OUT_MIN, RC_OUT_MAX, RC_ROLL_RATE_MIN, RC_ROLL_RATE_MAX));
+                _rcMappedCommands[2] = /*_rollMedianFilter->process(*/Map(_rcCommands[0], RC_OUT_MIN, RC_OUT_MAX, RC_ROLL_RATE_MIN, RC_ROLL_RATE_MAX);//);
                 //Pitch
-                _rcMappedCommands[1] = _pitchMedianFilter->process(-Map(_rcCommands[1], RC_OUT_MIN, RC_OUT_MAX, RC_PITCH_RATE_MIN, RC_PITCH_RATE_MAX)); //Needs to be reverse
+                _rcMappedCommands[1] = /*_pitchMedianFilter->process(*/-Map(_rcCommands[1], RC_OUT_MIN, RC_OUT_MAX, RC_PITCH_RATE_MIN, RC_PITCH_RATE_MAX);//); //Needs to be reverse
             }
             else
             {
@@ -91,7 +91,7 @@
             _rcMappedCommands[3] = -1;
             
             //If connection has been down for 10 loops then assume the connection really is lost
-            if(i > 10) Disarm();
+            if(i > 10 && _armed == true) Disarm();
         }
         Thread::wait(20);
     }
--- a/serialPortMonitor.h	Thu Jan 22 18:03:22 2015 +0000
+++ b/serialPortMonitor.h	Tue Feb 10 20:55:44 2015 +0000
@@ -338,6 +338,7 @@
             break;
             
         case '1':
+            _levelOffset = false;
             _zeroValues[0] = 0;
             _zeroValues[1] = 0;
             _zeroValues[2] = 0;