PD Control for KL05Z

Dependencies:   QEI mbed

Revision:
2:f84a70291ac8
Parent:
1:8ff6c7474d95
Child:
3:f169c357a44d
--- 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) {