1.0

Dependencies:   PM2_Libary

Files at this revision

API Documentation at this revision

Comitter:
morfdan
Date:
Mon Apr 12 08:47:18 2021 +0000
Parent:
10:c5d85e35758c
Commit message:
1.0

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c5d85e35758c -r b728d9fbe3e0 main.cpp
--- a/main.cpp	Wed Apr 07 12:13:50 2021 +0000
+++ b/main.cpp	Mon Apr 12 08:47:18 2021 +0000
@@ -45,10 +45,11 @@
 /* create servo objects */
 Servo servo_S1(PB_2);
 Servo servo_S2(PC_8);
-// Servo servo_S3(PC_6); // not needed in this example
+Servo servo_S3(PC_6); // not needed in this example
 int servoPeriod_mus = 20000;
 int servoOutput_mus_S1 = 0;
 int servoOutput_mus_S2 = 0;
+int servoOutput_mus_S3 = 0;
 int servo_counter = 0;
 int loops_per_second = static_cast<int>(ceilf(1.0f/(0.001f*(float)Ts_ms)));
 
@@ -81,7 +82,7 @@
             dist = analogIn.read() * 3.3f;
 
             /* command a speed to dc motors M1 and M2*/
-            speedController_M1.setDesiredSpeedRPS( 1.0f);
+            speedController_M1.setDesiredSpeedRPS( 1.0f, 100);
             speedController_M2.setDesiredSpeedRPS(-0.5f);
             /* write output voltage to motor M3 */
             pwmOut_M3.write(0.75);
@@ -89,12 +90,16 @@
             /* command servo position via output time, this needs to be calibrated */
             servo_S1.SetPosition(servoOutput_mus_S1);
             servo_S2.SetPosition(servoOutput_mus_S2);
+            servo_S3.SetPosition(servoOutput_mus_S3);
             if (servoOutput_mus_S1 <= servoPeriod_mus & servo_counter%loops_per_second == 0 & servo_counter != 0) {
                 servoOutput_mus_S1 += 100;
             }
             if (servoOutput_mus_S2 <= servoPeriod_mus & servo_counter%loops_per_second == 0 & servo_counter != 0) {
                 servoOutput_mus_S2 += 100;
             }
+            if (servoOutput_mus_S3 <= servoPeriod_mus & servo_counter%loops_per_second == 0 & servo_counter != 0) {
+            servoOutput_mus_S3 += 100;
+            }
             servo_counter++;
 
             /* visual feedback that the main task is executed */
@@ -110,17 +115,19 @@
 
             servoOutput_mus_S1 = 0;
             servoOutput_mus_S2 = 0;
+            servoOutput_mus_S3 = 0;
             servo_S1.SetPosition(servoOutput_mus_S1);
             servo_S2.SetPosition(servoOutput_mus_S2);
-
+            servo_S2.SetPosition(servoOutput_mus_S3);
             led = 0;
         }
 
         /* do only output via serial what's really necessary (this makes your code slow)*/
-        printf("%3.3f, %3d, %3d, %3d, %3.3f, %3.3f;\r\n",
+        printf("%3.3f, %3d, %3d, %3d, %3.3d, %3.3f, %3.3f;\r\n",
                dist,
                servoOutput_mus_S1,
                servoOutput_mus_S2,
+               servoOutput_mus_S3,
                encoderCounter_M3.read(),
                speedController_M1.getSpeedRPS(),
                speedController_M2.getSpeedRPS());