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.
Quadcopter.h
- Committer:
- moklumbys
- Date:
- 2015-02-19
- Revision:
- 3:84d246dccb8d
- Parent:
- 0:341a08dbf9ba
- Child:
- 4:90ce5817667b
File content as of revision 3:84d246dccb8d:
#ifndef QUADCOPTER_H #define QUADCOPTER_H #include "mbed.h" #include "Servo.h" //class used for creating a user friendly interface for controlling quadcopter motors class Quadcopter { public: //constructor of the instance. FL correspond to Front_Left, FR to Front Right... Quadcopter(PinName FL, PinName FR, PinName BL, PinName BR); //function used to calibrate all 4 ESC before actually flying the copter //it takes min and max values, which are in range from 0.0 to 1.0 //it does not matter which of inputs is min and which is max as function checks that itself //If inputs are out of boundaries, min value becomes 0.0, and max value becomes 1.0 automatically void calibrate (float min, float max); //function for runing motors //Function takes array of 4 variables, which corresponds to the speed for all 4 motors //speeds are in range from 0.0 to 1.0 void run (float* speed); //function used calculate the speed at which each of the motors should run to be able to stabilise the quadcopter //speed here is the current speed for each motor, actSpeed is the output speed at which motors should run //rollDiff & pitchDiff are both calculated using PID library function PID::compute(); void stabilise (float* speed, float* actSpeed, float rollDiff, float pitchDiff); private: float min_calibrate; //min value at which each motor is calibrated float max_calibrate //max value ... Servo* motor[4]; //motors are used with Servo library as ESC take the same input as usual Servo motors... 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 }; #endif