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

rosbridge how to subscribe from multi rostopic

asked 2012-07-24 11:21:20 -0500

koprenee gravatar image

I know that use such function I can use msg subscribe from the topic called /sensorPacket:

connection.callService('/rosjs/subscribe','["/sensorPacket",0]',function(rsp) { alert('subscribed to /sensorPacket'); });

But I want information from 2 topics, for example /a and /b . How can I realize? can I just use in such way:

connection.callService('/rosjs/subscribe','["/a,/b",0]',function(rsp) { alert('subscribed to /sensorPacket'); });

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
1

answered 2012-07-24 11:45:20 -0500

updated 2012-07-24 15:42:38 -0500

You can reuse callbacks for multiple subscription requests and as the handler for incoming messages.

subscription_ok_callback = function(rsp) {
    alert("subscribed to /sensorPacket");
}

connection.callService("/rosjs/subscribe", '["/a", 0]', subscription_ok_callback);
connection.callService("/rosjs/subscribe", '["/b", 0]', 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);
edit flag offensive delete link more
1

answered 2012-07-24 15:40:27 -0500

Actually, my first answer was incorrect, and I have edited it for correctness.

edit flag offensive delete link more
0

answered 2012-07-24 14:44:46 -0500

koprenee gravatar image

Actually, I can use "connection.addHandler('/a',function(msg) {.....});" to get msg from topic /a .
And what I want is to use msg from both topic /a and topic /b in the same handler.

I'm not sure there's any way to use msg from two topics in one handler.

By the way, using your example I found that rsp is "OK" but not the msg from topic, so what does the rsp's content mean? just subscribe is successful?

Thank you for your kindness!

edit flag offensive delete link more
0

answered 2012-07-24 19:26:22 -0500

koprenee gravatar image

Thank you, It's helpful for me!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-07-24 11:21:20 -0500

Seen: 574 times

Last updated: Jul 24 '12