Successful acro and level mode now! Relying on MPU9250 as base sensor. I'm working continuously on tuning and features :) NEWEST VERSION ON: https://github.com/MaEtUgR/FlyBed (CODE 100% compatible/copyable)

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Servo.h Source File

Servo.h

00001 // based on http://mbed.org/users/jdenkers/code/Servo/
00002 
00003 #ifndef SERVO_H
00004 #define SERVO_H
00005 
00006 #include "mbed.h"
00007 
00008 /** Class to control a servo on any pin, without using pwm
00009  *
00010  * Example:
00011  * @code
00012  * // Keep sweeping servo from left to right
00013  * #include "mbed.h"
00014  * #include "Servo.h"
00015  * 
00016  * Servo Servo1(p20);
00017  *
00018  * Servo1.Enable(1500,20000);
00019  *
00020  * while(1) {
00021  *     for (int pos = 1000; pos < 2000; pos += 25) {
00022  *         Servo1.SetPosition(pos);  
00023  *         wait_ms(20);
00024  *     }
00025  *     for (int pos = 2000; pos > 1000; pos -= 25) {
00026  *         Servo1.SetPosition(pos); 
00027  *         wait_ms(20); 
00028  *     }
00029  * }
00030  * @endcode
00031  */
00032 
00033 class Servo {
00034 
00035 public:
00036     /** Create a new Servo object on any mbed pin
00037      *
00038      * @param Pin Pin on mbed to connect servo to
00039      */
00040     Servo(PinName Pin, int frequency);
00041     void SetFrequency(int frequency);
00042     
00043     /** Change the position of the servo. Position in us
00044      *
00045      * @param NewPos The new value of the servos position (us)
00046      */
00047     void SetPosition(int NewPos);
00048     
00049     /** Enable the servo. Without enabling the servo won't be running. Startposition and period both in us.
00050      *
00051      * @param StartPos The position of the servo to start (us) 
00052      * @param Period The time between every pulse. 20000 us = 50 Hz(standard) (us)
00053      */
00054     void Enable(int StartPos, int Period);
00055     
00056     //Disable the servo. After disabling the servo won't get any signal anymore
00057     void Disable();
00058     
00059     //operator for confortable positioning
00060     void operator=(int position);
00061     
00062 
00063 private:
00064     void StartPulse();
00065     void EndPulse();
00066 
00067     int Position;
00068     DigitalOut ServoPin;
00069     Ticker Pulse;
00070     Timeout PulseStop;
00071 };
00072 
00073 #endif