Sharing c++ instance in two ros node
Hello everyone,
I recently got a problem while using ros:
Now: Let's say we have two robots, each robot has one ROS node. They need the same map for working. And the map is a instance of c++ class. Currently the map will be intialized both in robot1 and robot2, but it seems unefficient to me, because if I have 1000 robots, then the map need to be intialized in each robot.
Goal: it will be nice, if map class only need to be initialized once, and then shared between robots. With ros msg or srv seems not possible for me, since there are a lot of functions included in „Map“ class.
Thanks guys in advance! :)
Asked by YY on 2020-09-18 07:27:16 UTC
Comments
Have you looked at the map server? ROS has facilities to load a single map and let multiple subscribers it. http://wiki.ros.org/map_server
Asked by JackB on 2020-09-18 14:37:19 UTC
Hi @JackB, thanks, I just had a look. It seems map_server need to use ROS specific map format. In my usecase, the "map" class has different format than the ROS map and it has more information. It's very similar to the openDrive format. http://www.opendrive.org/docs/OpenDRIVEFormatSpecRev1.1D.pdf . So it seems to me hard to use the map_server, please correct me if I understand it wrong. :)
Asked by YY on 2020-09-18 14:46:47 UTC
Ah, well that is a little more complicated :) It looks like that format is an xml description file, which is from what I see, not natively supported by ROS. You may be able to define a custom message type link text but it seems like it will get pretty complex pretty quick. Question for you, why do you run both robots on the same node? Should you not have one node for robot1 and one node for robot2?
Asked by JackB on 2020-09-18 14:55:57 UTC
Hi @JackB, you are right, the "map" is not natively supported by ROS, that's way I created a C++ wrapper for the map information. Two robots has two different nodes, maybe I didn't explain it clearly, but they are in different nodes. And I currently cannot find a way to share memory or object in two ros nodes.
Asked by YY on 2020-09-18 14:59:56 UTC
Ah now I think I understand your problem. You should consider ROS nodelets link text. I am not an expert on this, but my understanding is that with nodelets your nodes share a common process space. This means that they share the same heap (I think), which means you can share memory between different nodes. ROS formalizes this idea with "zero copy pointer passing between publish and subscribe calls within the same node". Does this sound closer to what you are looking for?
Asked by JackB on 2020-09-18 15:11:00 UTC
I know this work for ROS messages, but not sure about sharing memory "manually" outside of the ROS interface. If you can't get your information into a ROS message maybe this won't help you?
Asked by JackB on 2020-09-18 15:13:46 UTC
Hi @JackB, thanks for your help again. I just had a look to the nodelets. It seems to me that I can still only pass the ROS msg but via c++ pointer (nodelet) instead of TCP (node). https://medium.com/@waleedmansoor/understanding-ros-nodelets-c43a11c8169e
The plugin seems something I need http://wiki.ros.org/pluginlib, not sure.
Asked by YY on 2020-09-19 03:39:40 UTC
Yes I think you can only share the data with ROS msg ConstPtr which is a limitation. I look forward to hearing about how you solve this problem if you do.
Asked by JackB on 2020-09-19 10:45:29 UTC
I'm a beginner but from my reading about ROS, it is possible to create a customized message since ROS supports serialized networks so you can send class objects.
Asked by CroCo on 2021-10-28 04:39:55 UTC
@Croco, Hi, thanks for commenting. We didn't continue to research it any more. But it's a valuable suggestion. :)
Asked by YY on 2021-10-28 12:56:44 UTC