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

Revision history [back]

While the ROS specific stuff looks OK on first glance, it is always helpful to post the full error message instead of just saying "invalid arguments" ;-)

I assume that the way you try to create your string is your main problem. Try

for (int i = 1; i < 6; i++)
{
  std::stringstream topicName;
  topicName << "/vrep/visionSensorData" << i;
  sub[i] = n.subscribe(topicName.str().c_str(), 1, boost::bind(&newImageTrigger_trgI, _1, i));
}

to subscribe to the topics /vrep/visionSensorData1 .. /vrep/visionSensorData6

While the ROS specific stuff looks OK on first glance, it is always helpful to post the full error message instead of just saying "invalid arguments" ;-)

I assume that the way you try to create your string is your main problem. Try

for (int i = 1; i < 6; i++)
{
  std::stringstream topicName;
  topicName << "/vrep/visionSensorData" << i;
  sub[i] = n.subscribe(topicName.str().c_str(), 1, boost::bind(&newImageTrigger_trgI, _1, i));
}

to subscribe to the topics /vrep/visionSensorData1 .. /vrep/visionSensorData6

P.S.: Oh, and look up how to write to a vector (either resize beefore the loop if you already know the final size, or use push_back() in the loop.

While the ROS specific stuff looks OK on first glance, it is always helpful to post the full error message instead of just saying "invalid arguments" ;-)

I assume that the way you try to create your string is your main problem. Try

for (int i = 1; i < 6; i++)
{
  std::stringstream topicName;
  topicName << "/vrep/visionSensorData" << i;
  sub[i] = n.subscribe(topicName.str().c_str(), 1, boost::bind(&newImageTrigger_trgI, _1, i));
}

to subscribe to the topics /vrep/visionSensorData1 .. /vrep/visionSensorData6

P.S.: Oh, and look up how to write to a vector (either resize beefore before the loop if you already know the final size, or use push_back() push_back() in the loop.loop).