How to start ros2 publisher right after boot

asked 2022-11-14 01:13:24 -0500

hodudu gravatar image

updated 2022-11-14 01:50:03 -0500

ravijoshi gravatar image

Hello,

I have tried to start ros2 publisher with *.service(systemd).

.service file is

[Unit]
Description=XXX_script
After=multi-user.target

[Service]
Type=oneshot
Environment="HOME=root"
ExecStart=/bin/bash -c 'source /opt/ros/eloquent/setup.bash; source /home/manager/robot_ws/install/setup.bash; /home/manager/robot_ws/src/prepare/start_publisher.sh'
RemainAfterExit=true

[Install]
WantedBy=multi-user.target

start_publisher.sh is

#!/bin/sh

/bin/bash -c "source /opt/ros/eloquent/setup.bash"
sleep 0.5
/bin/bash -c "source /home/manager/robot_ws/install/setup.bash"
ros2 run demo_nodes_cpp talker

I got error messages like below.

manager@manager-desktop:~$ sudo systemctl status fw-run_ros2_publisher.service
● fw-run_ros2_publisher.service - Prepare for phm controller
   Loaded: loaded (/lib/systemd/system/fw-run_ros2_publisher.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2022-11-14 16:00:56 KST; 9min ago
  Process: 6050 ExecStart=/bin/bash -c source /opt/ros/eloquent/setup.bash; source /home/manager/robot_ws/install/setup.bash; /home/manager/robot_ws/src/prepare/start_publisher.sh (code=exited, status=250)
 Main PID: 6050 (code=exited, status=250)

Nov 14 16:00:55 manager-desktop bash[6050]: with this new error message:
Nov 14 16:00:55 manager-desktop bash[6050]:   'context is zero-initialized, at /tmp/binarydeb/ros-eloquent-rcl-0.8.5/src/rcl/context.c:52'
Nov 14 16:00:55 manager-desktop bash[6050]: rcutils_reset_error() should be called after error handling to avoid this.
Nov 14 16:00:55 manager-desktop bash[6050]: <<<
Nov 14 16:00:55 manager-desktop bash[6050]: [ERROR] [rclcpp]: failed to finalize context: context is zero-initialized, at /tmp/binarydeb/ros-eloquent-rcl-0.8.5/src/rcl/context.c:52
Nov 14 16:00:55 manager-desktop bash[6050]: terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
Nov 14 16:00:55 manager-desktop bash[6050]:   what():  failed to initialize rcl: error not set
Nov 14 16:00:56 manager-desktop systemd[1]: fw-run_ros2_publisher.service: Main process exited, code=exited, status=250/n/a
Nov 14 16:00:56 manager-desktop systemd[1]: fw-run_ros2_publisher.service: Failed with result 'exit-code'.
Nov 14 16:00:56 manager-desktop systemd[1]: Failed to start XXX_script.

Could anyone tell me how to resolve this error messages?

Thank you.

edit retag flag offensive close merge delete

Comments

With ROS1 you could follow this tutorial: https://roboticsbackend.com/make-ros-... (robot_upstart package) - maybe there is a similar package for ROS2? I found this discussion and this about it, worth a read

ljaniec gravatar image ljaniec  ( 2022-11-14 06:45:17 -0500 )edit