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

Committer:
joe4465
Date:
Fri May 16 14:22:18 2014 +0000
Revision:
2:b3b771c8f7d1
Parent:
1:045edcf091f3
Child:
3:82665e39f1ea
second commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joe4465 0:0010a5abcc31 1 #include "mbed.h"
joe4465 0:0010a5abcc31 2 #include "rtos.h"
joe4465 0:0010a5abcc31 3 #include "FreeIMU.h"
joe4465 0:0010a5abcc31 4 #include "PID.h"
joe4465 0:0010a5abcc31 5 #include "ConfigFile.h"
joe4465 0:0010a5abcc31 6 #include "beep.h"
joe4465 0:0010a5abcc31 7 #include <sstream>
joe4465 0:0010a5abcc31 8
joe4465 0:0010a5abcc31 9 #ifndef HARDWARE_H
joe4465 0:0010a5abcc31 10 #define HARDWARE_H
joe4465 0:0010a5abcc31 11
joe4465 0:0010a5abcc31 12 //Constants
joe4465 0:0010a5abcc31 13 #define IMU_YAW_ANGLE_MAX 180
joe4465 0:0010a5abcc31 14 #define IMU_YAW_ANGLE_MIN -180
joe4465 0:0010a5abcc31 15 #define IMU_ROLL_ANGLE_MAX 90
joe4465 0:0010a5abcc31 16 #define IMU_ROLL_ANGLE_MIN -90
joe4465 0:0010a5abcc31 17 #define IMU_PITCH_ANGLE_MAX 90
joe4465 0:0010a5abcc31 18 #define IMU_PITCH_ANGLE_MIN -90
joe4465 0:0010a5abcc31 19 #define IMU_YAW_RATE_MAX 360
joe4465 0:0010a5abcc31 20 #define IMU_YAW_RATE_MIN -360
joe4465 0:0010a5abcc31 21 #define IMU_ROLL_RATE_MAX 360
joe4465 0:0010a5abcc31 22 #define IMU_ROLL_RATE_MIN -360
joe4465 0:0010a5abcc31 23 #define IMU_PITCH_RATE_MAX 360
joe4465 0:0010a5abcc31 24 #define IMU_PITCH_RATE_MIN -360
joe4465 1:045edcf091f3 25 #define RC_YAW_RATE_MAX 90
joe4465 1:045edcf091f3 26 #define RC_YAW_RATE_MIN -90
joe4465 1:045edcf091f3 27 #define RC_ROLL_RATE_MAX 90
joe4465 1:045edcf091f3 28 #define RC_ROLL_RATE_MIN -90
joe4465 1:045edcf091f3 29 #define RC_PITCH_RATE_MAX 90
joe4465 1:045edcf091f3 30 #define RC_PITCH_RATE_MIN -90
joe4465 1:045edcf091f3 31 #define RC_ROLL_ANGLE_MAX 45
joe4465 1:045edcf091f3 32 #define RC_ROLL_ANGLE_MIN -45
joe4465 1:045edcf091f3 33 #define RC_PITCH_ANGLE_MAX 45
joe4465 1:045edcf091f3 34 #define RC_PITCH_ANGLE_MIN -45
joe4465 0:0010a5abcc31 35 #define RC_THRUST_MAX 1
joe4465 0:0010a5abcc31 36 #define RC_THRUST_MIN 0
joe4465 0:0010a5abcc31 37 #define MOTORS_OFF 0
joe4465 0:0010a5abcc31 38 #define MOTORS_MIN 1060
joe4465 0:0010a5abcc31 39 #define MOTORS_MAX 1860
joe4465 0:0010a5abcc31 40 #define MOTORS_ARMED 1000
joe4465 0:0010a5abcc31 41 #define RATE_PID_CONTROLLER_OUTPUT_MAX 1
joe4465 0:0010a5abcc31 42 #define RATE_PID_CONTROLLER_OUTPUT_MIN -1
joe4465 0:0010a5abcc31 43 #define UPDATE_FREQUENCY 500
joe4465 0:0010a5abcc31 44 #define MOTOR_PWM_FREQUENCY 500
joe4465 1:045edcf091f3 45 #define RCMIN -127
joe4465 1:045edcf091f3 46 #define RCMAX 127
joe4465 0:0010a5abcc31 47
joe4465 0:0010a5abcc31 48 //Shared Variables
joe4465 0:0010a5abcc31 49 float _yawRatePIDControllerP, _yawRatePIDControllerI, _yawRatePIDControllerD, _pitchRatePIDControllerP, _pitchRatePIDControllerI, _pitchRatePIDControllerD, _rollRatePIDControllerP, _rollRatePIDControllerI, _rollRatePIDControllerD;
joe4465 0:0010a5abcc31 50 float _yawStabPIDControllerP, _yawStabPIDControllerI, _yawStabPIDControllerD, _pitchStabPIDControllerP, _pitchStabPIDControllerI, _pitchStabPIDControllerD, _rollStabPIDControllerP, _rollStabPIDControllerI, _rollStabPIDControllerD;
joe4465 0:0010a5abcc31 51 float _zeroValues[3] = {0,0,0}; //Yaw, pitch, roll
joe4465 1:045edcf091f3 52 float _rcMappedCommands[4] = {0,0,0,0}; //Yaw, pitch, roll, thrust
joe4465 0:0010a5abcc31 53 bool _armed = false;
joe4465 0:0010a5abcc31 54 bool _rate = false;
joe4465 0:0010a5abcc31 55 bool _stab = true;
joe4465 0:0010a5abcc31 56 bool _initialised = true;
joe4465 0:0010a5abcc31 57
joe4465 0:0010a5abcc31 58 //PID controllers
joe4465 0:0010a5abcc31 59 PID *_yawRatePIDController;
joe4465 0:0010a5abcc31 60 PID *_pitchRatePIDController;
joe4465 0:0010a5abcc31 61 PID *_rollRatePIDController;
joe4465 0:0010a5abcc31 62 PID *_yawStabPIDController;
joe4465 0:0010a5abcc31 63 PID *_pitchStabPIDController;
joe4465 0:0010a5abcc31 64 PID *_rollStabPIDController;
joe4465 0:0010a5abcc31 65
joe4465 0:0010a5abcc31 66 //Config file
joe4465 0:0010a5abcc31 67 LocalFileSystem local("local");
joe4465 0:0010a5abcc31 68 ConfigFile _configFile;
joe4465 0:0010a5abcc31 69
joe4465 0:0010a5abcc31 70 //Threads
joe4465 0:0010a5abcc31 71 Thread *_statusThread;
joe4465 0:0010a5abcc31 72 Thread *_serialPortMonitorThread;
joe4465 0:0010a5abcc31 73 Thread *_flightControllerThread;
joe4465 0:0010a5abcc31 74
joe4465 0:0010a5abcc31 75 //HARDWARE////////////////////////////////////////////////////////////////////////////////////
joe4465 0:0010a5abcc31 76 // M1 M2
joe4465 0:0010a5abcc31 77 // \ /
joe4465 0:0010a5abcc31 78 // \/
joe4465 0:0010a5abcc31 79 // /\
joe4465 0:0010a5abcc31 80 // / \
joe4465 0:0010a5abcc31 81 // M3 M4
joe4465 0:0010a5abcc31 82
joe4465 0:0010a5abcc31 83 //Motors
joe4465 0:0010a5abcc31 84 PwmOut _motor1(p22);
joe4465 0:0010a5abcc31 85 PwmOut _motor2(p23);
joe4465 0:0010a5abcc31 86 PwmOut _motor3(p24);
joe4465 0:0010a5abcc31 87 PwmOut _motor4(p25);
joe4465 0:0010a5abcc31 88
joe4465 0:0010a5abcc31 89 //USB serial
joe4465 0:0010a5abcc31 90 Serial _wiredSerial(USBTX, USBRX); // tx, rx
joe4465 0:0010a5abcc31 91
joe4465 0:0010a5abcc31 92 //Wireless Serial
joe4465 0:0010a5abcc31 93 Serial _wirelessSerial(p9, p10);
joe4465 0:0010a5abcc31 94
joe4465 0:0010a5abcc31 95 //PPM
joe4465 1:045edcf091f3 96 InterruptIn _PPMSignal(p7);
joe4465 0:0010a5abcc31 97
joe4465 0:0010a5abcc31 98 //Battery monitor
joe4465 0:0010a5abcc31 99 DigitalIn _batteryMonitor(p8);
joe4465 0:0010a5abcc31 100
joe4465 0:0010a5abcc31 101 //Onboard LED's
joe4465 0:0010a5abcc31 102 DigitalOut _led1(LED1);
joe4465 0:0010a5abcc31 103 DigitalOut _led2(LED2);
joe4465 0:0010a5abcc31 104 DigitalOut _led3(LED3);
joe4465 0:0010a5abcc31 105 DigitalOut _led4(LED4);
joe4465 0:0010a5abcc31 106
joe4465 0:0010a5abcc31 107 //External LED's
joe4465 0:0010a5abcc31 108 DigitalOut _output1(p11);
joe4465 0:0010a5abcc31 109 DigitalOut _output2(p12);
joe4465 0:0010a5abcc31 110 DigitalOut _output3(p5);
joe4465 0:0010a5abcc31 111 DigitalOut _output4(p6);
joe4465 0:0010a5abcc31 112
joe4465 0:0010a5abcc31 113 //Buzzer
joe4465 0:0010a5abcc31 114 Beep _buzzer(p26);
joe4465 0:0010a5abcc31 115
joe4465 0:0010a5abcc31 116 //IMU
joe4465 0:0010a5abcc31 117 FreeIMU _freeIMU;
joe4465 0:0010a5abcc31 118
joe4465 0:0010a5abcc31 119 #endif