ForceTorque: shift the wrench to the sensor origin before rotating it #4241
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.
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>?
the fix looks good, just a minor comment in the integration test
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.
Approved these changes.
@mergifyio backport gz-sim10 gz-sim8
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>
iche033
Jackmeson1
🦟 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
Rmap sensor axes to joint axes andppoint 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_Jandτ_S = Rᵀ (τ_J - p × F_J). Sensors with only an offset, only a rotation, or neither read the same as before.To reproduce:
SensorPoseOffsetintest/integration/force_torque_system.ccnow 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).What I ran: Ubuntu 24.04.5, GCC 13.3, DART, on
gz-sim10at11271a1ef, where the three changed files are byte-identical tomainat2e5a062c7. 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, thegz-sim10build succeeded and all three tests of the binary passed in three runs. gz-cmake'scpplint.pyis clean on the two changed.ccfiles. I did not buildmainitself (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
- [x] Jetty
- [ ] Ionic
- [ ] Harmonic
- [ ] Fortress
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
Subscriptionteardown fix from #4238 if the branch still has the older helper.Checklist
codecheckpassed (See contributing) (gz-cmake'scpplint.pyon the changed.ccfiles only)INTEGRATION_force_torque_system, see above)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-byandGenerated-bymessages.