If you want to use BLDC with FUTABA without going backward, use it
Dependencies: mbed Servo Pulse1
main.cpp
- Committer:
- kyucheol
- Date:
- 2019-12-21
- Revision:
- 2:4e3761881124
- Parent:
- 1:1e4ebe0da2ea
- Child:
- 3:c47e538f3aec
File content as of revision 2:4e3761881124:
#include "mbed.h" #include "Servo.h" #include "Map.h" #include "Pulse1.h" PwmOut led_left(LED1); //확인용 LED1 PwmOut led_right(LED2); //확인용 LED2 Servo bldc_left(D12); // 왼쪽 BLDC Servo bldc_right(PC_7); // 오른쪽 BLDC PulseInOut Channel1(A0); //채널1, futaba기준 좌우방향(오른쪽 조이스틱) PulseInOut Channel2(A1); //채널2, futaba기준 상하방향(오른쪽 조이스틱) PulseInOut Channel3(A2); //채널3, futaba기준 상하방향(왼쪽 조이스틱) int main() { bldc_left.write(0); // BLDC 초기 설정 bldc_right.write(0); led_left = 1; led_right=1; wait(0.5); bldc_left.write(1); bldc_right.write(1); led_left =0; led_right=0; wait(2); bldc_left.write(0); bldc_right.write(0); wait(2); float raw1,raw2,raw3; float mod1,mod2,mod3,mod4,mod5; printf("\nBLDC Setup & end\n"); while (1) { raw1 = Channel1.read_high_us(30000); raw2 = Channel2.read_high_us(30000); raw3 = Channel3.read_high_us(30000); printf("raw1=%.0f mV\t", raw1); mod1 = map(raw1, 1450, 1000, 0, 100); // 후진 mod2 = map(raw1, 1550, 2000, 0, 100); // 전진 printf("raw2=%.0f mV\t", raw2); mod3 = map(raw2, 1450, 1000, 0, 100); // 좌회전 mod4 = map(raw2, 1550, 2000, 0, 100); // 우회전 printf("raw3=%.0f mV\t", raw3); mod5 = map(raw3, 920, 2080, 0, 100); printf("mod1=%.0f mV\t", mod1); printf("mod2=%.0f mV\t", mod2); printf("mod3=%.0f mV\t", mod3); printf("mod4=%.0f mV\t", mod4); printf("mod5=%.0f mV\t", mod5); mod1 = mod1/100; mod2 = mod2/100; mod3 = mod3/100; mod4 = mod4/100; mod5 = mod5/100; printf("measure1 = %f mV\t", mod1); printf("measure2 = %f mV\t", mod2); printf("measure3 = %f mV\n", mod3); printf("measure4 = %f mV\n", mod4); printf("measure5 = %f mV\n", mod5); if(mod3 > 2) { mod4 = 0; } if(mod4 > 2) { mod3 = 0; } float bldc_l, bldc_r; bldc_l = mod1 - mod3 + mod4; bldc_r = mod1 + mod3 - mod4; bldc_left.write(mod1); bldc_right.write(mod2); led_left.write(mod1); led_right.write(mod2); } }