Skip to content

Commit

Permalink
create smach shutdown handler
Browse files Browse the repository at this point in the history
  • Loading branch information
talhabw committed Dec 21, 2024
1 parent dde52f1 commit 1fed630
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions auv_smach/scripts/main_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import rospy
import smach
import signal
import auv_smach
from std_srvs.srv import Trigger, TriggerRequest
from auv_smach.initialize import InitializeState
from auv_smach.gate import NavigateThroughGateState
from auv_smach.red_buoy import RotateAroundBuoyState
Expand Down Expand Up @@ -42,6 +44,12 @@ def __init__(self):

rospy.Subscriber("/taluy/propulsion_board/status", Bool, self.enabled_callback)

self.cancel_align_controller_service = rospy.ServiceProxy(
"/taluy/control/align_frame/cancel", Trigger
)

signal.signal(signal.SIGINT, self.shutdown_handler)

self.sm = smach.StateMachine(outcomes=["succeeded", "preempted", "aborted"])

with self.sm:
Expand Down Expand Up @@ -130,6 +138,15 @@ def enabled_callback(self, msg):
# restart
rospy.Timer(rospy.Duration(0.1), self.start)

def shutdown_handler(self):
rospy.loginfo("Starting cleanup before exiting smach")

rospy.loginfo("Calling cancel_align_controller service")
self.cancel_align_controller_service(TriggerRequest())

rospy.loginfo("Cleanup complete. Shutting down.")
rospy.signal_shutdown("SIGINT received.")


if __name__ == "__main__":
rospy.init_node("main_state_machine")
Expand Down

0 comments on commit 1fed630

Please sign in to comment.