ToB企服应用市场:ToB评测及商务社交产业平台
标题:
ubuntu20.04中设置包罗ros节点的文件自启动
[打印本页]
作者:
盛世宏图
时间:
2024-6-11 11:43
标题:
ubuntu20.04中设置包罗ros节点的文件自启动
若文件里包罗了ros话题的发布和接收,那么设置自启动时,应该首先将roscore设置为自启动。
首先确保roscore有一个systemd服务文件。如果还没有,需要在/etc/systemd/system/下创建一个。比方,一个基本的roscore.service文件大概如下所示:
[Unit]
Description=ROS Master Node
After=network.target
[Service]
Type=simple
User=your_username # 使用你的用户名
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/ros/melodic/bin # 根据需要修改
Environment=LD_LIBRARY_PATH=/opt/ros/melodic/lib:/usr/lib # 根据需要修改
ExecStart=/bin/bash -c "source /opt/ros/melodic/setup.bash && roscore"
Restart=on-failure
[Install]
WantedBy=multi-user.target
复制代码
上面文件中的 PATH 路径检察方式:打开一个终端并输入echo $PATH
LD_LIBRARY_PATH:输入echo $LD_LIBRARY_PATH来检察LD_LIBRARY_PATH
上面文件中的melodic要替换成自己的ros版本号。
我的roscore.service文件为:
[Unit]
Description=ROS Master Node
After=network.target
[Service]
Type=simple
User=ubuntu
Environment=PATH=/opt/ros/noetic/bin:/home/ubuntu/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Environment=LD_LIBRARY_PATH=/opt/ros/noetic/lib
ExecStart=/bin/bash -c "source /opt/ros/noetic/setup.bash && roscore"
Restart=on-failure
[Install]
WantedBy=multi-user.target
复制代码
然后依次运行:
sudo systemctl daemon-reload
sudo systemctl start roscore.service
sudo systemctl status roscore.service
复制代码
二、设置包罗ros节点的文件自启动
包罗ros节点的文件为terminal2car_receive.py
[Unit]
Description=Terminal to Car Receiver Service
After=network.target roscore.service
Requires=roscore.service
[Service]
Type=simple
ExecStart=/path/to/your/script_or_command_to_start_terminal2car_receive
Restart=on-failure
[Install]
WantedBy=multi-user.target
复制代码
上述文件中的/path/to/your/script_or_command_to_start_terminal2car_receive 要替换成运行terminal2car_receive.py时的完整路径。
terminal2car_receive.py的自启动服务文件名称为:terminal2car_receive.service,内容为:
[Unit]
Description=Terminal to Car Receiver Service
After=network.target roscore.service
Requires=roscore.service
[Service]
Type=simple
ExecStart=/usr/bin/env python3 /home/ubuntu/ccy/glove_car_bt/ros_udp_udp-main/src/udp_udp/scripts/terminal2car_receive.py
Restart=on-failure
[Install]
WantedBy=multi-user.target
复制代码
依次运行:
sudo systemctl daemon-reload
sudo systemctl start terminal2car_receive.service
sudo systemctl status terminal2car_receive.service
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4