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
hardware.h@1:045edcf091f3, 2014-05-16 (annotated)
- Committer:
- joe4465
- Date:
- Fri May 16 14:18:05 2014 +0000
- Revision:
- 1:045edcf091f3
- Parent:
- 0:0010a5abcc31
- Child:
- 2:b3b771c8f7d1
first commit
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:0010a5abcc31 | 52 | float _ratePIDControllerOutputs[3] = {0,0,0}; //Yaw, pitch, roll |
joe4465 | 0:0010a5abcc31 | 53 | float _stabPIDControllerOutputs[3] = {0,0,0}; //Yaw, pitch, roll |
joe4465 | 0:0010a5abcc31 | 54 | float _motorPower [4] = {0,0,0,0}; |
joe4465 | 0:0010a5abcc31 | 55 | float _ypr[3] = {0,0,0}; // Yaw, pitch, roll |
joe4465 | 1:045edcf091f3 | 56 | float _rcMappedCommands[4] = {0,0,0,0}; //Yaw, pitch, roll, thrust |
joe4465 | 0:0010a5abcc31 | 57 | bool _armed = false; |
joe4465 | 0:0010a5abcc31 | 58 | bool _rate = false; |
joe4465 | 0:0010a5abcc31 | 59 | bool _stab = true; |
joe4465 | 0:0010a5abcc31 | 60 | bool _initialised = true; |
joe4465 | 0:0010a5abcc31 | 61 | |
joe4465 | 0:0010a5abcc31 | 62 | //PID controllers |
joe4465 | 0:0010a5abcc31 | 63 | PID *_yawRatePIDController; |
joe4465 | 0:0010a5abcc31 | 64 | PID *_pitchRatePIDController; |
joe4465 | 0:0010a5abcc31 | 65 | PID *_rollRatePIDController; |
joe4465 | 0:0010a5abcc31 | 66 | PID *_yawStabPIDController; |
joe4465 | 0:0010a5abcc31 | 67 | PID *_pitchStabPIDController; |
joe4465 | 0:0010a5abcc31 | 68 | PID *_rollStabPIDController; |
joe4465 | 0:0010a5abcc31 | 69 | |
joe4465 | 0:0010a5abcc31 | 70 | //Config file |
joe4465 | 0:0010a5abcc31 | 71 | LocalFileSystem local("local"); |
joe4465 | 0:0010a5abcc31 | 72 | ConfigFile _configFile; |
joe4465 | 0:0010a5abcc31 | 73 | |
joe4465 | 0:0010a5abcc31 | 74 | //Threads |
joe4465 | 0:0010a5abcc31 | 75 | Thread *_statusThread; |
joe4465 | 0:0010a5abcc31 | 76 | Thread *_serialPortMonitorThread; |
joe4465 | 0:0010a5abcc31 | 77 | Thread *_flightControllerThread; |
joe4465 | 0:0010a5abcc31 | 78 | |
joe4465 | 0:0010a5abcc31 | 79 | //HARDWARE//////////////////////////////////////////////////////////////////////////////////// |
joe4465 | 0:0010a5abcc31 | 80 | // M1 M2 |
joe4465 | 0:0010a5abcc31 | 81 | // \ / |
joe4465 | 0:0010a5abcc31 | 82 | // \/ |
joe4465 | 0:0010a5abcc31 | 83 | // /\ |
joe4465 | 0:0010a5abcc31 | 84 | // / \ |
joe4465 | 0:0010a5abcc31 | 85 | // M3 M4 |
joe4465 | 0:0010a5abcc31 | 86 | |
joe4465 | 0:0010a5abcc31 | 87 | //Motors |
joe4465 | 0:0010a5abcc31 | 88 | PwmOut _motor1(p22); |
joe4465 | 0:0010a5abcc31 | 89 | PwmOut _motor2(p23); |
joe4465 | 0:0010a5abcc31 | 90 | PwmOut _motor3(p24); |
joe4465 | 0:0010a5abcc31 | 91 | PwmOut _motor4(p25); |
joe4465 | 0:0010a5abcc31 | 92 | |
joe4465 | 0:0010a5abcc31 | 93 | //USB serial |
joe4465 | 0:0010a5abcc31 | 94 | Serial _wiredSerial(USBTX, USBRX); // tx, rx |
joe4465 | 0:0010a5abcc31 | 95 | |
joe4465 | 0:0010a5abcc31 | 96 | //Wireless Serial |
joe4465 | 0:0010a5abcc31 | 97 | Serial _wirelessSerial(p9, p10); |
joe4465 | 0:0010a5abcc31 | 98 | |
joe4465 | 0:0010a5abcc31 | 99 | //PPM |
joe4465 | 1:045edcf091f3 | 100 | InterruptIn _PPMSignal(p7); |
joe4465 | 0:0010a5abcc31 | 101 | |
joe4465 | 0:0010a5abcc31 | 102 | //Battery monitor |
joe4465 | 0:0010a5abcc31 | 103 | DigitalIn _batteryMonitor(p8); |
joe4465 | 0:0010a5abcc31 | 104 | |
joe4465 | 0:0010a5abcc31 | 105 | //Onboard LED's |
joe4465 | 0:0010a5abcc31 | 106 | DigitalOut _led1(LED1); |
joe4465 | 0:0010a5abcc31 | 107 | DigitalOut _led2(LED2); |
joe4465 | 0:0010a5abcc31 | 108 | DigitalOut _led3(LED3); |
joe4465 | 0:0010a5abcc31 | 109 | DigitalOut _led4(LED4); |
joe4465 | 0:0010a5abcc31 | 110 | |
joe4465 | 0:0010a5abcc31 | 111 | //External LED's |
joe4465 | 0:0010a5abcc31 | 112 | DigitalOut _output1(p11); |
joe4465 | 0:0010a5abcc31 | 113 | DigitalOut _output2(p12); |
joe4465 | 0:0010a5abcc31 | 114 | DigitalOut _output3(p5); |
joe4465 | 0:0010a5abcc31 | 115 | DigitalOut _output4(p6); |
joe4465 | 0:0010a5abcc31 | 116 | |
joe4465 | 0:0010a5abcc31 | 117 | //Buzzer |
joe4465 | 0:0010a5abcc31 | 118 | Beep _buzzer(p26); |
joe4465 | 0:0010a5abcc31 | 119 | |
joe4465 | 0:0010a5abcc31 | 120 | //IMU |
joe4465 | 0:0010a5abcc31 | 121 | FreeIMU _freeIMU; |
joe4465 | 0:0010a5abcc31 | 122 | |
joe4465 | 0:0010a5abcc31 | 123 | #endif |