forked from marva/sumorobot-web
some changes
This commit is contained in:
parent
d662e205a4
commit
d59c0c9450
@ -117,6 +117,12 @@ window.addEventListener('load', function() {
|
||||
var foundTrue = false;
|
||||
// Function to process code and highlight blocks and lines
|
||||
function processCode(index) {
|
||||
|
||||
if(sumorobot.disconnected || !sumorobot.codeExecute) {
|
||||
$('.btn-stop').click();
|
||||
return;
|
||||
}
|
||||
|
||||
// When all lines are already processed
|
||||
if (lines.length == 0) return;
|
||||
// Split into code and block ID
|
||||
|
@ -8,10 +8,14 @@ var Sumorobot = function(wsUri, robotId) {
|
||||
this.watchdogCounter = 0;
|
||||
// When connection was intentionally closed
|
||||
this.terminate = false;
|
||||
// when there is no connection with robot
|
||||
this.disconnected = true;
|
||||
// To store Blockly code
|
||||
this.blocklyCode = '';
|
||||
// If robot is moving
|
||||
this.moving = false;
|
||||
|
||||
this.codeExecute = false;
|
||||
// Sensor data
|
||||
this.sensors = {
|
||||
'opponent': 99,
|
||||
@ -33,10 +37,11 @@ Sumorobot.prototype.connect = function() {
|
||||
self.connectionTimer = setInterval(function() {
|
||||
if (self.watchdogCounter == 0 && !self.terminate) {
|
||||
$("#battery img").attr("src", "assets/img/battery_disconnected.png");
|
||||
self.disconnected = true;
|
||||
}
|
||||
// Reset watchdog counter
|
||||
self.watchdogCounter = 0;
|
||||
}, 3000);
|
||||
}, 1500);
|
||||
// When the WebSocket gets connected
|
||||
this.websocket.onopen = function(evt) {
|
||||
// Setup a timer to ping the robot
|
||||
@ -60,8 +65,11 @@ Sumorobot.prototype.connect = function() {
|
||||
this.websocket.onmessage = function(evt) {
|
||||
// When scope is received
|
||||
var data = evt.data.replace(/'/g, '"').toLowerCase();
|
||||
self.disconnected = false;
|
||||
|
||||
// Get SumoRobot battery voltage
|
||||
self.sensors = JSON.parse(data);
|
||||
self.codeExecute = self.sensors.state;
|
||||
// When sensor data received
|
||||
if (self.sensors['battery_voltage']) {
|
||||
if (self.sensors['battery_voltage'] > 4.0) {
|
||||
@ -85,6 +93,7 @@ Sumorobot.prototype.connect = function() {
|
||||
Sumorobot.prototype.send = function(cmd, val) {
|
||||
if (cmd !== 'ping' && cmd !== 'stop') {
|
||||
this.moving = true;
|
||||
this.codeExecute = true;
|
||||
} else {
|
||||
this.moving = false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user