ROS and copy-pasted objects

Report crashes, strange behaviour, or apparent bugs
Post Reply
cedric.pradalier
Posts: 3
Joined: 03 May 2013, 10:26

ROS and copy-pasted objects

Post by cedric.pradalier »

Hello,

I've just noticed that the ROS plugin behaves improperly (I think) when dealing with copy-pasted object with a non empty suffix ("#1"), at least if the publisher name is built from the name returned by simGetObjectName(handle). This is due to the fact the "#" character is invalid in ROS names, both in TFs and in topics. The attach patch (on 3.2.0) corrects this by replacing "#" with "_" in all names. I can provide the diff file on request.
This might be implemented in a more subtle way, but given that this code is normally only called at initialization, I did not bother.

Code: Select all

diff -Naur ../../ros_packages_orig/vrep_plugin/src/ROS_server.cpp vrep_plugin/src/ROS_server.cpp
--- ../../ros_packages_orig/vrep_plugin/src/ROS_server.cpp	2015-02-17 16:01:30.407267833 +0100
+++ vrep_plugin/src/ROS_server.cpp	2015-02-17 16:04:51.137648058 +0100
@@ -54,10 +54,18 @@
 
 static std::string objNameToFrameId(const std::string & name) 
 {
-	std::string slash("/");
-	if (name[0] == '/') 
-		return(name);
-	return(slash+name);
+	std::string slash("/"), out;
+	if (name[0] == '/') {
+		out = name;
+    } else {
+		out = slash + name;
+    }
+    for (size_t i=0;i<out.size();i++) {
+        if (out[i]=='#') {
+            out[i] = '_';
+        }
+    }
+    return out;
 }
 
 struct SPointCloudPublisherData : public SSpecificPublisherData
@@ -314,6 +322,11 @@
 	}
 	// 2. Check if we have already such a topic name. If yes, generate a new name:
 	std::string nm(topicName);
+    for (size_t i=0;i<nm.size();i++) {
+        if (nm[i] == '#') {
+            nm[i]='_';
+        }
+    }
 	ind=getPublisherIndexFromTopicName(topicName);
 	if ( (ind==-1)&&(nm.compare("info")==0) )
 	{ // special case: the info stream is handled differently (always active when V-REP is running, not only during simulations)
@@ -2046,7 +2059,13 @@
 	if (streamCmd>=simros_strmcmdreserved_start)
 		return(-1);
 	// 2. Try to add a new subscriber with the given topic name:
-	CSubscriberData* sub=new CSubscriberData(node,topicName,queueSize,streamCmd,auxInt1,auxInt2,auxString,callbackTag_before,callbackTag_after,&images_streamer,imgStreamerCnt);
+	std::string nm(topicName);
+    for (size_t i=0;i<nm.size();i++) {
+        if (nm[i] == '#') {
+            nm[i]='_';
+        }
+    }
+	CSubscriberData* sub=new CSubscriberData(node,nm.c_str(),queueSize,streamCmd,auxInt1,auxInt2,auxString,callbackTag_before,callbackTag_after,&images_streamer,imgStreamerCnt);
 	if (sub->getIsValid())
 	{
 		subscribers.push_back(sub);

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: ROS and copy-pasted objects

Post by coppelia »

Good catch, thanks Cedric!

The underscore char might also be used in an object name in V-REP, so, is there a special char that we might use that works for ROS and that is not one of the following?
  • Regular alphabet chars (small and capital)
  • Numbers
  • '_'
  • '('
  • ')'
Cheers

cedric.pradalier
Posts: 3
Joined: 03 May 2013, 10:26

Re: ROS and copy-pasted objects

Post by cedric.pradalier »

You're right, an object name_0 (without suffix) would conflict with name#0. The only reliable way I can think of is to replace the # with a /. I can't see a situation where we would have an ambiguity unless someone explicitly forces a name with a "/0" in the lua code.

The topic names are discussed in http://wiki.ros.org/Names and you'll see that there is not much freedom.

Post Reply