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 24:672abc3f02b7, committed 2017-10-06
- Comitter:
- tvlogman
- Date:
- Fri Oct 06 12:34:54 2017 +0000
- Parent:
- 23:917179f72762
- Child:
- 25:df780572cfc8
- Commit message:
- First iteration - work in progress (doesn't work yet)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Oct 06 12:03:26 2017 +0000
+++ b/main.cpp Fri Oct 06 12:34:54 2017 +0000
@@ -43,7 +43,7 @@
// MOTOR CONTROL PART
bool m1_direction = false;
-int posRevRange = 2; // describes the ends of the position range in complete motor output shaft revolutions in both directions
+int posRevRange = 5; // 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;
@@ -64,16 +64,18 @@
// Initializing position and integral errors
float posError = 0;
float integralError = 0;
-float totalError = posError + integralError;
+float derivativeError = 0;
+float e_prev = 0;
+float totalError = posError + integralError + derivativeError;
// readEncoder reads counts and revs and logs results to serial window
-void getError(float &posError, float &integralError){
+void getError(float &posError, float &integralError, float &derivativeError){
counts = Encoder.getPulses();
double motor1Position = 2*3.14*(counts/(131*64.0f));
pc.printf("%0.2f revolutions \r\n", motor1Position);
posError = getReferencePosition() - motor1Position;
-
integralError = integralError + Ts*posError;
+ derivativeError = derivativeError - e_prev;
totalError = posError + integralError;
pc.printf("Error is %0.2f \r \n", totalError);
}
