Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reef align into autoscore #15

Closed
wants to merge 13 commits into from
26 changes: 15 additions & 11 deletions src/main/deploy/autoscore/coralLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ const setCoralImg = (level) => {
coralImage.src = `coralLevelImages/coral${level}.png`;
}

const coralImgPos = coralImage.getBoundingClientRect();
//this is radius not actual width
const coralWidth = (coralImgPos.right-coralImgPos.left) / 2;
const coralHeight = (coralImgPos.bottom-coralImgPos.top) / 2;
const coralX = coralImgPos.left + coralWidth;
const coralY = coralImgPos.top + coralHeight;
coralImage.addEventListener("mousemove", (event) => {
["mousemove", "touchmove"].forEach(_ => coralImage.addEventListener(_, (event) => {
//this is radius not actual width
const coralImgPos = coralImage.getBoundingClientRect();
const coralHeight = (coralImgPos.bottom-coralImgPos.top) / 2;
const coralY = coralImgPos.top + coralHeight;
let mouseY = event.clientY;
let ydiff = coralY - mouseY;
if(_ == "touchmove") {
mouseY = event.changedTouches[0].clientY;
ydiff = coralY - mouseY;
}
if(!coralSelected) {
if(ydiff > coralHeight * 0.4) {
setCoralImg("L4");
Expand All @@ -38,8 +40,10 @@ coralImage.addEventListener("mousemove", (event) => {
prevCoralLevel = 1;
}
}
});
coralImage.addEventListener("mouseleave", () => {
}));


["mouseleave", "touchend"].forEach(_ => coralImage.addEventListener(_, () => {
if(coralSelected) {
if(coralLevel == 1) {
setCoralImg("L1");
Expand All @@ -53,7 +57,7 @@ coralImage.addEventListener("mouseleave", () => {
} else {
setCoralImg("None");
}
})
}));

coralImage.onclick = () => {
coralSelected = !coralSelected;
Expand All @@ -62,7 +66,7 @@ coralImage.onclick = () => {
coralImage.src = `coralLevelImages/coralL${coralLevel}.png`;
coralText.innerText = `Coral Level: ${coralLevel}`;
if(areaSelected) {
confirmReefButton.innerText = `Score at Level ${coralLevel} and Area ${reefArea}`;
confirmReefButton.innerText = `Score at Level ${coralLevel} and Area ${numberToLetter[11-(reefArea+4)%12]}`;
}
} else {
setCoralImg("None");
Expand Down
70 changes: 47 additions & 23 deletions src/main/deploy/autoscore/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,7 @@

<body>
<div class="scoringContainer" style="display: none;">
<div class="reefContainer">
<div class="levelContainer" style="display: none;">
<div class="Level" id="L4">
Level 4 Score
</div>
<div class="Level" id="L3">
Level 3 Score
</div>
<div class="Level" id="L2">
Level 2 Score
</div>
<div class="Level" id="L1">
Level 1 Score
</div>
</div>
<div class="reefContainer" style="display: none;">
<div class="coralLevelImage">
<img src="coralLevelImages/coralNone.png" alt="" id="coral">
</div>
Expand All @@ -43,19 +29,16 @@ <h1 class="reefText" id="areaText">Reef Area: None</h1>
<div class="Button" id="confirmReefButton">
Choose Robot Alignment
</div>
<div class="Button" id="cancelCommand">
Cancel Command
</div>
</div>
</div>
<div class="processorContainer">
<div class="processorContainer" style="display: none;">
<div class="buttonContainer">
<div class="Button" id="processorScore">
Score Processor
</div>
</div>
</div>
<div class="netContainer">
<div class="netContainer" style="display: none;">
<div class="buttonContainer">
<div class="Button" id="netScoreRed">
Score Net on Red Side
Expand All @@ -65,7 +48,7 @@ <h1 class="reefText" id="areaText">Reef Area: None</h1>
</div>
</div>
</div>
<div class="coralIntakeContainer">
<div class="coralIntakeContainer" style="display: none;">
<div class="buttonContainer">
<div class="Button" id="coralIntakeTop">
Intake Coral Top
Expand All @@ -75,9 +58,50 @@ <h1 class="reefText" id="areaText">Reef Area: None</h1>
</div>
</div>
</div>
<div class="manualContainer" style="display: none;">
<div>
<h1 id="manualText">
Scoring on Area _ and Level _
</h1>
</div>
<div>
<div class="Button" id="cancel">
Cancel Command
</div>
</div>
<div>
<div class="Button" id="score">
Score!
</div>
</div>
<div class="pivotContainer">
<div class="Button" id="pivotForward">
Move Pivot Forward
</div>
<div class="Button" id="pivotBack">
Move Pivot Backwards
</div>
</div>
<div class="elevatorContainer">
<div class="Button" id="elevatorUp">
Move Elevator Up
</div>
<div class="Button" id="elevatorDown">
Move Elevator Down
</div>
</div>
<div class="wristContainer">
<div class="Button" id="wristForward">
Move Wrist Forward
</div>
<div class="Button" id="wristBack">
Move Wrist Backwards
</div>
</div>
</div>
</div>
<div class="messageContainer" style="display: none">
<h1 id="messageDisplay"></h1>
<div class="messageContainer" style="display: none;">
<h1 id="messageDisplay">NO ROBOT CONNECTION</h1>
</div>
<script src="ntsetup.js"></script>
<script src="robotCommunication.js"></script>
Expand Down
69 changes: 36 additions & 33 deletions src/main/deploy/autoscore/reefPlacement.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
const locationImg = document.getElementById("locationSelect");
const confirmReefButton = document.getElementById("confirmReefButton");

let inPicker = false;
locationImg.onmouseenter = () => inPicker = true;
locationImg.onmouseleave = () => {
if(!areaSelected) {
inPicker = false;
locationImg.src = "locationSelectorImages/locationSelectorNone.png";
}
}

document.addEventListener("mousemove", (event) => {
if(inPicker && !areaSelected) {
let imgPosition = locationImg.getBoundingClientRect();
let imageCenterX = imgPosition.left + (imgPosition.right-imgPosition.left) / 2;
let imageCenterY = imgPosition.top + (imgPosition.bottom-imgPosition.top) / 2;

let x = event.clientX-imageCenterX;
let y = imageCenterY-event.clientY;

let angleRadians = Math.atan2(x, y);
let angleDegrees = angleRadians * (180 / Math.PI);
if(angleRadians < 0) {
angleDegrees = 360 + angleRadians * (180 / Math.PI);
["touchmove", "mousemove"].forEach(_ => {
locationImg.addEventListener(_, (event) => {
if(!areaSelected) {
let imgPosition = locationImg.getBoundingClientRect();
let imageCenterX = imgPosition.left + (imgPosition.right-imgPosition.left) / 2;
let imageCenterY = imgPosition.top + (imgPosition.bottom-imgPosition.top) / 2;

let x = event.clientX-imageCenterX;
let y = imageCenterY-event.clientY;
if(_ == "touchmove") {
x = event.changedTouches[0].clientX-imageCenterX;
y = imageCenterY-event.changedTouches[0].clientY;
}

let angleRadians = Math.atan2(x, y);
let angleDegrees = angleRadians * (180 / Math.PI);
if(angleRadians < 0) {
angleDegrees = 360 + angleRadians * (180 / Math.PI);
}
reefArea = Math.floor(((angleDegrees-120) % 360)/30) + 5;
if(reefArea == -1) {
locationImg.src = `locationSelectorImages/locationSelectorNone.png`;
} else {
locationImg.src = `locationSelectorImages/locationSelector${reefArea < 5 ? reefArea+8 : reefArea-4}.png`;
}
}
reefArea = Math.floor(((angleDegrees-120) % 360)/30) + 5;
if(reefArea == -1) {
locationImg.src = `locationSelectorImages/locationSelectorNone.png`;
} else {
locationImg.src = `locationSelectorImages/locationSelector${
reefArea < 5 ? reefArea+8 : reefArea-4
}.png`;
});
});

["touchend", "mouseleave"].forEach(_ => {
locationImg.addEventListener(_, () => {
if(!areaSelected) {
locationImg.src = "locationSelectorImages/locationSelectorNone.png";
}
}
});
});

let areaText = document.getElementById("areaText");
Expand All @@ -41,15 +44,15 @@ let areaSelectionText = document.getElementById("areaSelectionText");
locationImg.onclick = () => {
areaSelected = !areaSelected;
if(areaSelected) {
areaText.innerText = `Reef Area: ${reefArea}`;
areaText.innerText = `Reef Area: ${numberToLetter[11-(reefArea+4)%12]}`;
areaSelectionText.innerText = "Click again to reselect";
locationImg.src = "locationSelectorImages/locationSelectorNone.png";
} else {
confirmReefButton.innerText = `Choose Robot Alignment`;
areaText.innerText = `Reef Area: None`;
areaSelectionText.innerText = "Click the area you want to go to.";
locationImg.src = "locationSelectorImages/locationSelectorNone.png";
}
if(coralSelected) {
confirmReefButton.innerText = `Score at Level ${coralLevel} and Area ${reefArea}`;
confirmReefButton.innerText = `Score at Level ${coralLevel} and Area ${numberToLetter[11-(reefArea+4)%12]}`;
}
}
68 changes: 54 additions & 14 deletions src/main/deploy/autoscore/robotCommunication.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ function valueUpdateHandler( topic, timestamp_us, value ) {
console.log("value updated: " + topic.name);
if(topic.name == "/webcom/Alliance") {
setAlliance(value);
} else if(topic.name == "/webcom/isDone" && value===true) {
document.getElementById("manualText").innerText = `Scoring on Area ${numberToLetter[11-(reefArea+4)%12]} and Level ${coralLevel}`;
showContainer("manualContainer");
["pivotForward", "pivotBack", "elevatorUp", "elevatorDown", "wristForward", "wristBack"].forEach(
id => {
const elt = document.getElementById(id);
const eltinterval = setInterval(() => {
if(window.getComputedStyle(elt).backgroundColor == "rgb(200, 0, 0)") {
setCommand(id);
}
}, 0.02);
intervalList.push(eltinterval);
}
);
}
}

Expand Down Expand Up @@ -97,27 +111,26 @@ let coralLevel = -1;
let reefArea = -1;
let coralSelected = false;
let areaSelected = false;
let intervalList = [];

let reefScoreButtonClickable = true;
const resetReefStuff = () => {
const resetReef = () => {
coralSelected = false;
areaSelected = false;
coralLevel = -1;
document.getElementById("confirmReefButton").innerText = `Choose Robot Alignment`;
document.getElementById("areaSelectionText").innerText = "Hover to the area you want to go to.";
document.getElementById("coral").src = `coralLevelImages/coralNone.png`;
document.getElementById("areaText").innerText = "Reef Area: None";
document.getElementById("coralText").innerText = "Coral Level: None";
document.getElementById("locationSelect").src = "locationSelectorImages/locationSelectorNone.png";
intervalList.forEach(ivl => clearInterval(ivl));
intervalList.length = 0;
}

document.getElementById("confirmReefButton").onclick = async () => {
if(reefScoreButtonClickable && coralSelected && areaSelected) {
reefScoreButtonClickable = false;
confirmReefButton.innerText = "Scoring...";
await scoreReef(reefArea, coralLevel);
confirmReefButton.innerText = "Choose Robot Alignment";
reefScoreButtonClickable = true;
resetReefStuff();
if(coralSelected && areaSelected) {
scoreReef(reefArea, coralLevel);
document.getElementById("confirmReefButton").innerText = "Scoring...";
}
}

Expand All @@ -136,7 +149,6 @@ const scoreProcessor = async () => {
}

const intakeCoral = async (isAtTopSide) => {
console.log("intaking coral");
if(isAtTopSide) {
setCommand("intakeCoralTop");
} else {
Expand Down Expand Up @@ -168,15 +180,43 @@ const connection = () => {
messageContainer.style.display = "none";
scoringContainer.style.display = "flex";
msgDisplay.innerText = "";
resetReef();
showContainer("reefContainer");
}

document.getElementById("cancelCommand").onclick = () => {
document.getElementById("cancel").onclick = () => {
setCommand("cancel");
resetReef();
showContainer("reefContainer");
}

processorContainer.style = "display: none";
netContainer.style = "display: none";
coralIntakeContainer.style = "display: none";
document.getElementById("score").onclick = () => {
setCommand("score");
resetReef();
showContainer("reefContainer");
}

let currentContainer = "reefContainer";

const showContainer = (container) => {
document.querySelector(`.${currentContainer}`).style.display = "none";
currentContainer = container;
document.querySelector(`.${currentContainer}`).style.display = "flex";
}

noConnection();

const numberToLetter = [
'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
'L'
];
Loading
Loading