2015-05-29 16:21:09 -04:00
|
|
|
var ros = new ROSLIB.Ros();
|
|
|
|
|
|
2015-06-01 11:50:07 -04:00
|
|
|
ros.topics = [];
|
|
|
|
|
ros.nodes = [];
|
|
|
|
|
|
2015-06-01 12:39:59 -04:00
|
|
|
ros.recording = false;
|
|
|
|
|
|
|
|
|
|
|
2015-06-10 18:27:56 -04:00
|
|
|
ros.connectionName = 'ws://192.168.1.105:9090';
|
2015-06-01 12:39:59 -04:00
|
|
|
|
2015-05-29 16:21:09 -04:00
|
|
|
// If there is an error on the backend, an 'error' emit will be emitted.
|
|
|
|
|
ros.on('error', function(error) {
|
|
|
|
|
document.getElementById("ConnectionIPForm").className = "form-group has-warning has-feedback";
|
|
|
|
|
document.getElementById("ConnectionIPInput").value = ros.connectionName;
|
|
|
|
|
document.getElementById("ConnectionIPLabel").innerHTML = 'No connection';
|
|
|
|
|
document.getElementById("ConnectionButton").className = "btn btn-warning"
|
|
|
|
|
document.getElementById("rosbridgeconnection_badge").innerHTML = 'No connection';
|
2015-06-01 11:50:07 -04:00
|
|
|
document.getElementById("ROSNodes").innerHTML = "";
|
2015-05-29 16:21:09 -04:00
|
|
|
|
|
|
|
|
rosbridgeconnection_badge
|
|
|
|
|
console.log(error);192
|
|
|
|
|
});
|
|
|
|
|
// Find out exactly when we made a connection.
|
|
|
|
|
ros.on('connection', function() {
|
|
|
|
|
console.log('Connection made!');
|
|
|
|
|
document.getElementById("ConnectionIPForm").className = "form-group has-success has-feedback";
|
|
|
|
|
document.getElementById("ConnectionIPInput").value = ros.connectionName;
|
|
|
|
|
document.getElementById("ConnectionIPLabel").innerHTML = 'Connection made at:';
|
|
|
|
|
document.getElementById("rosbridgeconnection_badge").innerHTML = 'Connected';
|
|
|
|
|
document.getElementById("ConnectionButton").className = "btn btn-success"
|
2015-06-10 18:27:56 -04:00
|
|
|
|
2015-05-29 16:21:09 -04:00
|
|
|
|
2015-06-01 11:50:07 -04:00
|
|
|
ros.nodes = [];
|
|
|
|
|
ros.topics = [];
|
2015-06-10 18:27:56 -04:00
|
|
|
|
2015-05-29 16:21:09 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ros.on('close', function() {
|
|
|
|
|
console.log('Connection closed.');
|
2015-06-01 11:50:07 -04:00
|
|
|
|
|
|
|
|
document.getElementById("ConnectionIPForm").className = "form-group has-warning has-feedback";
|
|
|
|
|
document.getElementById("ConnectionIPLabel").innerHTML = 'Connection closed';
|
|
|
|
|
document.getElementById("ConnectionButton").className = "btn btn-warning"
|
|
|
|
|
document.getElementById("rosbridgeconnection_badge").innerHTML = 'Connection closed';
|
|
|
|
|
ros.nodes = [];
|
|
|
|
|
ros.topics = [];
|
2015-05-29 16:21:09 -04:00
|
|
|
});
|
|
|
|
|
// Create a connection to the rosbridge WebSocket server.
|
|
|
|
|
ros.connect(ros.connectionName);
|
|
|
|
|
|
|
|
|
|
|
2015-06-01 12:39:59 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Publishers
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
function publishBagMessage(bagFilename)
|
|
|
|
|
{
|
|
|
|
|
var bagMessage = new ROSLIB.Message({
|
|
|
|
|
data : bagFilename
|
|
|
|
|
})
|
|
|
|
|
bagPublisher.publish(bagMessage)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
// Topics
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
var bagPublisher = new ROSLIB.Topic({
|
|
|
|
|
ros : ros,
|
|
|
|
|
name : 'bag_publisher',
|
|
|
|
|
messageType : 'std_msgs/String'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var bagNotifier = new ROSLIB.Topic({
|
|
|
|
|
ros : ros,
|
|
|
|
|
name : 'bag_notifier',
|
|
|
|
|
messageType : 'std_msgs/String'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
// Subscribers
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bagNotifier.subscribe(function(message) {
|
|
|
|
|
if (message.data === "STARTED") {
|
|
|
|
|
document.getElementById("recordButtonText").innerHTML = "Stop"
|
|
|
|
|
document.getElementById("recordButton").className = "btn btn-danger"
|
|
|
|
|
} else {
|
|
|
|
|
document.getElementById("recordButtonText").innerHTML = "Start"
|
|
|
|
|
document.getElementById("recordButton").className = "btn btn-primary"
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Functions
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-29 16:21:09 -04:00
|
|
|
// attept to connect to the ros master from the IP given orgrab it from the form
|
|
|
|
|
ros.attemptConnection = function(ipAddress)
|
|
|
|
|
{
|
|
|
|
|
if( typeof ipAddress !== "undefined")
|
|
|
|
|
{
|
|
|
|
|
ros.connectionName = ipAddress;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ros.connectionName = document.getElementById("ConnectionIPInput").value
|
|
|
|
|
}
|
|
|
|
|
console.log('Connection = ' + ros.connectionName);
|
|
|
|
|
ros.connect(ros.connectionName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getTopics() {
|
|
|
|
|
|
|
|
|
|
var topicsClient = new ROSLIB.Service({
|
|
|
|
|
ros : ros,
|
|
|
|
|
name : '/rosapi/topics',
|
|
|
|
|
serviceType : '/rosapi/Topics'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request = new ROSLIB.ServiceRequest();
|
|
|
|
|
|
2015-06-01 11:50:07 -04:00
|
|
|
// ros.topics = [];
|
2015-05-29 16:21:09 -04:00
|
|
|
topicsClient.callService(request, function(result) {
|
|
|
|
|
ros.topics = result.topics;
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-01 11:50:07 -04:00
|
|
|
return ros.topics;
|
2015-05-29 16:21:09 -04:00
|
|
|
};
|
|
|
|
|
|
2015-06-01 09:12:32 -04:00
|
|
|
function getNodes() {
|
|
|
|
|
|
|
|
|
|
var topicsClient = new ROSLIB.Service({
|
|
|
|
|
ros : ros,
|
|
|
|
|
name : '/rosapi/nodes',
|
|
|
|
|
serviceType : '/rosapi/nodes'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request = new ROSLIB.ServiceRequest();
|
|
|
|
|
|
2015-06-01 11:50:07 -04:00
|
|
|
// ros.nodes = [];
|
2015-06-01 09:12:32 -04:00
|
|
|
topicsClient.callService(request, function(result) {
|
|
|
|
|
ros.nodes = result.nodes;
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-01 11:50:07 -04:00
|
|
|
return ros.nodes;
|
2015-06-01 09:12:32 -04:00
|
|
|
};
|
|
|
|
|
|
2015-05-29 16:21:09 -04:00
|
|
|
function getTime() {
|
|
|
|
|
|
|
|
|
|
var topicsClient = new ROSLIB.Service({
|
|
|
|
|
ros : ros,
|
|
|
|
|
name : '/rosapi/get_time',
|
|
|
|
|
serviceType : '/rosapi/GetTime'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var request = new ROSLIB.ServiceRequest({});
|
|
|
|
|
|
|
|
|
|
topicsClient.callService(request, function(result) {
|
|
|
|
|
console.log("Getting Time...");
|
|
|
|
|
console.log(result.time.secs);
|
|
|
|
|
});
|
2015-06-01 12:39:59 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function toggleRecording()
|
|
|
|
|
{
|
|
|
|
|
document.getElementById("recordButtonText").innerHTML = "Wait"
|
|
|
|
|
document.getElementById("recordButton").className = "btn btn-warning"
|
|
|
|
|
if (!ros.recording) {
|
|
|
|
|
ros.recording = true
|
|
|
|
|
publishBagMessage(document.getElementById("recordText").value)
|
|
|
|
|
} else {
|
|
|
|
|
ros.recording = false
|
|
|
|
|
publishBagMessage("STOP")
|
|
|
|
|
}
|
2015-06-10 18:27:56 -04:00
|
|
|
}
|