ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
If both topics are sensor packets, and you want the same callback function to handle them both, then you would do:
callback = function(rsp) {
alert("subscribed to /sensorPacket");
}
connection.callService("/rosjs/subscribe", '["/a", 0]', callback);
connection.callService("/rosjs/subscribe", '["/b", 0]', callback);
Remember though, that callback is called for incoming messages on the topic, not as a confirmation that the subscription was successful.
2 | No.2 Revision |
If both topics are sensor packets, You can reuse callbacks for multiple subscription requests and you want as the same callback function to handle them both, then you would do:handler for incoming messages.
callback subscription_ok_callback = function(rsp) {
alert("subscribed to /sensorPacket");
}
connection.callService("/rosjs/subscribe", '["/a", 0]', callback);
subscription_ok_callback);
connection.callService("/rosjs/subscribe", '["/b", 0]', callback);
subscription_ok_callback);
message_received_callback = function(msg) {
alert("received a message: " + msg);
}
connection.addHandler("/a", message_received_callback);
connection.addHandler("/b", message_received_callback);
Remember though, that callback is called for incoming messages on the topic, not as a confirmation that the subscription was successful.