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-20
- Revision:
- 5:2aa78a442132
- Parent:
- 4:90ce5817667b
- Child:
- 6:a6b8e508643d
File content as of revision 5:2aa78a442132:
#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. * * @param FL - Front Left motor. * @param FR - Front Right motor. * @param BL - Back Left motor. * @param BR - Back Right motor. * */ Quadcopter(PinName FL, PinName FR, PinName BL, PinName BR); /** * Function used to calibrate all 4 ESC before actually flying the quadcopter. * 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 * * @param min - minimum value for the ESC in range from 0.0 to 1.0. * @param max - maximum value for the ESC in range from 0.0 to 1.0. */ void calibrate (float min, float max); /** * function for runing motors. * * @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. */ void run (float* speed); /** * Function used to calculate the speed at which each of the motors should run to be able to stabilise the quadcopter. * * @param speed - current speed for each motor. * @param actSpeed - actual speed at which motors should run * @param rollDiff - calculated using PID library function PID::compute(); * @param pitchDiff - 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