ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
2 | No.2 Revision |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
Edit: Using member-function as objects is done the same way as you'd do it without boost::bind.
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(&callback, this, _1, i));
3 | No.3 Revision |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
Edit: Using member-function as objects is done the same way as you'd do it without boost::bind.
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(&callback, boost::bind(&MyClass::callback, this, _1, i));
4 | No.4 Revision |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
Edit: Using a member-function as objects of an actual object is done the same way as you'd do it without boost::bind.
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", 1, boost::bind(&MyClass::callback, this, _1, i));
5 | No.5 Revision |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", node.subscribe(sub_name, 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
Edit: Using a member-function of an actual object is done the same way as you'd do it without boost::bind.
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe("sub_name", node.subscribe(sub_name, 1, boost::bind(&MyClass::callback, this, _1, i));
6 | No.6 Revision |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe(sub_name, 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
Edit: Using a member-function of an actual object is done the same way as you'd do it without boost::bind.
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe(sub_name, 1, boost::bind(&MyClass::callback, this, _1, i));
Edit 2: With respect to the new question, the first thing I'd try is templating the subscriber to the correct datatype:
7 | Added templated version |
Just use boost::bind to create a "virtual" callback function based on your "real" one. I haven't got the syntax for callbacks to objects in my head right now, but
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe(sub_name, 1, boost::bind(callback, _1, i));
would create 10 subscribers that are each tied to the function callback(msg_type msg, int i).
Edit: Using a member-function of an actual object is done the same way as you'd do it without boost::bind.
for (int i = 0; i < 10, i++)
sub[i] = node.subscribe(sub_name, 1, boost::bind(&MyClass::callback, this, _1, i));
Edit 2: With respect to the new question, the first thing I'd try is templating the subscriber to the correct datatype:
[...]
sub[i] = node.subscribe<sensor_msgs::JointState>(sub_name, 1, boost::bind(&Myclass::callback, this, _1, i));
[...}