Measure persistent dual-camera Move visibility

This commit is contained in:
Meta Vens 2026-07-13 00:17:00 +01:00
commit f80881e0d7
3 changed files with 134 additions and 0 deletions

View file

@ -146,6 +146,14 @@ if (args.Any(arg => string.Equals(arg, "--muninn-move-odin-live-smoke", StringCo
: 0);
}
if (args.Any(arg => string.Equals(arg, "--muninn-move-visibility-window-smoke", StringComparison.OrdinalIgnoreCase)))
{
return RunMuninnMoveVisibilityWindowSmoke(
ParseStringOption(args, "--odin-cultmesh-uri", "cultmesh://127.0.0.1:17871/rendezvous/provider-catalog"),
ParseIntOption(args, "--duration-seconds", 15),
ParseStringOption(args, "--output", "artifacts/move-calibration/muninn-visibility-window.mpack"));
}
if (args.Any(arg => string.Equals(arg, "--move-fusion-smoke", StringComparison.OrdinalIgnoreCase)))
{
return RunMoveFusionSmoke();
@ -2010,6 +2018,100 @@ static int RunMuninnMoveOdinLiveSmoke(
throw new TimeoutException($"No live frame arrived from Odin-discovered stream {streamId}.");
}
static int RunMuninnMoveVisibilityWindowSmoke(string odinCultMeshUri, int durationSeconds, string outputPath)
{
var sources = new[]
{
(Provider: "muninn.telemetry.nightwing", Stream: "muninn:nightwing:move-evidence"),
(Provider: "muninn.telemetry.nightwing-eye0", Stream: "muninn:nightwing:eye-0:move-evidence")
};
var leases = new List<(string Provider, string Stream, MimirMoveProofEvidenceRingLease Lease)>();
try
{
foreach (var source in sources)
{
var configuration = new MimirMoveProofRuntimeConfiguration
{
OdinCultMeshUri = odinCultMeshUri,
MuninnProviderId = source.Provider,
EvidenceStreamId = source.Stream
};
if (!MimirOdinMoveProofEvidenceRingProvider.Instance.TryOpenEvidenceRing(configuration, out var lease, out var diagnostic) || lease is null)
{
throw new InvalidOperationException($"{source.Provider}: {diagnostic}");
}
leases.Add((source.Provider, source.Stream, lease));
}
var startedAtNs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000;
var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(Math.Max(1, durationSeconds));
var seenFrames = new HashSet<string>(StringComparer.Ordinal);
var framesByProvider = sources.ToDictionary(source => source.Provider, _ => 0, StringComparer.Ordinal);
var controllersByProvider = sources.ToDictionary(source => source.Provider, _ => new HashSet<string>(StringComparer.Ordinal), StringComparer.Ordinal);
var observations = new List<MoveVisibilityObservation>();
while (DateTime.UtcNow < deadline)
{
foreach (var source in leases)
{
if (!source.Lease.Ring.TryAcquireLatestRead(out var frameLease)) continue;
using (frameLease)
{
var frame = MimirMuninnMoveEvidenceAdapter.DeserializeStreamFrame(frameLease.Memory[..frameLease.Handle.ByteLength]);
if (!seenFrames.Add($"{source.Provider}:{frame.FrameId}")) continue;
framesByProvider[source.Provider]++;
controllersByProvider[source.Provider].UnionWith(frame.ControllerStates.Select(state => state.MoveId));
observations.AddRange(frame.MarkerCandidates
.Where(marker => !string.IsNullOrWhiteSpace(marker.MoveId))
.Select(marker => new MoveVisibilityObservation(
source.Provider, marker.CameraId, marker.MoveId, frame.FrameId, frame.PublishedAtNs,
marker.CenterXPx, marker.CenterYPx, marker.RadiusPx, marker.Score)));
}
}
Thread.Sleep(5);
}
var correspondences = observations
.GroupBy(observation => observation.MoveId, StringComparer.Ordinal)
.SelectMany(group =>
{
var first = group.Where(value => value.ProviderId == sources[0].Provider).ToArray();
var second = group.Where(value => value.ProviderId == sources[1].Provider).ToArray();
return first.Select(left => second
.Select(right => new MoveCrossCameraCorrespondence(left.MoveId, left, right, Math.Abs(left.PublishedAtNs - right.PublishedAtNs)))
.OrderBy(pair => pair.AbsoluteSkewNs).FirstOrDefault())
.Where(pair => pair is not null)!;
})
.Cast<MoveCrossCameraCorrespondence>()
.ToArray();
var receipt = new MoveVisibilityWindowReceipt(
"mimir.move_visibility_window.v1", startedAtNs,
DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000,
sources.Select(source => source.Provider).ToArray(), observations.ToArray(), correspondences);
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(outputPath))!);
File.WriteAllBytes(outputPath, MessagePackSerializer.Serialize(receipt));
var visibleByProvider = observations.GroupBy(value => value.ProviderId).ToDictionary(
group => group.Key, group => group.Select(value => value.MoveId).Distinct().Order().ToArray());
Console.WriteLine(JsonSerializer.Serialize(new
{
receipt.Schema,
outputPath,
framesByProvider,
controllersByProvider = controllersByProvider.ToDictionary(pair => pair.Key, pair => pair.Value.Order().ToArray()),
observations = observations.Count,
correspondences = correspondences.Length,
visibleByProvider
}));
return sources.All(source => framesByProvider[source.Provider] > 0) &&
sources.All(source => visibleByProvider.ContainsKey(source.Provider)) &&
correspondences.Length > 0 ? 0 : 1;
}
finally
{
foreach (var source in leases) source.Lease.Dispose();
}
}
static int RunMuninnMoveCultMeshStreamSmoke(string nativeReservoirPath)
{
if (!File.Exists(nativeReservoirPath))

View file

@ -0,0 +1,31 @@
using MessagePack;
namespace Mimir.Runtime.Synchronization;
[MessagePackObject]
public sealed record MoveVisibilityObservation(
[property: Key(0)] string ProviderId,
[property: Key(1)] string CameraId,
[property: Key(2)] string MoveId,
[property: Key(3)] string FrameId,
[property: Key(4)] long PublishedAtNs,
[property: Key(5)] float CenterXPx,
[property: Key(6)] float CenterYPx,
[property: Key(7)] float RadiusPx,
[property: Key(8)] float Confidence);
[MessagePackObject]
public sealed record MoveCrossCameraCorrespondence(
[property: Key(0)] string MoveId,
[property: Key(1)] MoveVisibilityObservation First,
[property: Key(2)] MoveVisibilityObservation Second,
[property: Key(3)] long AbsoluteSkewNs);
[MessagePackObject]
public sealed record MoveVisibilityWindowReceipt(
[property: Key(0)] string Schema,
[property: Key(1)] long StartedAtNs,
[property: Key(2)] long EndedAtNs,
[property: Key(3)] string[] Providers,
[property: Key(4)] MoveVisibilityObservation[] Observations,
[property: Key(5)] MoveCrossCameraCorrespondence[] Correspondences);

View file

@ -176,3 +176,4 @@
{"ts": "2026-07-12T20:50:27+01:00", "type": "decision", "status": "ok", "note": "Use upstream PSMoveAPI as Muninn's optical/LED transport backend. Nightwing now has current libpsmoveapi.so and libpsmoveapi_tracker.so built against packaged OpenCV 4.6 with V4L2 camera control and installed under /usr/local. Official psmove pair created BlueZ info and HID SDP cache records for wired F5, A3, and A6; unplugged A8 still needs one USB pairing pass. The provisional luma extractor is not valid final tracking authority."}
{"ts": "2026-07-12T21:00:36+01:00", "type": "verification", "status": "ok", "note": "Live Nightwing Bluetooth handoff proved 2026-07-12 after official PSMoveAPI pairing: move-000704a6be5f migrated from USB to BlueZ Bluetooth, remained connected at 40% with /dev/input/js3 and HID_UNIQ 00:07:04:a6:be:5f, retained the same stable Move ID in Mimir's Odin-discovered four-controller evidence frame, and the large identity-colored sphere remained glowing. The red status LED blink pattern is not the connection witness; BlueZ HID path, Mimir frame identity, and visible sphere are."}
{"ts": "2026-07-13T00:10:04+01:00", "type": "scar", "status": "open", "note": "Move tracking false-blocker: both Nightwing PS3 Eyes were already physically positioned. The missing authority was software process isolation and persistent dual-provider ingestion. Do not ask the operator to rearrange hardware without first probing all live devices/providers. Repeated one-shot Mimir probes also misuse Muninn's single-client RUDP evidence server; visibility sweeps must keep one persistent subscription per provider."}
{"ts": "2026-07-13T00:16:58+01:00", "type": "verification", "status": "partial", "note": "Persistent dual-provider visibility window separated transport from optics: nightwing-eye0 delivered 2 frames and all 4 controller IDs but 0 labelled markers; primary nightwing delivered 0 frames, consistent with its single-client evidence server remaining occupied after prior one-shot probes. Restart observers before the next window; do not infer camera visibility from discovery or controller presence."}