Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_two_motor_drivetrain(l_motor, r_motor, output):
result = drivetrains.TwoMotorDrivetrain(speed=1 * units.fps).calculate(
l_motor, r_motor
)
result = (result.vx_fps, result.omega)
assert abs(result[0] - output[0]) < 0.001
assert abs(result[1] - output[1]) < 0.001
def test_four_motor_swerve_drivetrain(
lr_motor,
rr_motor,
lf_motor,
rf_motor,
lr_angle,
rr_angle,
lf_angle,
rf_angle,
output,
):
wheelbase = sqrt(2)
result = drivetrains.four_motor_swerve_drivetrain(
lr_motor,
rr_motor,
lf_motor,
rf_motor,
lr_angle,
rr_angle,
lf_angle,
rf_angle,
speed=1,
x_wheelbase=wheelbase,
y_wheelbase=wheelbase,
)
assert abs(result.vx_fps - output[0]) < 0.001
assert abs(result.vy_fps - output[1]) < 0.001
assert abs(result.omega - output[2]) < 0.001
def update_sim(self, hal_data, now, tm_diff):
'''
Called when the simulation parameters for the program need to be
updated.
:param now: The current time as a float
:param tm_diff: The amount of time that has passed since the last
time that this function was called
'''
# Simulate the drivetrain
l_motor = hal_data['pwm'][1]['value']
r_motor = hal_data['pwm'][2]['value']
speed, rotation = drivetrains.two_motor_drivetrain(l_motor, r_motor)
self.physics_controller.drive(speed, rotation, tm_diff)
# update position (use tm_diff so the rate is constant)
self.position += hal_data['pwm'][4]['value'] * tm_diff * 3
# update limit switches based on position
if self.position <= 0:
switch1 = True
switch2 = False
elif self.position > 10:
switch1 = False
switch2 = True
else:
updated.
:param now: The current time as a float
:param tm_diff: The amount of time that has passed since the last
time that this function was called
'''
# Simulate the drivetrain
# -> Remember, in the constructor we inverted the left motors, so
# invert the motor values here too!
lr_motor = -hal_data['pwm'][1]['value']
rr_motor = hal_data['pwm'][2]['value']
lf_motor = -hal_data['pwm'][3]['value']
rf_motor = hal_data['pwm'][4]['value']
vx, vy, vw = drivetrains.mecanum_drivetrain(lr_motor, rr_motor, lf_motor, rf_motor)
self.physics_controller.vector_drive(vx, vy, vw, tm_diff)