-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Input/Debug Steering Deviation Sanity Alarm (#113)
* added deviation sanity check * finish watchdog * fixed up watchdog and added to launch files * Revert "added deviation sanity check" This reverts commit 355cd2b. * pylint * updated telematics fix publisher * added debugs, allowed clean shutdown, and created proper alarms --------- Co-authored-by: Mehul Goel <[email protected]> Co-authored-by: Buggy <[email protected]>
- Loading branch information
1 parent
89bb787
commit 7c9e218
Showing
6 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!-- roslaunch buggy main.launch --> | ||
|
||
<launch> | ||
<node name="foxglove" pkg="foxglove_bridge" type="foxglove_bridge" /> | ||
<node name="watchdog" pkg="buggy" type="watchdog.py" args = "--self_name SC" output="screen"/> | ||
</launch> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
|
||
import rospy | ||
|
||
from std_msgs.msg import Bool, Int8, Float64 | ||
|
||
class Watchdog: | ||
|
||
STEERING_DEVIANCE = 4 #deg | ||
|
||
def __init__(self, self_name) -> None: | ||
self.alarm = 0 #Check this alarm value | ||
""" | ||
0 - OK | ||
1 - WARNING | ||
2 - ERROR | ||
""" | ||
|
||
self.commanded_steering = 0 | ||
self.inAutonSteer = False | ||
|
||
rospy.Subscriber( | ||
self_name + "/buggy/input/steering", Float64, self.set_input_steering | ||
) | ||
rospy.Subscriber( | ||
self_name + "/buggy/debug/steering_angle", Float64, self.check_stepper_steering | ||
) | ||
rospy.Subscriber( | ||
self_name + "/buggy/debug/use_auton_steer", Bool, self.set_auton_steer | ||
) | ||
|
||
self.alarm_publisher = rospy.Publisher(self_name + "/debug/sanity_warning", Int8, queue_size=1) | ||
self.alarm_publish_rate = rospy.Rate(100) #10ms per alarm | ||
|
||
def set_input_steering(self, msg): | ||
rospy.logdebug("Got input steering of: " + str(msg.data)) | ||
self.commanded_steering = msg.data | ||
|
||
def set_auton_steer(self, msg): | ||
if (msg.data and not self.inAutonSteer): | ||
rospy.loginfo("ENTERED AUTON") | ||
if (not msg.data and self.inAutonSteer): | ||
rospy.logwarn("EXITED AUTON") | ||
self.alarm = 0 #No alarm if not in auton | ||
self.inAutonSteer = msg.data | ||
|
||
def check_stepper_steering(self, msg): | ||
stepper_steer = msg.data | ||
rospy.logdebug("Firmware's reported stepper degree: " + str(stepper_steer)) | ||
if (self.alarm < 2): | ||
self.alarm = 0 | ||
if abs(stepper_steer - self.commanded_steering) > Watchdog.STEERING_DEVIANCE: | ||
if self.inAutonSteer: | ||
self.alarm = 2 # ERROR | ||
rospy.logerr("STEPPER DEVIANCE (DEGREES OFF): " + str(abs(stepper_steer - self.commanded_steering))) | ||
else: | ||
rospy.logdebug("(Non Auton) Stepper Deviance of: " + str(abs(stepper_steer - self.commanded_steering))) | ||
|
||
elif abs(stepper_steer - self.commanded_steering) > Watchdog.STEERING_DEVIANCE//2: | ||
if self.inAutonSteer: | ||
self.alarm = max(self.alarm, 1) | ||
rospy.logwarn("STEPPER POSSIBILY DEVIATING (DEGREES OFF): " + str(abs(stepper_steer - self.commanded_steering))) | ||
else: | ||
rospy.logdebug("(Non Auton) Stepper possibly deviating: " + str(abs(stepper_steer - self.commanded_steering))) | ||
|
||
def loop(self): | ||
while not rospy.is_shutdown(): | ||
#publish alarm | ||
ros_alarm = Int8() | ||
ros_alarm.data = self.alarm | ||
self.alarm_publisher.publish(ros_alarm) | ||
|
||
self.alarm_publish_rate.sleep() | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--self_name", type=str, help="name of ego-buggy", required=True | ||
) | ||
args, _ = parser.parse_known_args() | ||
self_name = args.self_name | ||
rospy.init_node("watchdog") | ||
rospy.loginfo("INITIALIZED WATCHDOG NODE") | ||
watchdog = Watchdog(self_name=self_name) | ||
watchdog.loop() |