-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
26 lines (20 loc) · 775 Bytes
/
controller.py
File metadata and controls
26 lines (20 loc) · 775 Bytes
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
class PIDController:
def __init__(self, Kp, Ki, Kd, start_error, start_time):
self.curr_error = start_error
self.curr_time = start_time
self.Kp = Kp
self.Ki = Ki
self.Kd = Kd
self.sensitivity = 5
def get_controller_output(self, new_time, new_error):
time_diff = new_time - self.curr_time
error_integral_estimate = (new_error + self.curr_error) * time_diff / 2.0
error_derivative_estimate = (new_error - self.curr_error) / time_diff
self.curr_error = new_error
self.curr_time = new_time
# CORE FORUMLA:
return (
self.Kp * self.curr_error
+ self.Ki * error_integral_estimate
+ self.Kd * error_derivative_estimate
)