An incomplete quadcopter control programme.

Dependencies:   mbed

Committer:
Gurvan
Date:
Wed Jul 17 15:58:25 2013 +0000
Revision:
0:9cb9445a11f0
Pour Zobson, fi(r)st commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gurvan 0:9cb9445a11f0 1 /* mbed PwmIn Library
Gurvan 0:9cb9445a11f0 2 * Copyright (c) 2008-2010, sford
Gurvan 0:9cb9445a11f0 3 *
Gurvan 0:9cb9445a11f0 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Gurvan 0:9cb9445a11f0 5 * of this software and associated documentation files (the "Software"), to deal
Gurvan 0:9cb9445a11f0 6 * in the Software without restriction, including without limitation the rights
Gurvan 0:9cb9445a11f0 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Gurvan 0:9cb9445a11f0 8 * copies of the Software, and to permit persons to whom the Software is
Gurvan 0:9cb9445a11f0 9 * furnished to do so, subject to the following conditions:
Gurvan 0:9cb9445a11f0 10 *
Gurvan 0:9cb9445a11f0 11 * The above copyright notice and this permission notice shall be included in
Gurvan 0:9cb9445a11f0 12 * all copies or substantial portions of the Software.
Gurvan 0:9cb9445a11f0 13 *
Gurvan 0:9cb9445a11f0 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Gurvan 0:9cb9445a11f0 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Gurvan 0:9cb9445a11f0 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Gurvan 0:9cb9445a11f0 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Gurvan 0:9cb9445a11f0 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Gurvan 0:9cb9445a11f0 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Gurvan 0:9cb9445a11f0 20 * THE SOFTWARE.
Gurvan 0:9cb9445a11f0 21 */
Gurvan 0:9cb9445a11f0 22
Gurvan 0:9cb9445a11f0 23 #ifndef MBED_PWMIN_H
Gurvan 0:9cb9445a11f0 24 #define MBED_PWMIN_H
Gurvan 0:9cb9445a11f0 25
Gurvan 0:9cb9445a11f0 26 #include "mbed.h"
Gurvan 0:9cb9445a11f0 27
Gurvan 0:9cb9445a11f0 28 /** PwmIn class to read PWM inputs
Gurvan 0:9cb9445a11f0 29 *
Gurvan 0:9cb9445a11f0 30 * Uses InterruptIn to measure the changes on the input
Gurvan 0:9cb9445a11f0 31 * and record the time they occur
Gurvan 0:9cb9445a11f0 32 *
Gurvan 0:9cb9445a11f0 33 * @note uses InterruptIn, so not available on p19/p20
Gurvan 0:9cb9445a11f0 34 */
Gurvan 0:9cb9445a11f0 35 class PwmIn {
Gurvan 0:9cb9445a11f0 36 public:
Gurvan 0:9cb9445a11f0 37 /** Create a PwmIn
Gurvan 0:9cb9445a11f0 38 *
Gurvan 0:9cb9445a11f0 39 * @param p The pwm input pin (must support InterruptIn)
Gurvan 0:9cb9445a11f0 40 */
Gurvan 0:9cb9445a11f0 41 PwmIn(PinName p);
Gurvan 0:9cb9445a11f0 42
Gurvan 0:9cb9445a11f0 43 /** Read the current period
Gurvan 0:9cb9445a11f0 44 *
Gurvan 0:9cb9445a11f0 45 * @returns the period in seconds
Gurvan 0:9cb9445a11f0 46 */
Gurvan 0:9cb9445a11f0 47 float period();
Gurvan 0:9cb9445a11f0 48
Gurvan 0:9cb9445a11f0 49 /** Read the current pulsewidth
Gurvan 0:9cb9445a11f0 50 *
Gurvan 0:9cb9445a11f0 51 * @returns the pulsewidth in seconds
Gurvan 0:9cb9445a11f0 52 */
Gurvan 0:9cb9445a11f0 53 float pulsewidth();
Gurvan 0:9cb9445a11f0 54
Gurvan 0:9cb9445a11f0 55 /** Read the current dutycycle
Gurvan 0:9cb9445a11f0 56 *
Gurvan 0:9cb9445a11f0 57 * @returns the dutycycle as a percentage, represented between 0.0-1.0
Gurvan 0:9cb9445a11f0 58 */
Gurvan 0:9cb9445a11f0 59 float dutycycle();
Gurvan 0:9cb9445a11f0 60
Gurvan 0:9cb9445a11f0 61 protected:
Gurvan 0:9cb9445a11f0 62 void rise();
Gurvan 0:9cb9445a11f0 63 void fall();
Gurvan 0:9cb9445a11f0 64
Gurvan 0:9cb9445a11f0 65 InterruptIn _p;
Gurvan 0:9cb9445a11f0 66 Timer _t;
Gurvan 0:9cb9445a11f0 67 int _pulsewidth, _period, _temp_pulsewidth;
Gurvan 0:9cb9445a11f0 68 };
Gurvan 0:9cb9445a11f0 69
Gurvan 0:9cb9445a11f0 70 #endif