调用服务
callserver_demo.py
#!/usr/bin/env python
import rospy
from std_srvs.srv import Empty
if __name__ == "__main__":
rospy.init_node('service_demo',anonymous=True)
rospy.wait_for_service('/move_base/clear_costmaps')
clear_costmap = rospy.ServiceProxy('move_base/clear_costmaps', Empty)
r = rospy.Rate(0.2)
r.sleep()
rospy.loginfo("clear_costmap...")
clear_costmap()
上面代码完成/move_base/clear_costmaps
服务的调用,即等于rosservice call /move_base/clear_costmaps
动态设置参数
通过rosrun rqt_reconfigure rqt_reconfigure
设置参数改为使用代码调用修改
reconfigure_demo.py
import rospy
import dynamic_reconfigure.client
if __name__ == "__main__":
rospy.init_node('reconfigure_demo',anonymous=True)
client = dynamic_reconfigure.client.Client("/move_base/DWAPlannerROS", timeout=4, config_callback=None)
client.update_configuration({"xy_goal_tolerance":0.05})
上面代码完成/move_base/DWAPlannerROS/xy_goal_tolerance
,设置完成后通过rosrun rqt_reconfigure rqt_reconfigure
或者rosparam get /move_base/DWAPlannerROS/xy_goal_tolerance
可以查看到该参数是否被修改