I would like to launch my ROS2 nodes right after boot my PC. I'm using Ubuntu 22.04 and humble now. As far as i know, I have to make '.service' file in /etc/systemd/system to auto launch my node.
This is my service file
[Unit]
Description=Ros2 launch
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/launch.sh
Restart=on-failure
[Install]
RequiredBy=multi-user.target
and this is shell script file that i want to execute (launch.sh)
#!/bin/bash
source /opt/ros/humble/setup.bash
source /home/robot/robot_ws/install/setup.bash
source /home/robot/ydlidar_ros2_driver/install/setup.bash
ros2 launch /home/robot/ydlidar_ros2_driver/launch/ydlidar_launch.py
echo "hello"
I changed permission of my service file and shell script as 777 also, but still didn't work. Error is like follow
○ launching.service - Ros2 launch
Loaded: loaded (/etc/systemd/system/launching.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2024-04-12 19:17:38 KST; 18s ago
Process: 26374 ExecStart=/usr/local/bin/launch.sh (code=exited, status=0/SUCCESS)
Main PID: 26374 (code=exited, status=0/SUCCESS)
CPU: 1.288s
Apr 12 19:17:38 robot launch.sh[26459]: This error state is being overwritten:
Apr 12 19:17:38 robot launch.sh[26459]: 'rcutils_expand_user failed, at ./src/logging_dir.c:81'
Apr 12 19:17:38 robot launch.sh[26459]: with this new error message:
Apr 12 19:17:38 robot launch.sh[26459]: 'Failed to get logging directory, at ./src/rcl_logging_spdlog.cpp:83'
Apr 12 19:17:38 robot launch.sh[26459]: rcutils_reset_error() should be called after error handling to avoid this.
Apr 12 19:17:38 robot launch.sh[26459]: <<<
Apr 12 19:17:38 robot launch.sh[26459]: [ERROR] [launch]: Caught exception in launch (see debug for traceback): failed to initialize logging: Failed to get logging directory, at ./src/rcl_logging_spdlog.cpp:83
Apr 12 19:17:38 robot launch.sh[26374]: hello
Apr 12 19:17:38 robot systemd[1]: launching.service: Deactivated successfully.
Apr 12 19:17:38 robot systemd[1]: launching.service: Consumed 1.288s CPU time.
~
~
~
~
~
~
lines 1-17/17 (END)
First question is is there any part that i miss something. I really have no idea and if there is any other way can start node automatically right after boot the PC please I really need your help
If i change shell script (launch.sh) only small part '&'
#!/bin/bash
source /opt/ros/humble/setup.bash
source /home/robot/robot_ws/install/setup.bash &
source /home/robot/ydlidar_ros2_driver/install/setup.bash &
ros2 launch /home/robot/ydlidar_ros2_driver/launch/ydlidar_launch.py
echo "hello"
result is follow.
○ launching.service
- Ros2 launch
Loaded: loaded (/etc/systemd/system/launching.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Fri 2024-04-12 19:28:25 KST; 1s ago
Process: 26885 ExecStart=/usr/local/bin/launch.sh (code=exited, status=0/SUCCESS)
Main PID: 26885 (code=exited, status=0/SUCCESS)
CPU: 1.261s
Apr 12 19:28:24 robot systemd[1]: Started Ros2 launch.
Apr 12 19:28:25 robot launch.sh[26931]: [INFO] [launch]: All log files can be found below /root/.ros/log/2024-04-12-19-28-25-111127-robot-26931
Apr 12 19:28:25 robot launch.sh[26931]: [INFO] [launch]: Default logging verbosity is set to INFO
Apr 12 19:28:25 robot launch.sh[26931]: [ERROR] [launch]: Caught exception in launch (see debug for traceback): Caught exception when trying to load file of format [py]: "package 'ydlidar_ros2_driver' not found, searching: ['/opt/ros/humble']"
Apr 12 19:28:25 robot launch.sh[26885]: hello
Apr 12 19:28:25 robot systemd[1]: launching.service: Deactivated successfully.
Apr 12 19:28:25 robot systemd[1]: launching.service: Consumed 1.261s CPU time.
lines 1-14/14 (END)
second question is why both show different result
Thank you for read my question. If there is anything that I didn't follow the rule of community please tell me. I will fix it right away