From 9bfa2884652de6b57e16a38e81118667321ad1d6 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Wed, 11 Jun 2025 17:39:15 +0200 Subject: [PATCH] Only send pose messages for remote things from a site server --- src/Participant.cs | 4 ++-- src/Participants/ParticipantUDP.cs | 36 +++++++++++++++--------------- src/Participants/SiteServer.cs | 32 ++++++++++++++++++++++++++ src/Thing.cs | 5 ++++- 4 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/Participant.cs b/src/Participant.cs index 6944992..5cb2527 100644 --- a/src/Participant.cs +++ b/src/Participant.cs @@ -113,7 +113,7 @@ namespace RoboidControl { ); //Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId)); if (thing == null) - Console.WriteLine($"Could not find thing {this.networkId} [{networkId}/{thingId}]"); + Console.WriteLine($"Unknown Thing {this.networkId} [{networkId}/{thingId}]"); return thing; } @@ -123,7 +123,7 @@ namespace RoboidControl { /// The thing to add /// If true, the thing.id is regenerated if it is zero public void Add(Thing thing, bool checkId = true) { - Console.WriteLine("Add Thing to participant"); + // Console.WriteLine("Add Thing to participant"); if (checkId && thing.id == 0) { thing.id = (byte)(this.things.Count + 1); this.things.Add(thing); diff --git a/src/Participants/ParticipantUDP.cs b/src/Participants/ParticipantUDP.cs index 297ffc4..7adb8a4 100644 --- a/src/Participants/ParticipantUDP.cs +++ b/src/Participants/ParticipantUDP.cs @@ -236,25 +236,25 @@ namespace RoboidControl { // if (this.isIsolated) // continue; - if (currentTimeMS > this.nextSendUpdate) { - for (int thingIx = 0; thingIx < owner.things.Count; thingIx++) { - Thing thing = owner.things[thingIx]; - if (thing == null) - continue; + // if (currentTimeMS > this.nextSendUpdate) { + // for (int thingIx = 0; thingIx < owner.things.Count; thingIx++) { + // Thing thing = owner.things[thingIx]; + // if (thing == null) + // continue; - foreach (Participant participant in Participant.participants) { - if (participant == this || participant == owner) - continue; + // foreach (Participant participant in Participant.participants) { + // if (participant == this || participant == owner) + // continue; - Console.WriteLine($"[{thing.owner.networkId}/{thing.id}] Pose ---> {participant.networkId}"); - PoseMsg poseMsg = new(thing.owner.networkId, thing, true); - participant.Send(poseMsg); - } - } - } + // Console.WriteLine($"[{thing.owner.networkId}/{thing.id}] Pose ---> {participant.networkId}"); + // PoseMsg poseMsg = new(thing.owner.networkId, thing, true); + // participant.Send(poseMsg); + // } + // } + // } } - if (currentTimeMS > this.nextSendUpdate) - this.nextSendUpdate = currentTimeMS + this.sendUpdateIntervalMS; + // if (currentTimeMS > this.nextSendUpdate) + // this.nextSendUpdate = currentTimeMS + this.sendUpdateIntervalMS; } #endregion Update @@ -490,7 +490,7 @@ namespace RoboidControl { } protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg, bool isRemote) { - Console.WriteLine("--- New Thing"); + // Console.WriteLine("--- New Thing"); Thing newThing = msg.thingType switch { Thing.Type.TouchSensor => new TouchSensor(owner.root), Thing.Type.DifferentialDrive => new DifferentialDrive(owner.root), @@ -528,7 +528,7 @@ namespace RoboidControl { } protected virtual void Process(Participant sender, PoseMsg msg) { -#if DEBUG2 +#if DEBUG Console.WriteLine($"{this.name}: Process PoseMsg [{msg.networkId}/{msg.thingId}] {msg.poseType}"); #endif Participant owner = Participant.GetParticipant(msg.networkId); diff --git a/src/Participants/SiteServer.cs b/src/Participants/SiteServer.cs index 55df31c..3cf016c 100644 --- a/src/Participants/SiteServer.cs +++ b/src/Participants/SiteServer.cs @@ -95,6 +95,38 @@ namespace RoboidControl { } } + protected override void UpdateOtherThings(ulong currentTimeMS) { + for (int ownerIx = 0; ownerIx < Participant.participants.Count; ownerIx++) { + Participant owner = Participant.participants[ownerIx]; + if (owner == null || owner == this) + continue; + + owner.Update(); + + if (currentTimeMS < this.nextSendUpdate) + continue; + + // for (int thingIx = 0; thingIx < owner.things.Count; thingIx++) { + // Thing thing = owner.things[thingIx]; + foreach (Thing thing in owner.things) { + if (thing == null) + continue; + + foreach (Participant participant in Participant.participants) { + if (participant == this || participant == owner) + continue; + + PoseMsg poseMsg = new(thing.owner.networkId, thing); + if (poseMsg.poseType != 0) + Console.WriteLine($"[{thing.owner.networkId}/{thing.id}] Pose ---> {participant.networkId}"); + participant.Send(poseMsg); + } + } + } + if (currentTimeMS > this.nextSendUpdate) + this.nextSendUpdate = currentTimeMS + this.sendUpdateIntervalMS; + } + #endregion Update #region Receive diff --git a/src/Thing.cs b/src/Thing.cs index 34b3d93..0d5fd4d 100644 --- a/src/Thing.cs +++ b/src/Thing.cs @@ -341,7 +341,10 @@ namespace RoboidControl { public bool orientationUpdated = false; public void ReplaceOrientation(SwingTwist newOrientation) { - this._orientation = newOrientation; + if (newOrientation != this._orientation) { + this._orientation = newOrientation; + orientationUpdated = true; + } } private Spherical _linearVelocity = Spherical.zero;