本文主要是介绍ros launch的条件判断,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
launch输入参数条件判断
1. launch文件 camera.launch
根据输入参数arg1指定是否允许usb_cam节点,并设置对应的参数type
<launch><arg name="arg1" default="true"/><group if="$(arg arg1)"><node name="usb_cam" pkg="usb_cam" type="usb_cam_node" ><param name="video_device" value="/dev/video0" /><param name="image_width" value="1280" /><param name="image_height" value="720" /><param name="framerate" value="10" /><param name="pixel_format" value="mjpeg" /><param name="camera_frame_id" value="usb_cam" /><param name="io_method" value="mmap"/></node></group><node pkg="ssd_pkg" name="ssd" type="merge.py" respawn="true" output="screen"> <rosparam file="$(find ssd_pkg)../config.yaml" command="load"/></node><group ns="image"><rosparam unless="$(arg arg1)" param="type">camera_cv2</rosparam><rosparam if="$(arg arg1)" param="type">camear</rosparam><param name="camera" type="int" value="0" /><param name="confidence" type="int" value="50" /><param name="weights" value="/home/fly/catkin_ws/src/ssd_pkg/src/weights/yolov5s.pt" /></group>
</launch>
注意这里的条件判断只能使用bool类型true或false,改为其它值会报错
Value error:xxx is not a ‘bool’ type
- 运行脚本 run.sh
#! /bin/bash #执行launch
if [ $# -gt 0 ];thenroslaunch ssd_pkg merge.launch arg1:=false
elseroslaunch ssd_pkg merge.launch
fi
- 执行文件代码
if rospy.has_param('image'):image = rospy.get_param('image')confidence = image['confidence'] / 100weights = image['weights']type = image['type']print("============", image['type'])camera_detect(type, weights, confidence)
这篇关于ros launch的条件判断的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!