概述
想要实现ROS的开机自启,您需要完成一下文件的创建!用sudo gedit 文件名.后缀 创建文件
/etc/systemd/system/roscore.service
该文件将启动roscore,您需要确保在[TODO]处填写用户名,并将动力学更改为所使用的ROS版本。
[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
此文件存储您的环境变量
#!/bin/sh
export ROS_HOSTNAME=$(hostname).localexport ROS_MASTER_URI=http://$ROS_HOSTNAME:11311
/etc/systemd/system/roslaunch.service
该文件定义了运行启动文件的systemd服务。再次确保用您的用户名替换[TODO]
[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
该文件负责运行您指定的启动文件。确保输入您的用户名和启动文件的名称
#!/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”
接下来,通过在终端中执行以下操作,使脚本可执行文件并启用systemd脚本
$ sudo systemctl enable roscore.service
$ sudo systemctl enable roslaunch.service
$ sudo chmod +x /usr/sbin/roslaunch
计算机重新启动后,运行“ $ rostopic list”以验证ROS是否正在运行。
最后
以上就是曾经手链为你收集整理的(7)ROS开机自启动一的全部内容,希望文章能够帮你解决(7)ROS开机自启动一所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复