其实就是调参嘛。
代码调参,外部手动调参。
rosparam 有什么功能
先看看有什么。打开一个乌龟先。
roscore
rosrun turtlesim turtlesim_node
来看看有什么参数。
rosparam list
整容前
动刀子吧。
**记得要刷新一下,在乌龟里面的service调用 rosservice call /call "{}"
还可以把现在的参数保存下来,下次直接套上。
rosparam dump xxxxx.yaml
这个就是保存文件。
下次要弄个一样的龟,就跑一下
rosparam load xxxx.yaml
记得刷新一下。
这个就是外部手动调参了。
来个代码调参。还是在scripts里面新增文件,parameter_config.py
#!/usr/bin/env python
import sys
import rospy
from std_srvs.srv import Empty
def parameter_config():
rospy.init_node('parameter_config', anonymous=True)
red = rospy.get_param('/turtlesim/background_r')
green = rospy.get_param('/turtlesim/background_g')
blue = rospy.get_param('/turtlesim/background_b')
rospy.loginfo("Get Background Color[%d, %d, %d]", red, green, blue)
rospy.set_param('/turtlesim/background_r', 255)
rospy.set_param('/turtlesim/background_g', 255)
rospy.set_param('/turtlesim/background_b', 255)
rospy.loginfo("Set Backgound Color[255, 255, 255]")
red = rospy.get_param('/turtlesim/background_r')
green = rospy.get_param('/turtlesim/background_g')
blue = rospy.get_param('/turtlesim/background_b')
rospy.loginfo("Get New Background Color[%d, %d, %d]", red, green, blue)
rospy.wait_for_service('/clear')
try:
clear_background = rospy.ServiceProxy('/clear', Empty)
reponse = clear_background()
return reponse
except rospy.ServiceException, e:
print "Service call failed: %s" %e
if __name__ == "__main__":
parameter_config()
可以跑一下了。
就是换个色而已。。。
***不知道什么问题,我有时候跑不出来。有时候就可以。这还要看RP的?