Projekt

Dependencies:   PM2_Libary

Revision:
37:3c427322799d
Parent:
36:f678d693969f
Child:
38:ba15402d9c94
diff -r f678d693969f -r 3c427322799d main.cpp
--- a/main.cpp	Wed Apr 06 11:05:29 2022 +0200
+++ b/main.cpp	Wed Apr 06 11:34:41 2022 +0200
@@ -28,7 +28,7 @@
 float kp = 0.1f;                            // define custom kp, this is the default speed controller gain for gear box 78.125:1
 
 // SpeedController speedController_M2(counts_per_turn, kn, max_voltage, pwm_M2, encoder_M2); // default 78.125:1 gear box  with default contoller parameters
-SpeedController speedController_M2(counts_per_turn * k_gear, kn / k_gear, max_voltage, pwm_M1, encoder_M1); // parameters adjusted to 100:1 gear
+SpeedController speedController_M1(counts_per_turn * k_gear, kn / k_gear, max_voltage, pwm_M1, encoder_M1); // parameters adjusted to 100:1 gear
 float max_speed_rps = 0.5f;                 // define maximum speed that the position controller is changig the speed, has to be smaller or equal to kn * max_voltage
 
 
@@ -37,10 +37,10 @@
 
     int counter_user_button = 0;
     bool counter_stopp = 0;
-    enable_motors = 0;
+    enable_motors = 1;
 
     while(1){
-        printf( "counter %d    stopp %d    button %d \n",counter_user_button, counter_stopp, !user_button.read());
+        
         if ((user_button.read() == 0) & (counter_stopp == 0)) {
             counter_user_button++;
             counter_stopp = 1;
@@ -52,17 +52,19 @@
         if (counter_user_button >= 3){
             counter_user_button = 1;
         }
-
-    
-        }
+        float speed_counter;
         switch (counter_user_button){
             case 1:
-            enable_motors = 1;
+            speed_counter = 0.5f;
             break;
             case 2:
-            enable_motors = 0;
+            speed_counter = 0.0f;
             break; 
         }
+    speedController_M1.setDesiredSpeedRPS(speed_counter);
+    printf( "counter %d    stopp %d    button %d \n",counter_user_button, counter_stopp, !user_button.read());
+    }
+        
 }