Tests
CalculateAngles verpacken
This commit is contained in:
43
public/calculateAngles.js
Normal file
43
public/calculateAngles.js
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* calculateAngles module
|
||||
*
|
||||
* Browser + Server + Jest (CJS) kompatibel
|
||||
*/
|
||||
|
||||
function calculate(foundMarkers, jsonRobot) {
|
||||
// --- X of the Hand-Joint ---
|
||||
const validOns = new Set(['Base', 'Arm1', 'Joint1']);
|
||||
const foundById = new Map(foundMarkers.map(f => [f.id, f]));
|
||||
|
||||
const markersMovingFixedX = jsonRobot.Marker.filter(m => validOns.has(m.on));
|
||||
const markersXPosition = new Map();
|
||||
|
||||
const xs = markersMovingFixedX
|
||||
.map(m => {
|
||||
const f = foundById.get(m.id);
|
||||
return f ? f.position[0] - m.relPos[0] : null;
|
||||
})
|
||||
.filter(x => x !== null);
|
||||
|
||||
const xAvg = xs.length
|
||||
? xs.reduce((a, b) => a + b, 0) / xs.length
|
||||
: 0;
|
||||
|
||||
return {
|
||||
meta: {
|
||||
module: 'calculateAngles',
|
||||
timestamp: new Date().toISOString()
|
||||
},
|
||||
inputs: {
|
||||
markers: foundMarkers ?? null,
|
||||
robot: jsonRobot ?? null
|
||||
},
|
||||
status: 'ok',
|
||||
result: {
|
||||
xAvg
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
module.exports = { calculate };
|
||||
Reference in New Issue
Block a user