Search code examples
python-3.xros

ROS Action Server not working in SMACH state machine: Still waiting for action server '/ActionServer' to start... is it running?


I'm trying to implement a state machine (SMACH) that uses Move Base Flex following this tutorial. Therefore, my state machine (which would be too complex to show completely here) proceed as follows:

1. State: launches all required launch-files that are necessary including the move base flex - launchfile using subprocess:

   ...
   try:
            log4 = open('/home/faps/catkin_ws/src/pathplanning/state_machine/logs/move_base_flex_log.txt', 'w')
            process4 = subprocess.Popen('roslaunch joggingblinde_2dnav move_base_flex.launch',
                                        stdout=log4, stderr=subprocess.STDOUT,
                                        shell=True, preexec_fn=os.setsid)
   except Exception:
            f = open("/home/faps/catkin_ws/src/pathplanning/state_machine/logs/main_log.txt", "a")
            f.write('state: ' + 'launch_service_nodes' + '; error: ' + 'Error in move_base_flex-node.\n')
            f.close()
            os.killpg(os.getpgid(process4.pid), signal.SIGTERM)
            userdata.in_termination_cause[0] = 'error'
            return 'aborted'
   ...

with the launch-file looking as follows:

<launch>
  <!-- Move Base Flex -->
  <master auto="start"/>
  <node pkg="mbf_costmap_nav" type="mbf_costmap_nav" respawn="false" name="move_base_flex" output="screen">
    <param name="tf_timeout" value="1.5"/>
    <param name="planner_max_retries" value="3"/>
    <rosparam file="$(find joggingblinde_2dnav)/config/planners.yaml" command="load" />
    <rosparam file="$(find joggingblinde_2dnav)/config/costmap_common_params.yaml" command="load" ns="global_costmap"/>
    <rosparam file="$(find joggingblinde_2dnav)/config/costmap_common_params.yaml" command="load" ns="local_costmap" />
    <rosparam file="$(find joggingblinde_2dnav)/config/global_costmap_params.yaml" command="load" />
    <rosparam file="$(find joggingblinde_2dnav)/config/local_costmap_params.yaml" command="load" />
  </node>
</launch> 

2. State: computing new goalpoint and writing the resulting goalpoint into the corresponding userdata-variable. (I've tested this one: the goalpoint exists after this state, so it's not empty.)

3. State: calling the get_path action of move base flex like described in the linked tutorial above:

smach.StateMachine.add('GET_GLOBAL_PATH_IN_GOAL_CHECK_SM', 
                       smach_ros.SimpleActionState(
                           '/move_base_flex/get_path',
                           GetPathAction,
                           goal_slots=['target_pose'],
                           result_slots=['path']
                       ),
                       transitions={
                       'succeeded': 'FEEDBACK_IN_GOAL_CHECK_SM',
                       'aborted': 'SECURE_STATE_IN_GOAL_CHECK_SM',
                       'preempted': 'preempted'
                       },
                       remapping={
                       'target_pose': 'test_goal'
                       }
)

When running the state machine, everything works fine until state 3 is called which throws a warning:

'Still waiting for action server '/move_base_flex/get_path' to start... is it running?'

The exact terminal output looks like this: terminal output

Most issue threads dealing with similar errors are caused because the given namespace is wrong or because the Action Server isn't running (which apparently can be checked by rostopic list).

Using rostopic list shows, that the Action Server is running and that the namespace is correct. rostopic list output


Solution

  • Move Base Flex somehow appears to not work properly when started inside SMACH.

    The Problem is that the action servers are started after the plugins are loaded, meaning that when mbf gets stuck loading the plugins, it won't start the action servers.

    In my case, when starting mbf inside SMACH, it somehow fails to subscribe to the topics that are required by the costmap-plugin (due to the map-param of static layer) and therefore gets stuck.

    Starting mbf outside of SMACH and THEN starting SMACH however works perfectly fine.

    For more information, visit the corresponding issue thread.