ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
5

Multiple dynamic_reconfigure servers in the same node? [Python]

asked 2011-11-30 02:09:14 -0600

updated 2018-10-25 09:35:05 -0600

Evgeny gravatar image

It is possible to have multiple dynamic_reconfigure servers in the same node?

When I try that I get this error message:

Tried to advertise a service that is already advertised in this node

Moreover, the first configuration server become unusable.

I though that it should be possible since a set of nodelets can run on the same node with different dynamic configuration servers. Or it is more complex than it seems?

Edit: Check a more updated question about this issue: https://answers.ros.org/question/2890...

edit retag flag offensive close merge delete

Comments

#q289040 is similar and much more recent than this.

lucasw gravatar image lucasw  ( 2018-05-04 15:26:30 -0600 )edit

3 Answers

Sort by » oldest newest most voted
5

answered 2012-03-28 10:35:31 -0600

updated 2012-08-16 02:12:31 -0600

This is exactly an example of what I was talking. Thanks joq. Just notice that two different node have to be created with different subnames.

Thanks. In any case IHMO it is worthnote that multiple does not seem possible in python because the dynamic_reconfigure server implementation. See

$ head -70 `rospack find dynamic_reconfigure`/src/dynamic_reconfigure/server.py

I propose a patch at the end of this response with some modification on this file to achieve this feature.

I show a example code below about how could be done it with C++.

bool configure_server_callback_a(mypkg::myconfig &config, uint32_t level)
{
  return config;
}

bool configure_server_callback_b(mypkg::myconfig &config, uint32_t level)
{
  return config;
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "test_multiple_configure");

  ros::NodeHandle nh_a("~/a");
  ros::NodeHandle nh_b("~/b");

  dynamic_reconfigure::Server<mypkg::myconfig> cfg_server_a(nh_a);
  dynamic_reconfigure::Server<mypkg::myconfig> cfg_server_b(nh_b);

  dynamic_reconfigure::Server<mypkg::myconfig>::CallbackType f_a, f_b;
  f_a = boost::bind(configure_server_callback_a, _1, _2);
  f_b = boost::bind(configure_server_callback_a, _1, _2);

  cfg_server_a.setCallback(f_a);
  cfg_server_b.setCallback(f_b);

  ros::spin();
}

To have multiple dynamic_reconfigure servers on the same node I propose the following patch for the dynamic_reconfigure source:

--- a/src/dynamic_reconfigure/server.py Sun Jan 15 19:33:19 2012 -0800
+++ b/src/dynamic_reconfigure/server.py Thu Aug 16 14:06:26 2012 +0200
@@ -51,7 +51,7 @@
 from dynamic_reconfigure.encoding import *

 class Server(object):
-    def __init__(self, type, callback):
+     def __init__(self, type, callback,namespace_prefix=""):
         self.mutex = threading.Lock()
         self.type = type
         self.config = type.defaults.copy()
@@ -61,17 +61,19 @@
         self.callback = callback
         self._clamp(self.config) 

+   self.namespace_prefix=("~/"+namespace_prefix+'/').replace('//','/')
+
         # setup group defaults
         self.config['groups'] = get_tree(self.description)
         self.config = initial_config(encode_config(self.config), type.config_description)

-        self.descr_topic = rospy.Publisher('~parameter_descriptions', ConfigDescrMsg, latch=True)
+        self.descr_topic = rospy.Publisher(self.namespace_prefix+'parameter_descriptions', ConfigDescrMsg, latch=True)
         self.descr_topic.publish(self.description);
-        
-        self.update_topic = rospy.Publisher('~parameter_updates', ConfigMsg, latch=True)
+
+        self.update_topic = rospy.Publisher(self.namespace_prefix+'parameter_updates', ConfigMsg, latch=True)
         self._change_config(self.config, type.all_level)

-        self.set_service = rospy.Service('~set_parameters', ReconfigureSrv, self._set_callback)
+        self.set_service = rospy.Service(self.namespace_prefix+'set_parameters', ReconfigureSrv, self._set_callback)

     def update_configuration(self, changes):
         with self.mutex:
@@ -89,7 +91,7 @@

     def _copy_to_parameter_server(self):
         for param in extract_params(self.type.config_description):
-            rospy.set_param('~' + param['name'], self.config[param['name']])
+            rospy.set_param(self.namespace_prefix+ param['name'], self.config[param['name']])

     def _change_config(self, config, level):
         self.config = self.callback(config, level)

edit flag offensive delete link more

Comments

If you have not already, I recommend opening a Track enhancement ticket for your patch.

joq gravatar image joq  ( 2012-08-16 04:03:17 -0600 )edit
Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2012-08-16 21:16:53 -0600 )edit

Hi in the tutorial "http://wiki.ros.org/dynamic_reconfigure/Tutorials/SettingUpDynamicReconfigureForANode" there is no node handle specified in the code, does this means if you don’t give the constructor a handle it will use some default handle?

Sentinal_Bias gravatar image Sentinal_Bias  ( 2013-12-05 12:12:37 -0600 )edit

That is the point that was being discussed in this question. As far as I tested (in fuerte) it was not possible to create multiple dynamic_reconfigure servers (in python) since you could not specify the url or namespace of the dynamic reconfigure server. Conversely, it is possible to do it in c++.

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2013-12-16 09:25:03 -0600 )edit
3

answered 2012-03-28 09:46:51 -0600

joq gravatar image

I believe you can define multiple servers using different ros::NodeHandle instances with separate subordinate namespaces.

edit flag offensive delete link more
1

answered 2012-08-16 21:39:01 -0600

AndrewStraw gravatar image

I was doing something very similar. See this gist (and this ROS ticket for why I didn't submit it). It's obsolete for me now, so I won't push on this. But in comparison to your patch, I also modified the _copy_from_parameter_server() and _change_config() methods.

edit flag offensive delete link more

Comments

Yep, thanks Andrew. I solved that and submitted a second version of the patch.

Pablo Iñigo Blasco gravatar image Pablo Iñigo Blasco  ( 2012-08-17 01:19:38 -0600 )edit

Question Tools

Stats

Asked: 2011-11-30 02:09:14 -0600

Seen: 3,535 times

Last updated: Sep 06 '18