Skip to content

Instantly share code, notes, and snippets.

@cmower
Last active April 27, 2023 14:52
Show Gist options
  • Save cmower/076b811cefba46b1952b86d9c1b6f4fd to your computer and use it in GitHub Desktop.
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.
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