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

Add events to calibration, and fix some stuff/cleanup #24

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
node_modules
dist
src
index.html.gz
index.html.gz
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function compress() {
return gulp
.src('dist/index.html')
.pipe(gzip({ gzipOptions: { level: 9 } }))
.pipe(gulp.dest('.'))
.pipe(gulp.dest('dist'))
.pipe(size())
}

Expand Down
Binary file removed index.html.gz
Binary file not shown.
65 changes: 60 additions & 5 deletions www/js/calculatesCalibrationStuff.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ function walkLines(tlLine, trLine, blLine, brLine, stepSize) {
brLine = lines[3]
}

return { tlLine, trLine, blLine, brLine }
const result = { tlLine, trLine, blLine, brLine, changeMade }

sendCalibrationEvent({
walkedlines: result,
});

return result;
}

/**
Expand Down Expand Up @@ -206,7 +212,14 @@ function magneticallyAttractedLinesFitness(measurement, individual) {
measurement.TLtension = TL
measurement.TRtension = TR

return { fitness: finalFitness, lines: { tlLine: tlLine, trLine: trLine, blLine: blLine, brLine: brLine } }
const result ={ fitness: finalFitness, lines: { tlLine: tlLine, trLine: trLine, blLine: blLine, brLine: brLine } }
sendCalibrationEvent({
lines: result,
individual,
measurement
});

return result;
}

/**
Expand Down Expand Up @@ -486,6 +499,11 @@ function scaleMeasurementsBasedOnTension(measurements, guess) {


function findMaxFitness(measurements) {

sendCalibrationEvent({
initialGuess
}, true);

let currentGuess = JSON.parse(JSON.stringify(initialGuess));
let stagnantCounter = 0;
let totalCounter = 0;
Expand All @@ -497,15 +515,21 @@ function findMaxFitness(measurements) {
clearCanvas();

currentGuess = computeLinesFitness(measurements, currentGuess);

if (1/currentGuess.fitness > 1/bestGuess.fitness) {
bestGuess = JSON.parse(JSON.stringify(currentGuess));
stagnantCounter = 0;
} else {
stagnantCounter++;
}
totalCounter++;
console.log("Total Counter: " + totalCounter);
// console.log("Total Counter: " + totalCounter);
sendCalibrationEvent({
final: false,
guess: currentGuess,
bestGuess: bestGuess,
totalCounter
});

if(totalCounter % 100 == 0){
document.getElementById('messages').value += "Fitness: " + (1/bestGuess.fitness).toFixed(7) + " in " + totalCounter + "\n";
Expand Down Expand Up @@ -544,6 +568,11 @@ function findMaxFitness(measurements) {
sendCommand('$/Maslow_blY=' + bestGuess.bl.y.toFixed(1));
sendCommand('$/Maslow_brX=' + bestGuess.br.x.toFixed(1));
sendCommand('$/Maslow_brY=' + bestGuess.br.y.toFixed(1));
sendCalibrationEvent({
good: true,
final: true,
bestGuess: bestGuess
}, true);
refreshSettings(current_setting_filter);
saveMaslowYaml();

Expand All @@ -556,6 +585,12 @@ function findMaxFitness(measurements) {
setTimeout(function() {
sendCommand('$System/Control=RESTART');
}, 2000);
} else {
sendCalibrationEvent({
good: false,
final: true,
guess: bestGuess
}, true);
}
}
}
Expand All @@ -565,7 +600,27 @@ function findMaxFitness(measurements) {
}



/**
* This function will allow us to hook data into events that we can just copy this file into another project
* to have the calibration run in other contexts and still gather events from the calculations to plot things, gather data, etc.
*/
function sendCalibrationEvent(dataToSend, log=false) {
try{
if (log) {
console.log(JSON.stringify(dataToSend,null,2));
} else if(dataToSend.totalCounter) {
console.log("total counter:", dataToSend.totalCounter);
}
document.body.dispatchEvent(new CustomEvent(CALIBRATION_EVENT_NAME, {
bubbles: true,
cancelable: true,
detail: dataToSend
}));
} catch (err) {
console.error('Unexpected:', err)
}
}
const CALIBRATION_EVENT_NAME = 'calibration-data';
//This is where the program really begins. The above is all function definitions
//The way that the progam works is that we basically guess where the four corners are and then
//check to see how good that guess was. To see how good a guess was we "draw" circles from the four corner points
Expand Down
1 change: 1 addition & 0 deletions www/js/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function Monitor_output_Update(message) {
outlc.startsWith("echo:") ||
outlc.startsWith("Config:") ||
outlc.startsWith("echo:Unknown command: \"echo\"") ||
outlc.startsWith("[MSG:INFO: Heartbeat]") ||
outlc.startsWith("echo:enqueueing \"*\"")
) {
continue;
Expand Down
10 changes: 5 additions & 5 deletions www/js/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ function process_cmd() {
process_cmd();
}

} //else if (http_cmd_list.length > 0)console.log("processing");
} //else if (http_cmd_list.length > 0)console.log("processing");
}

function AddCmd(cmd_fn, id) {
if (http_cmd_list.length > max_cmd) {
errorfn(999, translate_text_item("Server not responding"));
http_errorfn(999, translate_text_item("Server not responding"));
return;
}
var cmd_id = 0;
Expand Down Expand Up @@ -95,17 +95,17 @@ function SendGetHttp(url, result_fn, error_fn, id, max_id) {
if (typeof max_id != 'undefined') cmd_max_id = max_id;
//else console.log("No Max ID defined");
for (p = 0; p < http_cmd_list.length; p++) {
//console.log("compare " + (max_id - cmd_max_id));
//console.log("compare " + (max_id - cmd_max_id));
if (http_cmd_list[p].id == cmd_id) {
cmd_max_id--;
//console.log("found " + http_cmd_list[p].id + " and " + cmd_id);
//console.log("found " + http_cmd_list[p].id + " and " + cmd_id);
}
if (cmd_max_id <= 0) {
console.log("Limit reached for " + id);
return;
}
}
} //else console.log("No ID defined");
} //else console.log("No ID defined");
//console.log("adding " + url);
var cmd = {
cmd: url,
Expand Down
17 changes: 11 additions & 6 deletions www/js/tablet.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ sendMove = function (cmd) {
}

moveHome = function () {

//We want to move to the opposite of the machine's current X,Y cordinates
var x = parseFloat(id('mpos-x').innerText)
var y = parseFloat(id('mpos-y').innerText)
Expand Down Expand Up @@ -392,7 +392,7 @@ function tabletShowMessage(msg, collecting) {
msg = '<span style="color:red;">' + msg + '</span>'
}


}

function tabletShowResponse(response) {}
Expand Down Expand Up @@ -751,8 +751,13 @@ function tabletGetFileList(path) {
}

function tabletInit() {
tabletGetFileList('/')
requestModes()
// put in a timeout to allow things to settle. when they were here at startup ui froze from time to time.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this too I think

setTimeout(() => {
tabletGetFileList('/');
requestModes();
loadConfigValues();
loadCornerValues();
}, 1000);
}

function arrayToXYZ(a) {
Expand Down Expand Up @@ -1104,7 +1109,7 @@ id('tablettab').addEventListener('activate', askMachineBbox, false)
// a) required setting a fixed message window height, or
// b) the message window would extend past the screen bottom when messages were added
function height(element) {
return element.getBoundingClientRect().height
return element?.getBoundingClientRect()?.height
}
function heightId(eid) {
return height(id(eid))
Expand Down Expand Up @@ -1266,7 +1271,7 @@ function saveConfigValues(){
sendCommand('$/Maslow_tlY=' + machineHeight)
sendCommand('$/Maslow_trX=' + machineWidth)
sendCommand('$/Maslow_trY=' + machineHeight)
sendCommand('$/Maslow_brX=' + machineWidth)
sendCommand('$/Maslow_brX=' + machineWidth)
}

refreshSettings(current_setting_filter);
Expand Down