convert_KeilToMbed
Dependencies: DigitDisplay Motor PID mbed millis
Fork of DagonFly__RoadToJapan_15Mei_Ultimate by
Diff: main.cpp
- Revision:
- 41:336a19289c2d
- Parent:
- 40:5b937cac959a
- Child:
- 42:6caf8bd5abbc
--- a/main.cpp Sat Feb 18 03:24:05 2017 +0000 +++ b/main.cpp Sat Feb 18 11:33:00 2017 +0000 @@ -61,10 +61,10 @@ double last_error = 0, current_error, sum_error = 0; double last_error2 = 0, current_error2, sum_error2 = 0; float rpm, rpm2; -float target_rpm = 13.0, target_rpm2 = 15.0; -const float maxRPM = 27, minRPM = 0; // Limit 25 atau 27 +float target_rpm = 15.0, target_rpm2 = 17.0; +const float maxRPM = 28, minRPM = 0; // Limit 25 atau 27 -const float pwmPowerUp = 0.7; +const float pwmPowerUp = 0.8; const float pwmPowerDown = -0.9; float jarak_ping=0; @@ -241,13 +241,13 @@ if (target_rpm>maxRPM-2){ target_rpm = maxRPM-2; } - if (target_rpm<minRPM){ + if (target_rpm<minRPM+8){ target_rpm = minRPM; } if (target_rpm2>maxRPM){ target_rpm2 = maxRPM; } - if (target_rpm2<minRPM+2){ + if (target_rpm2<minRPM+2+8){ target_rpm2 = minRPM+2; } } @@ -381,11 +381,11 @@ else if(!limitTengah){ isReload = true; } - else if(jarak_ping > 4){ + else if((jarak_ping > 4) && !flag_Pneu){ powerScrew.speed(pwmPowerUp); } - else if(jarak_ping < 3) { - powerScrew.speed(pwmPowerDown); + else if((jarak_ping < 3.5 ) && !flag_Pneu) { + powerScrew.speed(-0.1); } else{ powerScrew.brake(1); @@ -472,7 +472,10 @@ wait_ms(1000); // initializing encoder + pneumatik =1; + setCenter(); + wait_ms(500); //initializing PING @@ -483,8 +486,8 @@ while(1) { // interupsi pembacaan PING setiap 30 ms - if(millis() - previousMillis4 >= 30){ - jarak_ping = pingAtas.Read_cm()/2; + if(millis() - previousMillis4 >= 5){ //30 + jarak_ping = (float)pingAtas.Read_cm()/2; pingAtas.Send(); previousMillis4 = millis(); @@ -503,7 +506,7 @@ aktuator(); launcher(); reloader(); - if ((millis()-previousMillis3 >= 425)&&(flag_Pneu)){ + if ((millis()-previousMillis3 >= 370)&&(flag_Pneu)){ pneumatik = 1; flag_Pneu = false; }