Dependencies:   mbed Servo Pulse1

Files at this revision

API Documentation at this revision

Comitter:
kyucheol
Date:
Fri Dec 27 09:16:54 2019 +0000
Parent:
3:c47e538f3aec
Commit message:
Can use if you want BLDC motor without Backward

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c47e538f3aec -r c9fda60b0332 main.cpp
--- a/main.cpp	Sat Dec 21 08:52:52 2019 +0000
+++ b/main.cpp	Fri Dec 27 09:16:54 2019 +0000
@@ -3,12 +3,14 @@
 #include "Map.h"
 #include "Pulse1.h"
 
+// 후진 불가능한 BLDC 사용 
+
 
 PwmOut led_left(LED1); //확인용 LED1
 PwmOut led_right(LED2); //확인용 LED2
 
-Servo bldc_left(D12); // 왼쪽 BLDC
-Servo bldc_right(PC_7); // 오른쪽 BLDC
+Servo bldc_left(PB_8); // 왼쪽 BLDC D12
+Servo bldc_right(PB_9); // 오른쪽 BLDC PC_7
 
 PulseInOut Channel1(A0); //채널1, futaba기준 좌우방향(오른쪽 조이스틱)
 PulseInOut Channel2(A1); //채널2, futaba기준 상하방향(오른쪽 조이스틱)
@@ -18,20 +20,19 @@
     bldc_left.write(0); // BLDC 초기 설정
     bldc_right.write(0);
     
-    led_left = 1;
-    led_right=1;
-    
+    led_left = 1; // 확인을 위한 LED
+    led_right=1; // 확인을 위한 LED
     wait(0.5);
     
     bldc_left.write(1);
     bldc_right.write(1);
     
-    led_left =0;
-    led_right=0;
+    led_left =0; // 확인을 위한 LED
+    led_right=0; // 확인을 위한 LED
     wait(2);
     
-    bldc_left.write(0);
-    bldc_right.write(0);
+    bldc_left.write(0); // BLDC 초기 설정
+    bldc_right.write(0); // BLDC 초기 설정
     wait(2);
     
     float raw1,raw2,raw3;
@@ -46,20 +47,19 @@
         raw3 = Channel3.read_high_us(30000);
         
         
-        printf("raw1=%.0f mV\t", raw1);
-        mod1 =  map(raw1, 1450, 1000, 0, 60); // 후진 //PWM 150을 변환
-        mod2 =  map(raw1, 1550, 2000, 0, 60); // 전진 //PWM 150을 변환
+        //printf("raw1=%.0f mV\t", raw1);
+        mod1 =  map(raw2, 1450, 1000, 0, 60); // 후진 //PWM 150을 변환
+        mod2 =  map(raw2, 1550, 2000, 0, 90); // 전진 //PWM 150을 변환
         
         
         
-        printf("raw2=%.0f mV\t", raw2);
-        mod3 =  map(raw2, 1450, 1000, 0, 60); // 좌회전 //PWM 150을 변환
-        mod4 =  map(raw2, 1550, 2000, 0, 60); // 우회전 //PWM 150을 변환
+        //printf("raw2=%.0f mV\t", raw2);
+        mod3 =  map(raw1, 1450, 1000, 0, 60); // 좌회전 //PWM 150을 변환
+        mod4 =  map(raw1, 1550, 2000, 0, 60); // 우회전 //PWM 150을 변환
         
-        printf("raw3=%.0f mV\t", raw3);
+        //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);
@@ -74,35 +74,35 @@
         
         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("measure3 = %f mV\t", mod3);
+        printf("measure4 = %f mV\t", mod4);
         printf("measure5 = %f mV\n", mod5);
         
         
-        if(mod3 > 0.02) { // 2
+        if(mod3 > 0.01) { // 2
             mod4 = 0;
             }
             
-        if(mod4 > 0.02) { // 2
+        if(mod4 > 0.01) { // 2
             mod3 = 0;
             }
             
         
         float bldc_l, bldc_r; // bldc 왼쪽 오른쪽 선언
-        bldc_l = mod1 - mod3 + mod4;
-        bldc_r = mod1 + mod3 - mod4;
+        bldc_l = mod2 - mod3 + mod4;
+        bldc_r = mod2 + mod3 - mod4;
         
         if(bldc_l >= 0.6) { // PWM 150을 변환
             bldc_l = 0.6;
             }
-        if(bldc_l <= 0.08) { // PWM 20을 변환
+        if(bldc_l <= 0.03) { // PWM 20을 변환
             bldc_l = 0;
             }
             
         if(bldc_r >= 0.6) { // PWM 150을 변환
             bldc_r = 0.6;
             }
-        if(bldc_r <= 0.08) { // PWM 20을 변환
+        if(bldc_r <= 0.03) { // PWM 20을 변환
             bldc_r = 0;
             }