Skip to content

Commit a58ac13

Browse files
Added a queue to the watchdog
Stores STEERING_INSTRUCTION_MAX_LEN last steering instructions, comparing them with the stepper steering and sending off an error if the minimum difference is too large
1 parent 7c9e218 commit a58ac13

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

rb_ws/src/buggy/scripts/watchdog/watchdog.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
from std_msgs.msg import Bool, Int8, Float64
88

9+
from collections import deque
10+
11+
STEERING_INSTRUCTION_MAX_LEN = 10
12+
913
class Watchdog:
1014

1115
STEERING_DEVIANCE = 4 #deg
@@ -18,7 +22,8 @@ def __init__(self, self_name) -> None:
1822
2 - ERROR
1923
"""
2024

21-
self.commanded_steering = 0
25+
self.steering_instructions = deque(maxlen=STEERING_INSTRUCTION_MAX_LEN)
26+
2227
self.inAutonSteer = False
2328

2429
rospy.Subscriber(
@@ -36,7 +41,7 @@ def __init__(self, self_name) -> None:
3641

3742
def set_input_steering(self, msg):
3843
rospy.logdebug("Got input steering of: " + str(msg.data))
39-
self.commanded_steering = msg.data
44+
self.steering_instructions.append(msg.data)
4045

4146
def set_auton_steer(self, msg):
4247
if (msg.data and not self.inAutonSteer):
@@ -49,16 +54,25 @@ def set_auton_steer(self, msg):
4954
def check_stepper_steering(self, msg):
5055
stepper_steer = msg.data
5156
rospy.logdebug("Firmware's reported stepper degree: " + str(stepper_steer))
52-
if (self.alarm < 2):
57+
if self.alarm < 2:
5358
self.alarm = 0
54-
if abs(stepper_steer - self.commanded_steering) > Watchdog.STEERING_DEVIANCE:
59+
60+
# Finds the minimum difference between the stepper's reported angle and the last 10 steering instructions
61+
steer_instruct_diff_min = min(
62+
map(
63+
lambda steer: abs(stepper_steer - steer),
64+
self.steering_instructions
65+
)
66+
)
67+
68+
if steer_instruct_diff_min > Watchdog.STEERING_DEVIANCE:
5569
if self.inAutonSteer:
5670
self.alarm = 2 # ERROR
5771
rospy.logerr("STEPPER DEVIANCE (DEGREES OFF): " + str(abs(stepper_steer - self.commanded_steering)))
5872
else:
5973
rospy.logdebug("(Non Auton) Stepper Deviance of: " + str(abs(stepper_steer - self.commanded_steering)))
6074

61-
elif abs(stepper_steer - self.commanded_steering) > Watchdog.STEERING_DEVIANCE//2:
75+
elif steer_instruct_diff_min > Watchdog.STEERING_DEVIANCE // 2:
6276
if self.inAutonSteer:
6377
self.alarm = max(self.alarm, 1)
6478
rospy.logwarn("STEPPER POSSIBILY DEVIATING (DEGREES OFF): " + str(abs(stepper_steer - self.commanded_steering)))

0 commit comments

Comments
 (0)