开机自动启动ros节点--robot_upstart

1.安装package,默认是indigo版本

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

2.执行install命令

根据自己实际工程souce下

root@RK3399:/mnt# source devel_isolated/setup.bash

安装launch

rosrun robot_upstart install cartographer_turtlebot/launch/kinco_start.launch --job kinco --logdir /root/.ros/log

cartographer_turtlebot是工程包名,kinco_start.launch是需要自动启动的launch,--job指定别名,--logdir指定log保存地址。

rosrun robot_upstart install 命令帮助

root@RK3399:/mnt# rosrun robot_upstart install -h                                                                                  
usage: install [-h] [--job JOB] [--interface ethN] [--user NAME]
               [--setup path/to/setup.bash] [--rosdistro DISTRO]
               [--master http://MASTER:11311] [--logdir path/to/logs]
               [--augment] [--provider [upstart|systemd]] [--symlink]
               pkg/path [pkg/path ...]

Use this tool to quickly and easily create system startup jobs which run one
or more ROS launch files as a daemonized background process on your computer.
More advanced users will prefer to access the Python API from their own setup
scripts, but this exists as a simple helper, an example, and a compatibility
shim for previous versions of robot_upstart which were bash-based.

positional arguments:
  pkg/path              Package and path to install job launch files from.
                        Make sure the path starts with the package name (e.g.
                        don't pass absolute path nor a path starting from
                        workspace top folder etc.)

optional arguments:
  -h, --help            show this help message and exit
  --job JOB             Specify job name. If unspecified, will be constructed
                        from package name.
  --interface ethN      Specify network interface name to associate job with.
  --user NAME           Specify user to launch job as.
  --setup path/to/setup.bash
                        Specify workspace setup file for the job launch
                        context.
  --rosdistro DISTRO    Specify ROS distro this is for.
  --master http://MASTER:11311
                        Specify an alternative ROS_MASTER_URI for the job
                        launch context.
  --logdir path/to/logs
                        Specify an a value for ROS_LOG_DIR in the job launch
                        context.
  --augment             Bypass creating the job, and only copy user files.
                        Assumes the job was previously created.
  --provider [upstart|systemd]
                        Specify provider if the autodetect fails to identify
                        the correct provider
  --symlink             Create symbolic link to job launch files instead of
                        copying them.

运行安装后

root@RK3399:/mnt# rosrun robot_upstart install cartographer_turtlebot/launch/kinco_start.launch --job kinco --logdir /root/.ros/log
/lib/systemd/systemd
Preparing to install files to the following paths:
  /etc/ros/kinetic/kinco.d/.installed_files
  /etc/ros/kinetic/kinco.d/kinco_start.launch
  /etc/systemd/system/multi-user.target.wants/kinco.service
  /lib/systemd/system/kinco.service
  /usr/sbin/kinco-start
  /usr/sbin/kinco-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 kinco

3.添加systemd需要的环境变量

查看变量位置 /lib/systemd/system/kinco.service。次文件在upstart安装后会自动改变,需要安装ros launch后再修改此文件的环境变量

root@RK3399:~# systemctl status kinco
* kinco.service - "bringup kinco"
   Loaded: loaded (/lib/systemd/system/kinco.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2016-02-12 00:28:01 CST; 2 years 7 months ago
 Main PID: 521 (kinco-start)

根据自己工程的实际情况修改环境变量

# THIS IS A GENERATED FILE, NOT RECOMMENDED TO EDIT.

[Unit]
Description="bringup kinco"
After=network.target

[Service]
Type=simple
Environment="HOME=/root"
EnvironmentFile=-/mnt/src/config/param/environ.kinco
ExecStart=/usr/sbin/kinco-start

[Install]
WantedBy=multi-user.target

4.启动launch,以后开机会自动开启

root@RK3399:/mnt# systemctl daemon-reload
root@RK3399:/mnt# service kinco start

 

你可能感兴趣的:(ros,ros,upstart,systemd,ros)