gazeboObject.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:arm_scenario_simulator 作者: cmaestre 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号