Ask Your Question
0

Unable to establish a connection using rosbridge

asked 2012-11-18 08:25:03 -0600

Saphrosit gravatar image

updated 2012-11-29 23:19:35 -0600

Hi, I'm trying to use rosjs in order to establish a connection with a rosbridge server (and do some simple task like subscribe a topic), with no luck.

Here's my test.html:

<!DOCTYPE html>
<html>
<head>
<title>rosjs Publisher Subscriber Tutorial</title>
<script type="text/javascript" src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script>

<script>
function log(msg) {$('#log').append(msg.toString() + '<br>');  }

function start() {

    document.write("Start() called<br>");
    log("Connecting to rosbridge.");
    var node = new ros.Connection("ws://mymachinename:9090");

    node.setOnClose(function(e) {
        document.write("Disconnected or can't connect");
        log("Disconnected or Can't Connect.");
    });
    node.setOnError(function(e) {
        document.write("Unknown error");
        log("Unknown error!");
    });
    node.setOnOpen(function(e) {
        document.write("Connection established");
        log("Connection to rosbridge established.");

   //publish the time every 1000 miliseconds

    setInterval(function(){
        var currentTime=new Date();
        var hours=currentTime.getHours();
        var minutes=currentTime.getMinutes();
        var seconds=currentTime.getSeconds();
        var timeMessage="It is now "+ hours+ ":" + minutes + ":"+ seconds ;
        node.publish('/talker', 'std_msgs/String', ros.json({data: timeMessage}));
    }, 1000);

    node.subscribe('/talker', 'std_msgs/String', function(msg){        

        document.write("Subscribed");
        log(msg.data) 
    });
});
}

</script></head>
<body onload="start()" style="margin:0;padding:0;background-color:white;overflow:hidden">
<div style="font-family: fixed-width; font-size: small;" id="log"></div>

</body>
</html>

I'm launching both roscore and

rosrun rosbridge_server rosbridge.py

The problem is that on the browser I only see "Start() called", and nothing else. I don't see error messages on the server, but only

Rosbridge server started on port 9090

Any suggestion on what I'm doing wrong? I'm using fuerte and Ubuntu 12.04.

EDIT:

Since I mostly copy-pasted the code from the rosjs tutorial, can anybody tell me how can I notify the error?

edit retag flag offensive close merge delete

Comments

If you are using Google Chrome, you can hit Ctrl-Shift-J to view the debugging console to find out where your script is breaking.

Pi Robot gravatar imagePi Robot ( 2012-11-18 15:42:43 -0600 )edit

@PiRobot Thanks, that was helpful :)

Saphrosit gravatar imageSaphrosit ( 2012-11-20 04:55:39 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-11-20 04:52:21 -0600

Saphrosit gravatar image

updated 2012-11-20 04:53:49 -0600

Actually there were more than one error. This simple "helloworld" worked for me:

<!DOCTYPE html>
<html>
<head>
<title>rosjs hello world</title>
<script type="text/javascript" src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script>

<script>
function log(msg) {('#log').append(msg.toString() + '<br>');  }

function start() {

    document.write("Start() called<br>");
    var node = new ros.Connection("ws://localhost:9090");

    node.setOnClose(function(e) {
        document.write("Disconnected or can't connect");
    });
    node.setOnError(function(e) {
        document.write("Unknown error");
    });
    node.setOnOpen(function(e) {
        document.write("Connection established<br>");

        document.write("Publishing<br>");
        node.publish('/talker', 'std_msgs/String', '{"data": "Hello World" }');
        document.write("Published<br>");

        try {
            node.addHandler('/talker', function(msg){  
        document.write("Subscribed " + msg.data.toString() + "<br>"); });
        }
        catch (error) {
            document.write("error");
        }
        node.callService('/rosjs/subscribe','["/talker",-1]',function(e) { document.write("error in call");});     
    });
}

</script>

</head>
<body onload="start()" style="margin:0;padding:0;background-color:white;overflow:hidden">
<div style="font-family: fixed-width; font-size: small;" id="log"></div>
</body>
</html>
edit flag offensive delete link more

Comments

hello how would you run this

suhar gravatar imagesuhar ( 2013-03-17 19:46:18 -0600 )edit

The javascript link appears to be dead.

Toucan gravatar imageToucan ( 2019-03-18 14:59:59 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2012-11-18 08:25:03 -0600

Seen: 1,522 times

Last updated: Nov 29 '12