Update 18 Februari 2017, PID laucnher dan Base sudah diperbarui

Dependencies:   Motor PID Joystick_OrdoV5 mbed millis

Fork of MainProgram_BaseBaru_otomatis-reloader by KRAI 2017

Revision:
37:67d54563af90
Parent:
36:5963c9a49485
Child:
38:3ef6754bd8d8
diff -r 5963c9a49485 -r 67d54563af90 main.cpp
--- a/main.cpp	Tue Feb 14 16:20:35 2017 +0000
+++ b/main.cpp	Tue Feb 14 17:11:20 2017 +0000
@@ -62,6 +62,7 @@
 double last_error2 = 0, current_error2, sum_error2 = 0;
 float rpm, target_rpm = 8.0;
 float rpm2, target_rpm2 = 10.0;
+float maxRPM = 40, minRPM = 0;
 float pwmPowerUp        = 0.75;
 float pwmPowerDown      = -0.80;
 bool henti=false, hentis=false; 
@@ -115,8 +116,8 @@
 encoderKRAI encoderBase(PC_4, PB_15, 2000, encoderKRAI::X2_ENCODING);   //inA, inB, pin Indeks (NC = tak ada), 2xresolusi, mode pembacaan
 
 /* Deklarasi Encoder Launcher */
-encoderKRAI encLauncherBlk( PC_10, PC_11, 28, encoderKRAI::X2_ENCODING);
-encoderKRAI encLauncherDpn( PD_2, PC_12, 28, encoderKRAI::X2_ENCODING);
+encoderKRAI encLauncherBlk( PC_10, PC_11, 28, encoderKRAI::X4_ENCODING);
+encoderKRAI encLauncherDpn( PD_2, PC_12, 28, encoderKRAI::X4_ENCODING);
 
 /* Deklarasi Motor Base */
 Motor motorDpn(PB_9, PA_12, PC_5);    // pwm, fwd, rev
@@ -173,7 +174,7 @@
         // Motor Launcher
         caseJoystick = 5;
     }
-    else if (joystick.R2_click && (target_rpm2 < 20)){
+    else if (joystick.R2_click && (target_rpm2 < 40)){
         // Target Pulse PID ++ Motor Depan
          caseJoystick = 6;
     }  
@@ -181,7 +182,7 @@
         // Target Pulse PID -- Motor Depan
          caseJoystick = 7;
     }
-    else if (joystick.R3_click && (target_rpm < 20  )){
+    else if (joystick.R3_click && (target_rpm < 40 )){
         // Target Pulse PID ++ Motor Belakang
          caseJoystick = 8;
     }
@@ -247,6 +248,21 @@
     encoderBase.reset();
 }
 
+void init_rpm (){
+    if (target_rpm>maxRPM){
+        target_rpm = maxRPM;
+    }
+    if (target_rpm<minRPM){
+        target_rpm = minRPM;
+    }
+    if (target_rpm2>maxRPM){
+        target_rpm2 = maxRPM;
+    }
+    if (target_rpm2<minRPM){
+        target_rpm2 = minRPM;
+    }
+}
+
 void aktuator()
 {
     switch (case_joy) {
@@ -296,24 +312,28 @@
         {
             // Target Pulse PID ++ Motor Depan
             target_rpm2 = target_rpm2++;
+            init_rpm();
             break;
         }
         case (7) : 
         {
             // Target Pulse PID -- Motor Depan
             target_rpm2 = target_rpm2--;
+            init_rpm();
             break;
         }
         case (8) : 
         {
             // Target Pulse PID ++ Motor Belakang=
             target_rpm = target_rpm++;
+            init_rpm();
             break;
         }
         case (9) : 
         {
             // Target Pulse PID -- Motor Belakang
             target_rpm = target_rpm--;
+            init_rpm();
             break;
         }
         case (10) :