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

Get list of topics via rosbridge and websocket

asked 2013-10-01 02:23:06 -0600

tropic gravatar image

I am currently using rosbridge 2.0 to communicate with ROS via websocket. In connection with this I would like to retrieve a list of all topics through my interface. As I can read from the rosbridge website it should be possible to retrieve a list of topics currently running in ROS via a service call, however, I cannot figure out how this should be done since there are no examples. There is a link on the rosbridge website to a pdf with more information, but this link is unfortunately outdated and does not work.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
0

answered 2013-10-01 07:22:48 -0600

tropic gravatar image

So I can answer this question myself now. I do not know what I was thinking when implementing this, because I already did it successfully for reading topics. I simply forgot to serialize my message as a JSON object. Now that I have done that, I can retrieve all available ROS topics.

For calling the topics and services I also found these two links very useful: http://docs.ros.org/hydro/api/rosapi/html/index-msg.html https://github.com/RobotWebTools/rosbridge_suite/blob/groovy-devel/ROSBRIDGE_PROTOCOL.md

edit flag offensive delete link more
1

answered 2013-10-01 04:45:14 -0600

Pi Robot gravatar image

This function appears to do the trick under ROS Groovy and Ubuntu 12.04. However, the function doesn't always seem to return the list of topics (especially if run immediately after loading the webpage) and I'm guessing it's because it's not waiting for the result from the service call (although that is only a guess). Is there a "wait_for_service" or "timeout" parameter for rosbridge service calls?

function getTopics() {
    var topicsClient = new ROSLIB.Service({
    ros : ros,
    name : '/rosapi/topics',
    serviceType : 'rosapi/Topics'
    });

    var request = new ROSLIB.ServiceRequest();

    topicsClient.callService(request, function(result) {
    console.log("Getting topics...");
    console.log(result.topics);
    });
};
edit flag offensive delete link more

Comments

Hello, i tried that and it works. But i cant return the result from the function. Do you know how to return that ?

Eduardo Soares gravatar image Eduardo Soares  ( 2019-09-23 11:54:48 -0600 )edit
1

answered 2013-10-01 02:45:39 -0600

rtoris288 gravatar image

updated 2017-02-03 02:36:56 -0600

Here is an example in JavaScript on how to make the call, but the service call can easily be ported to other languages as well:

https://github.com/RobotWebTools/rosl...

edit flag offensive delete link more

Comments

So it should look something like this if you also look at the service call on the rosbridge website? {'op': 'call_service', 'service': '/rosapi/topics', 'arg': 'rosapi/Topics'}. However, I get the "Unable to deserialize message..." when sending this. Any suggestions?

tropic gravatar image tropic  ( 2013-10-01 03:25:54 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-10-01 02:23:06 -0600

Seen: 5,076 times

Last updated: Feb 03 '17