Last active
April 27, 2023 14:52
-
-
Save cmower/076b811cefba46b1952b86d9c1b6f4fd to your computer and use it in GitHub Desktop.
How to get robot description (i.e. string containing URDF) from the robot state publisher node in ROS 2 Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rclpy.node import Node | |
from rcl_interfaces.srv import GetParameters | |
class MyNode(Node): | |
def get_robot_description(self) -> str: | |
client = self.create_client( | |
GetParameters, "robot_state_publisher/get_parameters" | |
) | |
while not client.wait_for_service(timeout_sec=1.0): | |
pass | |
request = GetParameters.Request() | |
request.names = ["robot_description"] | |
future = client.call_async(request) | |
rclpy.spin_until_future_complete(self, future) | |
result = future.result() | |
return result.values[0].string_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment