A library used for controlling a quadcopter. It provides an easy to use interface, which allows to mount, calibrate and run motors. It is also able to calibrate the actual speed according to calculated PID roll & pitch difference. I used the original Servo library as ESC modules use the same PWM signal as Servo motors.

Dependents:   QuadcopterProgram

Committer:
moklumbys
Date:
Fri Feb 20 00:28:52 2015 +0000
Revision:
5:2aa78a442132
Parent:
4:90ce5817667b
Child:
6:a6b8e508643d
added documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
moklumbys 0:341a08dbf9ba 1 #ifndef QUADCOPTER_H
moklumbys 0:341a08dbf9ba 2 #define QUADCOPTER_H
moklumbys 0:341a08dbf9ba 3
moklumbys 0:341a08dbf9ba 4 #include "mbed.h"
moklumbys 0:341a08dbf9ba 5 #include "Servo.h"
moklumbys 0:341a08dbf9ba 6
moklumbys 3:84d246dccb8d 7 //class used for creating a user friendly interface for controlling quadcopter motors
moklumbys 3:84d246dccb8d 8
moklumbys 0:341a08dbf9ba 9 class Quadcopter {
moklumbys 0:341a08dbf9ba 10 public:
moklumbys 5:2aa78a442132 11 /**
moklumbys 5:2aa78a442132 12 * Constructor.
moklumbys 5:2aa78a442132 13 *
moklumbys 5:2aa78a442132 14 * @param FL - Front Left motor.
moklumbys 5:2aa78a442132 15 * @param FR - Front Right motor.
moklumbys 5:2aa78a442132 16 * @param BL - Back Left motor.
moklumbys 5:2aa78a442132 17 * @param BR - Back Right motor.
moklumbys 5:2aa78a442132 18 *
moklumbys 5:2aa78a442132 19 */
moklumbys 0:341a08dbf9ba 20 Quadcopter(PinName FL, PinName FR, PinName BL, PinName BR);
moklumbys 3:84d246dccb8d 21
moklumbys 5:2aa78a442132 22 /**
moklumbys 5:2aa78a442132 23 * Function used to calibrate all 4 ESC before actually flying the quadcopter.
moklumbys 5:2aa78a442132 24 * It does not matter which of inputs is min and which is max as function checks that itself.
moklumbys 5:2aa78a442132 25 * If inputs are out of boundaries, min value becomes 0.0, and max value becomes 1.0 automatically
moklumbys 5:2aa78a442132 26 *
moklumbys 5:2aa78a442132 27 * @param min - minimum value for the ESC in range from 0.0 to 1.0.
moklumbys 5:2aa78a442132 28 * @param max - maximum value for the ESC in range from 0.0 to 1.0.
moklumbys 5:2aa78a442132 29 */
moklumbys 0:341a08dbf9ba 30 void calibrate (float min, float max);
moklumbys 3:84d246dccb8d 31
moklumbys 5:2aa78a442132 32 /**
moklumbys 5:2aa78a442132 33 * function for runing motors.
moklumbys 5:2aa78a442132 34 *
moklumbys 5:2aa78a442132 35 * @param speed - array of 4 variables, which corresponds to the speed for all 4 motors. speeds are in range from 0.0 to 1.0.
moklumbys 5:2aa78a442132 36 */
moklumbys 0:341a08dbf9ba 37 void run (float* speed);
moklumbys 3:84d246dccb8d 38
moklumbys 5:2aa78a442132 39 /**
moklumbys 5:2aa78a442132 40 * Function used to calculate the speed at which each of the motors should run to be able to stabilise the quadcopter.
moklumbys 5:2aa78a442132 41 *
moklumbys 5:2aa78a442132 42 * @param speed - current speed for each motor.
moklumbys 5:2aa78a442132 43 * @param actSpeed - actual speed at which motors should run
moklumbys 5:2aa78a442132 44 * @param rollDiff - calculated using PID library function PID::compute();
moklumbys 5:2aa78a442132 45 * @param pitchDiff - calculated using PID library function PID::compute();
moklumbys 5:2aa78a442132 46 *
moklumbys 5:2aa78a442132 47 */
moklumbys 0:341a08dbf9ba 48 void stabilise (float* speed, float* actSpeed, float rollDiff, float pitchDiff);
moklumbys 3:84d246dccb8d 49
moklumbys 0:341a08dbf9ba 50 private:
moklumbys 3:84d246dccb8d 51
moklumbys 3:84d246dccb8d 52 float min_calibrate; //min value at which each motor is calibrated
moklumbys 4:90ce5817667b 53 float max_calibrate; //max value ...
moklumbys 3:84d246dccb8d 54 Servo* motor[4]; //motors are used with Servo library as ESC take the same input as usual Servo motors...
moklumbys 3:84d246dccb8d 55 float map(float x, float in_min, float in_max, float out_min, float out_max); //function for mapping values in the range from min calibrate to max_calibrate
moklumbys 0:341a08dbf9ba 56 };
moklumbys 0:341a08dbf9ba 57
moklumbys 0:341a08dbf9ba 58 #endif