Michael Ernst Peter / PM2_Libary

Dependencies:   LSM9DS1 RangeFinder FastPWM

Dependents:   PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board ... more

Revision:
30:05abc1d2a2b9
Parent:
29:335fb9b01ca7
--- a/PositionController.cpp	Fri May 13 20:53:33 2022 +0000
+++ b/PositionController.cpp	Sat May 14 08:19:21 2022 +0000
@@ -24,8 +24,7 @@
     speedFilter.setFrequency(LOWPASS_FILTER_FREQUENCY);
     desiredSpeed = 0.0f;
     actualSpeed = 0.0f;
-    float initialRotation = (float)encoderCounter.read()/counts_per_turn;
-    this->initialRotation = initialRotation;
+    this->initialRotation = (float)encoderCounter.read()/counts_per_turn;
     actualRotation  = initialRotation;
     desiredRotation = initialRotation;
     
@@ -156,12 +155,13 @@
         actualSpeed = speedFilter.filter((float)countsInPastPeriod/counts_per_turn/TS*60.0f);
         actualRotation = actualRotation + actualSpeed/60.0f*TS;
 
+        // trajectory needs to be calculated in rotations*60 so that all units are in RPM
         motion.incrementToPosition(60.0f * desiredRotation, TS);       
         float desiredRotationMotion = motion.getPosition();
         float desiredVelocityMotion = motion.getVelocity();
 
         // calculate motor phase voltages
-        desiredSpeed  = p *(desiredRotationMotion - 60.0f * actualRotation) + 0.0f * desiredVelocityMotion;
+        desiredSpeed  = p *(desiredRotationMotion - 60.0f * actualRotation) + 0.0f * desiredVelocityMotion; // using velocity feedforward here will lead to overshoot
         
         if (desiredSpeed < -max_speed) desiredSpeed = -max_speed;
         else if (desiredSpeed > max_speed) desiredSpeed = max_speed;