PM2 Library

Dependencies:   PM2_Libary

Files at this revision

API Documentation at this revision

Comitter:
jashaalm
Date:
Mon Apr 12 08:47:13 2021 +0000
Parent:
10:c5d85e35758c
Commit message:
first commit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Apr 07 12:13:50 2021 +0000
+++ b/main.cpp	Mon Apr 12 08:47:13 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)));
 
@@ -68,6 +69,7 @@
     /* enable servos, you can also disable them */
     servo_S1.Enable(servoOutput_mus_S1, servoPeriod_mus);
     servo_S2.Enable(servoOutput_mus_S2, servoPeriod_mus);
+    servo_S3.Enable(servoOutput_mus_S3, servoPeriod_mus);
 
     while (true) {
 
@@ -81,7 +83,7 @@
             dist = analogIn.read() * 3.3f;
 
             /* command a speed to dc motors M1 and M2*/
-            speedController_M1.setDesiredSpeedRPS( 1.0f);
+            speedController_M1.setDesiredSpeedRPS( 2.0f);
             speedController_M2.setDesiredSpeedRPS(-0.5f);
             /* write output voltage to motor M3 */
             pwmOut_M3.write(0.75);
@@ -89,12 +91,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 +116,20 @@
 
             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_S3.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, %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());