Skip to content

Commit

Permalink
use aborted outcome to call cancel_align_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
talhabw committed Dec 22, 2024
1 parent ee70ac7 commit 1fed4e1
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions auv_smach/scripts/main_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import rospy
import smach
import signal
import auv_smach
from auv_smach.common import CancelAlignControllerState
from std_srvs.srv import Trigger, TriggerRequest
from auv_smach.initialize import InitializeState
from auv_smach.gate import NavigateThroughGateState
Expand Down Expand Up @@ -44,12 +44,6 @@ 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 All @@ -60,7 +54,7 @@ def __init__(self):
transitions={
"succeeded": "NAVIGATE_THROUGH_GATE",
"preempted": "preempted",
"aborted": "aborted",
"aborted": "CANCEL_ALIGN_CONTROLLER",
},
)
smach.StateMachine.add(
Expand All @@ -69,7 +63,7 @@ def __init__(self):
transitions={
"succeeded": "NAVIGATE_AROUND_RED_BUOY",
"preempted": "preempted",
"aborted": "aborted",
"aborted": "CANCEL_ALIGN_CONTROLLER",
},
)
smach.StateMachine.add(
Expand All @@ -82,7 +76,7 @@ def __init__(self):
transitions={
"succeeded": "NAVIGATE_TO_TORPEDO_TASK",
"preempted": "preempted",
"aborted": "aborted",
"aborted": "CANCEL_ALIGN_CONTROLLER",
},
)
smach.StateMachine.add(
Expand All @@ -94,7 +88,7 @@ def __init__(self):
transitions={
"succeeded": "NAVIGATE_TO_BIN_TASK",
"preempted": "preempted",
"aborted": "aborted",
"aborted": "CANCEL_ALIGN_CONTROLLER",
},
)
smach.StateMachine.add(
Expand All @@ -105,7 +99,7 @@ def __init__(self):
transitions={
"succeeded": "NAVIGATE_TO_OCTAGON_TASK",
"preempted": "preempted",
"aborted": "aborted",
"aborted": "CANCEL_ALIGN_CONTROLLER",
},
)
smach.StateMachine.add(
Expand All @@ -116,6 +110,15 @@ def __init__(self):
transitions={
"succeeded": "succeeded",
"preempted": "preempted",
"aborted": "CANCEL_ALIGN_CONTROLLER",
},
)
smach.StateMachine.add(
"CANCEL_ALIGN_CONTROLLER",
CancelAlignControllerState(),
transitions={
"succeeded": "aborted",
"preempted": "preempted",
"aborted": "aborted",
},
)
Expand All @@ -138,15 +141,6 @@ 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 1fed4e1

Please sign in to comment.