Skip to content

Commit

Permalink
chassis: Latency compensate drive encoder readings
Browse files Browse the repository at this point in the history
  • Loading branch information
auscompgeek committed Feb 15, 2024
1 parent dd530ed commit dacd782
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions components/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def __init__(
else config_groups.InvertedValue.COUNTER_CLOCKWISE_POSITIVE
)

# Note: we change the dimension of the drive encoder readings
# here from wheel rotations to metres.
drive_gear_ratio_config = FeedbackConfigs().with_sensor_to_mechanism_ratio(
1 / self.DRIVE_MOTOR_REV_TO_METRES
)
Expand Down Expand Up @@ -149,11 +151,14 @@ def get_rotation(self) -> Rotation2d:
return Rotation2d(self.get_angle_integrated())

def get_speed(self) -> float:
# velocity is in rot/s, return in m/s
return self.drive.get_velocity().value
return self.drive.get_velocity().get_latency_compensated_value(
self.drive.get_acceleration()
)

def get_distance_traveled(self) -> float:
return self.drive.get_position().value
return self.drive.get_position().get_latency_compensated_value(
self.drive.get_velocity()
)

def set(self, desired_state: SwerveModuleState):
if self.module_locked:
Expand Down

0 comments on commit dacd782

Please sign in to comment.