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

How to start ROS2 node automatically after starting the system?

asked 2019-09-26 00:16:21 -0500

D0l0RES gravatar image

How to make autostart of nodes in ROS2 at system startup? I tried through rc.local and nothing good came of it.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2019-10-02 03:00:50 -0500

Dmitriy gravatar image

updated 2019-10-02 03:12:17 -0500

We use systemd service with properly defined environment variables, works fine. Example:

[Unit]
Description="Project daemon"

[Service]
Environment="ROS_DOMAIN_ID=42"
Environment="LD_LIBRARY_PATH=/opt/project/install/lib:/opt/ros/dashing/lib"
Environment="PYTHONPATH=/opt/project/install/lib/python3.6/site-packages:/opt/ros/dashing/lib/python3.6/site-packages/"
Environment="AMENT_PREFIX_PATH=/opt/project/install:/opt/ros/dashing"

ExecStart=/opt/ros/dashing/bin/ros2 launch --debug project_bringup project.launch.py
Restart=on-failure

[Install]
WantedBy=multi-user.target
edit flag offensive delete link more

Comments

1

Can you tell us more infos about that? For instance: where do you put that file? And why did you specify WantedBy ?

Andromeda gravatar image Andromeda  ( 2021-08-11 08:13:10 -0500 )edit

Can someone please explain how can I know what to put in the "Environment"? I tried to put in the paths I get when running "printenv | grep -i ROS" (I get much longer paths for some reason) but I still get "Package not found" when running the service.

Lar gravatar image Lar  ( 2023-02-13 04:33:43 -0500 )edit
-1

answered 2019-09-26 03:07:50 -0500

aPonza gravatar image

updated 2019-09-26 03:15:14 -0500

Not really a ROS-related question, but you likely want to look into cron (assuming *nix since you speak of rc.local) with @reboot, for example as seen in this article.

There are plenty of questions about the details of what else you need to do though: try googling "ros node at startup site:answers.ros.org" and see what's applicable to ROS2 as well.

EDIT: best answer for ROS1 even though I couldn't find a ROS2 equivalent of the robot_upstart package.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-09-26 00:16:21 -0500

Seen: 2,926 times

Last updated: Oct 02 '19