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