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.
Revision 2:f84a70291ac8, committed 2013-09-02
- Comitter:
- benkatz
- Date:
- Mon Sep 02 13:22:34 2013 +0000
- Parent:
- 1:8ff6c7474d95
- Child:
- 3:f169c357a44d
- Commit message:
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Sep 01 19:50:00 2013 +0000
+++ b/main.cpp Mon Sep 02 13:22:34 2013 +0000
@@ -28,26 +28,24 @@
}
-void updateCommand(float desired_position, float KP, float KD){
+void updateCommand(void){
position = pulsesToRadians(encoder.getPulses()); //use the getPulses functin to read encoder position, convert value to radians
old_error = error;
- error = position - desired_position;
- command = KP*error + KD*sample_period*(error-old_error); //modify the command based on position feedback
+ error = position - goal_position;
+ command = p_gain*error + d_gain*sample_period*(error-old_error); //modify the command based on position feedback
}
-void update(void){ //The function attached to the ticker can't take inputs
- updateCommand(goal_position, p_gain, d_gain);
-}
+
int main() {
- SampleFrequency.attach(&update, sample_period); //Encoder will be sampled at 2.5 kHz
+ SampleFrequency.attach(&updateCommand, sample_period); //Encoder will be sampled at 2.5 kHz
while(1) {