Record the zero-gravity readings before the gravity feedforward: the 2 s ragdoll hashes and the reach hashes

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-26 06:46:58 +01:00
commit 93e85a5a33
3 changed files with 28 additions and 5 deletions

View file

@ -89,11 +89,15 @@ public sealed class IkReachTests
[Fact]
public void Zero_gravity_reach_lands_the_wrist()
{
// State hashes recorded at origin/main e47e3d3, before the gravity feedforward: in zero gravity Drive writes the PD torque only, so they never move.
var recorded = new ulong[] { 2780975657960733482ul, 1878696821643337211ul, 486659158273771449ul };
var worst = 0f;
foreach (var offset in Targets)
for (var k = 0; k < Targets.Length; k++)
{
var (error, _) = Reach(offset, gravity: 0f, weldPelvis: false);
_out.WriteLine($"zero gravity, offset {offset}: wrist error {error * 100f:F2} cm");
var offset = Targets[k];
var (error, hash) = Reach(offset, gravity: 0f, weldPelvis: false);
_out.WriteLine($"zero gravity, offset {offset}: wrist error {error * 100f:F2} cm, hash {hash}");
Assert.Equal(recorded[k], hash);
worst = MathF.Max(worst, error);
Assert.True(error < FreeBound, $"wrist error {error * 100f:F2} cm at {offset} exceeds {FreeBound * 100f:F1} cm");
}

View file

@ -15,12 +15,12 @@ internal sealed class RagdollScenario : IDisposable
public readonly Quat[] Target;
private int _steps;
public RagdollScenario(ulong seed)
public RagdollScenario(ulong seed, float gravityY = -10f)
{
var (bodies, joints, _) = Ragdoll.Needs(Plan);
Strength = new float[Plan.Joints.Count];
Target = new Quat[Plan.Joints.Count];
World = new Box3DSoaWorld(capacity: bodies + 1, jointCapacity: joints);
World = new Box3DSoaWorld(capacity: bodies + 1, gravityY: gravityY, jointCapacity: joints);
World.AddStaticBox(1, (0f, -0.5f, 0f), (20f, 0.5f, 20f), friction: 0.8f);
Ragdoll = Ragdoll.Build(World, Plan, (0f, 0f), firstStableId: 100);
Array.Fill(Target, Quat.Identity);

View file

@ -183,6 +183,25 @@ public sealed class RagdollTests
Assert.True(TorqueNorm(s, s.Plan.PartIndex("Thigh", Side.Left)) > 1f); // the ball joint does not
}
/// <summary>
/// Zero gravity: Drive writes the PD torque and nothing else (the feedforward is skipped), so the 2 s state hash of a free ragdoll, seeds 1-3, is the one recorded at
/// origin/main e47e3d3, before the gravity feedforward. Goldens move only where a ruling says; this one pins that the feedforward is zero where gravity is.
/// </summary>
[Fact]
public void A_zero_gravity_world_replays_the_hash_recorded_before_the_gravity_feedforward()
{
var recorded = new ulong[] { 4596821165163159072ul, 2187121869401780341ul, 2995211072229544614ul };
var got = new ulong[3];
for (var k = 0; k < 3; k++)
{
using var s = new RagdollScenario((ulong)(k + 1), gravityY: 0f);
s.Run(2f);
got[k] = s.StateHash();
}
Assert.True(recorded.SequenceEqual(got), string.Join(", ", got));
}
[Fact]
public void Driving_a_tick_allocates_nothing()
{