Unable to establish a connection using rosbridge
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?
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.
@PiRobot Thanks, that was helpful :)