Skip to content

Commit a5d47de

Browse files
committed
Retuned Turn and Straight again
1 parent d58ae5d commit a5d47de

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

XRPLib/differential_drive.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ def straight(self, distance: float, max_effort: float = 0.5, timeout: float = No
151151

152152
if main_controller is None:
153153
main_controller = PID(
154-
kp = 0.04,
155-
ki = 0.0125,
156-
kd = 0.025,
157-
min_output = 0.225,
158-
max_output = max_effort,
159-
max_integral = 35,
160-
tolerance = 0.1,
154+
kp = 0.1,
155+
ki = 0.04,
156+
kd = 0.06,
157+
min_output = 0.25,
158+
max_output = 0.5,
159+
max_integral = 10,
160+
tolerance = 0.25,
161161
tolerance_count = 3,
162162
)
163163

164164
# Secondary controller to keep encoder values in sync
165165
if secondary_controller is None:
166166
secondary_controller = PID(
167-
kp = 0.03, kd=0.003,
167+
kp = 0.075, kd=0.005,
168168
)
169169

170170
if self.imu is not None:
@@ -228,8 +228,8 @@ def turn(self, turn_degrees: float, max_effort: float = 0.5, timeout: float = No
228228
"""
229229

230230
if max_effort < 0:
231-
max_effort *= -1
232-
turn_degrees *= -1
231+
max_effort = -max_effort
232+
turn_degrees = -turn_degrees
233233

234234
time_out = Timeout(timeout)
235235
starting_left = self.get_left_encoder_position()
@@ -238,20 +238,19 @@ def turn(self, turn_degrees: float, max_effort: float = 0.5, timeout: float = No
238238
if main_controller is None:
239239
main_controller = PID(
240240
kp = 0.02,
241-
ki = 0.005,
242-
kd = 0.012,
241+
ki = 0.001,
242+
kd = 0.00165,
243243
min_output = 0.35,
244-
max_output = max_effort,
245-
max_derivative = 0.5,
246-
max_integral = 50,
247-
tolerance = 0.5,
248-
tolerance_count = 2
244+
max_output = 0.5,
245+
max_integral = 75,
246+
tolerance = 1,
247+
tolerance_count = 3
249248
)
250249

251250
# Secondary controller to keep encoder values in sync
252251
if secondary_controller is None:
253252
secondary_controller = PID(
254-
kp = 1,
253+
kp = 1.0,
255254
)
256255

257256
if use_imu and (self.imu is not None):

XRPLib/pid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def update(self, error: float) -> float:
8787
derivative = (error - self.prev_error) / timestep
8888

8989
# derive output
90-
output = self.kp * error + self.ki * integral + self.kd * derivative
90+
output = self.kp * error + self.ki * integral - self.kd * derivative
9191
self.prev_error = error
9292
self.prev_integral = integral
9393

0 commit comments

Comments
 (0)