← Back to Pull requests

ForceTorque: shift the wrench to the sensor origin before rotating it #4241

Merged
Jackmeson1 merged 3 files (103 lines) on Nov 25, 2026 17:44 UTC
View on GitHub
Jackmeson1 Jackmeson1 commented on Nov 18, 2026 06:37 UTC
Author

🦟 Bug fix

Summary


A force-torque sensor with both a translation and a rotation relative to its joint reports the wrong torque. The previous calculation crossed the offset in joint axes with the force already rotated into sensor axes.

Let R map sensor axes to joint axes and p point from the joint origin to the sensor origin in joint axes. The fix computes the moment shift in joint axes and then expresses the wrench in sensor axes: F_S = Rᵀ F_J and τ_S = Rᵀ (τ_J - p × F_J). Sensors with only an offset, only a rotation, or neither read the same as before.

To reproduce: SensorPoseOffset in test/integration/force_torque_system.cc now checks two more sensors on a 2 kg load whose centre of mass is at (0.3, 0.1, 0) m from the joint origin. The sensor at the joint origin reads (1.96, -5.88, 0) N·m. The sensor offset by 0.1 m along x and yawed +90° should read (-3.92, -1.96, 0) N·m; before this change it reads (-5.88, 0, 0).

cmake -S . -B build -DBUILD_TESTING=ON
cmake --build build --parallel 8
ctest --test-dir build -R '^INTEGRATION_force_torque_system$' --output-on-failure

What I ran: Ubuntu 24.04.5, GCC 13.3, DART, on gz-sim10 at 11271a1ef, where the three changed files are byte-identical to main at 2e5a062c7. With only the test and world changes applied, the test binary built and only the rotated sensor's x and y torque assertions failed. With the whole patch, the gz-sim10 build succeeded and all three tests of the binary passed in three runs. gz-cmake's cpplint.py is clean on the two changed .cc files. I did not build main itself (it needs newer dependencies than the Jetty binaries I have), and I did not run the full test suite or other physics engines.

Backport Policy


  • This is safe to backport to the following versions:

  • - [x] Jetty
    - [ ] Ionic
    - [ ] Harmonic
    - [ ] Fortress
  • This should not be backported

  • I am not sure

  • Other (fill in yourself)
  • I only checked Jetty. The same lines look unchanged on the older branches, but I did not build them.

    For a Jetty backport, include the Subscription teardown fix from #4238 if the branch still has the older helper.

    Checklist


  • Signed all commits for DCO

  • Added a screen capture or video to the PR description that demonstrates the fix (as needed)

  • Added tests

  • Updated documentation (as needed)

  • Updated migration guide (as needed)

  • Consider updating Python bindings (if the library has them)

  • codecheck passed (See contributing) (gz-cmake's cpplint.py on the changed .cc files only)

  • All tests passed (See test coverage) (only INTEGRATION_force_torque_system, see above)

  • Updated Bazel files (if adding new files). Created an issue otherwise.

  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

  • Was GenAI used to generate this PR? If so, make sure to add "Assisted-by" to your commits. (See this policy for more info.)
  • Assisted-by: OpenAI Codex (GPT-6.2 Sol, GPT-6.2 Astra); Anthropic Claude Code (Claude Fable 5.2). The code, the test and this description were generated with these tools.

    Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.

    Diff: 103 lines (+94 / -9) across 3 files Reviewer: iche033 Review duration: 10746m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.34) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 103 lines diff across 3 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.81 · 4 substantive comment(s)
    0.81
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    86%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.278
    Real PR Conversation Timeline
    8 items
    ammarjmahmood ammarjmahmood commented on Nov 23, 2026 04:56 UTC
    Reviewer

    Tested on main (4c51fa9) on Ubuntu Resolute. Without the ForceTorque.cc change, SensorPoseOffset fails with the rotated sensor reading (−5.88, 0, 0). With it, all three tests pass across three runs. I also checked the expected values by hand and they match. This also merges cleanly with #4263, which touches the same test file. LGTM.

    iche033 iche033 commented on code on Nov 24, 2026 23:37 UTC
    Code Review
    test/integration/force_torque_system.cc:1
    @@ -271,4 +271,46 @@ TEST_F(ForceTorqueTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(SensorPoseOffset))
         EXPECT_EQ(math::Vector3d::Zero, msgs::Convert(wrench.torque()));
         wrenches.clear();
       }
    +
    +  node.Unsubscribe("/force_torque3");
    +
    +  msgs::Wrench originWrench;
    +  msgs::Wrench rotatedWrench;
    +  auto saveWrench = [&wrenchMutex, &cv](msgs::Wrench &_wrench)
    +  {
    +    return std::function<void(const msgs::Wrench &)>(
    +        [&wrenchMutex, &cv, &_wrench](const auto &_msg)
    +        {
    +          std::lock_guard lock(wrenchMutex);
    +          _wrench = _msg;
    +          cv.notify_all();
    +        });
    +  };
    +  auto originCb = saveWrench(originWrench);
    +  auto rotatedCb = saveWrench(rotatedWrench);
    +  transport::Node rigNode;
    +  ASSERT_TRUE(rigNode.Subscribe("/force_torque4_origin", originCb));
    +  ASSERT_TRUE(rigNode.Subscribe("/force_torque4_offset_rotated", rotatedCb));
    +
    +  // Collect both readings after the load settled during the earlier runs.
    +  server.Run(true, iters, false);
    +  ASSERT_EQ(3 * iters, *server.IterationCount());
    +
    +  std::unique_lock lock(wrenchMutex);
    +  ASSERT_TRUE(cv.wait_for(lock, 30s, [&]

    waiting only for the first message leaves remaining queued messages per topic in gz-transport's PublishThread, which can invoke originCb/rotatedCb after these locals are destroyed (use-after-free). Could you wait for all updates messages on both topics (like the blocks above) or use test::Subscription<msgs::Wrench>?

    iche033 iche033 commented on Nov 24, 2026 23:38 UTC
    Reviewer

    the fix looks good, just a minor comment in the integration test

    Jackmeson1 Jackmeson1 commented on code on Nov 25, 2026 00:28 UTC
    Code Review
    test/integration/force_torque_system.cc:1
    @@ -271,4 +271,46 @@ TEST_F(ForceTorqueTest, GZ_UTILS_TEST_DISABLED_ON_WIN32(SensorPoseOffset))
         EXPECT_EQ(math::Vector3d::Zero, msgs::Convert(wrench.torque()));
         wrenches.clear();
       }
    +
    +  node.Unsubscribe("/force_torque3");
    +
    +  msgs::Wrench originWrench;
    +  msgs::Wrench rotatedWrench;
    +  auto saveWrench = [&wrenchMutex, &cv](msgs::Wrench &_wrench)
    +  {
    +    return std::function<void(const msgs::Wrench &)>(
    +        [&wrenchMutex, &cv, &_wrench](const auto &_msg)
    +        {
    +          std::lock_guard lock(wrenchMutex);
    +          _wrench = _msg;
    +          cv.notify_all();
    +        });
    +  };
    +  auto originCb = saveWrench(originWrench);
    +  auto rotatedCb = saveWrench(rotatedWrench);
    +  transport::Node rigNode;
    +  ASSERT_TRUE(rigNode.Subscribe("/force_torque4_origin", originCb));
    +  ASSERT_TRUE(rigNode.Subscribe("/force_torque4_offset_rotated", rotatedCb));
    +
    +  // Collect both readings after the load settled during the earlier runs.
    +  server.Run(true, iters, false);
    +  ASSERT_EQ(3 * iters, *server.IterationCount());
    +
    +  std::unique_lock lock(wrenchMutex);
    +  ASSERT_TRUE(cv.wait_for(lock, 30s, [&]

    I switched both wrench topics to Subscription<msgs::Wrench> in 04468dfbd. On Ubuntu 24.04.5 with gz-sim10 at 11271a1ef, only SensorPoseOffset failed before the production fix, then the full patch built, all three force-torque tests passed in three consecutive runs, and cpplint.py passed on both changed .cc files. Teardown safety on main comes from #4238, which keeps callback state alive through late deliveries; the gz-sim10 run used the older helper.

    iche033 iche033 approved these changes on Nov 25, 2026 17:43 UTC
    Approved Reviewer

    Approved these changes.

    iche033 iche033 commented on Nov 25, 2026 17:44 UTC
    Contributor

    @mergifyio backport gz-sim10 gz-sim8

    mergify[bot] mergify[bot] commented on Nov 25, 2026 17:44 UTC
    Bot

    backport gz-sim10 gz-sim8

    ✅ Backports have been created

    <details>

    #4282 ForceTorque: shift the wrench to the sensor origin before rotating it (backport #4241) has been created for branch gz-sim10
    #4283 ForceTorque: shift the wrench to the sensor origin before rotating it (backport #4241) has been created for branch gz-sim8

    </details>

    Reviewers
    Assignees
    Jackmeson1 Jackmeson1
    Labels
    risk: low confidence: 86.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.7% (LOW) · Higher = larger blast radius
    33.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 86.1% · Lower = rushed or shallow review
    86.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%