## For instruction on writing tutorials ## http://www.ros.org/wiki/WritingTutorials #################################### ##FILL ME IN #################################### ## for a custom note with links: ## note = This tutorials assumes that you have completed [[dynamic_reconfigure/Tutorials/SettingUpDynamicReconfigureForANode(python)| Setting up Dynamic Reconfigure for a Node(python)]] or [[dynamic_reconfigure/Tutorials/SettingUpDynamicReconfigureForANode(cpp)|(c++)]] ## for the canned note of "This tutorial assumes that you have completed the previous tutorials:" just add the links ## note.0= ## descriptive title for the tutorial ## title = Using the Dynamic Reconfigure Python Client ## multi-line description to be displayed in search ## description = This tutorial cover basic setup and usage of the dynamic_reconfigure client. ## the next tutorial description (optional) ## next = ## links to next tutorial (optional) ## next.0.link= ## next.1.link= ## what level user is this tutorial for ## level= (BeginnerCategory, IntermediateCategory, AdvancedCategory) ## keywords = #################################### <> <> = The Code = Now that we have a node that we can reconfigure, we need to write a node to reconfigure it. Create a file called client.py in the nodes directory and add the following code to it: {{{#!python #!/usr/bin/env python import rospy import dynamic_reconfigure.client def callback(config): rospy.loginfo("Config set to {int_param}, {double_param}, {str_param}, {bool_param}, {size}".format(**config)) if __name__ == "__main__": rospy.init_node("dynamic_client") client = dynamic_reconfigure.client.Client("dynamic_tutorials", timeout=30, config_callback=callback) r = rospy.Rate(0.1) x = 0 b = False while not rospy.is_shutdown(): x = x+1 if x>10: x=0 b = not b client.update_configuration({"int_param":x, "double_param":(1/(x+1)), "str_param":str(rospy.get_rostime()), "bool_param":b, "size":1}) r.sleep() }}} = The Breakdown = Writing a dynamic reconfigure client is very simple: {{{#!python #!/usr/bin/env python import rospy import dynamic_reconfigure.client }}} We first import rospy and dynamic_reconfigure.client. {{{#!python def callback(config): rospy.loginfo("Config set to {int_param}, {double_param}, {str_param}, {bool_param}, {size}".format(**config)) }}} We then define a callback which will print the config returned by the server. There are two main differences between this callback and the servers, one it does not need to return an updated config object, two it does not have the "level" argument. This callback is optional. {{{#!python if __name__ == "__main__": rospy.init_node("dynamic_client") client = dynamic_reconfigure.client.Client("dynamic_tutorials", timeout=30, config_callback=callback) r = rospy.Rate(0.1) x = 0 b = False while not rospy.is_shutdown(): x = x+1 if x>10: x=0 b = not b client.update_configuration({"int_param":x, "double_param":(1/(x+1)), "str_param":str(rospy.get_rostime()), "bool_param":b, "size":1}) r.sleep() }}} Lastly we initialize ROS and our Client. Our main loop runs once every ten seconds and simply calls {{{update_configuration}}} on the client every time. Note that you need not use a full configuration and could also pass in a dictionary with only one of the parameters as well. = Run It! = Once again make the node executable: {{{chmod +x nodes/client.py}}} Launch a core and your server node, and launch your new client node. If you've done everything correctly, both your client and server should begin to print out matching configurations every ten seconds. ## AUTOGENERATED DO NOT DELETE ## TutorialCategory ## DynamicReconfigureCategory ## FILL IN THE STACK TUTORIAL CATEGORY HERE