移除停稳等待配置并统一内部默认时序
This commit is contained in:
parent
82fcca0533
commit
0b04d000e8
@ -425,7 +425,7 @@ public class RecipeNode : EditorNode
|
||||
AiConfirmation = step.AiConfirmation is null ? null : new AiConfirmation
|
||||
{
|
||||
MinConfidence = step.AiConfirmation.MinConfidence,
|
||||
CheckWindowMs = step.AiConfirmation.CheckWindowMs, CheckSettleMs = step.AiConfirmation.CheckSettleMs,
|
||||
CheckWindowMs = step.AiConfirmation.CheckWindowMs,
|
||||
EvidenceMode = step.AiConfirmation.EvidenceMode,
|
||||
ObservationPreRollMs = step.AiConfirmation.ObservationPreRollMs, ObservationMinMs = step.AiConfirmation.ObservationMinMs,
|
||||
ObservationMaxMs = step.AiConfirmation.ObservationMaxMs, ObservationSampleMs = step.AiConfirmation.ObservationSampleMs,
|
||||
@ -495,7 +495,7 @@ public class RecipeNode : EditorNode
|
||||
AiConfirmation = new AiConfirmation
|
||||
{
|
||||
MinConfidence = step.AiMinConfidence,
|
||||
CheckWindowMs = step.AiCheckWindowMs, CheckSettleMs = step.AiCheckSettleMs,
|
||||
CheckWindowMs = step.AiCheckWindowMs,
|
||||
EvidenceMode = step.AiEvidenceMode, ObservationPreRollMs = step.AiObservationPreRollMs,
|
||||
ObservationMinMs = step.AiObservationMinMs, ObservationMaxMs = step.AiObservationMaxMs,
|
||||
ObservationSampleMs = step.AiObservationSampleMs, ObservationMaxFrames = step.AiObservationMaxFrames, ObservationRequestMaxFrames = step.AiObservationRequestMaxFrames,
|
||||
@ -825,10 +825,9 @@ public class StepNode : EditorNode
|
||||
public double? KeyFrameSeconds { get => _keyFrameSeconds; set { if (SetProperty(ref _keyFrameSeconds, value)) RaisePropertyChanged(nameof(KeyFrameLabel)); } }
|
||||
public string KeyFrameLabel => string.IsNullOrEmpty(KeyFrameBase64) ? "尚未保存关键帧" : $"已保存关键帧:{KeyFrameSeconds:0.###} 秒(保存配方后持久化)";
|
||||
|
||||
private int _aiCheckWindowMs = 10000, _aiCheckSettleMs = 100;
|
||||
private int _aiCheckWindowMs = 10000;
|
||||
public int AiCheckWindowMs { get => _aiCheckWindowMs; set { if (SetProperty(ref _aiCheckWindowMs, value)) RaisePropertyChanged(nameof(AiContinueAfterWindow)); } }
|
||||
public bool AiContinueAfterWindow { get => AiCheckWindowMs > 0; set { if (value != AiContinueAfterWindow) AiCheckWindowMs = value ? 10000 : 0; } }
|
||||
public int AiCheckSettleMs { get => _aiCheckSettleMs; set => SetProperty(ref _aiCheckSettleMs, value); }
|
||||
private string _aiEvidenceMode = VisionEvidenceMode.SingleFrame;
|
||||
private int _aiObservationPreRollMs = 1000, _aiObservationMinMs = 2400, _aiObservationMaxMs = 10000,
|
||||
_aiObservationSampleMs = 400, _aiObservationMaxFrames = 24, _aiObservationRequestMaxFrames = 12;
|
||||
@ -867,7 +866,7 @@ public class StepNode : EditorNode
|
||||
{
|
||||
if (value is null) return;
|
||||
AiMinConfidence = value.MinConfidence;
|
||||
AiCheckWindowMs = value.CheckWindowMs; AiCheckSettleMs = value.CheckSettleMs;
|
||||
AiCheckWindowMs = value.CheckWindowMs;
|
||||
AiEvidenceMode = value.EvidenceMode; AiObservationPreRollMs = value.ObservationPreRollMs;
|
||||
AiObservationMinMs = value.ObservationMinMs; AiObservationMaxMs = value.ObservationMaxMs;
|
||||
AiObservationSampleMs = value.ObservationSampleMs; AiObservationMaxFrames = value.ObservationMaxFrames; AiObservationRequestMaxFrames = value.ObservationRequestMaxFrames;
|
||||
|
||||
@ -173,10 +173,6 @@
|
||||
<Grid ColumnDefinitions="2*,3*" Margin="0,0,0,6">
|
||||
<TextBlock Text="检查窗口(毫秒)" TextWrapping="Wrap" Margin="0,0,8,0" VerticalAlignment="Center" />
|
||||
<NumericUpDown Grid.Column="1" Value="{Binding AiCheckWindowMs, Mode=TwoWay}" Minimum="0" Maximum="60000" Increment="500" />
|
||||
</Grid>
|
||||
<Grid ColumnDefinitions="2*,3*" Margin="0,0,0,6">
|
||||
<TextBlock Text="停稳等待(毫秒)" TextWrapping="Wrap" Margin="0,0,8,0" VerticalAlignment="Center" />
|
||||
<NumericUpDown Grid.Column="1" Value="{Binding AiCheckSettleMs, Mode=TwoWay}" Minimum="100" Maximum="3000" Increment="50" />
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@ -418,7 +418,7 @@ public partial class RecipeEditorViewModel
|
||||
step.StableFrames = node.Detection?.StableFrames; step.Tolerance = node.Detection?.Tolerance;
|
||||
step.ImageMode = node.AiImageMode; step.ImageRegion = node.AiImageRegion;
|
||||
step.Inspection = new() { EvidenceMode = node.AiEvidenceMode, CheckWindowMs = node.AiCheckWindowMs > 0 ? node.AiCheckWindowMs : null,
|
||||
CheckSettleMs = node.AiCheckSettleMs, ObservationMinMs = node.AiObservationMinMs,
|
||||
ObservationMinMs = node.AiObservationMinMs,
|
||||
ObservationMaxMs = node.AiObservationMaxMs, ObservationMaxFrames = node.AiObservationMaxFrames,
|
||||
ObservationRequestMaxFrames = node.AiObservationRequestMaxFrames };
|
||||
}
|
||||
@ -433,7 +433,7 @@ public partial class RecipeEditorViewModel
|
||||
{
|
||||
var ai = step.AiConfirmation!;
|
||||
return new SopAgentImageScope(index + 1, VisionImageMode.Resolve(ai), ai.ImageRegion,
|
||||
ai.HandPadding, ai.HandMinSize, ai.HandMemoryMs, ai.EvidenceMode, ai.CheckWindowMs, ai.CheckSettleMs,
|
||||
ai.HandPadding, ai.HandMinSize, ai.HandMemoryMs, ai.EvidenceMode, ai.CheckWindowMs,
|
||||
ai.ObservationMaxMs, ai.ObservationMaxFrames, ai.ObservationRequestMaxFrames, ai.TimeoutSeconds);
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ namespace SopHelper.Engine.Sop;
|
||||
|
||||
public partial class SopEngine
|
||||
{
|
||||
private const int HandSettleMs = 100;
|
||||
private readonly Dictionary<int, ContinuousCheck> _continuousChecks = [];
|
||||
public event Action<int, IReadOnlyList<VisionEvidenceFrame>>? DecisionCandidatesObserved;
|
||||
private double PriorCompletedEvidenceTime() => _acceptedEvidenceTimes.Where(p => p.Key < _index)
|
||||
@ -72,7 +73,7 @@ public partial class SopEngine
|
||||
state.LastMotionSeconds = seconds; state.Anchors = selected;
|
||||
state.StoredBoundary = false;
|
||||
}
|
||||
else if ((seconds - state.LastMotionSeconds) * 1000 >= state.Step.AiConfirmation!.CheckSettleMs)
|
||||
else if ((seconds - state.LastMotionSeconds) * 1000 >= HandSettleMs)
|
||||
state.SawQuiet = true;
|
||||
var trigger = EvaluateCaptureGate(state.Step, frame, state.Gate, "continuous");
|
||||
if (trigger.IsMet && !state.GateWasMet)
|
||||
@ -92,9 +93,9 @@ public partial class SopEngine
|
||||
if (state.Triggered && state.ElapsedMs >= state.Step.AiConfirmation!.CheckWindowMs) return;
|
||||
if (IsHandInside(state.Step, frame)) { state.OutsideSince = null; state.StoredOutside = false; }
|
||||
else state.OutsideSince ??= seconds;
|
||||
var quietBoundary = !state.StoredBoundary && (seconds - state.LastMotionSeconds) * 1000 >= state.Step.AiConfirmation!.CheckSettleMs;
|
||||
var quietBoundary = !state.StoredBoundary && (seconds - state.LastMotionSeconds) * 1000 >= HandSettleMs;
|
||||
var outsideBoundary = !state.StoredOutside && state.OutsideSince is { } outside
|
||||
&& (seconds - outside) * 1000 >= state.Step.AiConfirmation!.CheckSettleMs;
|
||||
&& (seconds - outside) * 1000 >= HandSettleMs;
|
||||
if (state.Triggered && (quietBoundary || outsideBoundary) && state.Step.AiConfirmation!.EvidenceMode == VisionEvidenceMode.SingleFrame)
|
||||
{
|
||||
var boundary = CaptureDecision(state.Step, frame, state.Gate.HandRegion, capture, crop, out _, notify: false);
|
||||
@ -180,11 +181,11 @@ public partial class SopEngine
|
||||
if (client is null || options.EvidenceMode == VisionEvidenceMode.Sequence && !client.SupportsSequences)
|
||||
{ state.Reason = "检查服务未配置或不支持所需证据"; return new() { Message = state.Reason + ";窗口到期后记录未通过并继续" }; }
|
||||
if (state.Window.Error is { } error) { state.Reason = error; return new() { Message = error }; }
|
||||
var quiet = (state.LatestSeconds - state.LastMotionSeconds) * 1000 >= options.CheckSettleMs;
|
||||
var quiet = (state.LatestSeconds - state.LastMotionSeconds) * 1000 >= HandSettleMs;
|
||||
// 按配置间隔检查当前新图,不能为历史补判扩大等待时间。
|
||||
var interval = Math.Max(50, options.RetryDelayMs);
|
||||
var sinceRequest = state.Attempts == 0 ? state.ElapsedMs : Environment.TickCount64 - state.LastSubmittedAt;
|
||||
var firstWait = Math.Min(interval, Math.Max(50, options.CheckSettleMs));
|
||||
var firstWait = Math.Min(interval, Math.Max(50, HandSettleMs));
|
||||
var freshEvent = discrete && state.LatestTriggerSeconds > state.LastSubmittedSourceSeconds
|
||||
&& sinceRequest >= Math.Max(50, options.RetryDelayMs);
|
||||
var timeToCheck = state.Attempts == 0 ? quiet || sinceRequest >= firstWait : sinceRequest >= interval || freshEvent;
|
||||
|
||||
@ -8,7 +8,6 @@ public sealed class AiConfirmation
|
||||
{
|
||||
/// <summary>0 保留原来的等待策略;正值为触发后的检查预算,到期未确认则跳过。</summary>
|
||||
public int CheckWindowMs { get; set; }
|
||||
public int CheckSettleMs { get; set; } = 100;
|
||||
public string EvidenceMode { get; set; } = VisionEvidenceMode.SingleFrame;
|
||||
public int ObservationPreRollMs { get; set; } = 1000;
|
||||
public int ObservationMinMs { get; set; } = 2400;
|
||||
@ -33,7 +32,6 @@ public static class VisionEvidenceMode
|
||||
public const string SingleFrame = "single_frame", Sequence = "sequence";
|
||||
public static bool IsCheckPolicyValid(AiConfirmation options) => options.CheckWindowMs == 0
|
||||
|| options.CheckWindowMs is >= 500 and <= 60000
|
||||
&& options.CheckSettleMs is >= 100 and <= 3000 && options.CheckSettleMs < options.CheckWindowMs
|
||||
&& IsObservationValid(options);
|
||||
public static bool IsValid(AiConfirmation options) => options.EvidenceMode == SingleFrame
|
||||
|| options.EvidenceMode == Sequence && IsObservationValid(options);
|
||||
|
||||
@ -18,7 +18,7 @@ public static class SopStepDesignPrompt
|
||||
- 触发区和送检区可以独立。image_mode=fixed_region/full_frame/hand,image_region须覆盖完整验收关系;局部细节优先清晰ROI,整体位置需要完整空间上下文。默认主区域,hand_move默认终点,禁止假设跟手范围必然覆盖主体。
|
||||
- 已缓存的旧图不能排队补判为实时通过;运行仅检查新鲜单图,记录触发/取图/提交/返回时间、图片数量、耗时和超时。
|
||||
|
||||
inspection:evidence_mode只能为single_frame;check_window_ms=500–60000为本步多次观察总窗口,不是单次模型耗时;check_settle_ms=100–3000且小于总窗口。新步骤默认观察10秒、停稳100ms;每次dlite最多500ms,超时不延长。人的动作连续,不能让人停下来等待;适时取新图复查,仅在窗口到期仍未通过时跳过,不限制检查次数,整轮不计合格。
|
||||
inspection:evidence_mode只能为single_frame;check_window_ms=500–60000为本步多次观察总窗口,不是单次模型耗时。新步骤默认观察10秒;每次dlite最多500ms,超时不延长。人的动作连续,不能让人停下来等待;适时取新图复查,仅在窗口到期仍未通过时跳过,不限制检查次数,整轮不计合格。
|
||||
提交前核对:全程操作完整、有据、有序不重叠、区域有效、单图可辨、触发对应本步、正反状态可区分。仅为具体缺口补看,不重复读清楚的图,不凭措辞修改反复调用工具。步骤生成和dlite回测是独立操作。
|
||||
""";
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ public sealed record SopVideoAnalysisRequest(string Recipe, string Instructions,
|
||||
public sealed record SopAgentPrompt(int Round, long EstimatedTokens, int ContextLength, string Compression, string Text);
|
||||
public sealed record SopAgentTrace(string Kind, int Round, string Text, IReadOnlyList<SopAgentTraceImage>? Images = null);
|
||||
public sealed record SopAgentTraceImage(string Name, byte[] Jpeg);
|
||||
public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame, int CheckWindowMs = 0, int CheckSettleMs = 350, int ObservationMaxMs = 10000, int ObservationMaxFrames = 24, int ObservationRequestMaxFrames = 12, int TimeoutSeconds = 30);
|
||||
public sealed record SopAgentImageScope(int StepIndex, string Mode, string Region, int HandPadding, int HandMinSize, int HandMemoryMs, string EvidenceMode = VisionEvidenceMode.SingleFrame, int CheckWindowMs = 0, int ObservationMaxMs = 10000, int ObservationMaxFrames = 24, int ObservationRequestMaxFrames = 12, int TimeoutSeconds = 30);
|
||||
public sealed record SopAgentChatTurn(string Role, string Text);
|
||||
public sealed record SopAgentChatResult(string Reply, SopVideoDraft? Draft, IReadOnlyList<SopVideoFrame> ObservedFrames);
|
||||
public sealed class SopVideoDraft
|
||||
@ -59,7 +59,6 @@ public sealed class SopDraftInspectionPolicy
|
||||
{
|
||||
[JsonPropertyName("evidence_mode")] public string? EvidenceMode { get; set; }
|
||||
[JsonPropertyName("check_window_ms")] public int? CheckWindowMs { get; set; }
|
||||
[JsonPropertyName("check_settle_ms")] public int? CheckSettleMs { get; set; }
|
||||
[JsonPropertyName("observation_min_ms")] public int? ObservationMinMs { get; set; }
|
||||
[JsonPropertyName("observation_max_ms")] public int? ObservationMaxMs { get; set; }
|
||||
[JsonPropertyName("observation_max_frames")] public int? ObservationMaxFrames { get; set; }
|
||||
@ -69,7 +68,6 @@ public sealed class SopDraftInspectionPolicy
|
||||
{
|
||||
target.EvidenceMode = EvidenceMode ?? target.EvidenceMode;
|
||||
target.CheckWindowMs = CheckWindowMs ?? target.CheckWindowMs;
|
||||
target.CheckSettleMs = CheckSettleMs ?? target.CheckSettleMs;
|
||||
target.ObservationMinMs = ObservationMinMs ?? target.ObservationMinMs;
|
||||
target.ObservationMaxMs = ObservationMaxMs ?? target.ObservationMaxMs;
|
||||
target.ObservationMaxFrames = ObservationMaxFrames ?? target.ObservationMaxFrames;
|
||||
@ -79,7 +77,7 @@ public sealed class SopDraftInspectionPolicy
|
||||
public static SopDraftInspectionPolicy From(AiConfirmation options) => new()
|
||||
{
|
||||
EvidenceMode = options.EvidenceMode, CheckWindowMs = options.CheckWindowMs > 0 ? options.CheckWindowMs : null,
|
||||
CheckSettleMs = options.CheckSettleMs, ObservationMinMs = options.ObservationMinMs,
|
||||
ObservationMinMs = options.ObservationMinMs,
|
||||
ObservationMaxMs = options.ObservationMaxMs, ObservationMaxFrames = options.ObservationMaxFrames,
|
||||
ObservationRequestMaxFrames = options.ObservationRequestMaxFrames
|
||||
};
|
||||
|
||||
@ -10,9 +10,10 @@ internal static class InspectionPolicyChecks
|
||||
template.Sop.Steps = [new() { AiConfirmation = new() { MinConfidence = .94, RetryDelayMs = 4100 } }];
|
||||
var draft = new SopVideoDraft { Steps = [new() { Inspection = new() { EvidenceMode = "sequence",
|
||||
CheckWindowMs = 22000, ObservationMaxFrames = 24, ObservationRequestMaxFrames = 9 } }] };
|
||||
var legacy = JsonSerializer.Deserialize<SopDraftInspectionPolicy>("""{"check_window_ms":10000,"max_checks":1}""")!;
|
||||
var legacy = JsonSerializer.Deserialize<SopDraftInspectionPolicy>("""{"check_window_ms":10000,"max_checks":1,"check_settle_ms":3000}""")!;
|
||||
SopVideoDraftClient.ValidateInspection(legacy);
|
||||
Check(!JsonSerializer.Serialize(legacy).Contains("max_checks"), "旧草稿次数参数应被忽略且不再输出");
|
||||
Check(!JsonSerializer.Serialize(legacy).Contains("max_checks")
|
||||
&& !JsonSerializer.Serialize(legacy).Contains("check_settle_ms"), "旧草稿次数和停稳参数应被忽略且不再输出");
|
||||
var before = SopConfigLoader.ToYaml(template);
|
||||
var roundTrip = JsonSerializer.Deserialize<SopVideoDraft>(JsonSerializer.Serialize(draft))!;
|
||||
var config = SopDraftConfigBuilder.Build(template, roundTrip);
|
||||
@ -26,7 +27,7 @@ internal static class InspectionPolicyChecks
|
||||
Reject(() => SopVideoDraftClient.ValidateCapabilities(draft, request with { CurrentDraft = draft }), "旧草稿不能豁免单图要求");
|
||||
foreach (var invalid in new SopDraftInspectionPolicy[] {
|
||||
new() { EvidenceMode = "unknown" }, new() { CheckWindowMs = 0 },
|
||||
new() { CheckWindowMs = 500, CheckSettleMs = 600 }, new() { ObservationMinMs = 11000 },
|
||||
new() { CheckWindowMs = 499 }, new() { ObservationMinMs = 11000 },
|
||||
new() { ObservationRequestMaxFrames = 33 }, new() { ObservationMaxFrames = 2 } })
|
||||
Reject(() => SopVideoDraftClient.ValidateInspection(invalid), "非法策略不能进入回测或配方");
|
||||
template.Sop.Steps = [];
|
||||
|
||||
@ -53,15 +53,14 @@ internal static class Program
|
||||
var config = new SopConfig();
|
||||
config.Sop.Steps.Add(new() { Id = 1, Description = "状态变化", AiConfirmation = new()
|
||||
{ EvidenceMode = VisionEvidenceMode.Sequence, ObservationMinMs = 1800, ObservationMaxFrames = 13, ObservationRequestMaxFrames = 7, ObservationSampleMs = 300,
|
||||
CheckWindowMs = 7000, CheckSettleMs = 450 } });
|
||||
CheckWindowMs = 7000 } });
|
||||
var editor = RecipeNode.From(config, "试验.yaml", false);
|
||||
Check(editor.Steps[0].UsesSequenceEvidence, "编辑器须识别过程时序模式");
|
||||
var restored = SopConfigLoader.Parse(SopConfigLoader.ToYaml(editor.ToConfig())).Sop.Steps[0].AiConfirmation!;
|
||||
Check(restored.EvidenceMode == VisionEvidenceMode.Sequence && restored.ObservationMinMs == 1800
|
||||
&& restored.ObservationMaxFrames == 13 && restored.ObservationRequestMaxFrames == 7 && restored.ObservationSampleMs == 300,
|
||||
"编辑保存不得丢失时序模式、缓存容量与单次请求预算");
|
||||
Check(editor.Steps[0].AiContinueAfterWindow && restored.CheckWindowMs == 7000
|
||||
&& restored.CheckSettleMs == 450, "编辑保存须保留连续操作限时复检参数");
|
||||
Check(editor.Steps[0].AiContinueAfterWindow && restored.CheckWindowMs == 7000, "编辑保存须保留连续操作限时复检参数");
|
||||
editor.Steps[0].AiContinueAfterWindow = false;
|
||||
Check(editor.ToConfig().Sop.Steps[0].AiConfirmation!.CheckWindowMs == 0, "关闭限时复检须恢复原等待策略");
|
||||
Console.WriteLine("PASS: 编辑器过程时序模式及观察参数往返保留");
|
||||
|
||||
@ -17,7 +17,7 @@ internal static class StepTransferChecks
|
||||
ViolationRules = [new() { Type = "object_removed", Description = "工具移除", Severity = 3 }],
|
||||
Detection = new() { Method = "hand_move", FromRegion = "start", ToRegion = "finish", Hand = "left", StableFrames = 7, Tolerance = 9, MinConfidence = .81f },
|
||||
AiConfirmation = new() { EvidenceMode = "sequence", ImageMode = "fixed_region", ImageRegion = "inspect_area", CheckWindowMs = 32900,
|
||||
CheckSettleMs = 550, ObservationMaxFrames = 26, ObservationRequestMaxFrames = 9, MinConfidence = .94,
|
||||
ObservationMaxFrames = 26, ObservationRequestMaxFrames = 9, MinConfidence = .94,
|
||||
TimeoutSeconds = 25, RetryDelayMs = 1700, HandPadding = 180, HandMemoryMs = 2400 } }];
|
||||
var original = JsonSerializer.Serialize(source);
|
||||
var text = SopStepTransfer.Export(source);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Concurrent;
|
||||
using SopHelper.Engine.Common;
|
||||
using SopHelper.Engine.Sop;
|
||||
|
||||
@ -28,7 +28,7 @@ internal static class ContinuousCheckTests
|
||||
config.Sop.Regions["r" + i] = new() { X1 = i * 100, Y1 = 0, X2 = i * 100 + 90, Y2 = 100 };
|
||||
config.Sop.Steps.Add(new() { Id = i + 1, Name = "工序" + i, Description = "结果到位",
|
||||
Detection = new() { Method = ConditionMethod.HandInRegion, Region = "r" + i, Hand = "right", StableFrames = 1 },
|
||||
AiConfirmation = new() { CheckWindowMs = 2000, CheckSettleMs = 150,
|
||||
AiConfirmation = new() { CheckWindowMs = 2000,
|
||||
RetryDelayMs = 500, ObservationSampleMs = 100 } });
|
||||
}
|
||||
return config;
|
||||
@ -42,9 +42,10 @@ internal static class ContinuousCheckTests
|
||||
var unlimitedConfig = Config(1);
|
||||
unlimitedConfig.Sop.Steps[0].AiConfirmation!.CheckWindowMs = 10000;
|
||||
unlimitedConfig.Sop.Steps[0].AiConfirmation!.RetryDelayMs = 50;
|
||||
var legacyYaml = SopConfigLoader.ToYaml(unlimitedConfig).Replace("check_window_ms: 10000", "check_window_ms: 10000\n max_checks: 1");
|
||||
var legacyYaml = SopConfigLoader.ToYaml(unlimitedConfig).Replace("check_window_ms: 10000", "check_window_ms: 10000\n max_checks: 1\n check_settle_ms: 3000");
|
||||
var legacyConfig = SopConfigLoader.Parse(legacyYaml);
|
||||
Check(!SopConfigLoader.ToYaml(legacyConfig).Contains("max_checks"), "旧次数参数须忽略且不再保存");
|
||||
Check(!SopConfigLoader.ToYaml(legacyConfig).Contains("max_checks")
|
||||
&& !SopConfigLoader.ToYaml(legacyConfig).Contains("check_settle_ms"), "旧次数和停稳参数须忽略且不再保存");
|
||||
var unlimitedClient = new Client();
|
||||
var unlimited = new SopEngine { VisionDecisionClient = unlimitedClient };
|
||||
unlimited.Load(legacyConfig); unlimited.Start();
|
||||
@ -79,7 +80,7 @@ internal static class ContinuousCheckTests
|
||||
engine.StepSnapshotChanged += snapshots.Add; engine.DecisionEvaluated += (_, _, _) => evaluated++;
|
||||
engine.ViolationRaised += _ => alarms++; engine.RoundFinished += result => passed = result;
|
||||
void Feed(int id, double seconds, int x) => engine.ProcessFrame(Frame(id, seconds, x), () => [(byte)id]);
|
||||
Feed(1, 0, 10); Feed(2, .1, 30);
|
||||
Feed(1, 0, 10); Feed(2, .05, 30);
|
||||
Check(client.Calls.Count == 0, "进入后仍在移动不能立即检查");
|
||||
Feed(3, .3, 30); await Until(() => client.Calls.Count == 1);
|
||||
var first = client.Calls.ElementAt(0);
|
||||
@ -147,13 +148,13 @@ internal static class ContinuousCheckTests
|
||||
"低于阈值的正向线索不能放行,但下一次检查应跟进新结果,不能回退到较早历史帧");
|
||||
following.Stop();
|
||||
var temporalConfig = Config();
|
||||
temporalConfig.Sop.Steps[0].AiConfirmation = new() { CheckWindowMs = 10000, CheckSettleMs = 2500, RetryDelayMs = 2500, ObservationMinMs = 5000 };
|
||||
temporalConfig.Sop.Steps[0].AiConfirmation = new() { CheckWindowMs = 10000, RetryDelayMs = 2500, ObservationMinMs = 5000 };
|
||||
temporalConfig.Sop.Steps[1].AiConfirmation = new() { CheckWindowMs = 10000, EvidenceMode = VisionEvidenceMode.Sequence };
|
||||
var temporalClient = new Client(); var temporal = new SopEngine { VisionDecisionClient = temporalClient };
|
||||
temporal.Load(temporalConfig); temporal.Start(); var frameIndex = 0;
|
||||
void TemporalFeed(double seconds, int x = 120) => temporal.ProcessFrame(Frame(frameIndex++, seconds, x), () => [(byte)frameIndex]);
|
||||
TemporalFeed(0, 10);
|
||||
foreach (var seconds in new[] { .4, .8, 1.2, 1.6, 2.0, 2.4, 2.8 }) TemporalFeed(seconds);
|
||||
TemporalFeed(2.8);
|
||||
await Until(() => temporalClient.Calls.Count == 1);
|
||||
Check(temporalClient.Calls.ElementAt(0).Request.SourceSeconds == 2.8, "测试前序结果必须来自实际较晚帧");
|
||||
temporalClient.Calls.ElementAt(0).Result.SetResult(new(true, .99, "前序完成"));
|
||||
@ -165,20 +166,20 @@ internal static class ContinuousCheckTests
|
||||
var effective = temporalClient.Calls.ElementAt(1).Request.Frames!;
|
||||
Check(effective[^1].SourceSeconds - effective[0].SourceSeconds >= 2.4, "首次过程检查必须覆盖配置要求的实际有效片段时长");
|
||||
temporal.Stop();
|
||||
var leaveConfig = Config(); leaveConfig.Sop.Steps[0].AiConfirmation!.CheckSettleMs = 350; leaveConfig.Sop.Steps[1].Detection!.Method = ConditionMethod.HandLeaveRegion;
|
||||
var leaveConfig = Config(); leaveConfig.Sop.Steps[1].Detection!.Method = ConditionMethod.HandLeaveRegion;
|
||||
var leaveClient = new Client(); var leave = new SopEngine { VisionDecisionClient = leaveClient };
|
||||
leave.Load(leaveConfig); leave.Start();
|
||||
void LeaveFeed(int id, double seconds, int x) => leave.ProcessFrame(Frame(id, seconds, x), () => [(byte)id]);
|
||||
LeaveFeed(0, 0, 10); LeaveFeed(1, .1, 120); LeaveFeed(2, .3, 10); LeaveFeed(3, .5, 10);
|
||||
LeaveFeed(0, 0, 10); LeaveFeed(1, .02, 120); LeaveFeed(2, .04, 10); LeaveFeed(3, .2, 10);
|
||||
await Until(() => leaveClient.Calls.Count == 1);
|
||||
leaveClient.Calls.ElementAt(0).Result.SetResult(new(true, .99, "前序结果"));
|
||||
await Until(() => { leave.ProcessFrame(Frame(3, .5, 10)); return leave.CurrentStep?.Id == 2; });
|
||||
await Until(() => { leave.ProcessFrame(Frame(3, .2, 10)); return leave.CurrentStep?.Id == 2; });
|
||||
LeaveFeed(4, .7, 10);
|
||||
Check(leaveClient.Calls.Count == 1, "离散动作不能复用早于前序完成的旧离开事件");
|
||||
LeaveFeed(5, .9, 120); LeaveFeed(6, 1.1, 10); LeaveFeed(7, 1.3, 10);
|
||||
await Until(() => leaveClient.Calls.Count == 2);
|
||||
Check(leaveClient.Calls.ElementAt(1).Request.SourceSeconds >= 1.1 && leaveClient.Calls.ElementAt(1).Request.TriggerObservation?.SourceSeconds == 1.1,
|
||||
"必须用前序结果之后新发生的离开事件触发检查,已采集的后续证据仍须保留");
|
||||
$"必须用前序结果之后新发生的离开事件触发检查:图={leaveClient.Calls.ElementAt(1).Request.SourceSeconds},触发={leaveClient.Calls.ElementAt(1).Request.TriggerObservation?.SourceSeconds}");
|
||||
leave.Stop();
|
||||
Console.WriteLine("PASS: 停稳触发、新帧重试、限时跳过、后续动作持续取证、挂起硬截止、迟到结果隔离和非合格整轮统计");
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user