Skip to content

Commit

Permalink
fix(rover_py): disable failsafe in brake test
Browse files Browse the repository at this point in the history
  • Loading branch information
hashemmm96 committed Jan 25, 2024
1 parent 653c26c commit d0a4334
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions rover_py/rover/servo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from canlib import Frame

from .rover import Envelope
from .rover import City, Envelope

FAILSAFE_OFF = 0
FAILSAFE_ON = 1
Expand Down Expand Up @@ -32,7 +32,7 @@ def set_steering_angle_frame(angle_deg):

def set_throttle_pulse_frame(pulse_mus):
data = [0] + list(pulse_mus.to_bytes(2, "little", signed=True))
return Frame(id_=Envelope.THROTTLE, dlc=3, data=data)
return Frame(id_=Envelope.THROTTLE, dlc=5, data=data)


def set_measure_period_frame(time_ms):
Expand All @@ -49,10 +49,16 @@ def set_reverse_direction():
return Frame(id_=Envelope.SERVO_REVERSE_DIRECTION, dlc=0, data=[])


def set_failsafe(on, timeout_ms=100, pulse_mus=1500):
def set_failsafe(on, city=City.SERVO, timeout_ms=100, pulse_mus=1500):
if city == City.MOTOR:
envelope = Envelope.MOTOR_FAILSAFE
else:
envelope = Envelope.SERVO_FAILSAFE

data = (
[on]
+ list(timeout_ms.to_bytes(2, "little"))
+ list(pulse_mus.to_bytes(2, "little"))
)
return Frame(id_=Envelope.SERVO_FAILSAFE, dlc=5, data=data)

return Frame(id_=envelope, dlc=5, data=data)
6 changes: 6 additions & 0 deletions rover_py/tests/test_braking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
ch.writeWait(rover.set_silent_mode(city=rover.City.SBUS_RECEIVER), -1)
sleep(3)

# Disable failsafe
ch.writeWait(servo.set_failsafe(servo.FAILSAFE_OFF, city=rover.City.MOTOR), -1)

# Accelerate
ch.writeWait(servo.set_throttle_pulse_frame(1600), -1)
sleep(1)
Expand All @@ -37,4 +40,7 @@
# Back to neutral. There is no braking in reverse mode.
ch.writeWait(servo.set_throttle_pulse_frame(1500), -1)

# Re-enable failsafe
ch.writeWait(servo.set_failsafe(servo.FAILSAFE_ON, city=rover.City.MOTOR), -1)

ch.busOff()

0 comments on commit d0a4334

Please sign in to comment.