def spawn_sdf(gazebo_name, path_to_sdf, position, orientation, static):
try:
with open (path_to_sdf, "r") as f:
xml=f.read().replace('\n', '')
if static:
root = ET.fromstring(xml) #parse the xml and retrieve the root element (sdf tag)*
static_tag = ET.Element(tag='static')
static_tag.text='true'
root.find('model').append(static_tag) # find the model tag and insert a static child
xml = ET.tostring(root) # get the new xml
print(xml)
GazeboObject.spawn_sdf_srv.wait_for_service()
resp_spawn = GazeboObject.spawn_sdf_srv(gazebo_name, xml, "/", Pose(position=position, orientation=orientation), "world")
if resp_spawn.success:
rospy.loginfo("creation of "+ gazebo_name + " successful")
return True
else:
rospy.logerr("Could not spawn "+path_to_sdf+" (from "+path_to_sdf+"), status : "+resp_spawn.status_message)
return False
except Exception as e:
rospy.logerr("Could not spawn "+path_to_sdf+" (from "+path_to_sdf+")" )
rospy.logerr(e)
return False
评论列表
文章目录