Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidSamuraj committed Feb 21, 2024
1 parent 97001b4 commit 40ace9b
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 35 deletions.
3 changes: 2 additions & 1 deletion src/main/kotlin/com/voidsamuraj/gcode/GCodeSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ object GCodeSender {
command.append("" + L).append(alphaChange / totalSteps).append(" ")
.append(S).append(betaChange / totalSteps)
}
if (speed != null && speed != -1.0) command.append(" F").append((speed * speedrate).toLong())
if (speed != null && speed != -1.0)
command.append(" F").append((speed * speedrate).toLong())
command.append("\n")
} else {
if (inSteps) {
Expand Down
10 changes: 9 additions & 1 deletion src/main/kotlin/com/voidsamuraj/routes/FileRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ fun Route.fileRoute(){
checkUserPermission(){
val fileName = call.parameters["fileName"]
if(fileName!=null){
GCodeSender.sendGCode(filesFolder+"/"+fileName)
val ret=GCodeSender.sendGCode(filesFolder+"/"+fileName)
when(ret){
GCodeSender.StateReturn.SUCCESS->call.respond(HttpStatusCode.OK, "Success")
GCodeSender.StateReturn.FAILURE->call.respond(HttpStatusCode.InternalServerError, "Failed to draw file")
GCodeSender.StateReturn.PORT_DISCONNECTED->{
GCodeSender.closePort()
call.respond(HttpStatusCode.ServiceUnavailable, "Connection lost")
}
}
call.respond(HttpStatusCode.OK, "File is processing")
}else
call.respond(HttpStatusCode.NotFound,"File not found")
Expand Down
39 changes: 27 additions & 12 deletions src/main/resources/files/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {setupCanvasHelper,getRotationHelperGroup}from '/static/sceneHelper.js'
import {showDialog}from '/static/helpers.js'
import {rotateArm1,rotateArm2}from '/static/movement.js'
import { OrbitControls } from '/static/three/examples/jsm/controls/OrbitControls.js';
import {getCanMoveArm, setupOptionMenu, getMovePrecision, getRotationPrecision, refreshPorts} from '/static/navigation.js'
import {getCanMoveArm, setupOptionMenu, getMovePrecision, getRotationPrecision, refreshPorts, demoMode} from '/static/navigation.js'

// main file to display and manage elements of arm and related UI

Expand Down Expand Up @@ -217,7 +217,8 @@ if(! /iPhone|iPad|iPod|Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navig
arm2Text.rotation.z += zoomChange * Math.PI / 180;
else
arm2Text.rotation.z -= zoomChange * Math.PI / 180;
moveArmByAngle((rightSide?zoomChange:-zoomChange),null);
if(!demoMode)
moveArmByAngle((rightSide?zoomChange:-zoomChange),null);
updateToolPos();
reacted=true;
}
Expand All @@ -236,7 +237,8 @@ if(! /iPhone|iPad|iPod|Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navig
arm2Text.rotation.z += zoomChange * Math.PI / 180;
else
arm2Text.rotation.z -= zoomChange * Math.PI / 180;
moveArmByAngle(null,(rightSide?zoomChange:-zoomChange));
if(!demoMode)
moveArmByAngle(null,(rightSide?zoomChange:-zoomChange));
updateToolPos();
reacted=true;
}
Expand Down Expand Up @@ -270,7 +272,8 @@ if(! /iPhone|iPad|iPod|Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navig
heightTextHeight //z
);
updateTextTexture(((currentHeight-minHeight)*scaleDisplayDivider).toFixed(2).toString(),40,heightText,-3.501+(defaultArmLength*2-arm1Length-arm2Length),0,heightTextHeight);
moveArmBy(null,null,currentHeight-lastHeight,rightSide);
if(!demoMode)
moveArmBy(null,null,currentHeight-lastHeight,rightSide);
toolMesh.translateY(currentHeight-lastHeight);
}
reacted=true;
Expand Down Expand Up @@ -563,7 +566,8 @@ async function setupMoveListener(){
if(canMove(currentToolX+armStep,currentToolY)){
currentToolX+=armStep;
moveToolOnSceneToPosition();
moveArmBy(armStep,null,null,rightSide);
if(!demoMode)
moveArmBy(armStep,null,null,rightSide);
updatePositionText();
}
break;
Expand All @@ -573,7 +577,8 @@ async function setupMoveListener(){
if(canMove(currentToolX-armStep,currentToolY)){
currentToolX-=armStep;
moveToolOnSceneToPosition();
moveArmBy(-armStep,null,null,rightSide);
if(!demoMode)
moveArmBy(-armStep,null,null,rightSide);
updatePositionText();
}
break;
Expand All @@ -583,7 +588,8 @@ async function setupMoveListener(){
if(canMove(currentToolX,currentToolY+armStep)){
currentToolY+=armStep;
moveToolOnSceneToPosition();
moveArmBy(null,armStep,null,rightSide);
if(!demoMode)
moveArmBy(null,armStep,null,rightSide);
updatePositionText();
}
break;
Expand All @@ -593,7 +599,8 @@ async function setupMoveListener(){
if(canMove(currentToolX,currentToolY-armStep)){
currentToolY-=armStep;
moveToolOnSceneToPosition();
moveArmBy(null,-armStep,null,rightSide);
if(!demoMode)
moveArmBy(null,-armStep,null,rightSide);
updatePositionText();
}
break;
Expand Down Expand Up @@ -710,17 +717,25 @@ function moveArmBy(x,y,z,isRightSide){
if(response.status == 500){
console.error("move fail");
}else if(response.status == 503){
onArmDisconnect();
}
}).catch(error => {
console.error('Error:', error);
});
}

/**
* Function to block move, deselect arm part, display notification
*/
export function onArmDisconnect(){
console.error("Connection lost");
showDialog(document.getElementById("alert"), document.getElementById("alert-msg"), 'e',"Arm connection lost");
changeSTLColor(lastSelectedMesh,armColor);
lastSelectedMesh=null;
refreshPorts();
}
}).catch(error => {
console.error('Error:', error);
});
}


/**
* Function to move physical arm by angle
* @param {number} firstArmAngle - relative movement of first arm, null if no movement
Expand Down
14 changes: 10 additions & 4 deletions src/main/resources/files/elements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as THREE from '/static/three/build/three.module.js'
import {onArmDisconnect} from '/static/display.js'

// Functions to draw elements on scene

Expand Down Expand Up @@ -452,19 +453,24 @@ export function drawArmRange(panelSize,armShift, arm1Length, arm2Length, MAX_ARM
* @param {callback(THEE.Vector,boolean)} onLineRead - function updating tool position in for displaying
* @param {number} xShift - shift of model position
* @param {boolean} isRightSide - specifies orientation of arm
* @TODO 1.display message in UI on file loading error
* 2.Check if sending code to arm blocks UI/Server
* 3.Synchronize arm code execution and Drawing state
* @TODO Synchronize arm code execution and Drawing state
*/
export function drawFile(scene,fileName,onLineRead,xShift,isRightSide){
const data = {isRightSide: ''+isRightSide};
const params = new URLSearchParams(data);

//sending code to arm
fetch("/files/"+fileName+"/draw", {method: "POST",body: params}).then(response => {

if (response.ok) {
console.log("File is processing.");
} else {
}else if(response.status == 500){
console.error("Failed to draw file");
}else if(response.status == 503){
onArmDisconnect();
}

else {
console.error("ERROR during file process. "+response);
}
})
Expand Down
55 changes: 38 additions & 17 deletions src/main/resources/files/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var buttons = document.querySelectorAll(".first");
var expanded = false;
var menuDisplayed = false;
var canMoveArm = false;
export var demoMode = false;

portMenu.style.minHeight = firstMenuStyle.height;
loadMenu.style.minHeight = firstMenuStyle.height;
Expand All @@ -114,7 +115,19 @@ firstMenuUl[1].style.transform = "translateY(" + optionMenuHide + ")";
export function getCanMoveArm() {
return canMoveArm;
}

/**
* Function to disable or activate loading buttons when arm is not connected.
* @param state boolean
*/
function blockLoadButtons(state){
let loadFileButtons = document.querySelectorAll('.loadFileButtons');
loadFileButtons.forEach(button => {
if(state)
button.setAttribute('disabled',"");
else
button.removeAttribute('disabled');
});
}
/**
* Function returns calculated units of move by single click.
* @returns {number}
Expand Down Expand Up @@ -369,7 +382,7 @@ function fillFilesTable() {
fileData[1] +
"</td><td>" +
fileData[2] +
"</td><td><button onClick=\"window.loadFile('" +
"</td><td><button class=\"loadFileButtons\" onClick=\"window.loadFile('" +
fileData[0] +
"')\">Load</button><button onClick=\"window.deleteFile('" +
fileData[0] +
Expand All @@ -394,6 +407,8 @@ function fillPortsTable() {
return response.json();
})
.then((data) => {
html +=
'<tr><td class="radioItem"><input type="radio" name="portList" id="demo" value="demo" ><label for="demo">DEMO MODE</label></td></tr>';
data.forEach((port) => {
if (port.length > 0)
html +=
Expand All @@ -415,19 +430,26 @@ function fillPortsTable() {
radioButtons.forEach((radioButton) => {
radioButton.addEventListener("change", function () {
if (this.checked) {
var formData = new FormData();
formData.append("port", this.value);
fetch("/ports/select", {
method: "POST",
body: formData,
}).then((response) => {
if (response.ok) {
connectToArm();
} else {
console.error("Cannot connect to arm");
showDialog(alertItem, alertMessage, 'e',"Cannot connect to arm");
}
});
if(this.value== "demo"){
canMoveArm = true;
demoMode = true;
showDialog(alertItem, alertMessage, 's',"DEMO MODE");
}else{
var formData = new FormData();
formData.append("port", this.value);
fetch("/ports/select", {
method: "POST",
body: formData,
}).then((response) => {
if (response.ok) {
demoMode = false;
connectToArm();
} else {
console.error("Cannot connect to arm");
showDialog(alertItem, alertMessage, 'e',"Cannot connect to arm");
}
});
}
}
});
});
Expand Down Expand Up @@ -661,12 +683,11 @@ loadFileButton.addEventListener("click", function () {
expanded = true;
turnOnOverlay();
loadMenu.style.left = barWidth;
canMoveArm = false;
blockLoadButtons(!canMoveArm);
} else {
expanded = false;
turnOffOverlay();
loadMenu.style.left = loadMenuHide;
canMoveArm = true;
}
}, time);
});
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/files/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,16 @@ input[type="number"]{
td>button:first-child{
background-color: #218838;
}
td>button:first-child:disabled{
background-color: #638e6d;
}
td>button:first-child:hover{
background-color: #28a745;
}

td>button:first-child:hover:disabled {
background-color: #638e6d;
}
.menu-button input[type=file] {
font-size: 100px;
height: 60px;
Expand Down

0 comments on commit 40ace9b

Please sign in to comment.