@@ -49,17 +49,23 @@ def __init__(self, left_motor: EncodedMotor, right_motor: EncodedMotor, imu: IMU
4949
5050 self .brake_at_zero_power = False
5151
52- if (wheel_diam == 0.0 ):
52+ # Resolve hardware defaults when the caller leaves the arg at its 0.0 sentinel;
53+ # honor any explicit non-zero value that is passed in.
54+ if wheel_diam == 0.0 :
5355 if "NanoXRP" in implementation ._machine :
5456 self .wheel_diam = 3.46
5557 else :
5658 self .wheel_diam = 6.0
59+ else :
60+ self .wheel_diam = wheel_diam
5761
58- if ( wheel_track == 0.0 ) :
62+ if wheel_track == 0.0 :
5963 if "NanoXRP" in implementation ._machine :
6064 self .wheel_track = 7.8
6165 else :
6266 self .wheel_track = 15.5
67+ else :
68+ self .wheel_track = wheel_track
6369
6470 self .heading_pid = None
6571 self .current_heading = None
@@ -267,7 +273,7 @@ def straight(self, distance: float, max_effort: float = 0.5, timeout: float = No
267273 # record current heading to maintain it
268274 current_heading = self .imu .get_yaw ()
269275 else :
270- current_heading = ((right_delta - left_delta )/ 2 )* 360 / (self .track_width * math .pi )
276+ current_heading = ((right_delta - left_delta )/ 2 )* 360 / (self .wheel_track * math .pi )
271277
272278 headingCorrection = secondary_controller .update (initial_heading - current_heading )
273279
@@ -363,7 +369,7 @@ def turn(self, turn_degrees: float, max_effort: float = 0.5, timeout: float = No
363369 turn_error = turn_degrees - self .imu .get_yaw ()
364370 else :
365371 # calculate turn error (in degrees) from the encoder counts
366- turn_error = turn_degrees - ((right_delta - left_delta )/ 2 )* 360 / (self .track_width * math .pi )
372+ turn_error = turn_degrees - ((right_delta - left_delta )/ 2 )* 360 / (self .wheel_track * math .pi )
367373
368374 # Pass the turn error to the main controller to get a turn speed
369375 turn_speed = main_controller .update (turn_error )
0 commit comments