ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
<html> <head> <script type="text/javascript" src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script> <script type="text/javascript"> function nop() {} /* console for logging */ var console = null;
function pub()
{
var connection2 = new ros.Connection("ws://127.0.0.1:9090");
connection2.setOnOpen(function (e) {
log('connected to ros for 2nd time');
log('attempting to send message over 2nd socket connection.');
connection2.publish('/recognizer/output', 'std_msgs/String', '{"data":' + '"On Pub Button Click Message"' + '}');
});
}
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
var connection2 = new ros.Connection("ws://127.0.0.1:9090");
connection2.setOnOpen(function (e) {
log('connected to ros for 2nd time');
log('attempting to send message over 2nd socket connection.');
connection2.publish('/recognizer/output', 'std_msgs/String', '{"data":' + '"On Display Date Button"' + '}');
});
}
function log(msg) {
console.innerHTML = console.innerHTML + msg + "<br/>";
}
function init() {
function waitForDOM() {
var cnsl = document.getElementById('console');
if (cnsl == null) {
setTimeout(waitForDOM, 100);
} else {
console = cnsl;
setTimeout(main, 0);
}
}
setTimeout(waitForDOM, 100);
}
function main() {
log('console initialized');
var connectInfo = document.location.toString();
log('url: ' + connectInfo);
var addressMatches = connectInfo.match(/address=([^&]*)/);
if (addressMatches == null) {
log('Problem extracting address!');
return;
}
var address = addressMatches[1];
log('address: ' + address);
var portMatches = connectInfo.match(/.*&port=([^&]*)/);
if (portMatches == null) {
log('Problem extracting port!');
return;
}
var port = portMatches[1];
log('port: ' + port);
log('creating ROSProxy connection object...');
var connection = null;
try {
connection = new ros.Connection('ws://' + address + ':' + port);
} catch (err) {
log('Problem creating proxy connection object!');
return;
}
log('created');
log('connecting to ' + address + ' on port ' + port + '...');
connection.setOnClose(function (e) {
log('connection closed');
});
connection.setOnError(function (e) {
log('network error!');
});
connection.setOnOpen(function (e) {
log('connected');
log('initializing ROSProxy...');
try {
connection.callService('/rosjs/topics', '[]', nop);
} catch (error) {
log('Problem initializing ROSProxy!');
return;
}
log('initialized');
log('running');
log('trying to publish a message');
connection.publish('/recognizer/output', 'std_msgs/String', '{"data":' + '"On Page Load Message"' + '}');
});
}
</script>
</head>
<body onload="init()">
<div id="console"></div>
<h1>Rosbridge Test Page</h1>
This page shows how to publish messages with json over rosbridge on page load and on button click event
<button type="button" onclick="displayDate()">Display Date</button> <button type="button" onclick="pub()">Publish String Message</button> </body> </html>
2 | No.2 Revision |
<html>
<head>
<html> <head> <script type="text/javascript" src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script>
src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script> <script type="text/javascript">
type="text/javascript"> function nop() {}
{} /* console for logging */
*/ var console = null;
});
}
function displayDate() { document.getElementById("demo").innerHTML=Date(); var
log('creating ROSProxy connection object...');
This
<p id="demo">This
page shows how to publish messages with json over rosbridge on page load and on button click <button type="button" onclick="displayDate()">Display Date</button>
<button type="button" onclick="pub()">Publish String Message</button>
</body>
Message</button> </body> </html>
3 | No.3 Revision |
<html> <head> <script type="text/javascript" src="http://brown-ros-pkg.googlecode.com/svn/tags/brown-ros-pkg/rosbridge/ros.js"></script> <script type="text/javascript"> function nop() {} /* console for logging */ var console = null;
function pub()
{
var connection2 = new ros.Connection("ws://127.0.0.1:9090");
connection2.setOnOpen(function (e) {
log('connected to ros for 2nd time');
log('attempting to send message over 2nd socket connection.');
connection2.publish('/recognizer/output', 'std_msgs/String', '{"data":' + '"On Pub Button Click Message"' +
}