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: headers/pid_controller.h
- Revision:
- 3:35deb5c21b33
- Parent:
- 1:6f18bb7a77a5
--- a/headers/pid_controller.h Thu Nov 15 17:22:50 2018 +0000
+++ b/headers/pid_controller.h Mon Nov 26 23:50:58 2018 +0000
@@ -1,44 +1,52 @@
#pragma once
-
#include "globals.h"
-const float KpX = 1;
-const float KdX = 0;
+const float g_KPX = 0.01;
+const float g_KDX = 0.03;
+const float g_KPW = 0.1;
+const float g_KDW = 0.1;
-const float KpW = 1;
-const float KdW = 0;
+const float g_MAX_SPEED = 0.3;
+const float g_MIN_SPEED = 0.08;
+const float g_DONE_THRESHOLD = 100;
class PIDController {
-public:
- PIDController();
-
- void reset() volatile;
- void update() volatile;
+ public:
+ PIDController();
+
+ void reset();
+ void update();
+
+ void set_goal_x(int counts);
+ void set_goal_w(int counts);
- void setXGoal(int counts);
- void setWGoal(int counts);
+ bool is_done() const;
+ char* get_data();
+
+ private:
+ void get_sensor_feedback();
+ void x_controller();
+ void w_controller();
+ void update_motor_pwm();
+ float limit_pwm(float pwm) const;
- 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 goal_x_;
+ int goal_w_;
+
+ float counts_x_;
+ float counts_w_;
+
+ float error_x_;
+ float error_w_;
+
+ float error_prev_x_;
+ float error_prev_w_;
+
+ float pwm_x_;
+ float pwm_w_;
+
+ int stop_cnt_;
+
+ char data_buf_[200];
};
+
