From 778054c54bdfa4297261d2fa3b7f87ad2455cb2c Mon Sep 17 00:00:00 2001
From: "GLEN TURNER (8GT6)" <8gt6@queensu.ca>
Date: Thu, 28 May 2015 17:06:36 -0400
Subject: [PATCH] Moving functions around. Haven't checked if it works yet
---
index.html | 109 +--------------------------------------------
launch/all.launch | 3 ++
src/ros_scripts.js | 100 +++++++++++++++++++++++++++++++++++++++++
src/update_guis.js | 44 ++++++++++++++++++
4 files changed, 149 insertions(+), 107 deletions(-)
create mode 100644 launch/all.launch
create mode 100644 src/ros_scripts.js
create mode 100644 src/update_guis.js
diff --git a/index.html b/index.html
index b5a953e..e7e797a 100644
--- a/index.html
+++ b/index.html
@@ -23,114 +23,9 @@
+
+
-
diff --git a/launch/all.launch b/launch/all.launch
new file mode 100644
index 0000000..f1305f4
--- /dev/null
+++ b/launch/all.launch
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/src/ros_scripts.js b/src/ros_scripts.js
new file mode 100644
index 0000000..320a977
--- /dev/null
+++ b/src/ros_scripts.js
@@ -0,0 +1,100 @@
+var ros = new ROSLIB.Ros();
+
+ros.connectionName = 'ws://192.168.1.102: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"
+ console.log(error);
+});
+// 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("ConnectionButton").className = "btn btn-success"
+});
+
+ros.on('close', function() {
+ console.log('Connection closed.');
+});
+// Create a connection to the rosbridge WebSocket server.
+ros.connect(ros.connectionName);
+
+
+// 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);
+}
+
+
+// LISTENER ///
+var voltageListener = new ROSLIB.Topic({
+ ros : ros,
+ name : '/asctec/LL_STATUS',
+ messageType : '/asctec_msgs/LLStatus'
+});
+
+voltageListener.subscribe(function(message) {
+ updateVoltage(message.battery_voltage_1/1000);
+ updateUpTime(message.up_time)
+});
+
+function updateVoltage(voltage)
+{
+
+ var voltage_min = 9.5;
+ var voltage_max = 12.5;
+ var voltage_range = voltage_max - voltage_min;
+
+ var voltage_percentage = (voltage - voltage_min) / voltage_range * 100;
+
+ var voltage_string = "";
+ voltage_string = voltage_string.concat(voltage_percentage);
+ voltage_string = voltage_string.substring(0,4);
+ voltage_string = voltage_string.concat('%');
+
+ document.getElementById("VoltageDisplay").style.width = voltage_string;
+ document.getElementById("VoltageDisplay").innerHTML = voltage_string;
+
+ if (voltage_percentage < 50 && voltage_percentage > 25 ) {
+ document.getElementById("VoltageDisplay").className = "progress-bar progress-bar-warning"
+ }
+ else if ( voltage_percentage <= 25)
+ {
+ document.getElementById("VoltageDisplay").className = "progress-bar progress-bar-danger"
+ var sound = document.getElementById("audio");
+ sound.play()
+ console.log("Pay Sound")
+ }
+ else
+ {
+ document.getElementById("VoltageDisplay").className = "progress-bar progress-bar-success"
+ }
+};
+
+function updateUpTime(time)
+{
+ document.getElementById("UpTime").innerHTML = time
+};
+
+
+function validateForm()
+{
+ ros.attemptConnection();
+ return false;
+};
diff --git a/src/update_guis.js b/src/update_guis.js
new file mode 100644
index 0000000..806519c
--- /dev/null
+++ b/src/update_guis.js
@@ -0,0 +1,44 @@
+function updateVoltage(voltage)
+{
+
+ var voltage_min = 9.5;
+ var voltage_max = 12.5;
+ var voltage_range = voltage_max - voltage_min;
+
+ var voltage_percentage = (voltage - voltage_min) / voltage_range * 100;
+
+ var voltage_string = "";
+ voltage_string = voltage_string.concat(voltage_percentage);
+ voltage_string = voltage_string.substring(0,4);
+ voltage_string = voltage_string.concat('%');
+
+ document.getElementById("VoltageDisplay").style.width = voltage_string;
+ document.getElementById("VoltageDisplay").innerHTML = voltage_string;
+
+ if (voltage_percentage < 50 && voltage_percentage > 25 ) {
+ document.getElementById("VoltageDisplay").className = "progress-bar progress-bar-warning"
+ }
+ else if ( voltage_percentage <= 25)
+ {
+ document.getElementById("VoltageDisplay").className = "progress-bar progress-bar-danger"
+ var sound = document.getElementById("audio");
+ sound.play()
+ console.log("Pay Sound")
+ }
+ else
+ {
+ document.getElementById("VoltageDisplay").className = "progress-bar progress-bar-success"
+ }
+};
+
+function updateUpTime(time)
+{
+ document.getElementById("UpTime").innerHTML = time
+};
+
+
+function validateForm()
+{
+ ros.attemptConnection();
+ return false;
+};
\ No newline at end of file