ubuntu系统使ROS程序开机启动方式汇总

一. 使用ubuntu系统相关方法

这种方法就是自己创建一个脚本文件,脚本中会配置ros的环境以及launch对应文件的命令

1.1 先创建一个脚本文件

  • 新建一个.sh文件,名字自启
  • 编辑脚本内容
  • eg:
#!/bin/bash
#配置环境
source /opt/ros/kinetic/setup.bash
source /home/omen/catkin_ws/devel/setup.bash
#配置rosTCP通信的IP地址
export ROS_IP=192.168.27.23
export ROS_MASTER_URI=http://192.168.27.23:11311
#执行对应的launch文件
roslaunch package_name xxx.launch
  • 给定脚本可执行权限
sudo chmod 777 xxx.sh

1.2 配置开机启动脚本

有两种方法,如下

使用ubuntu自带应用配置

首先打开终端,输入命令打开软件

gnome-session-properties

或者在屏幕左上角的搜索中输入:开机启动管理(中文)或者 Startup Applications Preferences(英文),也可以打开应用

然后可以新建一个启动项, 编辑对应内容

  • name : 名字
  • command : 命令,eg:gnome-terminal -x your_command.sh
  • comment :注释

注意:sh文件的权限,必须是可运行的, 路径为绝对路径!!!

即可完成配置

使用rc.local配置启动

ubuntu开机启动会自动执行rc.local文件中的内容,所以我们只需要编辑rc.local文件即可,这样不需要图形界面也可以配置,对于远程连接用户比较友好

sudo gedit /etc/rc.local

打开后如下

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0

我们可以在 exit 0 的上一行添加我们需要启动的脚本文件的路径即可,注意是绝对路径

即可完成配置

二. 使用ros功能包 robot-upstart

2.1 二进制安装功能包

sudo apt-get install ros-kinetic-robot-upstart

注:ros-kinetic-robot-upstart 是对应ros版本为kinetic,其他版本自行替换版本号即可

2.2 注册需要自启动的服务

roscore
rosrun robot_upstart install diff_bringup/launch/bringup.launch

注意:

  • 运行之后对应自启动的服务名称,默认是工程名(下划线之前的部分)
  • 运行之后可能会提示执行一行命令,执行即可

现在建立的service名称为diff,下面均以diff为例

使用以下命令开启对应服务

sudo service diff start

可以使用 以下命令查看已有服务名称

service --status-all

使用以下命令关闭对应服务

sudo service diff stop

使用以下命令卸载开机自启动服务

rosrun robot_upstart uninstall diff
  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值