robot.json editieren - board

This commit is contained in:
chk
2026-06-10 17:27:07 +02:00
parent 45513cf714
commit 6b3053dd76
4 changed files with 322 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import { fileURLToPath } from 'url';
import process from 'process';
import { spawn } from 'child_process';
import { WebcamClient } from './webcamClient.js';
import { assignByZRange, removeMarkerAssignment } from './editRobot.js';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
@@ -689,6 +690,54 @@ app.get('/api/board/latest', async (req, res) => {
}
});
// ── Robot-JSON bearbeiten ─────────────────────────────────────────────────────
/**
* POST /api/robot/assign-by-z
* Weist allen Markern in [zMin, zMax] mm das angegebene Set und/oder Link zu.
* Body: { zMin, zMax, set?, link? }
*/
app.post('/api/robot/assign-by-z', async (req, res) => {
try {
const { zMin, zMax, set, link } = req.body ?? {};
if (zMin == null || zMax == null) {
return res.status(400).json({ error: 'zMin und zMax sind erforderlich' });
}
if (!set && !link) {
return res.status(400).json({ error: 'Mindestens set oder link muss angegeben werden' });
}
const result = await assignByZRange(ROBOT_JSON, { zMin, zMax, set, link });
console.log(`robot/assign-by-z z=[${zMin}..${zMax}] set="${set}" link="${link}" → ${result.numChanged} geändert`);
return res.json(result);
} catch (err) {
console.error('robot/assign-by-z error:', err);
return res.status(500).json({ error: String(err) });
}
});
/**
* POST /api/robot/remove-marker
* Entfernt Set oder Link-Zuordnung eines Markers.
* Body: { markerId, removeFrom } removeFrom: 'set' | 'link'
*/
app.post('/api/robot/remove-marker', async (req, res) => {
try {
const { markerId, removeFrom } = req.body ?? {};
if (markerId == null) {
return res.status(400).json({ error: 'markerId ist erforderlich' });
}
if (!['set', 'link'].includes(removeFrom)) {
return res.status(400).json({ error: 'removeFrom muss "set" oder "link" sein' });
}
const result = await removeMarkerAssignment(ROBOT_JSON, { markerId, removeFrom });
console.log(`robot/remove-marker id=${markerId} from=${removeFrom} → changed=${result.changed}`);
return res.json(result);
} catch (err) {
console.error('robot/remove-marker error:', err);
return res.status(500).json({ error: String(err) });
}
});
/**
* POST /api/calibration/upload-npz
* Liest {camera}_calibration.npz aus der aktuellen Session und