diff --git a/backend/js/Node.js b/backend/js/Node.js new file mode 100644 index 0000000..f0f0d86 --- /dev/null +++ b/backend/js/Node.js @@ -0,0 +1,3 @@ +function Node (name) { + this.name = name; +} \ No newline at end of file diff --git a/backend/js/Topic.js b/backend/js/Topic.js new file mode 100644 index 0000000..4cf5077 --- /dev/null +++ b/backend/js/Topic.js @@ -0,0 +1,12 @@ +function Topic (name) { + this.name = name; + this.bag = true; + this.type = ""; +} + +Array.prototype.indexOfTopic = function(name) { + for (var i = 0; i < this.length; i++) + if (this[i].name == name) + return i; + return -1; +} \ No newline at end of file diff --git a/backend/js/custom_nodes.js b/backend/js/custom_nodes.js deleted file mode 100644 index 8b13789..0000000 --- a/backend/js/custom_nodes.js +++ /dev/null @@ -1 +0,0 @@ - diff --git a/backend/js/custom_topics.js b/backend/js/custom_topics.js deleted file mode 100644 index f1eb1cc..0000000 --- a/backend/js/custom_topics.js +++ /dev/null @@ -1,55 +0,0 @@ -function Topic(name, type) -{ - this.name = name; - this.type = type; - - this.includeInBag = false; - - this.equals = function (otherTopic) - { - if( this.name == otherTopic.name && this.type == otherTopic.type) - { - return true; - } - return false; - }; - -}; - -function containsTopic(obj, list) { - var x; - for (x in list) { - if (obj.equals(list[x])) { - return true; - } - } - - return false; -} - -function testToics() -{ - var topics = [new Topic("a","a_t"), new Topic("b","b_t"), new Topic("c","c_t")]; - - console.log("Testing Topic"); - - if (containsTopic(new Topic("a","a_t"),topics) == true) - { - console.log("pass") - } - else - { - console.log(" contains true fail") - } - - if (containsTopic(new Topic("d","d_t"),topics) == false) - { - console.log("pass") - } - else - { - console.log(" contains d fail") - } -} - -testToics(); \ No newline at end of file diff --git a/backend/js/ros_scripts.js b/backend/js/ros_scripts.js index 93b818c..d93df2b 100644 --- a/backend/js/ros_scripts.js +++ b/backend/js/ros_scripts.js @@ -1,6 +1,10 @@ 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'; ros.connectionName = 'ws://localhost:9090'; @@ -19,6 +23,7 @@ ros.on('error', function(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; @@ -33,7 +38,7 @@ ros.on('connection', function() { 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" @@ -51,6 +56,18 @@ ros.connect(ros.connectionName); 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 }) @@ -82,18 +99,77 @@ bagNotifier.subscribe(function(message) { if (message.data === "STARTED") { document.getElementById("recordButtonText").innerHTML = "Stop" document.getElementById("recordButton").className = "btn btn-danger" - } else { + } else if (message.data === "STOPPED") + { document.getElementById("recordButtonText").innerHTML = "Start" document.getElementById("recordButton").className = "btn btn-primary" } + + console.log("bagNotifier: " +message.data) }); + /////////////////////////////////////////////////////////////////////////////////// // Functions /////////////////////////////////////////////////////////////////////////////////// +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; + +} + // attept to connect to the ros master from the IP given orgrab it from the form ros.attemptConnection = function(ipAddress) @@ -112,13 +188,25 @@ ros.attemptConnection = function(ipAddress) 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") + 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") + } } } diff --git a/backend/js/update_guis.js b/backend/js/update_guis.js index 5a60a11..0764ada 100644 --- a/backend/js/update_guis.js +++ b/backend/js/update_guis.js @@ -1,6 +1,4 @@ -ros.topics = []; -ros.nodes = []; $("#myImage").click ( function (evt) { @@ -62,34 +60,41 @@ function updateVoltage(voltage) function updateTopicsGUI() { - ros.getTopics(function(result) - { - ros.topics = result; - } - ); + ros.getTopics(ros.buildTopicList); - var topics = ros.topics; + var topics = ros.getTopicsList(); - topics.sort(); if(topics != null){ var innerHTML = ""; for (var i = 0; i < topics.length; i++ ) { - innerHTML = innerHTML.concat(generateCheckbox(topics[i])); + innerHTML = innerHTML.concat(generateTopicCheckbox(topics[i])); } document.getElementById("ROSTopics").innerHTML = innerHTML; } }; -function generateCheckbox(name) +function generateTopicCheckbox(topic) { - var str = "
-