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: 199 times
Last updated: Jul 27 '21
subscription callback types ROS1 vs. ROS2
ROS2 topic list only working once (or any other command)
Installing ROS2-Dashing from source fails (Ubuntu 19.10 eoan)
ROS2 Run __params not affecting node
Long compile time for ROS2 interface package
rclpy fails to run on arm64 after cross-compilation
ROS2 nodes not discovered over network