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: 4DGL-uLCD-SE PID QEI SDFileSystem mbed
Revision 2:07a3107e7664, committed 2015-11-27
- Comitter:
- electromotivated
- Date:
- Fri Nov 27 15:30:50 2015 +0000
- Parent:
- 1:d69f57dcde02
- Child:
- 3:7fb9c4c7e24b
- Commit message:
- Banishing of a magic number
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Nov 26 17:31:59 2015 +0000
+++ b/main.cpp Fri Nov 27 15:30:50 2015 +0000
@@ -53,8 +53,12 @@
// this is encoder specific.
enum CONTROL_MODE{POSITION = 0, SPEED = 1};
bool control_mode = POSITION;
-float kp, ki, kd; // Gain variables for working
+float kp, ki, kd; // Gain variables for working
const float Ts = 0.04; // 25Hz Sample Freq (40ms Sample Time)
+const float Ts_PID_CALLBACK = Ts/2.0; // Update Motors and sensers twice as
+ // fast as PID sample rate, ensures
+ // PID feedback is upto date every
+ // time PID calculations run
// Vars to store gains for Speed and Position when switching Control modes
const float kp_init = 2.5; // Good Kp for Position Control
@@ -169,7 +173,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/2.0);
+ motor.attach(&pid_callback, Ts_PID_CALLBACK);
// Start PID sampling
pid.start();