Hideto Niwa
/
ESC_DC_Brushless_motor_test
ブラシレスモータESC回転プログラム例
main.cpp@1:1b9da3f8a084, 2019-08-13 (annotated)
- Committer:
- HidetoN
- Date:
- Tue Aug 13 15:17:42 2019 +0000
- Revision:
- 1:1b9da3f8a084
- Parent:
- 0:378b1492eaf6
BLmotor sample program;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:378b1492eaf6 | 1 | // Calibrate and arm ESC and then sweep through motor speed range |
4180_1 | 0:378b1492eaf6 | 2 | // To run: Hold down reset on mbed and power up ESC motor supply |
4180_1 | 0:378b1492eaf6 | 3 | // Wait for three power up beeps from ESC, then release reset (or apply power) on mbed |
4180_1 | 0:378b1492eaf6 | 4 | // See https://github.com/bitdump/BLHeli/blob/master/BLHeli_S%20SiLabs/BLHeli_S%20manual%20SiLabs%20Rev16.x.pdf |
4180_1 | 0:378b1492eaf6 | 5 | // for info on beep codes and calibration |
4180_1 | 0:378b1492eaf6 | 6 | #include "mbed.h" |
4180_1 | 0:378b1492eaf6 | 7 | #include "Servo.h" |
4180_1 | 0:378b1492eaf6 | 8 | PwmOut ledf(LED1); //throttle up test led with PWM dimming |
4180_1 | 0:378b1492eaf6 | 9 | |
HidetoN | 1:1b9da3f8a084 | 10 | Servo myservo(A1); |
4180_1 | 0:378b1492eaf6 | 11 | |
4180_1 | 0:378b1492eaf6 | 12 | int main() |
4180_1 | 0:378b1492eaf6 | 13 | { |
4180_1 | 0:378b1492eaf6 | 14 | myservo = 0.0; |
HidetoN | 1:1b9da3f8a084 | 15 | ledf = 1; |
4180_1 | 0:378b1492eaf6 | 16 | wait(0.5); //ESC detects signal |
4180_1 | 0:378b1492eaf6 | 17 | //Required ESC Calibration/Arming sequence |
4180_1 | 0:378b1492eaf6 | 18 | //sends longest and shortest PWM pulse to learn and arm at power on |
4180_1 | 0:378b1492eaf6 | 19 | myservo = 1.0; //send longest PWM |
HidetoN | 1:1b9da3f8a084 | 20 | ledf = 0; |
4180_1 | 0:378b1492eaf6 | 21 | wait(8); |
4180_1 | 0:378b1492eaf6 | 22 | myservo = 0.0; //send shortest PWM |
4180_1 | 0:378b1492eaf6 | 23 | wait(8); |
4180_1 | 0:378b1492eaf6 | 24 | //ESC now operational using standard servo PWM signals |
4180_1 | 0:378b1492eaf6 | 25 | while (1) { |
4180_1 | 0:378b1492eaf6 | 26 | for (float p=0.0; p<=1.0; p += 0.025) { //Throttle up slowly to full throttle |
4180_1 | 0:378b1492eaf6 | 27 | myservo = p; |
4180_1 | 0:378b1492eaf6 | 28 | ledf = p; |
4180_1 | 0:378b1492eaf6 | 29 | wait(1.0); |
4180_1 | 0:378b1492eaf6 | 30 | } |
4180_1 | 0:378b1492eaf6 | 31 | myservo = 0.0; //Motor off |
HidetoN | 1:1b9da3f8a084 | 32 | ledf = 0; |
4180_1 | 0:378b1492eaf6 | 33 | wait(4.0); |
4180_1 | 0:378b1492eaf6 | 34 | for (float p=1.0; p>=0.0; p -= 0.025) { //Throttle down slowly from full throttle |
4180_1 | 0:378b1492eaf6 | 35 | myservo = p; |
HidetoN | 1:1b9da3f8a084 | 36 | ledf = p; |
4180_1 | 0:378b1492eaf6 | 37 | wait(1.0); |
4180_1 | 0:378b1492eaf6 | 38 | } |
4180_1 | 0:378b1492eaf6 | 39 | myservo = 0.0; //Motor off |
HidetoN | 1:1b9da3f8a084 | 40 | ledf = 0; |
4180_1 | 0:378b1492eaf6 | 41 | wait(4.0); |
4180_1 | 0:378b1492eaf6 | 42 | } |
4180_1 | 0:378b1492eaf6 | 43 | } |