calculateAngles

Versuch, es vom Browser aus zugänglich zu machen
This commit is contained in:
chk
2026-05-11 16:46:26 +02:00
parent 33c946867e
commit ba2cc8f6ec
6 changed files with 537 additions and 6 deletions

View File

@@ -4,9 +4,27 @@
* Browser + Server + Jest (CJS) kompatibel
*/
function getAnalysisLogEl() {
if (typeof document === "undefined") return null;
return document.getElementById("analysis-log");
}
function appendToAnalysis(line) {
const el = getAnalysisLogEl();
if (!el) return;
const now = new Date().toISOString();
el.value += `[${now}] ${line}\n`;
el.scrollTop = el.scrollHeight;
}
function calculateXPos(listIdAndX, jsonRobot){
const partsMovingFixedX = new Set(['Base', 'Arm1', 'Joint1']);
const markersMovingFixedX = jsonRobot.Marker.filter(m => partsMovingFixedX.has(m.on));
appendToAnalysis("Calculate XPos");
const partsMovingFixedX = new Set(['Base', 'Arm1', 'Joint1']);
const markersMovingFixedX = jsonRobot.Marker.filter(m => partsMovingFixedX.has(m.on));
// Join: Robot-Marker ↔ Found-Marker
const markersListeWithRobotInfo = jsonRobot.Marker
@@ -169,7 +187,7 @@ const markerFound = markerUsed
return average, deviation;
}
function calculate(foundMarkers, jsonRobot) {
async function calculate(foundMarkers, jsonRobot) {
const foundById = new Map(foundMarkers.markers.map(f => [f.id, f.position_mm ]));
const { meanPx: x, stdDevPx: varx } = calculateXPos(foundById, jsonRobot);

View File

@@ -1,9 +1,21 @@
import { calculate } from './calculateAngles.js';
import cjs from './calculateAngles.js';
export const calculate = cjs.calculate;
export const optimizeRobot = cjs.optimizeRobot;
export async function fetchAndCalculate() {
const res = await fetch("/api/latest-snapshot");
console.log(res);
}
if (typeof window !== 'undefined') {
window.calculateAngles = window.calculateAngles || {};
window.calculateAngles.calculate = calculate;
window.calculateAngles.fetchAndCalculate = fetchAndCalculate;
// automatisch starten
fetchAndCalculate();
}
export { calculate };
export { calculate, fetchAndCalculate };

View File

@@ -35,7 +35,7 @@
GCodeMotor
</button>
<button id="btn-calculate">Calculate Actions</button>
<button id="btn-calculate" onclick="fetchAndCalculate()">Calculate Actions</button>
</div>
</div>
@@ -87,7 +87,10 @@
</div>
<script src="/calculateActions.js"></script>
<script type="module" src="/calculateAnglesBrowser.js"></script>
<script src="/client.js"></script>
<script> window.calculateAngles.fetchAndCalculate(); </script>
</body>
</html>