Ask Your Question
0

Script ROS to start at boot

asked 2016-09-13 12:39:05 -0600

waspinator gravatar image

updated 2016-09-13 13:29:08 -0600

I'm following the http://wiki.ros.org/roslibjs/Tutorial... example and running it in docker container.

It works if I manually type in the three commands by hand

  1. roscore &
  2. rosrun actionlib_tutorials fibonacci_server &
  3. roslaunch rosbridge_server rosbridge_websocket.launch

but now I'd like to start the server automatically when the container runs.

I tried to make a script with those 3 commands and call it once the container is booted, but it doesn't work. It seems maybe some of the later commands are being run before the earlier ones finish whatever it is they're doing.

I can make it work by adding sleep 10 commands between the ros commands, but that doesn't seem like a good solution. What happens if something takes longer than 10 seconds to start?

Is there a proper way to script ROS so that you don't have to manually type in commands? Would it involve systemd? I saw some answers talk about upstart, but that's not used much anymore.

Thanks

output after script is run

[ERROR] [1473788676.856009756]: [registerPublisher] Failed to contact master at [localhost:11311].  Retrying...
... logging to /root/.ros/log/bd282b86-79d9-11e6-a6d8-0242ac110002/roslaunch-7cc22b76aecc-41.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

... logging to /root/.ros/log/bd2b0c3e-79d9-11e6-898e-0242ac110002/roslaunch-7cc22b76aecc-43.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://7cc22b76aecc:43707/
ros_comm version 1.12.2


SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.2

NODES

auto-starting new master
started roslaunch server http://7cc22b76aecc:43708/

SUMMARY
========

PARAMETERS
 * /rosbridge_websocket/address:
 * /rosbridge_websocket/authenticate: False
 * /rosbridge_websocket/delay_between_messages: 0
 * /rosbridge_websocket/fragment_timeout: 600
 * /rosbridge_websocket/max_message_size: None
 * /rosbridge_websocket/port: 9090
 * /rosbridge_websocket/retry_startup_delay: 5
 * /rosdistro: kinetic
 * /rosversion: 1.12.2

NODES
  /
    rosapi (rosapi/rosapi_node)
    rosbridge_websocket (rosbridge_server/rosbridge_websocket)

auto-starting new master
process[master]: started with pid [71]
process[master]: started with pid [75]
ROS_MASTER_URI=http://7cc22b76aecc:11311/

setting /run_id to bd282b86-79d9-11e6-a6d8-0242ac110002
[ INFO] [1473788677.469727221]: Connected to master at [localhost:11311]
ROS_MASTER_URI=http://localhost:11311

ERROR: Unable to start XML-RPC server, port 11311 is already in use
Unhandled exception in thread started by <bound method XmlRpcNode.run of <rosgraph.xmlrpc.XmlRpcNode object at 0x7f2dd3104990>>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosgraph/xmlrpc.py", line 212, in run
    self._run()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosgraph/xmlrpc.py", line 281, in _run
    self._run_init()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosgraph/xmlrpc.py", line 231, in _run_init
    self.server = ThreadingXMLRPCServer((bind_address, port), log_requests)
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosgraph/xmlrpc.py", line 112, in __init__
    SimpleXMLRPCServer.__init__(self, addr, SilenceableXMLRPCRequestHandler, log_requests)
  File "/usr/lib/python2.7/SimpleXMLRPCServer.py", line 593, in __init__
    SocketServer.TCPServer.__init__(self, addr, requestHandler, bind_and_activate)
  File "/usr/lib/python2.7/SocketServer.py", line 417, in __init__
    self.server_bind()
  File "/usr/lib/python2.7/SocketServer.py", line 431, in server_bind
    self ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-09-26 16:09:10 -0600

waspinator gravatar image

I have figured out that I should be using roslaunch to orchestrate starting up ROS on its own.

Something like this I think should work. It will start ros core automatically.

<launch>

  <group ns="actionlib_tutorial">
    <node pkg="actionlib_tutorials" name="fibonacci_server" type="fibonacci_server.py" />
  </group>

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

</launch>
edit flag offensive delete link more

Comments

As you might have known by now, roslaunch starts roscore if there's none found running, so yes to using roslaunch.

130s gravatar image130s ( 2019-10-09 19:47:55 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-13 12:39:05 -0600

Seen: 512 times

Last updated: Sep 26 '16