🦉 Makes use of unique model per socket connection

This commit is contained in:
Rune Harlyk
2024-02-05 18:13:17 +01:00
parent 8286c5f3b5
commit 9347bccf5f
+3 -3
View File
@@ -162,7 +162,7 @@ const updateSystem = () => {
return system; return system;
}; };
const updateBodyState = (angles, position) => { const updateBodyState = (model, angles, position) => {
const Lp = [ const Lp = [
[100, -100, 100, 1], [100, -100, 100, 1],
[100, -100, -100, 1], [100, -100, -100, 1],
@@ -253,7 +253,7 @@ wss.on("connection", (ws) => {
ws.send( ws.send(
JSON.stringify({ JSON.stringify({
type: "angles", type: "angles",
angles: updateBodyState(data.angles, data.position), angles: updateBodyState(ws.clientState.model, data.angles, data.position),
}) })
); );
} else { } else {
@@ -310,7 +310,7 @@ app.post("/kinematic/angles/", (req, res) =>
app.get("/kinematic/bodystate", (req, res) => res.send(model.servos.angles)); app.get("/kinematic/bodystate", (req, res) => res.send(model.servos.angles));
app.post("/kinematic/bodystate", (req, res) => { app.post("/kinematic/bodystate", (req, res) => {
sendUpdateToSubscribers("angles", model.servos.angles); sendUpdateToSubscribers("angles", model.servos.angles);
res.send(updateBodyState(req.body.angles, req.body.position)); res.send(updateBodyState(model, req.body.angles, req.body.position));
}); });
// ----------------------------------------------------------- // // ----------------------------------------------------------- //