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:11:00 2015 +0000
Revision:
4:90ce5817667b
Parent:
3:84d246dccb8d
Child:
5:2aa78a442132
corrected some previous errors.

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 3:84d246dccb8d 11 //constructor of the instance. FL correspond to Front_Left, FR to Front Right...
moklumbys 0:341a08dbf9ba 12 Quadcopter(PinName FL, PinName FR, PinName BL, PinName BR);
moklumbys 3:84d246dccb8d 13
moklumbys 3:84d246dccb8d 14 //function used to calibrate all 4 ESC before actually flying the copter
moklumbys 3:84d246dccb8d 15 //it takes min and max values, which are in range from 0.0 to 1.0
moklumbys 3:84d246dccb8d 16 //it does not matter which of inputs is min and which is max as function checks that itself
moklumbys 3:84d246dccb8d 17 //If inputs are out of boundaries, min value becomes 0.0, and max value becomes 1.0 automatically
moklumbys 0:341a08dbf9ba 18 void calibrate (float min, float max);
moklumbys 3:84d246dccb8d 19
moklumbys 3:84d246dccb8d 20 //function for runing motors
moklumbys 3:84d246dccb8d 21 //Function takes array of 4 variables, which corresponds to the speed for all 4 motors
moklumbys 3:84d246dccb8d 22 //speeds are in range from 0.0 to 1.0
moklumbys 0:341a08dbf9ba 23 void run (float* speed);
moklumbys 3:84d246dccb8d 24
moklumbys 3:84d246dccb8d 25 //function used calculate the speed at which each of the motors should run to be able to stabilise the quadcopter
moklumbys 3:84d246dccb8d 26 //speed here is the current speed for each motor, actSpeed is the output speed at which motors should run
moklumbys 3:84d246dccb8d 27 //rollDiff & pitchDiff are both calculated using PID library function PID::compute();
moklumbys 0:341a08dbf9ba 28 void stabilise (float* speed, float* actSpeed, float rollDiff, float pitchDiff);
moklumbys 3:84d246dccb8d 29
moklumbys 0:341a08dbf9ba 30 private:
moklumbys 3:84d246dccb8d 31
moklumbys 3:84d246dccb8d 32 float min_calibrate; //min value at which each motor is calibrated
moklumbys 4:90ce5817667b 33 float max_calibrate; //max value ...
moklumbys 3:84d246dccb8d 34 Servo* motor[4]; //motors are used with Servo library as ESC take the same input as usual Servo motors...
moklumbys 3:84d246dccb8d 35 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 36 };
moklumbys 0:341a08dbf9ba 37
moklumbys 0:341a08dbf9ba 38 #endif