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.
headers/pid_controller.h@3:35deb5c21b33, 2018-11-26 (annotated)
- Committer:
- rwgriffithv
- Date:
- Mon Nov 26 23:50:58 2018 +0000
- Revision:
- 3:35deb5c21b33
- Parent:
- 1:6f18bb7a77a5
pid controller updated
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| dionigi | 1:6f18bb7a77a5 | 1 | #pragma once |
| dionigi | 1:6f18bb7a77a5 | 2 | #include "globals.h" |
| dionigi | 1:6f18bb7a77a5 | 3 | |
| rwgriffithv | 3:35deb5c21b33 | 4 | const float g_KPX = 0.01; |
| rwgriffithv | 3:35deb5c21b33 | 5 | const float g_KDX = 0.03; |
| rwgriffithv | 3:35deb5c21b33 | 6 | const float g_KPW = 0.1; |
| rwgriffithv | 3:35deb5c21b33 | 7 | const float g_KDW = 0.1; |
| dionigi | 1:6f18bb7a77a5 | 8 | |
| rwgriffithv | 3:35deb5c21b33 | 9 | const float g_MAX_SPEED = 0.3; |
| rwgriffithv | 3:35deb5c21b33 | 10 | const float g_MIN_SPEED = 0.08; |
| rwgriffithv | 3:35deb5c21b33 | 11 | const float g_DONE_THRESHOLD = 100; |
| dionigi | 1:6f18bb7a77a5 | 12 | |
| dionigi | 1:6f18bb7a77a5 | 13 | class PIDController { |
| rwgriffithv | 3:35deb5c21b33 | 14 | public: |
| rwgriffithv | 3:35deb5c21b33 | 15 | PIDController(); |
| rwgriffithv | 3:35deb5c21b33 | 16 | |
| rwgriffithv | 3:35deb5c21b33 | 17 | void reset(); |
| rwgriffithv | 3:35deb5c21b33 | 18 | void update(); |
| rwgriffithv | 3:35deb5c21b33 | 19 | |
| rwgriffithv | 3:35deb5c21b33 | 20 | void set_goal_x(int counts); |
| rwgriffithv | 3:35deb5c21b33 | 21 | void set_goal_w(int counts); |
| dionigi | 1:6f18bb7a77a5 | 22 | |
| rwgriffithv | 3:35deb5c21b33 | 23 | bool is_done() const; |
| rwgriffithv | 3:35deb5c21b33 | 24 | char* get_data(); |
| rwgriffithv | 3:35deb5c21b33 | 25 | |
| rwgriffithv | 3:35deb5c21b33 | 26 | private: |
| rwgriffithv | 3:35deb5c21b33 | 27 | void get_sensor_feedback(); |
| rwgriffithv | 3:35deb5c21b33 | 28 | void x_controller(); |
| rwgriffithv | 3:35deb5c21b33 | 29 | void w_controller(); |
| rwgriffithv | 3:35deb5c21b33 | 30 | void update_motor_pwm(); |
| rwgriffithv | 3:35deb5c21b33 | 31 | float limit_pwm(float pwm) const; |
| dionigi | 1:6f18bb7a77a5 | 32 | |
| rwgriffithv | 3:35deb5c21b33 | 33 | int goal_x_; |
| rwgriffithv | 3:35deb5c21b33 | 34 | int goal_w_; |
| rwgriffithv | 3:35deb5c21b33 | 35 | |
| rwgriffithv | 3:35deb5c21b33 | 36 | float counts_x_; |
| rwgriffithv | 3:35deb5c21b33 | 37 | float counts_w_; |
| rwgriffithv | 3:35deb5c21b33 | 38 | |
| rwgriffithv | 3:35deb5c21b33 | 39 | float error_x_; |
| rwgriffithv | 3:35deb5c21b33 | 40 | float error_w_; |
| rwgriffithv | 3:35deb5c21b33 | 41 | |
| rwgriffithv | 3:35deb5c21b33 | 42 | float error_prev_x_; |
| rwgriffithv | 3:35deb5c21b33 | 43 | float error_prev_w_; |
| rwgriffithv | 3:35deb5c21b33 | 44 | |
| rwgriffithv | 3:35deb5c21b33 | 45 | float pwm_x_; |
| rwgriffithv | 3:35deb5c21b33 | 46 | float pwm_w_; |
| rwgriffithv | 3:35deb5c21b33 | 47 | |
| rwgriffithv | 3:35deb5c21b33 | 48 | int stop_cnt_; |
| rwgriffithv | 3:35deb5c21b33 | 49 | |
| rwgriffithv | 3:35deb5c21b33 | 50 | char data_buf_[200]; |
| dionigi | 1:6f18bb7a77a5 | 51 | }; |
| rwgriffithv | 3:35deb5c21b33 | 52 |
