PID Motor Position Control using ESP8266 WiFi Module, US Digital E4P-100-079, LMD18200 H-Bridge Break Out, and HN-GH12-1634T 30:1 200RPM Motor
Dependencies: 4DGL-uLCD-SE PID QEI SDFileSystem mbed ESP8266_pid_mtrPos_webserver_SDcard_v2
Dependents: ESP8266_pid_mtrPos_webserver_SDcard_v2
Diff: main.cpp
- Revision:
- 9:ea167d8bdb4c
- Parent:
- 8:e92a874cde49
- Child:
- 10:10e747c23f6f
--- a/main.cpp Wed Nov 25 20:51:57 2015 +0000 +++ b/main.cpp Fri Nov 27 15:26:42 2015 +0000 @@ -78,7 +78,11 @@ const float kp_init = 2.5; const float ki_init = 5.0; const float kd_init = 0.25; -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();