Alpha stage commit. Console done.

Console Changes: changed the name of the tokens so that more helpful error messages. Added help text.
Moved command.jison to src.
Other Changes: Added more telemetry data about battery and rover status.
Finished gui commands, replaced to sliders from buttons and linked them to command console.
This commit is contained in:
jc4419 2021-06-14 20:37:05 +04:00
parent 6c221f6d12
commit 46519cfe19
4 changed files with 372 additions and 262 deletions

View file

@ -75,9 +75,9 @@ var command = (function(){
var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o}; var o=function(k,v,o,l){for(o=o||{},l=k.length;l--;o[k[l]]=v);return o};
var parser = {trace: function trace () { }, var parser = {trace: function trace () { },
yy: {}, yy: {},
symbols_: {"error":2,"command":3,"expr":4,"EOF":5,"MOVE":6,"WHITESPACE":7,"DIST":8,"HEADING":9,"PERCENTAGE":10,"STOP":11,"PSTOP":12,"CHARGETO":13,"TELERST":14,"$accept":0,"$end":1}, symbols_: {"error":2,"command":3,"expr":4,"EOF":5,"move":6,"whitespace":7,"distance":8,"heading_angle":9,"percentage":10,"stop":11,"pstop":12,"stop_duration":13,"charge_to":14,"telemetry_reset":15,"help":16,"$accept":0,"$end":1},
terminals_: {2:"error",5:"EOF",6:"MOVE",7:"WHITESPACE",8:"DIST",9:"HEADING",10:"PERCENTAGE",11:"STOP",12:"PSTOP",13:"CHARGETO",14:"TELERST"}, terminals_: {2:"error",5:"EOF",6:"move",7:"whitespace",8:"distance",9:"heading_angle",10:"percentage",11:"stop",12:"pstop",13:"stop_duration",14:"charge_to",15:"telemetry_reset",16:"help"},
productions_: [0,[3,2],[4,7],[4,1],[4,1],[4,3],[4,1]], productions_: [0,[3,2],[4,7],[4,1],[4,3],[4,3],[4,1],[4,1]],
performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) { performAction: function anonymous(yytext, yyleng, yylineno, yy, yystate /* action[1] */, $$ /* vstack */, _$ /* lstack */) {
/* this == yyval */ /* this == yyval */
@ -85,72 +85,43 @@ var $0 = $$.length - 1;
switch (yystate) { switch (yystate) {
case 2: case 2:
var inDist = String($$[$0-4]).substr(0, ((String($$[$0-4]).length) - 2)); var inDist = Number(String($$[$0-4]).substr(0, ((String($$[$0-4]).length) - 2)));
var inHdg = String($$[$0-2]).substr(0, ((String($$[$0-2]).length) - 3)); var inHdg = Number(String($$[$0-2]).substr(0, ((String($$[$0-2]).length) - 3)));
var inSpd = String($$[$0]).substr(0, ((String($$[$0]).length) - 1)); var inSpd = Number(String($$[$0]).substr(0, ((String($$[$0]).length) - 1)));
mode = 1; moveCmd(inDist,inHdg,inSpd);
reqDistance = Number(inDist);
reqHeading = Number(inHdg);
reqSpeed = Number(inSpd);
reqCharge = 0;
send_data();
updateCommandBuffer();
command_id++;
break; break;
case 3: case 3:
mode = 0; stpCmd();
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
send_data();
command_id = 0;
updateCommandBuffer()
break; break;
case 4: case 4:
mode = 1; var inStpDur = Number(String($$[$0]).substr(0, ((String($$[$0]).length) - 1)));
reqDistance = 0; pstpCmd(inStpDur);
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
send_data();
updateCommandBuffer();
command_id++;
break; break;
case 5: case 5:
mode = 1; var inChrg = Number(String($$[$0]).substr(0, ((String($$[$0]).length) - 1)));
reqDistance = 0; chrgCmd(inChrg);
reqHeading = 0;
reqSpeed = 0;
var inChrg = String($$[$0]).substr(0, ((String($$[$0]).length) - 1));
reqCharge = Number(inChrg);
send_data();
updateCommandBuffer();
command_id++;
break; break;
case 6: case 6:
mode = 1;
reqDistance = 0; telRst();
reqHeading = 0;
reqSpeed = 0; break;
reqCharge = 0; case 7:
send_data();
updateCommandBuffer(); printHelpDetails();
command_id++;
break; break;
} }
}, },
table: [{3:1,4:2,6:[1,3],11:[1,4],12:[1,5],13:[1,6],14:[1,7]},{1:[3]},{5:[1,8]},{7:[1,9]},{5:[2,3]},{5:[2,4]},{7:[1,10]},{5:[2,6]},{1:[2,1]},{8:[1,11]},{10:[1,12]},{7:[1,13]},{5:[2,5]},{9:[1,14]},{7:[1,15]},{10:[1,16]},{5:[2,2]}], table: [{3:1,4:2,6:[1,3],11:[1,4],12:[1,5],14:[1,6],15:[1,7],16:[1,8]},{1:[3]},{5:[1,9]},{7:[1,10]},{5:[2,3]},{7:[1,11]},{7:[1,12]},{5:[2,6]},{5:[2,7]},{1:[2,1]},{8:[1,13]},{13:[1,14]},{10:[1,15]},{7:[1,16]},{5:[2,4]},{5:[2,5]},{9:[1,17]},{7:[1,18]},{10:[1,19]},{5:[2,2]}],
defaultActions: {4:[2,3],5:[2,4],7:[2,6],8:[2,1],12:[2,5],16:[2,2]}, defaultActions: {4:[2,3],7:[2,6],8:[2,7],9:[2,1],14:[2,4],15:[2,5],19:[2,2]},
parseError: function parseError (str, hash) { parseError: function parseError (str, hash) {
if (hash.recoverable) { if (hash.recoverable) {
this.trace(str); this.trace(str);
@ -633,24 +604,28 @@ case 2:return 9
break; break;
case 3:return 10 case 3:return 10
break; break;
case 4:return 6 case 4:return 13
break; break;
case 5:return 12 case 5:return 6
break; break;
case 6:return 11 case 6:return 12
break; break;
case 7:return 13 case 7:return 11
break; break;
case 8:return 14 case 8:return 16
break; break;
case 9:return 5 case 9:return 14
break; break;
case 10:return 'INVALID' case 10:return 15
break;
case 11:return 5
break;
case 12:return 'invalid_command'
break; break;
} }
}, },
rules: [/^(?:\s)/,/^(?:\b[0-9]+mm\b)/,/^(?:\b([0-9]|[1-8][0-9]|9[0-9]|[12][0-9]{2}|3[0-4][0-9]|35[0-9])deg\b)/,/^(?:\b([0-9]|[1-8][0-9]|9[0-9]|100)%)/,/^(?:\bmove\b)/,/^(?:\bpstop\b)/,/^(?:\bstop\b)/,/^(?:\bcharge\sto\b)/,/^(?:\btelemetry\sreset\b)/,/^(?:$)/,/^(?:.)/], rules: [/^(?:\s)/,/^(?:\b[0-9]+mm\b)/,/^(?:\b([0-9]|[1-8][0-9]|9[0-9]|[12][0-9]{2}|3[0-4][0-9]|35[0-9])deg\b)/,/^(?:\b([0-9]|[1-8][0-9]|9[0-9]|100)%)/,/^(?:\b[0-9]+s\b)/,/^(?:\bmove\b)/,/^(?:\bpstop\b)/,/^(?:\bstop\b)/,/^(?:\bhelp\b)/,/^(?:\bcharge\sto\b)/,/^(?:\btelemetry\sreset\b)/,/^(?:$)/,/^(?:.)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10],"inclusive":true}} conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12],"inclusive":true}}
}); });
return lexer; return lexer;
})(); })();

View file

@ -25,6 +25,30 @@
margin: 0px; margin: 0px;
} }
.slider {
-webkit-appearance: none;
width: 100%;
height: 25px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.slider:hover {
opacity: 1;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
background: #000000;
cursor: pointer;
}
#command_space { #command_space {
width:100%; width:100%;
height: 200px; height: 200px;
@ -62,6 +86,8 @@
border: none; border: none;
border-radius: 5px; border-radius: 5px;
box-shadow: 0 3px rgb(161, 161, 161); box-shadow: 0 3px rgb(161, 161, 161);
-webkit-transition: .2s;
transition: background-color .2s;
} }
button:hover { button:hover {
@ -69,7 +95,6 @@
} }
button:active { button:active {
background-color: #349134;
box-shadow: 0 3px rgb(161, 161, 161); box-shadow: 0 3px rgb(161, 161, 161);
transform: translateY(1px); transform: translateY(1px);
} }
@ -80,100 +105,18 @@
display: table; display: table;
} }
</style> </style>
<script src="command.js"></script>
<script>
var connection = new WebSocket('ws://' + location.hostname + ':81/');
var command_id = 1;
var mode = 0;
var reqHeading = 0;
var reqDistance = 0;
var reqSpeed = 0;
var reqCharge = 0;
var state = 0;
var batteryVoltage = 0;
var batteryLevel = 0;
var totalTripDistance = 0;
var currentHeading = 0;
var current_pos = [,];
var current_x = 0;
var current_y = 0;
var signal_strength = 0;
var lastCompletedCommand_id = 0;
var ChargeStatus = 0;
connection.onmessage = function (event) {
var raw_data = event.data;
console.log(raw_data);
var data = JSON.parse(raw_data);
state = data.st;
batteryLevel = data.bV;
batteryVoltage = data.bV;
totalTripDistance = data.tD;
currentHeading = data.cH;
current_pos = data.pos;
current_x = current_pos[0];
current_y = current_pos[1];
signal_strength = data.rssi;
lastCompletedCommand_id = data.LCCid;
ChargeStatus = data.cS;
document.getElementById("SigStr").value = signal_strength;
document.getElementById("PosX").innerHTML = current_x;
document.getElementById("PosY").innerHTML = current_y;
document.getElementById("Hdg").innerHTML = currentHeading;
document.getElementById("TrpDist").innerHTML = totalTripDistance;
document.getElementById("btry_meter").value = batteryVoltage;
document.getElementById("ChgStat").innerHTML = (ChargeStatus ? "Charging" : "Discharging");
}
function send_data() {
var raw_data = '{"Cid":' + command_id + ',"mode":' + mode + ',"rH":' + reqHeading + ',"rD":' + reqDistance + ',"rS":' + reqSpeed + ',"rC":' + reqCharge + '}';
connection.send(raw_data);
console.log(raw_data);
}
function updateCommandBuffer(){
if((mode == 1) || (mode == -1) || (mode == 2)){
document.getElementById("command_buffer").innerHTML += '[' + command_id + '] ' + document.getElementById("commandInput").value + "<br>";
}else if(mode == 0){
document.getElementById("comand_buffer").innerHTML = "Rover Emergency Stop.\n Command buffer cleared. ";
document.getElementById("commandInput").value = "";
}
}
function commandError(){
}
function RunParser(){
var commandstring = document.getElementById("commandInput").value;
try{
command.parse(commandstring);
} catch(err){
alert(err);
}
}
</script>
</head> </head>
<body> <body>
<h1 style="text-align:center;">ROVER COMMAND CENTER</h1> <h1 style="text-align:center;">ROVER COMMAND CENTER</h1>
<div class="clearfix"> <div class="clearfix">
<table style="width:1000px; border-spacing: 10px; margin-left: auto; margin-right: auto;"> <table style="width:1100px; border-spacing: 10px; margin-left: auto; margin-right: auto;">
<tr> <tr>
<th style="width: 33%;"><h2>Control Panel</h2></th> <th style="width: 33%;"><h2>Control Panel</h2></th>
<th style="width: 33%;"><h2>Telemetry</h2></th> <th style="width: 33%;"><h2>Telemetry</h2></th>
<th style="width: 33%;"><h2>Command Buffer</h2></th> <th style="width: 33%;"><h2>Command Console</h2></th>
</tr> </tr>
<tr><hr></tr> <tr><hr></tr>
@ -193,28 +136,25 @@
</tr> </tr>
<tr><td colspan="6"><hr></td></tr> <tr><td colspan="6"><hr></td></tr>
<tr> <tr>
<td style="text-align: center;" colspan="6"><strong >Rotation</strong></td> <td style="text-align: center;" colspan="6"><strong> Set Heading to: </strong><strong id="SetHeading" style="font-size: 18px;">270</strong><strong>&#176;</strong></td>
</tr>
<tr>
<td><button><i>-90&#176;</i></button></td>
<td><button><i>-45&#176;</i></button></td>
<td><button><i>-30&#176;</i></button></td>
<td><button><i>30&#176;</i></button></td>
<td><button><i>45&#176;</i></button></td>
<td><button><i>90&#176;</i></button></td>
</tr>
<tr><td colspan="6"><hr></td></tr>
<tr>
<td style="text-align: center;" colspan="6"><strong>Translation</strong></td>
</tr> </tr>
<tr> <tr>
<td><button><i>-10000 mm</i></button></td> <td colspan="6"><input type ="range" min="0" max="359" value="270" class="slider" id="HdgSlider"></td>
<td><button><i>-1000 mm</i></button></td> </tr>
<td><button><i>-100 mm</i></button></td> <tr>
<td><button><i>100 mm</i></button></td> <td style="text-align: center;" colspan="6"><strong>Set Translation to: </strong><strong id="SetTrans" style="font-size: 18px;">180</strong><strong>mm</strong></td>
<td><button><i>1000 mm</i></button></td> </tr>
<td><button><i>10000 mm</i></button></td> <tr>
<td colspan="6"><input type ="range" min="0" max="1000" value="100" class="slider" id="TranSlider"></td>
</tr>
<tr>
<td style="text-align: center;" colspan="6"><strong>Set Speed to: </strong><strong id="SetSpd" style="font-size: 18px;">50</strong><strong>%</strong></td>
</tr>
<tr>
<td colspan="6"><input type ="range" min="0" max="100" value="50" class="slider" id="SpdSlider"></td>
</tr>
<tr>
<td colspan="6"><button onclick="setCmdMode(1); moveCmd(setTransto, setHdgto, setSpdto);">Send<br>Command</button></td>
</tr> </tr>
<tr><td colspan="6"><hr></td></tr> <tr><td colspan="6"><hr></td></tr>
</table> </table>
@ -224,12 +164,18 @@
<td style="vertical-align: top;"> <td style="vertical-align: top;">
<table style="width:100%; border-spacing: 5px; "> <table style="width:100%; border-spacing: 5px; ">
<tr><td colspan="6"><hr></td></tr> <tr><td colspan="2"><hr></td></tr>
<tr>
<td style="width:50%;"><label>Rover Status</label></td>
<td style="width:50%;"><strong id="Rov_status">X</strong>
</tr>
<tr><td colspan="2"><hr></td></tr>
<tr> <tr>
<td style="width:50%;"><label>Signal Strength</label></td> <td style="width:50%;"><label>Signal Strength</label></td>
<td style="width:50%;"><meter id="SigStr" min="-80" max="-30" low="-70" high="-50" optimum="-40" value="-XX" <td style="width:50%;"><meter id="SigStr" min="-80" max="-30" low="-70" high="-50" optimum="-40" value="-XX"
title="dB"></meter></td> title="dB"></meter></td>
</tr> </tr>
<tr><td colspan="2"><hr></td></tr>
<tr> <tr>
<td style="width:50%;"><label>Position</label></td> <td style="width:50%;"><label>Position</label></td>
<td style="width:50%;"><strong id="PosX">X</strong><strong>,</strong><strong id="PosY">Y</strong></td> <td style="width:50%;"><strong id="PosX">X</strong><strong>,</strong><strong id="PosY">Y</strong></td>
@ -242,16 +188,20 @@
<td style="width:50%;"><label>Trip Distance</label></td> <td style="width:50%;"><label>Trip Distance</label></td>
<td style="width:50%;"><strong id="TrpDist">X</strong><strong> mm</strong></td> <td style="width:50%;"><strong id="TrpDist">X</strong><strong> mm</strong></td>
</tr> </tr>
<tr><td colspan="2"><hr></td></tr>
<tr> <tr>
<td style="width:50%;"><label>Battery Voltage</label></td> <td style="width:50%;"><label>Battery Voltage</label></td>
<td style="width:50%;"><meter id="btry_meter" min="4.0" max="6.0" low="4.5" high="4.8" optimum="5.0" value="X.X" <td style="width:50%;"><strong id="btry_volt">X</strong><strong>V</strong></td>
title="V"></meter></td>
</tr> </tr>
<tr> <tr>
<td style="width:50%;"><label>Charge Status</label></td> <td style="width:50%;"><label>Battery Level</label></td>
<td style="width:50%;"><strong id="ChgStat">Disconnect</strong></td> <td style="width:50%;"><strong id="btry_lvl">X</strong><strong>%</strong></td>
</tr> </tr>
<tr>
<td style="width:50%;"><label>Battery Cycles</label></td>
<td style="width:50%;"><strong id="btry_cycls">X</strong></td>
</tr>
<tr><td colspan="2"><hr></td></tr>
</table> </table>
</td> </td>
@ -259,11 +209,11 @@
<!-- Command Buffer Section --> <!-- Command Buffer Section -->
<td style="vertical-align: top;"> <td style="vertical-align: top;">
<table style="width:100%; border-spacing: 5px; "> <table style="width:100%; border-spacing: 5px; ">
<tr><td><hr></td></tr> <tr><td colspan="2"><hr></td></tr>
<tr><td colspan="2"><div id="command_space"><p id="command_buffer" style="padding-left: 5px; font-size: 14px; font-family: 'Courier New', Courier, monospace;"></p></div></td></tr> <tr><td colspan="2"><div id="command_space"><p id="command_buffer" style="padding-left: 5px; font-size: 12px; font-family: 'Courier New', Courier, monospace;"></p></div></td></tr>
<tr> <tr>
<td><input type="text" placeholder="Type a command or 'help'." id="commandInput" value="" onkeyup="if(event.keyCode == 13){document.getElementById('commandEnter').click();}" style="width: 100%; font-size: 14px; font-family: 'Courier New', Courier, monospace;"></td> <td><input type="text" placeholder="Type a command or 'help'." id="commandInput" value="" onkeyup="if(event.keyCode == 13){document.getElementById('commandEnter').click();}" style="width: 100%; font-size: 14px; font-family: 'Courier New', Courier, monospace;"></td>
<td style="width: 7%; "><button onclick="RunParser()" id="commandEnter" style="height: 20px; width: 20px; padding: 3px 2px;">&crarr;</button></td> <td style="width: 7%; "><button onclick="setCmdMode(0); RunParser();" id="commandEnter" style="height: 20px; width: 20px; padding: 3px 2px;">&crarr;</button></td>
</tr> </tr>
</table> </table>
@ -274,5 +224,218 @@
</div> </div>
</body> </body>
<script src="command.js"></script>
<script>
var connection = new WebSocket('ws://' + location.hostname + ':81/');
var command_id = 1;
var mode = 0;
var reqHeading = 0;
var reqDistance = 0;
var reqSpeed = 0;
var reqCharge = 0;
var pstop_time = 0;
var state = 0;
var batteryVoltage = 0;
var batteryLevel = 0;
var totalTripDistance = 0;
var currentHeading = 0;
var current_pos = [,];
var current_x = 0;
var current_y = 0;
var signal_strength = 0;
var lastCompletedCommand_id = 0;
var batteryCycles = 0;
connection.onmessage = function (event) {
var raw_data = event.data;
console.log(raw_data);
var data = JSON.parse(raw_data);
state = data.st;
batteryLevel = data.bV;
batteryVoltage = data.bV;
batteryCycles = data.bC;
totalTripDistance = data.tD;
currentHeading = data.cH;
current_pos = data.pos;
current_x = current_pos[0];
current_y = current_pos[1];
signal_strength = data.rssi;
lastCompletedCommand_id = data.LCCid;
var rStatus = ""
if(state == -1){
rStatus = "Error";
}else if(state == 0){
rStatus = "Idle";
}else if(state == 1){
rStatus = "Moving";
}else if(state == 2){
rStatus = "Charging";
}else{
rStatus = "Undefined";
}
document.getElementById("Rov_status").innerHTML = rStatus;
document.getElementById("SigStr").value = signal_strength;
document.getElementById("PosX").innerHTML = current_x;
document.getElementById("PosY").innerHTML = current_y;
document.getElementById("Hdg").innerHTML = currentHeading;
document.getElementById("TrpDist").innerHTML = totalTripDistance;
document.getElementById("btry_volt").innerHTML = batteryVoltage;
document.getElementById("btry_lvl").innerHTML = batteryLevel;
document.getElementById("btry_cycls").innerHTML = batteryCycles;
}
function send_data() {
var raw_data = '{"Cid":' + command_id + ',"mode":' + mode + ',"rH":' + reqHeading + ',"rD":' + reqDistance + ',"rS":' + reqSpeed + ',"rC":' + reqCharge + ',"pSt":' + pstop_time + '}';
connection.send(raw_data);
console.log(raw_data);
}
function setCmdMode(mode){
cmdMode = mode;
}
function updateCommandBuffer(){
var bufferOutput = "";
if(cmdMode == 0){
bufferOutput = document.getElementById("commandInput").value;
}else if(cmdMode == 1){
bufferOutput = "move " + reqDistance + "mm " + reqHeading + "deg " + reqSpeed + "%";
}
if((mode == 1) || (mode == -1) || (mode == 2) || (mode == 3)){
document.getElementById("command_buffer").innerHTML += '[' + command_id + '] ' + bufferOutput + "<br>";
document.getElementById("commandInput").value = ""
}else if(mode == 0){
document.getElementById("command_buffer").innerHTML = "Rover Emergency Stop." + "<br>" +"Command buffer cleared." + "<br>";
document.getElementById("commandInput").value = "";
}
}
function printHelpDetails(){
document.getElementById("command_buffer").innerHTML =
("------------------------------------------" + "<br>" + "<br>" +
"Types of commands available:" + "<br>" + "<br>" +
"'move' moves rover along a given vector" + "<br>" +
"> move [distance]mm [heading]deg [speed]%" + "<br>" + "<br>" +
"'pstop' short for planned stop it stops the rover without reseting the command buffer" + "<br>" +
"> pstop" + "<br>" + "<br>" +
"'charge' stops the rover and recharges to a set battery level" + "<br>" +
"> charge to [percentage]%" + "<br>" + "<br>" +
"'telemetry reset' resets X,Y coordinates and Trip Distance" + "<br>" +
"> telemetry reset" + "<br>" + "<br>" +
"'stop' and emergency stop that stops the rover and resets the command buffer" + "<br>" +
"> stop" + "<br>" + "<br>" +
"------------------------------------------"
)
document.getElementById("commandInput").value = "";
}
function moveCmd(dist,hdg,spd){
mode = 1;
reqDistance = dist;
reqHeading = hdg;
reqSpeed = spd;
reqCharge = 0;
pstop_time = 0;
tel_rst = 0;
send_data();
updateCommandBuffer();
command_id++;
}
function stpCmd(){
mode = 0;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
pstop_time = 0;
tel_rst = 0;
send_data();
command_id = 1;
updateCommandBuffer();
}
function pstpCmd(pstp_tme){
mode = 3;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
pstop_time = pstp_tme;
tel_rst = 0;
send_data();
updateCommandBuffer();
command_id++;
}
function chrgCmd(chrglvl){
mode = 2;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = chrglvl;
pstop_time = 0;
tel_rst = 0;
send_data();
updateCommandBuffer();
command_id++;
}
function telRst(){
mode = -1;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
pstop_time = 0;
send_data();
updateCommandBuffer();
command_id++;
}
function RunParser(){
var commandstring = document.getElementById("commandInput").value;
try{
command.parse(commandstring);
} catch(err){
alert(err);
}
}
var setHdgto = 270;
var hdg_slider = document.getElementById("HdgSlider");
var hdg_output = document.getElementById("SetHeading");
hdg_output.innerHTML = hdg_slider.value;
hdg_slider.oninput = function() {
hdg_output.innerHTML = this.value;
setHdgto = this.value;
}
var setTransto = 100;
var tran_slider = document.getElementById("TranSlider");
var tran_output = document.getElementById("SetTrans");
tran_output.innerHTML = tran_slider.value;
tran_slider.oninput = function() {
tran_output.innerHTML = this.value;
setTransto = this.value;
}
var setSpdto = 50;
var spd_slider = document.getElementById("SpdSlider");
var spd_output = document.getElementById("SetSpd");
spd_output.innerHTML = spd_slider.value;
spd_slider.oninput = function() {
spd_output.innerHTML = this.value;
setSpdto = this.value;
}
</script>
</html> </html>

View file

@ -1,87 +0,0 @@
%lex
%%
\s return 'WHITESPACE'
\b[0-9]+"mm"\b return 'DIST'
\b([0-9]|[1-8][0-9]|9[0-9]|[12][0-9]{2}|3[0-4][0-9]|35[0-9])"deg"\b return 'HEADING'
\b([0-9]|[1-8][0-9]|9[0-9]|100)"%" return 'PERCENTAGE'
\bmove\b return 'MOVE'
\bpstop\b return 'PSTOP'
\bstop\b return 'STOP'
\bcharge\sto\b return 'CHARGETO'
\btelemetry\sreset\b return 'TELERST'
<<EOF>> return 'EOF'
. return 'INVALID'
/lex
%start command
%%
command
: expr EOF
;
expr
: MOVE WHITESPACE DIST WHITESPACE HEADING WHITESPACE PERCENTAGE
{
var inDist = String($3).substr(0, ((String($3).length) - 2));
var inHdg = String($5).substr(0, ((String($5).length) - 3));
var inSpd = String($7).substr(0, ((String($7).length) - 1));
mode = 1;
reqDistance = Number(inDist);
reqHeading = Number(inHdg);
reqSpeed = Number(inSpd);
reqCharge = 0;
send_data();
updateCommandBuffer();
command_id++;
}
| STOP
{
mode = 0;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
send_data();
command_id = 0;
updateCommandBuffer()
}
| PSTOP
{
mode = 1;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
send_data();
updateCommandBuffer();
command_id++;
}
| CHARGETO WHITESPACE PERCENTAGE
{
mode = 1;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
var inChrg = String($3).substr(0, ((String($3).length) - 1));
reqCharge = Number(inChrg);
send_data();
updateCommandBuffer();
command_id++;
}
| TELERST
{mode = 1;
reqDistance = 0;
reqHeading = 0;
reqSpeed = 0;
reqCharge = 0;
send_data();
updateCommandBuffer();
command_id++;}
;

59
Control/src/command.jison Normal file
View file

@ -0,0 +1,59 @@
%lex
%%
\s return 'whitespace'
\b[0-9]+"mm"\b return 'distance'
\b([0-9]|[1-8][0-9]|9[0-9]|[12][0-9]{2}|3[0-4][0-9]|35[0-9])"deg"\b return 'heading_angle'
\b([0-9]|[1-8][0-9]|9[0-9]|100)"%" return 'percentage'
\b[0-9]+"s"\b return 'stop_duration'
\bmove\b return 'move'
\bpstop\b return 'pstop'
\bstop\b return 'stop'
\bhelp\b return 'help'
\bcharge\sto\b return 'charge_to'
\btelemetry\sreset\b return 'telemetry_reset'
<<EOF>> return 'EOF'
. return 'invalid_command'
/lex
%start command
%%
command
: expr EOF
;
expr
: move whitespace distance whitespace heading_angle whitespace percentage
{
var inDist = Number(String($3).substr(0, ((String($3).length) - 2)));
var inHdg = Number(String($5).substr(0, ((String($5).length) - 3)));
var inSpd = Number(String($7).substr(0, ((String($7).length) - 1)));
moveCmd(inDist,inHdg,inSpd);
}
| stop
{
stpCmd();
}
| pstop whitespace stop_duration
{
var inStpDur = Number(String($3).substr(0, ((String($3).length) - 1)));
pstpCmd(inStpDur);
}
| charge_to whitespace percentage
{
var inChrg = Number(String($3).substr(0, ((String($3).length) - 1)));
chrgCmd(inChrg);
}
| telemetry_reset
{
telRst();
}
| help
{
printHelpDetails();
}
;