ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

[docker] how to make sure nodes start after master?

asked 2017-02-04 16:18:45 -0500

waspinator gravatar image

updated 2017-02-05 03:47:55 -0500

gvdhoorn gravatar image

I often find that my nodes try to start before master is ready, which breaks the system. How do I make sure that the nodes wait for master to be ready (or continually retry)? Using Docker's depends_on isn't guaranteed to work, since Docker only knows when the container is up, but not when ROS master is up.

docker-compose.ymal

version: '2'

services:

  robot-core:
    build:
      context: .
      dockerfile: robot_core.dockerfile
    volumes:
      - ../data/logs/robot_core:/root/.ros/

  robot-plan:
    build:
      context: .
      dockerfile: robot_plan.dockerfile
    environment:
      - "ROS_HOSTNAME=robot-plan"
      - "ROS_MASTER_URI=http://robot-core:11311"
    volumes:
      - ../data/logs/robot_plan:/root/.ros/

  resolvable:
    image: mgood/resolvable
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock
      - /etc/resolv.conf:/tmp/resolv.conf

robot-core.dockerfile (ros master node)

FROM ros:kinetic

RUN apt-get update \
    && apt-get install ros-kinetic-rosbridge-server --yes

RUN ln -snf /bin/bash /bin/sh
RUN mkdir -p /ros_workspace/src/robot_core
WORKDIR /ros_workspace
COPY ["robot_core", "/ros_workspace/src/robot_core"]
RUN source /opt/ros/kinetic/setup.bash; catkin_make

EXPOSE 9090 11311 33690

CMD source devel/setup.bash; roslaunch robot_core robot_core.launch

robot-core launch file

<launch>
  <include file="$(find rosbridge_server)/launch/rosbridge_websocket.launch" >
     <arg name="port" value="9090"/>
  </include>
</launch>

robot-plan.dockerfile (ROS slave node)

FROM ros:kinetic

RUN ln -snf /bin/bash /bin/sh
RUN mkdir -p /ros_workspace/src/robot_msgs
RUN mkdir -p /ros_workspace/src/robot_plan
WORKDIR /ros_workspace
COPY ["robot_msgs", "/ros_workspace/src/robot_msgs"]
COPY ["robot_plan", "/ros_workspace/src/robot_plan"]
RUN source /opt/ros/kinetic/setup.bash; catkin_make

EXPOSE 9090 11311 33690

CMD source devel/setup.bash; roslaunch robot_plan robot_plan.launch

robot-plan launch file

<launch>
    <node name="robot_plan" pkg="robot_plan" type="plan_server.py" output="screen" respawn="true">
        <rosparam command="load" file="$(find robot_plan)/config/config.yaml" />
    </node>
</launch>

reference: https://github.com/osrf/docker_images...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-02-04 16:34:05 -0500

ahendrix gravatar image

The --wait argument to roslaunch will make it wait until the rosmaster is ready; I believe this will do what you're looking for.

--wait and other roslaunch command-line arguments are documented on the roslaunch command line wiki page.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-02-04 16:18:45 -0500

Seen: 3,154 times

Last updated: Feb 05 '17