[英]How to get ROS xml param from launch file using Python
I have a launch file which extension is xml, and I would like to get the value of a parameter. 我有一个扩展名是xml的启动文件,我想得到一个参数的值。 This launch file is called ardrone.launch
此启动文件名为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. 例如,我想使用python从altitude_max,altitude_min和其他人获取值。 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.
我必须补充一点,这个文件位于名为launch的目录中,我调用它的文件位于一个名为scripts的目录中,脚本和启动都在同一个目录中。
Parameters set in a launch file are stored at the ROS parameter server . 在启动文件中设置的参数存储在ROS参数服务器中 。
Accessing these parameters from a python node is quite easy as is shown on this wiki page . 从python节点访问这些参数非常简单, 如此Wiki页面所示。 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: 在您的情况下,参数被定义为节点的私有参数 (因为它们在
<node>
标记内定义),因此在访问它们时必须使用~
作为前缀:
altitude_max = rospy.get_param('~altitude_max')
对我来说,rospy.get_param(“/ ardrone_driver / altitude_max”)有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.