[Documentation] [TitleIndex] [WordIndex

ROS integration

For example, if you want to call an actionlib action from SMACH, you can of course write a generic state, which would look something like this:

   1   class ManualActionState(smach.State):
   2      def __init__(self, outcomes=['succeeded', 
   3                                   'aborted',
   4                                   'preempted']):
   5        self.action_client = SimpleActionClient('action_name',
   6                                                ActionType)
   7        self.action_client.wait_for_server()
   8 
   9      
  10      def execute(self, userdata):
  11        goal = ActionGoal()
  12        ret = self.action_client.send_goal_and_wait
  13        if ret == ActionStatus.SUCCEEDED:
  14           return 'succeeded'
  15        elif ret == ActionStatus.PREEMPTED:
  16           return 'preempted'
  17        elif ret == ActionStatus.ABORTED:
  18           return 'aborted' 
  19 
  20 
  21 sm = StateMachine(['succeeded','aborted','preempted'])
  22 with sm:
  23     smach.StateMachine.add('TRIGGER_GRIPPER',
  24                            ManualActionState(),
  25                            rransitions={'succeeded':'APPROACH_PLUG'})

But you can call that same action with much less coding, using the SimpleActionState:

   1 sm = StateMachine(['succeeded','aborted','preempted'])
   2 with sm:
   3     smach.StateMachine.add('TRIGGER_GRIPPER',
   4                            SimpleActionState('action_server_namespace',
   5                                              ActionState),
   6                            transitions={'succeeded':'APPROACH_PLUG'})

SMACH ROS offers the same type of support for ROS services and ROS topics. For more details take a look at the tutorials.


2024-06-22 14:20