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: Encoder HIDScope MODSERIAL TouchButton mbed-dsp mbed
Fork of Robot2mooiemanier by
Revision 7:b40bbf5be443, committed 2014-10-30
- Comitter:
- Tanja2211
- Date:
- Thu Oct 30 15:16:04 2014 +0000
- Parent:
- 6:34da048d7168
- Child:
- 8:7bf274156e1f
- Commit message:
- pid functie bool toegevoegd
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Oct 30 14:50:35 2014 +0000
+++ b/main.cpp Thu Oct 30 15:16:04 2014 +0000
@@ -23,7 +23,7 @@
void Biceps();
void Calibratie_Triceps();
void Calibratie_Biceps();
-float pid(float setspeed, float measurement);
+float pid(float setspeed, float measurement, bool reset = false);
void motor2aansturing();
void motor1aansturing();
@@ -389,19 +389,24 @@
myled1=1;
myled2=1;
myled3=1;
- }
+ }
}
}
}//end int main
-float pid(float setspeed, float measurement)
+float pid(float setspeed, float measurement, bool reset)
{
float error;
static float prev_error = 0;
float out_p = 0;
static float out_i = 0;
float out_d = 0;
+ if(reset)
+ {
+ out_i = 0;
+ prev_error = 0;
+ }
error = setspeed-measurement;
out_p = error*K_P;
out_i += error*K_I;
@@ -612,7 +617,8 @@
{
if (motor1.getPosition()>= ANGLEMIN && toestand != SLAAN) {
- toestand = WACHTEN;
+ toestand = WACHTEN;
+ //out_i=0;
pc.printf("if1\n");
}
if (snelheidsstand != 0 && toestand == WACHTEN && stop == 0) { // stop = 0 in het begin let op dat dit na reset nog zo is
@@ -630,13 +636,14 @@
}
if (toestand == SLAAN && motor1.getPosition() <= ANGLEMAX) {
pc.printf("toestand = terugkeren\n\r");
+ //out_i=0;
toestand = TERUGKEREN;
stop = 1; //zorgt dat hij niet weer gaat slaan tot er gereset is...
}
if (toestand == TERUGKEREN) {
pc.printf("motor gaat terugkeren\n\r");
- //pid(Vreturn, motor1.getSpeed());
- new_pwm=Vreturn;
+ new_pwm=pid(setspeed, motor1.getSpeed());
+
pwm_motor1.write(new_pwm);
pc.printf("new pwm %f\r\n",new_pwm);
motordir1 = 0;
@@ -646,7 +653,7 @@
pc.printf("ifwachten\n");
}
if (toestand == SLAAN) {
- new_pwm =setspeed; //pid(setspeed, motor1.getSpeed());
+ pid(setspeed, motor1.getSpeed());
motordir1 = 1;
pwm_motor1.write(new_pwm);
pc.printf("SLAAN\n");
