AckTimeoutMarginMs deleted

alphons <alphons@heijden.com> 1 Aug 2026, 21:51
155deea79e7bfe4c23df31c76fbd669cf03d5ce8
3 files changed
  • RtRobotSharp/Models/RobotSerialSettings.cs
  • RtRobotSharp/Services/RobotSerialService.cs
  • RtRobotSharp/appsettings.json
diff --git a/RtRobotSharp/Models/RobotSerialSettings.cs b/RtRobotSharp/Models/RobotSerialSettings.cs
index 620cbb9..7cb1401 100644
--- a/RtRobotSharp/Models/RobotSerialSettings.cs
+++ b/RtRobotSharp/Models/RobotSerialSettings.cs
@@ -9,5 +9,4 @@ public class RobotSerialSettings
public int SpeedMs { get; set; } = 500;
public int DelayMs { get; set; } = 500;
public int ServoCount { get; set; } = 32;
- public int AckTimeoutMarginMs { get; set; } = 100;
}
diff --git a/RtRobotSharp/Services/RobotSerialService.cs b/RtRobotSharp/Services/RobotSerialService.cs
index eb57d3c..e31d3ba 100644
--- a/RtRobotSharp/Services/RobotSerialService.cs
+++ b/RtRobotSharp/Services/RobotSerialService.cs
@@ -16,13 +16,6 @@ public class RobotSerialService : IDisposable
{
private static readonly TimeSpan IdleFlushDelay = TimeSpan.FromMilliseconds(150);
private static readonly TimeSpan WriteGuardTimeout = TimeSpan.FromSeconds(2);
-
- // Measured on hardware: the controller only replies "OK" once it has actually
- // executed the move, i.e. after roughly Speed + Delay. Waiting a fixed 2s
- // regardless of that was needlessly generous - size the timeout to the command
- // instead, with a margin (Settings.AckTimeoutMarginMs) for normal transport/
- // processing jitter.
- private static readonly TimeSpan AckTimeoutMax = TimeSpan.FromSeconds(5);
private static readonly TimeSpan AckTimeoutDefault = TimeSpan.FromSeconds(2);
private readonly Lock gate = new();
@@ -228,8 +221,8 @@ public class RobotSerialService : IDisposable
// The controller replies "OK" only after it has actually executed the move,
// i.e. after roughly Speed + Delay - size the wait to that instead of a
// generic fixed timeout.
- var marginMs = Settings.AckTimeoutMarginMs;
- var timeoutMs = Math.Clamp(speedMs + delayMs + marginMs, marginMs, (int)AckTimeoutMax.TotalMilliseconds);
+ var marginMs = (int)(speedMs * 0.1);
+ var timeoutMs = speedMs + delayMs + marginMs;
Send(sb.ToString(), TimeSpan.FromMilliseconds(timeoutMs));
}
@@ -286,7 +279,7 @@ public class RobotSerialService : IDisposable
// even with WriteTimeout set - a known System.IO.Ports issue. Run it on a
// worker thread and give up on it after WriteGuardTimeout so the sender
// loop (and the app) never gets stuck waiting for it.
- var writeTask = Task.Run(() => currentPort.Write(command + "\r\n"));
+ var writeTask = Task.Run(() => currentPort.Write(command + "\r\n"), token);
var writeCompleted = await Task.WhenAny(writeTask, Task.Delay(WriteGuardTimeout, token));
if (writeCompleted != writeTask)
diff --git a/RtRobotSharp/appsettings.json b/RtRobotSharp/appsettings.json
index 41545b6..ee44619 100644
--- a/RtRobotSharp/appsettings.json
+++ b/RtRobotSharp/appsettings.json
@@ -11,7 +11,6 @@
"BaudRate": 115200,
"SpeedMs": 100,
"DelayMs": 200,
- "ServoCount": 32,
- "AckTimeoutMarginMs": 50
+ "ServoCount": 32
}
}
\ No newline at end of file