added client folders and cleaned index.html
This commit is contained in:
205
client/app/utilities/ros_scripts.js
Normal file
205
client/app/utilities/ros_scripts.js
Normal file
@@ -0,0 +1,205 @@
|
||||
var ros = new ROSLIB.Ros();
|
||||
|
||||
|
||||
ros.topics = Array();
|
||||
ros.nodes = Array();
|
||||
ros.recording = false;
|
||||
ros.connected = false;
|
||||
|
||||
// ros.connectionName = 'ws://192.168.1.105:9090';
|
||||
|
||||
function getQueryVariable(variable)
|
||||
{
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i=0;i<vars.length;i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if(pair[0] == variable){
|
||||
return pair[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var master = "localhost"
|
||||
master = getQueryVariable("master")
|
||||
if(master == null)
|
||||
{
|
||||
master = window.location.hostname
|
||||
//"localhost"
|
||||
}
|
||||
console.log('Master = ' + master);
|
||||
|
||||
ros.connectionName = 'ws://' + master + ':9090';
|
||||
// ros.connectionName = 'ws://localhost:9090';
|
||||
// ros.connectionName = 'ws://titan.aescape.co:9090';
|
||||
console.log('ros.connectionName = ' + ros.connectionName);
|
||||
|
||||
// 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';
|
||||
document.getElementById("ROSNodes").innerHTML = "No Nodes Detected";
|
||||
|
||||
rosbridgeconnection_badge
|
||||
console.log(error);
|
||||
});
|
||||
// Find out exactly when we made a connection.
|
||||
ros.on('connection', function() {
|
||||
ros.connected = true;
|
||||
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";
|
||||
|
||||
ros.nodes = Array();
|
||||
ros.topics = Array();
|
||||
|
||||
});
|
||||
|
||||
ros.on('close', function() {
|
||||
console.log('Connection closed.');
|
||||
ros.connected = false;
|
||||
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 = Array();
|
||||
ros.topics = Array();
|
||||
});
|
||||
// Create a connection to the rosbridge WebSocket server.
|
||||
//ros.connect(ros.connectionName);
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Publishers
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function publishBagMessage(bagFilename)
|
||||
{
|
||||
var bag_file_message = ""
|
||||
bag_file_message += bagFilename;
|
||||
if (bagFilename != "STOP")
|
||||
{
|
||||
for (topic in ros.topics)
|
||||
{
|
||||
if(ros.topics[topic].bag)
|
||||
{
|
||||
bag_file_message += " " + ros.topics[topic].name
|
||||
}
|
||||
}
|
||||
}
|
||||
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 if (message.data === "STOPPED")
|
||||
{
|
||||
document.getElementById("recordButtonText").innerHTML = "Start"
|
||||
document.getElementById("recordButton").className = "btn btn-primary"
|
||||
}
|
||||
|
||||
console.log("bagNotifier: " +message.data)
|
||||
});
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// attept to connect to the ros master from the IP given orgrab it from the form
|
||||
ros.attemptConnection = function(ipAddress)
|
||||
{
|
||||
ros.close();
|
||||
if( typeof ipAddress !== "undefined")
|
||||
{
|
||||
ros.connectionName = ipAddress;
|
||||
}
|
||||
else
|
||||
{
|
||||
ros.connectionName = document.getElementById("ConnectionIPInput").value
|
||||
}
|
||||
console.log('Connection = ' + ros.connectionName);
|
||||
ros.connect(ros.connectionName);
|
||||
getMasterName();
|
||||
}
|
||||
|
||||
function toggleRecording()
|
||||
{
|
||||
if(ros.connected)
|
||||
{
|
||||
document.getElementById("recordButtonText").innerHTML = "Wait"
|
||||
document.getElementById("recordButton").className = "btn btn-warning"
|
||||
|
||||
if (!ros.recording) {
|
||||
ros.recording = true
|
||||
topicstobag = " "
|
||||
for (i = 0; i < ros.topics.length; i ++)
|
||||
{
|
||||
if (ros.topics[i].bag == true)
|
||||
{
|
||||
topicstobag = topicstobag.concat(ros.topics[i].name + " ")
|
||||
}
|
||||
}
|
||||
publishBagMessage(document.getElementById("recordText").value + topicstobag)
|
||||
} else {
|
||||
ros.recording = false
|
||||
publishBagMessage("STOP")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getMasterName()
|
||||
{
|
||||
var service = new ROSLIB.Service({
|
||||
ros : ros,
|
||||
name : '/rosapi/service_host',
|
||||
serviceType : 'rosapi/ServiceHost'
|
||||
});
|
||||
|
||||
var request = new ROSLIB.ServiceRequest({
|
||||
service: '/rosout/get_loggers' // Only the master hosts this service.
|
||||
});
|
||||
|
||||
service.callService(request, function(result) {
|
||||
console.log('Master Name = ' + result.host);
|
||||
document.getElementById("MasterName").innerHTML = result.host;
|
||||
var title = result.host + " Lab UI"
|
||||
document.title = title;
|
||||
document.getElementById("Title").innerHTML = title;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user