6
6
7
7
from std_msgs .msg import Bool , Int8 , Float64
8
8
9
+ from collections import deque
10
+
11
+ STEERING_INSTRUCTION_MAX_LEN = 10
12
+
9
13
class Watchdog :
10
14
11
15
STEERING_DEVIANCE = 4 #deg
@@ -18,7 +22,8 @@ def __init__(self, self_name) -> None:
18
22
2 - ERROR
19
23
"""
20
24
21
- self .commanded_steering = 0
25
+ self .steering_instructions = deque (maxlen = STEERING_INSTRUCTION_MAX_LEN )
26
+
22
27
self .inAutonSteer = False
23
28
24
29
rospy .Subscriber (
@@ -36,7 +41,7 @@ def __init__(self, self_name) -> None:
36
41
37
42
def set_input_steering (self , msg ):
38
43
rospy .logdebug ("Got input steering of: " + str (msg .data ))
39
- self .commanded_steering = msg .data
44
+ self .steering_instructions . append ( msg .data )
40
45
41
46
def set_auton_steer (self , msg ):
42
47
if (msg .data and not self .inAutonSteer ):
@@ -49,16 +54,25 @@ def set_auton_steer(self, msg):
49
54
def check_stepper_steering (self , msg ):
50
55
stepper_steer = msg .data
51
56
rospy .logdebug ("Firmware's reported stepper degree: " + str (stepper_steer ))
52
- if ( self .alarm < 2 ) :
57
+ if self .alarm < 2 :
53
58
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 :
55
69
if self .inAutonSteer :
56
70
self .alarm = 2 # ERROR
57
71
rospy .logerr ("STEPPER DEVIANCE (DEGREES OFF): " + str (abs (stepper_steer - self .commanded_steering )))
58
72
else :
59
73
rospy .logdebug ("(Non Auton) Stepper Deviance of: " + str (abs (stepper_steer - self .commanded_steering )))
60
74
61
- elif abs ( stepper_steer - self . commanded_steering ) > Watchdog .STEERING_DEVIANCE // 2 :
75
+ elif steer_instruct_diff_min > Watchdog .STEERING_DEVIANCE // 2 :
62
76
if self .inAutonSteer :
63
77
self .alarm = max (self .alarm , 1 )
64
78
rospy .logwarn ("STEPPER POSSIBILY DEVIATING (DEGREES OFF): " + str (abs (stepper_steer - self .commanded_steering )))
0 commit comments