PID motor controll for the biorobotics project.

Dependencies:   FastPWM QEI

Dependents:   PID_example Motor_calibration Demo_mode Demo_mode ... more

Revision:
4:5353c5d0d2ed
Parent:
2:b30a467e90d3
Child:
5:5537072b0e2e
diff -r f1067b5bb5af -r 5353c5d0d2ed motor.cpp
--- a/motor.cpp	Mon Oct 29 15:27:56 2018 +0000
+++ b/motor.cpp	Wed Oct 31 06:13:15 2018 +0000
@@ -38,7 +38,19 @@
 void Motor::start(float period) {
     pid_period = period;
     pid.set_period(period);
-    motor_ticker.attach(this, &Motor::update, period);
+    motor_ticker.attach(callback(this, &Motor::update), period);
+}
+
+void Motor::stop() {
+    motor_ticker.detach();
+    target_angle = 0;
+    // Stop the actual motor.
+    pwm_out = 0.0;
+    dir_out = 0;
+    
+    pid.clear_state();
+    
+    printcount = 0;
 }
 
 void Motor::set_pid_k_values(double k_p, double k_i, double k_d) {