PM2_PES_board

Dependencies:   PM2_Libary

Revision:
9:f10b974d01e0
Parent:
8:9bb806a7f585
Child:
10:c5d85e35758c
--- a/main.cpp	Tue Apr 06 12:48:09 2021 +0200
+++ b/main.cpp	Tue Apr 06 12:19:34 2021 +0000
@@ -5,6 +5,7 @@
 #include "EncoderCounter.h"
 #include "Servo.h"
 #include "SpeedController.h"
+#include "FastPWM.h"
 // #include "FATFileSystem.h"
 // #include "SDBlockDevice.h"
 
@@ -26,10 +27,10 @@
 float    dist = 0.0f;
 
 /* create pwm objects */
-PwmOut pwmOut_m0(PB_13);
-PwmOut pwmOut_m1(PA_9);
-PwmOut pwmOut_m2(PA_10);
-float  Ts_pwm = 0.00005f;
+FastPWM pwmOut_m0(PB_13);
+FastPWM pwmOut_m1(PA_9);
+FastPWM pwmOut_m2(PA_10);
+double  Ts_pwm_s = 0.00005; // this needs to be a double value
 /* create enable dc motor digital out object */
 DigitalOut enable_motors(PB_15);
 /* create encoder read objects */
@@ -55,26 +56,22 @@
 // FATFileSystem fs("fs", &sd);
 
 int main()
-{   
+{
     user_button.fall(&button_fall);
     user_button.rise(&button_rise);
     loop_timer.start();
 
     /* initialize pwm */
-    pwmOut_m0.period(Ts_pwm);
-    pwmOut_m1.period(Ts_pwm);
-    pwmOut_m2.period(Ts_pwm);
+    pwmOut_m2.period(Ts_pwm_s);
     /* set pwm output zero at the beginning, range: 0...1 -> u_min...u_max */
-    pwmOut_m1.write(0.5f);
-    pwmOut_m0.write(0.5f);
-    pwmOut_m2.write(0.5f);
+    pwmOut_m2.write(0.5);
     /* enable driver DC motors */
     enable_motors = 1;
 
     /* initialize servo */
     servo_0.Enable(servoPeriod_mus_0, servoHolePeriod_mus); // 1 ms / 20 ms
     servo_1.Enable(servoPeriod_mus_0, servoHolePeriod_mus);
-    
+
     /*
     // example code for sd card, not tested from pmic, 02.04.2021
     printf("Test writing... ");
@@ -109,9 +106,9 @@
             /* read analog input */
             dist = analogIn.read() * 3.3f;
 
-            speedController_m0.setDesiredSpeedRPS( 0.5f);
-            speedController_m1.setDesiredSpeedRPS( 0.5f);
-            pwmOut_m2.write(0.75f);
+            speedController_m0.setDesiredSpeedRPS( 1.0f);
+            speedController_m1.setDesiredSpeedRPS(-0.5f);
+            pwmOut_m2.write(0.75);
 
             servo_0.SetPosition(servoPeriod_mus_0);
             servo_1.SetPosition(servoPeriod_mus_1);
@@ -125,14 +122,14 @@
 
             /* visual feedback that the main task is executed */
             led = !led;
-            
+
         } else {
 
             dist = 0.0f;
 
-            speedController_m0.setDesiredSpeedRPS(0.2f);
-            speedController_m1.setDesiredSpeedRPS(0.2f);
-            pwmOut_m2.write(0.5f);
+            speedController_m0.setDesiredSpeedRPS(0.0f);
+            speedController_m1.setDesiredSpeedRPS(0.0f);
+            pwmOut_m2.write(0.5);
 
             servoPeriod_mus_0 = 0;
             servoPeriod_mus_1 = 0;
@@ -146,9 +143,9 @@
 
         /* do only output what's really necessary*/
         printf("%3.3e, %3.3e, %3d, %3d; \r\n", speedController_m0.getSpeedRPS(),
-                                               speedController_m1.getSpeedRPS(),
-                                               servoPeriod_mus_0,
-                                               servoPeriod_mus_1);
+               speedController_m1.getSpeedRPS(),
+               servoPeriod_mus_0,
+               servoPeriod_mus_1);
 
         /* ------------- stop hacking ------------- -------------*/