ROS启动多launch文件的小技巧

https://wangcong.net/article/ROSLaunchTips.html

launch文件中则如下进行设置:
pkg对应文件的包名。

type是CMakeList.txt中对应该文件add_executable(pcan_test src/pcan_test)中可执行文件的名称,在python中则是文件名,因为Python的可执行文件就是文件本身(解释性语言,同Matlab),所以若用C++编程不要误写为文件名全称。

name表示节点启动后的名称,该名称会覆盖ros::init中初始化的名称。

output后参数表示从屏幕输出打印信息,否则打印信息会存储到某个临时文件里。

注:只需要在src下建立launch文件夹,然后在其中创建launch文件即可,不需要做其他工作。

参数里name是ros::param::get()中第一个字符串去掉“~”后的名称,launch会在运行时进行查找匹配,type是变量类型,value是具体值。以下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>
在ubuntu下进行节点启动顺序控制的简单策略就是通过shell实现 新建文件后命名为xxx.sh
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环境。

节点启动顺序控制策略就是如果某个节点必须先执行,可以单独为其写一个launch文件,然后通过shell控制先行启动。

编写保存后,在终端要给xxx.sh执行权限,sudo chmod a+x xxx.sh,之后可通过./xxx.sh进行启动,xxx代表任意字符。有关Ubuntu shell的其他操作,可以自行查询相关资料。

Debugs
Bug:
ERROR: cannot launch node of type [ros_tensorflow/imgTalker.py]: can’t locate node [imgTalker.py] in package [ros_tensorflow]
Debug: 修改为可执行
sudo chmod +x imgTalker.py

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值