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: 193 times
Last updated: Jul 27 '21
ROS2 Bag - DB3 CDR Deserialization
ros2 node list doesn not show node - Raspberry Pico
State of ROS2 on embedded MCUs
Difference in build_depend in package format 3 vs. package format 2
Is there a way to avoid having to "colcon build" every time I edit Python code?
how to organize data transfer between nodes on multiple PCs on ROS2
[ROS2-foxy] where to place source and header files and how to link them?
Nav2 lifecycle nodes don't autostart
Issue with creating a workspace (ROS2)
Using Occupancy Grids with ROS 2: frame problem and probability map