Indeed, also in C++ reading the urdf file contents into a string and use this string in the SpawnModel service works. Thanks for your help!
Robert Krug (Feb 23)editasked Feb 22
This post is a wiki. Anyone with karma >750 is welcome to improve it.
Hi,
In ROS electric, I want to spawn models in gazebo in a programmatic way via the /gazebo/spawn_urdf_model service. So I wrote a node implementing an according client but when I try to load models I get the following error from Gazebo: 'SpawnModel: Failure - model format is not URDF (nor COLLADA).' This also happens when I try calling the service from a terminal, e.g., rosservice call /gazebo/spawn_urdf_model '{model_name: "coke_can", model_xml: "/opt/ros/electric/stacks/simulator_gazebo/gazebo_worlds/objects/coke_can.urdf", robot_namespace: "/foo", initial_pose: {position: {x: 0, y: 0, z: 0}, orientation: {x: 0, y: 0, z: 0, w: 1}}, reference_frame: "world"}'. Trying to spawn the same object via rosrun gazebo spawn_model ... works perfectly fine. The error occurs in /gazebo/src/gazeboros.cpp in the method 'bool IsURDF(std::string model_xml)'. The TiXmlDocument which is parsed there always seems to be empty. Am I doing something wrong or is this a bug?
Thanks, -Robert-
answered Feb 22
This post is a wiki. Anyone with karma >750 is welcome to improve it.
You have to literally serialize the urdf file into a data structure. The service does not ask for the file path of the urdf, but rather the actual urdf. You might want to use the urdf parser.
I'm not sure if this works in C++ or not, but in Python, I simply read the entire contents of a urdf file directly into a string variable, and that works just fine.
Indeed, also in C++ reading the urdf file contents into a string and use this string in the SpawnModel service works. Thanks for your help!
Robert Krug (Feb 23)editAsked: Feb 22
Seen: 46 times
Last updated: Feb 22
ROS Answers is licensed under Creative Commons Attribution 3.0 Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.