Wifi Webserver to control the Speed of a motor using PID
Dependencies: 4DGL-uLCD-SE PID QEI SDFileSystem mbed
Diff: main.cpp
- Revision:
- 3:2151f4b584b5
- Parent:
- 2:f579e98b82de
- Child:
- 4:05e4ebafbcaf
--- a/main.cpp Wed Nov 25 20:49:22 2015 +0000 +++ b/main.cpp Fri Nov 27 15:29:13 2015 +0000 @@ -78,7 +78,11 @@ const float kp_init = 0.01; const float ki_init = 0.015; const float kd_init = 0.0001; -const float Ts_init = 0.04; // 25Hz Sample Freq (40ms Sample Time) +const float Ts_init = 0.04; // 25Hz Sample Freq (40ms Sample Time) +const float Ts_PID_CALLBACK = Ts_init/2.0; // Update Motors and sensers twice as + // fast as PID sample rate, ensures + // PID feedback is upto date every + // time PID calculations run PID pid(&setpoint, &feedback, &output, output_lower_limit, output_upper_limit, kp_init, ki_init, kd_init, Ts_init); @@ -171,7 +175,7 @@ // Update sensors and feedback twice as fast as PID sample time // this makes pid react in real-time avoiding errors due to // missing counts etc. - motor.attach(&pid_callback, Ts_init/2.0); + motor.attach(&pid_callback, Ts_PID_CALLBACK); // Start PID sampling pid.start();