ROS 1 by default does not start on bootup, but its really handy to be able to just power on a robot and have all your ROS nodes launch. There are many ways to do this in linux including the systemd, rc.local file. We recommend using systemd because it has logging builtin, it can be configured to try again if there are errors in bringup, and it can be stopped and restarted.

Systemd setup

You will need to create 3 files to setup systemd


/etc/systemd/system/roscore.service

This file will start roscore, you need to make sure to fill in your user name where is says [TODO] and change kinetic to whichever ROS version you are using


[Unit]
After=NetworkManager.service time-sync.target
[Service]
Type=forking
User=[TODO enter user name here]
# Start roscore as a fork and then wait for the tcp port to be opened
# —————————————————————-
# Source all the environment variables, start roscore in a fork
# Since the service type is forking, systemd doesn’t mark it as
# ‘started’ until the original process exits, so we have the
# non-forked shell wait until it can connect to the tcp opened by
# roscore, and then exit, preventing conflicts with dependant services
ExecStart=/bin/sh -c “. /opt/ros/kinetic/setup.sh; . /etc/ros/env.sh; roscore & while ! echo exit | nc localhost 11311 > /dev/null; do sleep 1; done”
[Install]
WantedBy=multi-user.target


/etc/ros/env.sh

This file stores your environment variables

#!/bin/sh
export ROS_HOSTNAME=$(hostname).localexport ROS_MASTER_URI=http://$ROS_HOSTNAME:11311


/etc/systemd/system/roslaunch.service

This file defines a systemd service that runs your launch file. Again make sure to replace the [TODO] with your user name

[Unit]
Requires=roscore.service
PartOf=roscore.service
After=NetworkManager.service time-sync.target roscore.service
[Service]
Type=simple
User=[TODO enter user name here]
ExecStart=/usr/sbin/roslaunch
[Install]
WantedBy=multi-user.target


/usr/sbin/roslaunch

This file is responsible for running the launch file you specify. Make sure to enter your username and the name of your launch file

#!/bin/bash
source ~/catkin_ws/devel/setup.bash
source /etc/ros/env.sh
export ROS_HOME=$(echo ~[TODO unter your username here)/.ros
[TODO place your roslaunch command here] &
PID=$!
wait “$PID”

Next make you script executable and enable your systemd scripts by exceuting the following in a terminal

$ sudo systemctl enable roscore.service
$ sudo systemctl enable roslaunch.service
$ sudo chmod +x /usr/sbin/roslaunch

Next Reboot!

Once the computer has rebooted run “$ rostopic list” to verify that ROS is now running.

Get In Touch

Need help using ROS to build an autonomous solution? Contact us to discuss our consulting capabilities.

Contact Us