2015-06-19 14:41:28 -07:00
|
|
|
var ros = new ROSLIB.Ros();
|
|
|
|
|
|
2015-06-29 16:56:20 -07:00
|
|
|
|
|
|
|
|
ros.topics = Array();
|
|
|
|
|
ros.nodes = Array();
|
2015-06-19 14:41:28 -07:00
|
|
|
ros.recording = false;
|
2015-06-29 16:56:20 -07:00
|
|
|
ros.connected = false;
|
2015-06-19 14:41:28 -07:00
|
|
|
|
|
|
|
|
// ros.connectionName = 'ws://192.168.1.105:9090';
|
|
|
|
|
ros.connectionName = 'ws://localhost:9090';
|
|
|
|
|
|
|
|
|
|
// 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);192
|
|
|
|
|
});
|
|
|
|
|
// Find out exactly when we made a connection.
|
|
|
|
|
ros.on('connection', function() {
|
2015-06-29 16:56:20 -07:00
|
|
|
ros.connected = true;
|
2015-06-19 14:41:28 -07:00
|
|
|
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 = [];
|
|
|
|
|
ros.topics = [];
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ros.on('close', function() {
|
|
|
|
|
console.log('Connection closed.');
|
2015-06-29 16:56:20 -07:00
|
|
|
ros.connected = false;
|
2015-06-19 14:41:28 -07: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 = [];
|
|
|
|
|
});
|
|
|
|
|
// Create a connection to the rosbridge WebSocket server.
|
|
|
|
|
ros.connect(ros.connectionName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Publishers
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
function publishBagMessage(bagFilename)
|
|
|
|
|
{
|
2015-06-29 16:56:20 -07:00
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-19 14:41:28 -07:00
|
|
|
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"
|
2015-06-29 16:56:20 -07:00
|
|
|
} else if (message.data === "STOPPED")
|
|
|
|
|
{
|
2015-06-19 14:41:28 -07:00
|
|
|
document.getElementById("recordButtonText").innerHTML = "Start"
|
|
|
|
|
document.getElementById("recordButton").className = "btn btn-primary"
|
|
|
|
|
}
|
2015-06-29 16:56:20 -07:00
|
|
|
|
|
|
|
|
console.log("bagNotifier: " +message.data)
|
2015-06-19 14:41:28 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2015-06-29 16:56:20 -07:00
|
|
|
|
2015-06-19 14:41:28 -07:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Functions
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2015-06-29 16:56:20 -07:00
|
|
|
ros.buildTopicList = function(fresh_topics)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// console.log(topics)
|
|
|
|
|
// fresh_topics = fresh_topics.sort();
|
|
|
|
|
// First check that all our current topics are in the list of fresh_topics
|
|
|
|
|
for( var topic = 0; topic < ros.topics.length; topic ++)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (fresh_topics.indexOf(ros.topics[topic].name) > -1)
|
|
|
|
|
{
|
|
|
|
|
// We know that we have already found that topic so we don't need to remove it
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// That topic is no longer being published so we need ro remove it
|
|
|
|
|
ros.topics.splice(topic,1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (var topic =0; topic < fresh_topics.length; topic ++ )
|
|
|
|
|
{
|
|
|
|
|
if (ros.topics.indexOfTopic(fresh_topics[topic]) > -1)
|
|
|
|
|
{
|
|
|
|
|
// We know that we have already found that topic so we don't need to re-add it
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// We do not have that topic so we need to add it
|
|
|
|
|
// create the new topic
|
|
|
|
|
var new_topic = new Topic(fresh_topics[topic]);
|
|
|
|
|
// make sure to put in in the list in the order
|
|
|
|
|
ros.topics.push(new_topic);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ros.topics.sort(function(a, b) {
|
|
|
|
|
if ( a.name < b.name )
|
|
|
|
|
return -1;
|
|
|
|
|
if ( a.name > b.name )
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ros.getTopicsList = function()
|
|
|
|
|
{
|
|
|
|
|
// var topicList = [];
|
|
|
|
|
return ros.topics;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-19 14:41:28 -07: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 toggleRecording()
|
|
|
|
|
{
|
2015-06-29 16:56:20 -07:00
|
|
|
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")
|
|
|
|
|
}
|
2015-06-19 14:41:28 -07:00
|
|
|
}
|
|
|
|
|
}
|