Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FastPWM HIDScope MODSERIAL QEI Matrix biquadFilter controller errorFetch mbed motorConfig refGen MatrixMath inverseKinematics
Fork of Minor_test_serial by
Revision 23:917179f72762, committed 2017-10-06
- Comitter:
- tvlogman
- Date:
- Fri Oct 06 12:03:26 2017 +0000
- Parent:
- 22:2e473e9798c0
- Child:
- 24:672abc3f02b7
- Commit message:
- Fixed the I-action bit: now I action is based on the position error multiplied by Ts added to the previous I error instead of the Ts multiplied by total I error.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 06 10:43:24 2017 +0000
+++ b/main.cpp Fri Oct 06 12:03:26 2017 +0000
@@ -43,7 +43,7 @@
// MOTOR CONTROL PART
bool m1_direction = false;
-int posRevRange = 5; // describes the ends of the position range in complete motor output shaft revolutions in both directions
+int posRevRange = 2; // describes the ends of the position range in complete motor output shaft revolutions in both directions
const float maxAngle = 2*3.14*posRevRange; // max angle in radians
const float Ts = 0.1;
@@ -73,7 +73,7 @@
pc.printf("%0.2f revolutions \r\n", motor1Position);
posError = getReferencePosition() - motor1Position;
- integralError = integralError + Ts*totalError;
+ integralError = integralError + Ts*posError;
totalError = posError + integralError;
pc.printf("Error is %0.2f \r \n", totalError);
}
@@ -81,7 +81,7 @@
// motorController sets a motorValue based on the position error. Sign indicates direction and magnitude indicates speed. Right now this is a simple feedforward
float motorController(float posError, float integralError){
float k_p = 5*pot2.read(); // use potmeter 2 to adjust k_p within range 0 to 1
- float k_i = 0.0000000001;
+ float k_i = 0.001; // How do I pick a reasonable value for k_i?
double motorValue = (posError*k_p)/maxAngle + 0.35 + k_i*integralError; // motorValue is the normalized voltage applied to motor magnitude pin between -1 and 1 added 0.35 as motorvalue of 0.35 does nothing
return motorValue;
}
