ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to write proper launch file by passing arguments?

asked 2020-11-02 08:59:32 -0500

Booooyaaaa gravatar image

I trying to write launch file. But i could not find proper solution anywhere.

Python code:

parser = argparse.ArgumentParser(description='Script to run MobileNet-SSD object detection network ')
parser.add_argument("--prototxt", default="/home/user/catkin_ws/src/human_ssd/model/MobileNetSSD_deploy.prototxt",
                                  help='Path to text network file: '
                                       'MobileNetSSD_deploy.prototxt for Caffe model or '
                                       )
parser.add_argument("--weights", default="/home/user/catkin_ws/src/human_ssd/model/MobileNetSSD_deploy.caffemodel",
                                 help='Path to weights: '
                                      'MobileNetSSD_deploy.caffemodel for Caffe model or '
                                      )
parser.add_argument("--thr", default=0.5, type=float, help="confidence threshold to filter out weak detections")
args = parser.parse_args(rospy.myargv()[1:])

Launch fie:

 <include file="$(find realsense2_camera)/launch/rs_camera.launch">
        <arg name="filters" default="temporal,spatial,hole_filling,decimation"/>
        <arg name="align_depth" default="true"/>
  </include>

  <arg name="--prototxt" default="$(find human_ssd)/model/MobileNetSSD_deploy.prototxt"/>
  <arg name="--thr"   default="0.3"/>
  <arg name="--weights" default="$(find human_ssd)/model/MobileNetSSD_deploy.caffemodel"/>

  <node pkg="human_ssd" type="detector.py" name="human_ssd_detector" output="screen">
        <param name="--prototxt" value="$(arg --prototxt)"/>
        <param name="--thr" value="$(arg --thr)"/>
        <param name="--weights" value="$(arg --weights)"/>
  </node>

So If i run command

roslaunch human_ssd detector.launch thr:=0.3

The thr takes the value of 0.5

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-11-02 10:21:16 -0500

Booooyaaaa gravatar image

Here I go answering my own question. XD

I changed the launch file in this way:

<launch>


  <arg name="filters" default="temporal,spatial,hole_filling,decimation"/>
  <arg name="align_depth" default="true"/>
  <arg name="prototxt" default="/home/user/catkin_ws/src/human_ssd/model/MobileNetSSD_deploy.prototxt"/>
  <arg name="thr"  default="0.3"/>
  <arg name="weights" default="/home/user/catkin_ws/src/human_ssd/model/MobileNetSSD_deploy.caffemodel"/>



  <include file="$(find realsense2_camera)/launch/rs_camera.launch">
  <arg name="filters" value="$(arg filters)"/>
  <arg name ="align_depth" value="$(arg align_depth)"/>
  </include>

  <node pkg="human_ssd" type="detector.py" name="human_ssd_detector" output="screen" args="--thr $(arg thr)  --prototxt $(arg prototxt) --weights $(arg weights)">
  </node>

</launch>

now i can easily pass my own parameters if not it will take default.

Eg:

roslaunch human_ssd detector.launch filters:=spatial thr:=0.6

the above command sets only spatial filter and changes threshold to 0.6

edit flag offensive delete link more

Question Tools

Stats

Asked: 2020-11-02 08:59:32 -0500

Seen: 978 times

Last updated: Nov 02 '20