ROS机器人底盘(33)-ROS程序开机自启动

1.概述

写了这么多ROSlaunch脚本,怎么才能开机就启动呢,本文介绍1种方法,使用ROSrobot_upstart包,下面以pibot_bringuppackage的bringup.launch演示

2.robot_upstart包

2.1 安装

使用pibot_install_ros.sh一键安装工具即可安装所有pibot所需要的ROS包,如需单独安装sudo apt-get install ros-{ROS_DIST}-robot-upstart

ROS_DIST即为indigo或者kinetic

2.2 设置

  • cd ~/pibot_ros/ros_ws/src && rosrun robot_upstart install pibot_bringup/launch/bringup.launch
pibot@pibot-desktop:~$ rosrun robot_upstart install pibot_bringup/launch/bringup.launch
/lib/systemd/systemd
Preparing to install files to the following paths:
 /etc/ros/kinetic/pibot.d/.installed_files
 /etc/ros/kinetic/pibot.d/bringup.launch
 /etc/systemd/system/multi-user.target.wants/pibot.service
 /lib/systemd/system/pibot.service
 /usr/sbin/pibot-start
 /usr/sbin/pibot-stop
Now calling: /usr/bin/sudo /opt/ros/kinetic/lib/robot_upstart/mutate_files
Filesystem operation succeeded.
** To complete installation please run the following command:
 sudo systemctl daemon-reload && sudo systemctl start pibot
  • 照着提示操作 sudo systemctl daemon-reload && sudo systemctl start pibot

2.3 测试

  • ps -aux | grep pibot_bringup查看进程
pibot@pibot-desktop:~/pibot_ros$ ps -aux | grep pibot_bringup
pibot    15971 96.3  0.7  85620  7488 ?        Rsl  23:26   1:13 /home/pibot/pibot_ros/ros_ws/devel/lib/pibot_bringup/pibot_driver __name:=pibot_driver __log:=/tmp/0656ed38-5ba5-11e9-be9a-b827ebff3168/pibot_driver-2.log

已经可以查到该进程了

  • rosnode list查看node
pibot@pibot-desktop:~$ rosnode list
/pibot_driver
/rosout

也可以看到2个node

  • roslaunch pibot keyboard_teleop.launch启动键盘控制程序,也可以支持控制小车了

为了验证程序是否开启启动了,重启后再次重复2.3的测试步骤即可

2.4 停止以及取消开机启动

  • 启动&停止
sudo service pibot start
sudo service pibot  stop
  • 取消
rosrun robot_upstart uninstall pibot

3 robot_upstart服务名称

可以看到上面的service名称为pibot,通过查看源码可以看到


job_name = args.job or pkg.split('_', 1)[0]

job_name取了args.job或者包名的下划线前面,上面例子args.job为空则用了pibot_bringup下划线前面即pibot

我们只需要指定job参数即可自定义
cd ~/pibot_ros/ros_ws/src && rosrun robot_upstart install pibot_bringup/launch/bringup.launch --job=mybringup

我们就可以使用sudo service mybringup start启动服务

4.总结

  • 添加启动项
cd ~/pibot_ros/ros_ws/src
rosrun robot_upstart install pibot_bringup/launch/bringup.launch --job=mybringup
sudo systemctl daemon-reload
  • 删除启动项
rosrun robot_upstart uninstall mybringup
  • 当次启动服务
sudo service mybringup start
  • 当次关闭服务
sudo service mybringup stop
  • 查看服务状态
sudo service mybringup status

你可能感兴趣的:(ROS机器人底盘(33)-ROS程序开机自启动)