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);