在ROS工程中常常須要啓動好幾個launch文件,比較不方便,有下面兩種方法能夠更高效些:html
pkg
對應文件的包名。node
type
是CMakeList.txt中對應該文件add_executable(pcan_test src/pcan_test)
中可執行文件的名稱,在python中則是文件名,由於Python的可執行文件就是文件自己(解釋性語言,同Matlab),因此若用C++編程不要誤寫爲文件名全稱。python
name
表示節點啓動後的名稱,該名稱會覆蓋ros::init
中初始化的名稱。web
output
後參數表示從屏幕輸出打印信息,不然打印信息會存儲到某個臨時文件裏。
shell
<launch>
<node pkg="uav_dl" name="position_control" type="position_control.py" output="screen" />
<node pkg="uav_dl" name="action_control" type="action_control.py" output="screen" />
<node pkg="uav_dl" name="goto_position_server" type="goto_position_server.py" output="screen" />
<node pkg="uav_dl" name="detect_object_server" type="detect_object_server.py" output="screen" />
<node pkg="uav_dl" name="tensorflow_detection" type="tensorflow_detection.py" output="screen" />
</launch>
注:只須要在src下創建launch文件夾,而後在其中建立launch文件便可,不須要作其餘工做。編程
參數裏name
是ros::param::get()
中第一個字符串去掉「~
」後的名稱,launch會在運行時進行查找匹配,type
是變量類型,value
是具體值。如下launch文件(包含私有變量和公有變量)。
ubuntu
<launch>
<arg name="fcu_url" default="serial:///dev/ttyACM0:921600" />
<arg name="gcs_url" default="udp://:14556@192.168.150.2:14550" />
<arg name="tgt_system" default="1" />
<arg name="tgt_component" default="50" />
<node name="mavros" pkg="mavros" type="mavros_node" output="screen">
<param name="fcu_url" value="$(arg fcu_url)" />
<param name="gcs_url" value="$(arg gcs_url)" />
<param name="target_system_id" value="$(arg tgt_system)" />
<param name="target_component_id" value="$(arg tgt_component)" />
<rosparam command="load" file="$(find mavros)/launch/px4_blacklist.yaml" />
<!-- enable heartbeat send and reduce timeout -->
<param name="conn_heartbeat" value="5.0" />
<param name="conn_timeout" value="5.0" />
<!-- automatically start mavlink on USB -->
<param name="startup_px4_usb_quirk" value="true" />
</node>
<node name="camera" pkg="usb_cam" type="usb_cam_node">
<param name="video_device" value="/dev/video0" />
<param name="image_width" value="800" />
<param name="image_height" value="600" />
<param name="pixel_format" value="mjpeg" />
<param name="framerate" value="30" />
<param name="camera_frame_id" value="webcam" />
</node>
<node name="viewer" pkg="image_view" type="image_view">
<remap from="image" to="/camera/image_raw" />
</node>
</launch>
新建文件後命名爲xxx.sh
bash
#!/bin/bash
roslaunch bhand_controller bhand_controller.launch &
sleep 5
echo "bhand controller starting success!"
roslaunch beginner_tutorials bhand_force_control.launch &
sleep 0.1
wait
exit 0
代碼解釋:第一行表示用bash執行,sleep
表示演示,echo
用來輸出必定內容,注意不要忘記句子後的」&
「符號。注:若ROS的關鍵詞不能在終端識別,需先source下ROS環境。ide
節點啓動順序控制策略就是若是某個節點必須先執行,能夠單獨爲其寫一個launch文件,而後經過shell控制先行啓動。ui