1. 程式人生 > >開機自動啟動ros節點--robot_upstart

開機自動啟動ros節點--robot_upstart

1.安裝package,預設是indigo版本

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

2.執行install命令

根據自己實際工程souce下

[email protected]:/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儲存地址。

[email protected]:/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.

執行安裝後

[email protected]:/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後再修改此檔案的環境變數

[email protected]:~# 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,以後開機會自動開啟

[email protected]:/mnt# systemctl daemon-reload
[email protected]:/mnt# service kinco start