diff --git a/src/Lodur.Body.Ymir/Ragdoll.cs b/src/Lodur.Body.Ymir/Ragdoll.cs
index 75a6e48..396d9cc 100644
--- a/src/Lodur.Body.Ymir/Ragdoll.cs
+++ b/src/Lodur.Body.Ymir/Ragdoll.cs
@@ -8,7 +8,9 @@ namespace Lodur.Body.Ymir
/// in plan order, the stable id firstStableId + part ordinal, the limb lane the part ordinal, the parent lane the lane of the part's
/// parent in the plan. The game owns the physics world: Build adds bodies to the caller's world and Lodur never creates or steps one.
/// is the muscle layer: it turns caller-owned strengths and target rotations into torques on the world's
- /// torque lanes and does nothing else to the physics. The binding holds no body numbers; the plan owns them.
+ /// torque lanes and does nothing else to the physics. Each muscle's torque is a PD term toward its target plus the gravity load of the
+ /// muscle's unsupported subtree times its strength, projected on the axes it has gains for (ruling gravity-feedforward-all-muscles), so
+ /// sag comes only from weakness; the load reads Ymir's Mass, ContactCount, JointOrigin and Gravity, and a body in contact carries none. The binding holds no body numbers; the plan owns them.
/// In a world with a particle system Build also places one liquid sensor per plan airway opening, and reads them.
///
public sealed class Ragdoll
@@ -18,6 +20,8 @@ namespace Lodur.Body.Ymir
private readonly int[] _jointLane;
private readonly int[] _sensorLane;
private readonly MuscleGains[] _gains;
+ // Subtree mass and mass-weighted position per part: scratch rebuilt every Drive, never read across ticks.
+ private readonly float[] _mass, _momentX, _momentY, _momentZ;
private Ragdoll(Box3DSoaWorld world, BodyPlan plan)
{
@@ -28,6 +32,10 @@ namespace Lodur.Body.Ymir
_sensorLane = new int[plan.AirwayOpenings.Count];
Array.Fill(_sensorLane, -1);
_gains = new MuscleGains[plan.Joints.Count];
+ _mass = new float[plan.Parts.Count];
+ _momentX = new float[plan.Parts.Count];
+ _momentY = new float[plan.Parts.Count];
+ _momentZ = new float[plan.Parts.Count];
}
/// The plan this ragdoll was built from.
@@ -104,7 +112,9 @@ namespace Lodur.Body.Ymir
///
/// Writes this tick's muscle torques onto the world's torque lanes: for each joint a PD torque toward
/// [joint] (the child's rotation relative to the parent in the joint frame, whose z axis is a hinge's axis; a hinge has no swing gains, so it takes torque about that axis only) scaled by [joint], applied to the child
- /// and, equal and opposite, to the parent. Both arrays are the caller's, one entry per plan joint;
+ /// and, equal and opposite, to the parent, plus the gravity feedforward: the torque about the joint origin that holds up the weight of the child's
+ /// subtree, except every body in contact with anything (a supported body, one lying or leaning, carries no load: ruling gravity-feedforward-count-gate),
+ /// times the strength and kept to the joint frame axes the muscle has gains for. A world with no gravity skips it. Both arrays are the caller's, one entry per plan joint;
/// nothing is copied or retained. Allocates nothing. Call once per step, before world.Step; the
/// world clears the lanes when it applies them.
///
@@ -129,6 +139,52 @@ namespace Lodur.Body.Ymir
v.TorqueX[child] += wx; v.TorqueY[child] += wy; v.TorqueZ[child] += wz;
v.TorqueX[parent] -= wx; v.TorqueY[parent] -= wy; v.TorqueZ[parent] -= wz;
}
+
+ var (gx, gy, gz) = _world.Gravity;
+ if (gx == 0f && gy == 0f && gz == 0f) return;
+ var n = _mass.Length;
+ for (var p = 0; p < n; p++)
+ {
+ var b = _bodyLane[p];
+ var load = v.ContactCount[b] > 0 ? 0f : v.Mass[b];
+ _mass[p] = load;
+ _momentX[p] = load * v.PositionX[b];
+ _momentY[p] = load * v.PositionY[b];
+ _momentZ[p] = load * v.PositionZ[b];
+ }
+
+ for (var p = n - 1; p > 0; p--) // BodyPlan puts every parent before its child
+ {
+ var q = Plan.ParentOf(p);
+ if (q < 0) continue;
+ _mass[q] += _mass[p];
+ _momentX[q] += _momentX[p];
+ _momentY[q] += _momentY[p];
+ _momentZ[q] += _momentZ[p];
+ }
+
+ for (var m = 0; m < _gains.Length; m++)
+ {
+ var j = _jointLane[m];
+ var c = Plan.Joints[m].Child;
+ var rx = _momentX[c] - _mass[c] * v.JointOriginX[j];
+ var ry = _momentY[c] - _mass[c] * v.JointOriginY[j];
+ var rz = _momentZ[c] - _mass[c] * v.JointOriginZ[j];
+ var k = MathF.Max(strengths[m], 0f);
+ // The muscle holds the load up: minus the gravity torque of the subtree's weight about the joint origin.
+ var tx = -k * (ry * gz - rz * gy);
+ var ty = -k * (rz * gx - rx * gz);
+ var tz = -k * (rx * gy - ry * gx);
+ var frame = new Quat(v.JointFrameX[j], v.JointFrameY[j], v.JointFrameZ[j], v.JointFrameW[j]);
+ frame.Conjugate().Rotate(tx, ty, tz, out var lx, out var ly, out var lz);
+ if (_gains[m].SwingStiffness <= 0f) { lx = 0f; ly = 0f; }
+ if (_gains[m].TwistStiffness <= 0f) lz = 0f;
+ frame.Rotate(lx, ly, lz, out var wx, out var wy, out var wz);
+ var child = v.JointBodyB[j];
+ var parent = v.JointBodyA[j];
+ v.TorqueX[child] += wx; v.TorqueY[child] += wy; v.TorqueZ[child] += wz;
+ v.TorqueX[parent] -= wx; v.TorqueY[parent] -= wy; v.TorqueZ[parent] -= wz;
+ }
}
///
diff --git a/tests/Lodur.Tests/ConnectedPainBoxTests.cs b/tests/Lodur.Tests/ConnectedPainBoxTests.cs
index d7ca2f8..fa6e2d3 100644
--- a/tests/Lodur.Tests/ConnectedPainBoxTests.cs
+++ b/tests/Lodur.Tests/ConnectedPainBoxTests.cs
@@ -12,9 +12,13 @@ namespace Lodur.Tests;
internal sealed class ConnectedPainBox : IDisposable
{
public const double Dt = 1.0 / 120.0;
- /// The stimulus box's half extent: 0.12 held the leak-free hand in the box until the break with the hand a forearm tip; the palm hangs 4 ticks early, so 0.125.
- public const float BoxHalf = 0.125f;
- /// Where the right palm settles at the hold pose (the box and the shoulder-right strength-1 pose are fixed; measured seed 1 from 3 s).
+ ///
+ /// The stimulus box's half extent, the smallest in 0.005 m steps that holds the shipped run's hand (seed 1) in the box from 2 s until the break. At e47e3d3 that was 0.125
+ /// (0.120 let the palm out 4 ticks early). With the gravity feedforward the will's failing sag, which the break no longer outruns, leaves the box earlier:
+ /// 0.125 lets it out 18 ticks early, 0.140 eight, 0.145 none. Limit 0.150: past it the hold no longer holds by intent.
+ ///
+ public const float BoxHalf = 0.145f;
+ /// The hold point: where the hold pose is solved to put the strength-1 right palm (the shoulder-right and elbow-right angles below; settled seed 1, 3-4 s, no leak), no longer where the controller sags it to.
public static readonly (float X, float Y, float Z) Box = (-0.210f, 1.116f, 0.441f);
public readonly Box3DSoaWorld World;
@@ -45,8 +49,11 @@ internal sealed class ConnectedPainBox : IDisposable
var withdrawPose = new Quat[Plan.Joints.Count];
Array.Fill(holdPose, Quat.Identity);
Array.Fill(withdrawPose, Quat.Identity);
- holdPose[Plan.JointIndex("Shoulder", Side.Right)] = Quat.FromAxisAngle(1f, 0f, 0f, -1.0f);
- holdPose[Plan.JointIndex("Elbow", Side.Right)] = Quat.FromAxisAngle(0f, 0f, 1f, -0.6f);
+ // The hold pose is solved by intent: the shoulder and elbow angles that put the settled strength-1 palm on Box (grid then refine over both, seed 1, 3-4 s,
+ // box silent): -0.70 and -0.36, 0.34 cm off. At e47e3d3 the same fit was -1.0 and -0.6, a pose that gravity sagged onto Box; with the feedforward the
+ // controller no longer sags, and -1.0, -0.6 would hold the palm well above it.
+ holdPose[Plan.JointIndex("Shoulder", Side.Right)] = Quat.FromAxisAngle(1f, 0f, 0f, -0.70f);
+ holdPose[Plan.JointIndex("Elbow", Side.Right)] = Quat.FromAxisAngle(0f, 0f, 1f, -0.36f);
withdrawPose[Plan.JointIndex("Shoulder", Side.Right)] = Quat.FromAxisAngle(1f, 0f, 0f, 0.3f);
withdrawPose[Plan.JointIndex("Elbow", Side.Right)] = Quat.FromAxisAngle(0f, 0f, 1f, -2.0f);
@@ -206,12 +213,22 @@ public sealed class ConnectedPainBoxTests
public void A_failing_will_sags_the_hold_even_with_no_leak_and_no_shake_while_a_strong_will_holds_still()
{
var plain = Run(seed: 1, new HoldParameters { FlinchGain = 0.0, StrainShake = 0.0 }, maxSeconds: 16.0);
- // Early, resolve is high and the weight near 1: the hand stays within 2.3 cm of the hold point (seed 1 measured 0.2-2.0 cm to 8 s).
+ // Early, resolve is high and the weight near 1: the hand stays within 2.3 cm of the hold point (seed 1 measured 0.1-1.7 cm over 3-6 s with the gravity feedforward; 0.2-2.0 cm to 8 s at e47e3d3).
for (var i = 3 * Hz; i < 6 * Hz; i++) Assert.True(Dist(plain.Hand[i].Hand, Centre) <= 0.023f, $"drift {Dist(plain.Hand[i].Hand, Centre)} at tick {i}");
- // Late, the will is nearly gone: the voluntary hold has gone slack and the arm sags well out of the box before the break (measured 0.155 m at 14.3 s).
+ // Late, the will is nearly gone: the voluntary hold has gone slack and the arm sags well out of the box before the break (measured 0.199 m at 14.3 s with the gravity feedforward, the will's weakness the only sag left; 0.155 m at e47e3d3).
Assert.True(Dist(plain.Hand[(int)plain.Broke - 60].Hand, Centre) > 0.1f);
}
+ [Fact]
+ public void The_hold_pose_puts_the_settled_palm_on_the_box_centre_at_full_strength()
+ {
+ // The pose is solved for this (0.34 cm at the fit): with a flat will and no leak the palm's mean from 3 to 4 s is within 0.5 cm of the hold point (0.24 cm measured).
+ var t = Run(seed: 1, new HoldParameters { FlinchGain = 0.0, StrainShake = 0.0 }, maxSeconds: 5.0, new DriveParameters { WillCurve = 0.001 });
+ var settled = t.Hand.Skip(3 * Hz).Take(Hz).ToList();
+ var mean = (X: settled.Average(h => h.Hand.X), Y: settled.Average(h => h.Hand.Y), Z: settled.Average(h => h.Hand.Z));
+ Assert.True(Dist(mean, Centre) <= 0.005f, $"settled palm {Dist(mean, Centre) * 100f:F2} cm from the hold point");
+ }
+
private static float VerticalPeakToPeak(Timeline t, int fromSecond)
{
var seg = t.Hand.Skip(fromSecond * Hz).Take(Hz).Select(h => h.Hand.Y).ToList();
@@ -222,7 +239,7 @@ public sealed class ConnectedPainBoxTests
public void Strain_shows_as_a_visible_shake_of_the_hand_which_the_shipped_amplitude_makes_and_zero_does_not()
{
// Seconds 8 to 13 of seed 1: strain is about 3, the will has not broken (it breaks at 14.75 s). Measured at the
- // palm with the shipped StrainShake 0.08 / ShakeHz 3.5: 3.2-5.5 cm peak to peak in hand height per second; at 0, 0.6-1.2 cm.
+ // palm with the shipped StrainShake 0.08 / ShakeHz 3.5: 3.3-4.6 cm peak to peak in hand height per second; at 0, 0.2-1.4 cm (3.2-5.5 and 0.6-1.2 cm at e47e3d3).
// (The shake was 0.03 on the forearm-tip hand, 3.9-4.7 cm there; the hands' mass damps the arm and the default rose to keep the rule.)
var shaking = Run(seed: 1, new HoldParameters(), maxSeconds: 16.0);
var still = Run(seed: 1, new HoldParameters { StrainShake = 0.0 }, maxSeconds: 16.0);
@@ -265,10 +282,11 @@ public sealed class ConnectedPainBoxTests
[Fact]
public void Seed_1_to_16_seconds_replays_the_world_the_break_and_the_deliberate_switch_recorded_at_the_will_mix()
{
- // Recorded at the ragdoll hands (palm region, hand-mass damping, StrainShake 0.08, box half 0.125); the line before was the will mix's
- // (broke=1770 withdrew=1782 flinches=16 hand=a0fafe85c80e98f7 world=83155f2abf0e7e91); the break moved two ticks, the flinch count did not.
+ // Recorded with the gravity feedforward and the re-solved hold (pose -0.70, -0.36, box half 0.145); the line before was recorded at e47e3d3, the ragdoll hands
+ // (palm region, hand-mass damping, StrainShake 0.08, box half 0.125, pose -1.0, -0.6): broke=1772 withdrew=1784 flinches=16 hand=17416bc7c2d12853 world=9f710f8186aff900.
+ // The break moved one tick, the flinch count did not; the hand and the world moved because the muscles now carry the arm's weight.
var t = Run(seed: 1, maxSeconds: 16.0);
- Assert.Equal("broke=1772 withdrew=1784 flinches=16 hand=17416bc7c2d12853 world=9f710f8186aff900",
+ Assert.Equal("broke=1773 withdrew=1785 flinches=16 hand=6db1f8d175e3e635 world=348765d9a09a27cf",
$"broke={t.Broke} withdrew={t.Withdrew} flinches={t.Flinches.Count} hand={HandTrackHash(t):x16} world={t.Hash:x16}");
}
}
diff --git a/tests/Lodur.Tests/HandTests.cs b/tests/Lodur.Tests/HandTests.cs
index f0d1921..f323b03 100644
--- a/tests/Lodur.Tests/HandTests.cs
+++ b/tests/Lodur.Tests/HandTests.cs
@@ -273,6 +273,13 @@ public sealed class HandTests
Assert.InRange(Reach(3f), -0.45f, -0.30f); // 0.35 past straight, a soft stop gives a little
}
+ ///
+ /// How far past its cone a hand joint may swing, at the geometric midpoint (deterministic-bound-margin) of the shipped worst and the least claimed mutant:
+ /// 0.0621 rad (wrist, seeds 1-3, four directions, both sides; 0.0557 thumb) against 0.6048 (the wrist added without its cone limit; the thumb reads 0.894), margin 3.1 each side.
+ /// The gravity feedforward lets the muscle press its full torque on Box3D's soft limit, which gives 0.0621 where the controller at e47e3d3 sagged off it (0.0587), and the old 0.06 bound.
+ ///
+ private const float ConeOvershoot = 0.194f;
+
[Theory]
[InlineData("Wrist", Side.Left, 1.0f)]
[InlineData("Wrist", Side.Right, 1.0f)]
@@ -288,7 +295,7 @@ public sealed class HandTests
s.Target[joint] = Quat.FromAxisAngle(ax, ay, 0f, 2.5f);
s.Run(2f);
var swing = Swing(s, joint);
- Assert.True(swing < cone + 0.06f, $"{label} {side} swung {swing} past its cone {cone} toward ({ax}, {ay})");
+ Assert.True(swing < cone + ConeOvershoot, $"{label} {side} swung {swing} past its cone {cone} toward ({ax}, {ay})");
reached = MathF.Max(reached, swing);
}
Assert.True(reached > cone - 0.15f, $"{label} {side} only swung {reached} of its cone {cone} in any direction");
diff --git a/tests/Lodur.Tests/IkReachTests.cs b/tests/Lodur.Tests/IkReachTests.cs
index 1c11f0c..118f350 100644
--- a/tests/Lodur.Tests/IkReachTests.cs
+++ b/tests/Lodur.Tests/IkReachTests.cs
@@ -29,7 +29,7 @@ public sealed class IkReachTests
private const float FreeBound = 0.0377f;
/// Runs the right arm toward shoulder + offset for four seconds and returns the wrist error, the final state hash and the torso drift.
- private static (float Error, ulong Hash) Reach((float X, float Y, float Z) offset, float gravity, bool weldPelvis)
+ private static (float Error, ulong Hash) Reach((float X, float Y, float Z) offset, float gravity, bool weldPelvis, float strengthValue = 1f)
{
var (bodies, joints, _) = Ragdoll.Needs(Plan);
using var world = new Box3DSoaWorld(capacity: bodies + (weldPelvis ? 1 : 0), gravityY: gravity, jointCapacity: joints + (weldPelvis ? 1 : 0));
@@ -43,7 +43,7 @@ public sealed class IkReachTests
var arm = ArmChain.Of(Plan, Side.Right, Dt);
var strength = new float[Plan.Joints.Count];
var target = new Quat[Plan.Joints.Count];
- Array.Fill(strength, 1f);
+ Array.Fill(strength, strengthValue);
Array.Fill(target, Quat.Identity);
var goal = (X: arm.ShoulderAnchor.X + offset.X, Y: arm.ShoulderAnchor.Y + offset.Y, Z: arm.ShoulderAnchor.Z + offset.Z);
var torso = ragdoll.BodyLane(arm.ParentPart);
@@ -105,14 +105,44 @@ public sealed class IkReachTests
_out.WriteLine($"shipped worst {worst * 100f:F2} cm, bound {FreeBound * 100f:F1} cm");
}
+ ///
+ /// Gravity reach bound at the geometric midpoint (deterministic-bound-margin) of the shipped worst, 3.97 cm over the three targets with the pelvis welded (3.01, 3.16, 3.97),
+ /// and the least claimed mutant, 24.01 cm (the feedforward off: 13.69, 10.16, 24.01): margin 2.46 each side. The controller no longer sags: zero gravity reads 0.89 cm here.
+ /// With the count gate off the shipped worst reads 0.89 cm: the right hand's thumb and fingers touch each other, so their weight leaves the arm's load (ruling
+ /// gravity-feedforward-count-gate, given up: self-contact counts as support; follow-up gravity-support-subtree-external).
+ ///
+ private const float GravityBound = 0.0976f;
+
[Fact]
- public void Gravity_reach_error_is_reported()
+ public void Gravity_reach_lands_the_wrist_at_full_strength()
{
+ var worst = 0f;
foreach (var offset in Targets)
{
var (error, _) = Reach(offset, gravity: -10f, weldPelvis: true);
- _out.WriteLine($"gravity on, pelvis welded, offset {offset}: wrist error {error * 100f:F1} cm (no bound; follow-up lodur-reach-tracking)");
- Assert.True(float.IsFinite(error));
+ _out.WriteLine($"gravity on, pelvis welded, offset {offset}: wrist error {error * 100f:F2} cm");
+ worst = MathF.Max(worst, error);
+ Assert.True(error < GravityBound, $"wrist error {error * 100f:F2} cm at {offset} exceeds {GravityBound * 100f:F2} cm");
+ }
+
+ _out.WriteLine($"shipped worst {worst * 100f:F2} cm, bound {GravityBound * 100f:F2} cm");
+ }
+
+ ///
+ /// The least a half-strength arm sags at any target, at the geometric midpoint of the shipped least (13.38 cm; 20.31, 13.38, 25.01) and the least claimed mutant (1.47 cm:
+ /// the feedforward without its strength factor, which holds the weight up at half strength; 18.95, 5.47, 1.47): margin 3.0 each side. A weak will sags (strength 0.5 is
+ /// weakness, not the controller), and the feedforward off reads 22.45, 17.18, 38.77 there.
+ ///
+ private const float WeakSag = 0.0443f;
+
+ [Fact]
+ public void A_half_strength_arm_still_sags_under_gravity_at_every_target()
+ {
+ foreach (var offset in Targets)
+ {
+ var (error, _) = Reach(offset, gravity: -10f, weldPelvis: true, strengthValue: 0.5f);
+ _out.WriteLine($"gravity on, pelvis welded, half strength, offset {offset}: wrist error {error * 100f:F2} cm");
+ Assert.True(error > WeakSag, $"half strength landed within {error * 100f:F2} cm at {offset}, under {WeakSag * 100f:F2} cm: weakness did not sag");
}
}
diff --git a/tests/Lodur.Tests/RagdollTests.cs b/tests/Lodur.Tests/RagdollTests.cs
index ab0fd54..7ad83ca 100644
--- a/tests/Lodur.Tests/RagdollTests.cs
+++ b/tests/Lodur.Tests/RagdollTests.cs
@@ -170,17 +170,64 @@ public sealed class RagdollTests
[Fact]
public void A_hinge_takes_torque_about_its_own_axis_only_and_a_ball_joint_takes_any()
{
+ // The gravity feedforward is the same under either target, so what differs is the PD term alone: the hinge turns what it can (its target's off-axis part changes nothing,
+ // bit for bit) and the ball joint takes the swing it is told.
using var s = new RagdollScenario(seed: 1);
Array.Clear(s.Strength);
- var offAxis = Quat.FromAxisAngle(1f, 0f, 0f, 0.3f); // about the joint frame's x: not the hinge axis (z)
- s.Target[s.Plan.JointIndex("Elbow", Side.Left)] = offAxis;
- s.Target[s.Plan.JointIndex("Hip", Side.Left)] = offAxis;
- s.Strength[s.Plan.JointIndex("Elbow", Side.Left)] = 1f;
- s.Strength[s.Plan.JointIndex("Hip", Side.Left)] = 1f;
+ var elbow = s.Plan.JointIndex("Elbow", Side.Left);
+ var hip = s.Plan.JointIndex("Hip", Side.Left);
+ var forearm = s.Plan.PartIndex("LowerArm", Side.Left);
+ var thigh = s.Plan.PartIndex("Thigh", Side.Left);
+ s.Strength[elbow] = 1f;
+ s.Strength[hip] = 1f;
+ (float X, float Y, float Z) Torque(int part) { var v = s.World.View; var i = s.Ragdoll.BodyLane(part); return (v.TorqueX[i], v.TorqueY[i], v.TorqueZ[i]); }
+
+ s.Target[elbow] = Quat.Identity;
+ s.Target[hip] = Quat.Identity;
ClearTorques(s);
s.Ragdoll.Drive(s.Strength, s.Target);
- Assert.Equal(0f, TorqueNorm(s, s.Plan.PartIndex("LowerArm", Side.Left))); // the hinge ignores what it cannot turn
- Assert.True(TorqueNorm(s, s.Plan.PartIndex("Thigh", Side.Left)) > 1f); // the ball joint does not
+ var straightForearm = Torque(forearm);
+ var straightThigh = Torque(thigh);
+
+ var offAxis = Quat.FromAxisAngle(1f, 0f, 0f, 0.3f); // about the joint frame's x: not the hinge axis (z)
+ s.Target[elbow] = offAxis;
+ s.Target[hip] = offAxis;
+ ClearTorques(s);
+ s.Ragdoll.Drive(s.Strength, s.Target);
+ Assert.Equal(straightForearm, Torque(forearm)); // the hinge ignores what it cannot turn
+ var t = Torque(thigh);
+ var change = MathF.Sqrt((t.X - straightThigh.X) * (t.X - straightThigh.X) + (t.Y - straightThigh.Y) * (t.Y - straightThigh.Y) + (t.Z - straightThigh.Z) * (t.Z - straightThigh.Z));
+ Assert.True(change > 1f, $"the ball joint's thigh torque moved {change} N m"); // the ball joint does not
+ }
+
+ [Fact]
+ public void The_gravity_feedforward_on_a_hinge_acts_about_its_axis_only()
+ {
+ // A forearm held out of the vertical (shoulder raised, elbow bent, everything at full strength for 1 s), then only the elbow strong: the load's torque about the elbow
+ // is not zero there, and what the forearm gets is along the elbow's axis, though the load's own torque is not (the hinge has twist gains only).
+ using var s = new RagdollScenario(seed: 1);
+ var shoulder = s.Plan.JointIndex("Shoulder", Side.Left);
+ var elbow = s.Plan.JointIndex("Elbow", Side.Left);
+ s.Target[shoulder] = Quat.FromAxisAngle(1f, 0f, 0f, -1.2f);
+ s.Target[elbow] = Quat.FromAxisAngle(0f, 0f, 1f, 0.8f);
+ s.Run(1f);
+ var forearm = s.Plan.PartIndex("LowerArm", Side.Left);
+ Array.Clear(s.Strength);
+ ClearTorques(s);
+ s.Ragdoll.Drive(s.Strength, s.Target);
+ var v = s.World.View;
+ var i = s.Ragdoll.BodyLane(forearm);
+ var (x0, y0, z0) = (v.TorqueX[i], v.TorqueY[i], v.TorqueZ[i]); // the wrist's and the elbow's tissue damping alone, which the difference below removes
+ s.Strength[elbow] = 1f;
+ ClearTorques(s);
+ s.Ragdoll.Drive(s.Strength, s.Target);
+ var (dx, dy, dz) = (v.TorqueX[i] - x0, v.TorqueY[i] - y0, v.TorqueZ[i] - z0);
+ var j = s.Ragdoll.JointLane(elbow);
+ new Quat(v.JointFrameX[j], v.JointFrameY[j], v.JointFrameZ[j], v.JointFrameW[j]).Rotate(0f, 0f, 1f, out var ax, out var ay, out var az);
+ var total = MathF.Sqrt(dx * dx + dy * dy + dz * dz);
+ var along = dx * ax + dy * ay + dz * az;
+ Assert.True(total > 0.5f, $"the held-out forearm gets {total} N m");
+ Assert.True(MathF.Abs(along) > total * 0.99999f, $"{total} N m on the forearm, {along} of it along the elbow axis");
}
///
diff --git a/tests/Lodur.Tests/SeatedOrientTests.cs b/tests/Lodur.Tests/SeatedOrientTests.cs
index 1fd92fb..0e2cb1c 100644
--- a/tests/Lodur.Tests/SeatedOrientTests.cs
+++ b/tests/Lodur.Tests/SeatedOrientTests.cs
@@ -36,8 +36,8 @@ public sealed class SeatedOrientTests
///
/// Head forward error bound after 2 s, degrees, set at the geometric midpoint (deterministic-bound-margin) of the shipped worst then, 1.030 deg, and the
- /// least claimed mutant, 15.233 deg (the look blended at half weight), and not loosened since: the shipped worst is now 1.080 deg over the two sounds with and
- /// without gravity, the half-weight mutant 15.729 deg. Layers off reads 29.7 deg.
+ /// least claimed mutant, 15.233 deg (the look blended at half weight), and not loosened since: the shipped worst is now 1.946 deg over the two sounds under gravity (1.080 without it; the
+ /// feedforward lifts the head's look to 1.946 from 0.814), the half-weight mutant 15.729 deg. Layers off reads 29.7 deg.
///
private const float LookBoundDegrees = 3.961f;
@@ -57,12 +57,14 @@ public sealed class SeatedOrientTests
private const float NearWardBound = 0.0576f;
///
- /// Under gravity, the head-height bound on each wrist: the geometric midpoint of the shipped worst, 18.68 cm, and the least claimed mutant, 25.41 cm
- /// (the via point's x at the midpoint). Also killed: the wrists sent sideways of the head, 31.21 cm; no spread, 34.79 cm; the arms at half weight, 62.17 cm. Not killed: the via point at the trunk front, 23.56 cm. The 11 to 13 cm over the zero-gravity case is
- /// the shoulder sagging under the arm's weight (swing 1.11 against a target of 1.50): follow-up lodur-gravity-feedforward. Not re-measured: spread halved
- /// and offset, and the clamped zero-twist swivel, each far above the bound before this cut.
+ /// Under gravity, the head-height bound on each wrist: the geometric midpoint of the shipped worst, 6.00 cm, and the least claimed mutant, 15.52 cm (the via point
+ /// at the trunk front, clearance 0): margin 1.61 each side. Also killed: the gravity feedforward off, 18.68 cm (the controller's own sag, which was the shipped
+ /// worst before it, 18.68); the wrists sent sideways of the head, 33.87 cm; the via point's x at the midpoint, 29.77 cm; no spread, 28.38 cm; the arms at half weight, 54.60 cm.
+ /// Not killed: every reach solved directly, 7.20 cm. The bound at e47e3d3, before the feedforward, was 21.78 cm (shipped worst 18.68, least claimed mutant 25.41, the via
+ /// point's x at the midpoint). With the count gate off the shipped worst reads 7.59 cm: bodies in self-contact leave the arm's load
+ /// (ruling gravity-feedforward-count-gate, given up: self-contact counts as support). Not re-measured: spread halved and offset, and the clamped zero-twist swivel.
///
- private const float GravityWardBound = 0.2178f;
+ private const float GravityWardBound = 0.0965f;
private readonly ITestOutputHelper _out;