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.
Diff: pid_controller.h
- Revision:
- 0:7a97ebb833eb
diff -r 000000000000 -r 7a97ebb833eb pid_controller.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pid_controller.h Sun May 05 00:02:11 2019 +0000
@@ -0,0 +1,54 @@
+#pragma once
+
+#include "globals.h"
+
+const float KpX = 0.01;
+const float KdX = 0.1;
+
+const float KpW = 0.003;
+const float KdW = 0;
+
+// for turning KpW=0.01, KdW=0.1
+
+const float min_speed = 0.08;
+const float max_speed = 0.16;
+
+const int done_limit = 150;
+
+class PIDController {
+public:
+ PIDController();
+
+ void reset() volatile;
+ void update() volatile;
+
+ void setXGoal(int counts);
+ void setWGoal(int counts);
+
+ bool isDone() volatile;
+ char* getData();
+private:
+ void getSensorFeedback() volatile;
+ void x_controller() volatile;
+ void w_controller() volatile;
+ void updateMotorPwm() volatile;
+
+ int m_goalW;
+ int m_goalX;
+
+ float m_pwmW;
+ float m_pwmX;
+
+ int m_errorW;
+ int m_errorX;
+ int m_errorW_old;
+ int m_errorX_old;
+
+ int m_countsW;
+ int m_countsX;
+
+ char buf[200];
+
+ int m_doneCounter;
+};
+