Generates a PID controller with parameters K_p, K_d and K_i

Dependents:   locomotion_pid_action_refactor_EMG

Files at this revision

API Documentation at this revision

Comitter:
tvlogman
Date:
Mon Oct 16 09:41:19 2017 +0000
Commit message:
Working controller library

Changed in this revision

controller.cpp Show annotated file Show diff for this revision Revisions of this file
controller.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 229271adbb37 controller.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controller.cpp	Mon Oct 16 09:41:19 2017 +0000
@@ -0,0 +1,15 @@
+#include "controller.h"
+#include "mbed.h"
+
+// Member function definitions
+controller::controller(float k_p, float k_d, float k_i):k_p(k_p), k_d(k_d), k_i(k_i){
+
+    }
+
+float controller::control(float e_pos, float e_der, float e_int){
+    float motorValue;
+    motorValue = k_p*e_pos + k_d*e_der + k_i*e_int;
+    return motorValue;
+    }
+    
+    
\ No newline at end of file
diff -r 000000000000 -r 229271adbb37 controller.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controller.h	Mon Oct 16 09:41:19 2017 +0000
@@ -0,0 +1,16 @@
+#ifndef CONTROLLER_H
+#define CONTROLLER_H
+
+#include "mbed.h"
+
+class controller {
+public:
+    controller(float k_p, float k_d, float k_i);
+    float control(float e_pos, float e_der, float e_int);
+    
+private:
+    float k_p;
+    float k_d;
+    float k_i;
+    };
+#endif
\ No newline at end of file