Skip to content

Commit c6c19ad

Browse files
committed
Encoder PIO fully functional, drivetrain methods all fixed
1 parent bb3504c commit c6c19ad

File tree

4 files changed

+7
-23
lines changed

4 files changed

+7
-23
lines changed

XRPLib/differential_drive.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def get_default_differential_drive(cls):
1919

2020
if cls._DEFAULT_DIFFERENTIAL_DRIVE_INSTANCE is None:
2121
cls._DEFAULT_DIFFERENTIAL_DRIVE_INSTANCE = cls(
22-
EncodedMotor.get_default_left_motor(),
23-
EncodedMotor.get_default_right_motor(),
22+
EncodedMotor.get_default_encoded_motor(0),
23+
EncodedMotor.get_default_encoded_motor(1),
2424
IMU.get_default_imu()
2525
)
2626

@@ -105,7 +105,7 @@ def straight(self, distance: float, speed: float = 0.5, timeout: float = None, m
105105

106106
if main_controller is None:
107107
main_controller = PID(
108-
kp = 2,
108+
kp = 0.5,
109109
minOutput = 0.12,
110110
maxOutput = speed,
111111
tolerance = 0.1,
@@ -115,7 +115,7 @@ def straight(self, distance: float, speed: float = 0.5, timeout: float = None, m
115115
# Secondary controller to keep encoder values in sync
116116
if secondary_controller is None:
117117
secondary_controller = PID(
118-
kp = 0.02,
118+
kp = 0.0175, kd=0.005,
119119
)
120120

121121
rotationsToDo = distance / (self.wheel_diam * math.pi)
@@ -228,11 +228,8 @@ def turn(self, turn_degrees: float, speed: float = 0.5, timeout: float = None, m
228228
if main_controller.is_done() or time_out.is_done():
229229
break
230230

231-
232231
self.set_effort(-turnSpeed - encoderCorrection, turnSpeed - encoderCorrection)
233232

234-
#print(turnError, turnSpeed)
235-
236233
time.sleep(0.01)
237234

238235
self.stop()

XRPLib/encoded_motor.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,6 @@ def get_default_encoded_motor(cls, index:int = 0):
5353
)
5454
motor = cls._DEFAULT_LEFT_MOTOR_INSTANCE
5555
return motor
56-
57-
@classmethod
58-
def get_default_encoded_motor(cls):
59-
"""
60-
Get the default XRP v2 right motor instance. This is a singleton, so only one instance of the drivetrain will ever exist.
61-
Motor pins set to 14 and 15 and the encoder pins set to 12 and 13
62-
"""
63-
64-
65-
66-
return cls._DEFAULT_RIGHT_MOTOR_INSTANCE
6756

6857
def __init__(self, motor: Motor, encoder: Encoder):
6958

XRPLib/encoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def get_position_ticks(self):
3131
return ticks
3232

3333
def get_position(self):
34-
return self.getTicks() / self.ticksPerShaftRotation
34+
return self.get_position_ticks() / self.ticksPerShaftRotation
3535

3636
@rp2.asm_pio(in_shiftdir=rp2.PIO.SHIFT_LEFT, out_shiftdir=rp2.PIO.SHIFT_RIGHT)
3737
def _encoder():

XRPLib/resetbot.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from XRPLib.encoded_motor import EncodedMotor
22

33
# using the EncodedMotor since the default drivetrain uses the IMU and takes 3 seconds to init
4-
left = EncodedMotor.get_default_left_motor()
5-
right = EncodedMotor.get_default_right_motor()
6-
left.set_effort(0.0)
7-
right.set_effort(0.0)
4+
for i in range(4):
5+
EncodedMotor.get_default_encoded_motor(i).reset_encoder_position()

0 commit comments

Comments
 (0)