ESC routines
ESC.h@0:c995af692179, 2016-05-30 (annotated)
- Committer:
- Decimus
- Date:
- Mon May 30 08:08:52 2016 +0000
- Revision:
- 0:c995af692179
[+]
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Decimus | 0:c995af692179 | 1 | /* mbed ESC Library |
Decimus | 0:c995af692179 | 2 | * Copyright (c) 2012 Oleg Evsegneev |
Decimus | 0:c995af692179 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
Decimus | 0:c995af692179 | 4 | */ |
Decimus | 0:c995af692179 | 5 | |
Decimus | 0:c995af692179 | 6 | #ifndef MBED_ESC_H |
Decimus | 0:c995af692179 | 7 | #define MBED_ESC_H |
Decimus | 0:c995af692179 | 8 | |
Decimus | 0:c995af692179 | 9 | #define MODE_PWM |
Decimus | 0:c995af692179 | 10 | //#define CIRC_TEST |
Decimus | 0:c995af692179 | 11 | |
Decimus | 0:c995af692179 | 12 | #include "mbed.h" |
Decimus | 0:c995af692179 | 13 | #include "Servo.h" |
Decimus | 0:c995af692179 | 14 | |
Decimus | 0:c995af692179 | 15 | class ESC { |
Decimus | 0:c995af692179 | 16 | |
Decimus | 0:c995af692179 | 17 | public: |
Decimus | 0:c995af692179 | 18 | |
Decimus | 0:c995af692179 | 19 | ESC(PinName x1, PinName x2, PinName y1, PinName y2, PinName led); |
Decimus | 0:c995af692179 | 20 | |
Decimus | 0:c995af692179 | 21 | /** Set thrust |
Decimus | 0:c995af692179 | 22 | * |
Decimus | 0:c995af692179 | 23 | * Sets thrust to motors |
Decimus | 0:c995af692179 | 24 | */ |
Decimus | 0:c995af692179 | 25 | void set( float x1, float x2, float y1, float y2 ); |
Decimus | 0:c995af692179 | 26 | |
Decimus | 0:c995af692179 | 27 | /** Stop motors |
Decimus | 0:c995af692179 | 28 | * |
Decimus | 0:c995af692179 | 29 | * Sets all motor thrust to 0.0 |
Decimus | 0:c995af692179 | 30 | */ |
Decimus | 0:c995af692179 | 31 | void stop(); |
Decimus | 0:c995af692179 | 32 | |
Decimus | 0:c995af692179 | 33 | /** Initialize esc |
Decimus | 0:c995af692179 | 34 | * |
Decimus | 0:c995af692179 | 35 | * 1.Plug in LiPO battery |
Decimus | 0:c995af692179 | 36 | * 2.ESC init (2sec led on) |
Decimus | 0:c995af692179 | 37 | * 3.ESC ready (led off) |
Decimus | 0:c995af692179 | 38 | */ |
Decimus | 0:c995af692179 | 39 | void initialize_(); |
Decimus | 0:c995af692179 | 40 | |
Decimus | 0:c995af692179 | 41 | /** Calibrate esc |
Decimus | 0:c995af692179 | 42 | * 1.Plug in external mcu power |
Decimus | 0:c995af692179 | 43 | * 2.Plug in LiPO battery (5sec led blinking) |
Decimus | 0:c995af692179 | 44 | * 3.ESC init (2sec led on) |
Decimus | 0:c995af692179 | 45 | * 4.ESC ready (led off) |
Decimus | 0:c995af692179 | 46 | */ |
Decimus | 0:c995af692179 | 47 | void calibrate_(); |
Decimus | 0:c995af692179 | 48 | |
Decimus | 0:c995af692179 | 49 | /** Blink led |
Decimus | 0:c995af692179 | 50 | */ |
Decimus | 0:c995af692179 | 51 | void blink(uint16_t delay); |
Decimus | 0:c995af692179 | 52 | |
Decimus | 0:c995af692179 | 53 | protected: |
Decimus | 0:c995af692179 | 54 | #ifdef MODE_PPM |
Decimus | 0:c995af692179 | 55 | Servo _esc_x1, _esc_x2, _esc_y1, _esc_y2; |
Decimus | 0:c995af692179 | 56 | Servo* _esca[4]; |
Decimus | 0:c995af692179 | 57 | #else |
Decimus | 0:c995af692179 | 58 | PwmOut _esc_x1, _esc_x2, _esc_y1, _esc_y2; |
Decimus | 0:c995af692179 | 59 | PwmOut* _esca[4]; |
Decimus | 0:c995af692179 | 60 | #endif |
Decimus | 0:c995af692179 | 61 | DigitalOut _led; |
Decimus | 0:c995af692179 | 62 | }; |
Decimus | 0:c995af692179 | 63 | |
Decimus | 0:c995af692179 | 64 | #endif |