How to get ROS xml param from launch file using Python

lmiguelvargasf picture lmiguelvargasf · Jun 26, 2015 · Viewed 9.5k times · Source

I have a launch file which extension is xml, and I would like to get the value of a parameter. This launch file is called ardrone.launch

<!-- This is a sample lanuch file, please change it based on your needs -->
<launch>
    <node name="ardrone_driver" pkg="ardrone_autonomy" type="ardrone_driver" output="screen" clear_params="true">
        <param name="outdoor" value="1" />
        <param name="flight_without_shell" value="1" />
        <param name="max_bitrate" value="4000" />
        <param name="bitrate" value="4000" />
        <param name="navdata_demo" value="0" />
        <param name="altitude_max" value="10000" />
        <param name="altitude_min" value="50" />
        <param name="euler_angle_max" value="0.35" />
        <param name="control_vz_max" value="2000" />
        <param name="control_yaw" value="1.75" />
    </node>
</launch>

For example, I would like to get the value from altitude_max, altitude_min, and the others using python. I have to add that this file is inside a directory called launch and the file where I am calling it is at a directory called scripts, and scripts and launch are both in the same directory.

Answer

luator picture luator · Jun 26, 2015

Parameters set in a launch file are stored at the ROS parameter server.

Accessing these parameters from a python node is quite easy as is shown on this wiki page. In your case the parameters are defined as private parameters of the node (because they are defined inside the <node> tag), so you have to prefix them with ~ when accessing them:

altitude_max = rospy.get_param('~altitude_max')