How to call dynamic_reconfugure service of base_local_planner through code
Hello everyone!
I want to modify the max_vel_x in base_local_planner_params.yaml at runtime. I followed the tutorial Dynamic Reconfigure Python Client to create a client :
#!/usr/bin/env python
PACKAGE = 'base_local_planner'
import roslib;roslib.load_manifest(PACKAGE)
import rospy
import dynamic_reconfigure.client
if __name__ == "__main__":
rospy.init_node("blp_client")
client = dynamic_reconfigure.client.Client("base_local_planner", timeout=4, config_callback=None)
r = rospy.Rate(0.33)
while not rospy.is_shutdown():
client.update_configuration({"max_vel_x":0.06})
r.sleep()
Then I ran roslaunch my_new_robot robot_config.launch
; roslaunch my_new_robot move_base.launch
; rosrun base_local_planner blp_client.py
(since I was using navigation).
But errors were reported:
youjian@youjian-laptop:~$ rosrun base_local_planner blp_client.py
Traceback (most recent call last):
File "/home/youjian/catkin_ws/src/base_local_planner/scripts/blp_client.py", line 16, in <module>
client = dynamic_reconfigure.client.Client("base_local_planner", timeout=4, config_callback=callback)
File "/opt/ros/indigo/lib/python2.7/dist-packages/dynamic_reconfigure/client.py", line 84, in __init__
self._set_service = self._get_service_proxy('set_parameters', timeout)
File "/opt/ros/indigo/lib/python2.7/dist-packages/dynamic_reconfigure/client.py", line 305, in _get_service_proxy
rospy.wait_for_service(service_name, timeout)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 143, in wait_for_service
raise ROSException("timeout exceeded while waiting for service %s"%resolved_name)
rospy.exceptions.ROSException: timeout exceeded while waiting for service /base_local_planner/set_parameters
I dig into dynamic_reconfigure/src/dynamic_reconfigure/client.py
:
line 65: @param name: name of the server to connect to (usually the node name)
So according to the error, it can't find a node called base_local_planner. Hence, I wonder if base_local_planner is a node,since I don't find ros::init(argc, argv, "base_local_planner")
which indicates a node in any files in base_local_planner package. If base_local_planner is not a node, what should I give to the 1st paramenter of the function Client(), or is there another way to modify the max_vel_x at runtime through code not command and rqt_reconfigure gui.
The following is some codes relative to dynamic_reconfigure in base_local_planner/src/trajectory_planner_ros.cpp:
dsrv_ = new dynamic_reconfigure::Server<BaseLocalPlannerConfig>(private_nh);
dynamic_reconfigure::Server<BaseLocalPlannerConfig>::CallbackType cb = boost::bind(&TrajectoryPlannerROS::reconfigureCB, this, _1, _2);
dsrv_->setCallback(cb);
thanks in advance!
You can use
rosnode list
to view all the nodes running at a time. Alternatively you can look in your launch file to see what you have named it, but I'm guessing you are using something like move_base to spawn that node, in which case the name won't be listed.Hi, shoemakerlevy9. I have tried
rosnode list
, there is indeed not node called base_local_planner. As you said the base_local_planner was spawned by the move_base, in this case what should I give to the 1st parameter of the Clinet().thanks.