Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Another option is to use systemd. A simple example:

Contents of /lib/systemd/system/robot.service:

[Unit]
Description=My Robot

[Service]
User=root
ExecStart=/home/me/catkin_ws/src/robot/scripts/start_robot.sh

[Install]
WantedBy=multi-user.target

Contents of /home/me/catkin_ws/src/robot/scripts/start_robot.sh:

bash -c "source /home/me/catkin_ws/devel/setup.bash && roslaunch robot robot.launch"

Then use systemctl to control it:

sudo systemctl start robot.service # start
sudo systemctl stop robot.service # stop
sudo systemctl enable robot.service # start on boot
sudo systemctl disable robot.service # disable start on boot

Another option is to use systemd. systemd. A simple example:

Contents of /lib/systemd/system/robot.service:/lib/systemd/system/robot.service:

[Unit]
Description=My Robot

[Service]
User=root
ExecStart=/home/me/catkin_ws/src/robot/scripts/start_robot.sh

[Install]
WantedBy=multi-user.target

Contents of /home/me/catkin_ws/src/robot/scripts/start_robot.sh:/home/myaccount/catkin_ws/src/robot/scripts/start_robot.sh:

bash -c "source /home/me/catkin_ws/devel/setup.bash && roslaunch robot robot.launch"

Then use systemctl systemctl to control it:

sudo systemctl start robot.service # start
sudo systemctl stop robot.service # stop
sudo systemctl enable robot.service # start on boot
sudo systemctl disable robot.service # disable start on boot

(Edit to add some debugging notes.)

Note that you can set "User=<any user="">." Debugging will be easier if you can use your typical login. Of course, you should never use root unless you absolutely have to.

Debugging a boot-time launch can be annoying, since you need to rely on logging. I typically use roslaunch --screen from the command line to develop and debug, then move to manual start/stop to do system tests, then only when when I'm ready to do a full end-to-end test do I enable start at boot.

A few tricks for debugging:

Set output="log" on all nodes. (The default is output to log, so you can just remove the output="screen" option as well.) This will send all ROS_INFO messages to log files so that they don't clutter up the systemd logs.

Add stdbuf -oL to your command line invocations:

bash -c "source /home/myaccount/catkin_ws/devel/setup.bash && stdbuf -oL roslaunch robot robot.launch"

This will flush the output buffers after every line so that you see log messages quickly.

To see errors, run systemctl status robot.service. To see ROS_INFO messages, run tail -f ~/.ros/log/latest/mynode-*-stdout.log".