Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chassis: Latency compensate encoder readings #110

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions components/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def __init__(
else 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 All @@ -138,18 +140,24 @@ def get_angle_absolute(self) -> float:

def get_angle_integrated(self) -> float:
"""Gets steer angle from motor's integrated relative encoder"""
return self.steer.get_position().value * math.tau
rot = self.steer.get_position().get_latency_compensated_value(
self.steer.get_velocity()
)
return rot * math.tau

def get_rotation(self) -> Rotation2d:
"""Get the steer angle as a 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
Loading