-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpid_controller.h
57 lines (42 loc) · 1.33 KB
/
pid_controller.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
enum robot_direction_t {
ROBOT_STOP,
ROBOT_FORWARD,
ROBOT_BACKWARD,
ROBOT_LEFT,
ROBOT_RIGHT
};
static robot_direction_t robot_direction = ROBOT_STOP;
enum motor_direction_t {
DIR_FORWARD,
DIR_BACKWARD
};
static motor_direction_t _left_direction = DIR_FORWARD;
static motor_direction_t _right_direction = DIR_FORWARD;
class PIDController {
private:
PIDController();
double _kp = 5, _ki = 0.055, _kd = 0.02;
double _input_left = 0, _output_left = 0, _setpoint_left = 0;
double _input_right = 0, _output_right = 0, _setpoint_right = 0;
int _left_gain = 0, _right_gain = 0;
long _temp_left = 0, _temp_right = 0;
double _scale = 2e-3;
void controller_left(void);
void controller_right(void);
public:
PIDController(PIDController const &) = delete;
PIDController operator= (PIDController const &) = delete;
static PIDController &get() {
static PIDController _context;
return _context;
}
int ticks_to_mm(int tick) { return (int) (tick * 1.175); }
void setup(void);
void run(void);
void stop(void);
double get_output_left(void) { return _output_left; }
double get_output_right(void) { return _output_right; }
void get_gains(int *left, int *right) { *left = _left_gain; *right = _right_gain; }
void set_gains(int left, int right) { _left_gain = left; _right_gain = right; }
};