ROS2: Read package version at runtime from python
Is it possible to read the version number listed in package.xml at runtime from python?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
Is it possible to read the version number listed in package.xml at runtime from python?
Answering my own question...
import os
import xml.etree.ElementTree as ET
from ament_index_python import get_package_share_directory
def get_package_version(pkg_name):
pkg_share_dir = get_package_share_directory(pkg_name)
package_xml_path = os.path.join(pkg_share_dir, "package.xml")
xmldata = ET.parse(package_xml_path)
version = xmldata.findall("version")[0].text
return version
Credit to @daniel-stonier for the suggestion.
Asked: 2021-07-26 13:58:12 -0500
Seen: 198 times
Last updated: Jul 27 '21
ROS2 Run __params not affecting node
Subscriber callback not triggering while in a while loop
How to disable Multicast in cyclone DDS?
Get all key/value pairs from custom ROS2 message
ROS2 Bag - DB3 CDR Deserialization
ROS2 interfacing with gazebo causes gzserver: symbol lookup error
rclpy fails to run on arm64 after cross-compilation
How do I use rosdep install to install individual dependencies?