Skip to content
Advertisement

How to pass arguments to ros launch file from bash script and how to create ros launch file running python script with those parser arguments

I have a python script which runs as follows:

JavaScript

I have launch file are follows:

JavaScript

Bash script as:

JavaScript

I want to pass this foldername in bash to roslaunch file (cam_calibrator.launch) as above, then get that folder-name as argument and send that to my python script “cameracalibrator.py” just like –size, –square and image:=/topic_name arguments as well to the image_pub_sub c++ script.

Also how to send those size and square arguments to python script in launch file?

Can anyone let me now please?

Advertisement

Answer

The roslaunch command line accept arguments, so yes it is possible to do this.

In your launch file, you must declare the arguments like this :

JavaScript

Then, you want to check the list of parameters supported by the nodes that you are using. Typically, I see that you are using the node cameracalibrator.py. If this node is well written, it defines to ROS the parameters that it uses, like image (which I am assuming is a ROS topic name). Once you know which parameter your node needs, you can provide it to ROS in your launch file like this:

(in this case, I am using the image parameter since it is the only one from your question where I am sure it is a normal ROS parameter)

JavaScript

Once you have such a ros launch file, you can call it with:

JavaScript

PS: it is recommended to use #!/usr/bin/env bash (or sh) instead of #!/bin/sh

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement