Skip to content

Take one position per continuous joint in the Pinocchio plugin (backport #350) - #364

Merged
christophfroehlich merged 2 commits into
jazzyfrom
mergify/bp/jazzy/pr-350
Dec 4, 2026
Merged

christophfroehlich merged 2 commits into
jazzyfrom
mergify/bp/jazzy/pr-350

Conversation

@mergify

@mergify mergify Bot commented Dec 4, 2026

Copy link
Copy Markdown

Description

Pinocchio stores a URDF continuous joint as (cos, sin), so the model has nq = 2 but nv = 1 for it. The Pinocchio plugin used nq as the joint count and copied the joint vector straight into the configuration (q_ = joint_pos). For a chain with a continuous joint this means:

  • A vector with one position per joint, as KDL takes it, is refused: with joint2 of the test URDF made continuous, calculate_jacobian on the 2-joint chain link1 -> link3 logs Invalid joint vector size (2). Expected size is 3. and returns false.
  • A vector of size nq passes the size check. calculate_link_transform then reads its values as (cos, sin), not as an angle. The Jacobian calls (calculate_jacobian, calculate_jacobian_inverse and both convert_*) throw an uncaught std::invalid_argument from computeFrameJacobian, because the Jacobian has nq columns and Pinocchio wants nv.

The joints outside the chain are locked with q_fixed = Zero(nq). Zeros are not a rotation for a continuous joint. For example, with joint1 continuous and the chain link2 -> link3, the transform of link3 comes back as [1 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 0 1], with the singular rotation diag(1, 0, 0). With the chain link1 -> link3 (used in the new test) the Jacobian is wrong as well.

Both lines date from the plugin's first version (#199).

The fix:

  • num_joints_ is model_.nv, so the joint vectors, the Jacobian and its inverse have one entry per joint, as in KDL.
  • A new private set_configuration() builds q_ from the joint positions: (cos, sin) for a continuous joint, the position as is for revolute and prismatic joints. It replaces q_ = joint_pos in the four methods that set it.
  • Joints outside the chain are locked at pinocchio::neutral(full_model).
  • initialize() returns false for a chain joint with nq != nv that is not continuous (planar, floating), since such a joint has no single position. This is a change for these chains: on master they initialize and calculate_link_transform works with a vector of size nq, but every Jacobian call throws std::invalid_argument from computeFrameJacobian (the Jacobian had nq columns, Pinocchio wants nv). Joints like these outside the chain are not affected.

Revolute-only chains are unchanged: there nq = nv and the configuration equals the joint vector.

Is this user-facing behavior change?

Yes. Robots with continuous joints now work with the Pinocchio plugin and take the same joint vectors as with KDL.

Did you use Generative AI?

Yes, Claude Code (Claude Opus 5.5) found the bug and wrote the fix, the tests and this description.

Additional Information

  • Two new tests in the common suite, so they run for both plugins: plugin_continuous_joint (joint2 continuous, chain link1 -> link3, expects the same Jacobian and transform as plugin_jacobian_and_transform_in_root_frame, plus a joint/Cartesian delta round trip) and plugin_continuous_joint_outside_chain (joint1 continuous, chain link1 -> link3, compares the Jacobian and transform with the revolute URDF). On master KDL passes both and Pinocchio fails both. With the fix both plugins pass all 14 tests (ros:rolling-ros-base, Pinocchio 4.1.0).
  • Putting back only the zero q_fixed makes plugin_continuous_joint_outside_chain fail again.
  • Outside the test suite I compared the two plugins with all three joints continuous, on the chains from the root, link1 and link2 to link3, at 500 random configurations each (angles up to +-6 rad). The Jacobian, the transform, the Jacobian inverse and the joint-to-Cartesian deltas agree to 2.5e-13.
  • colcon test passes for all three packages. The clang-format, ament_cpplint and ament_cppcheck hooks pass on the changed files (run one by one, clang-format 23.1.3 as pinned).
  • Add recursive mutex to KDL and Pinocchio plugins #340 (recursive mutex) edits the same files; a test merge of the two branches has no conflicts.
  • The jazzy branch has the same code, so this would need a backport.

TODOs

To send us a pull request, please:

  • Fork the repository.
  • Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
  • Ensure local tests pass. (colcon test and pre-commit run (requires you to install pre-commit by pip3 install pre-commit)
  • Commit to your fork using clear commit messages.
  • Send a pull request, answering any default questions in the pull request interface.
  • Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

This is an automatic backport of pull request #350 done by [Mergify](https://mergify.com).

(cherry picked from commit eb2f8e3)

# Conflicts:
#	kinematics_interface/test/kinematics_interface_common_tests.hpp
@mergify mergify Bot added the conflicts label Dec 4, 2026
@mergify

mergify Bot commented Dec 4, 2026

Copy link
Copy Markdown
Author

Cherry-pick of eb2f8e3 has failed:

On branch mergify/bp/jazzy/pr-350
Your branch is up to date with 'origin/jazzy'.

You are currently cherry-picking commit eb2f8e3.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   kinematics_interface_pinocchio/include/kinematics_interface_pinocchio/kinematics_interface_pinocchio.hpp
	modified:   kinematics_interface_pinocchio/src/kinematics_interface_pinocchio.cpp
	modified:   kinematics_interface_pinocchio/test/test_kinematics_interface_pinocchio.cpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   kinematics_interface/test/kinematics_interface_common_tests.hpp

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.81%. Comparing base (284c1a7) to head (7855147).

Files with missing lines Patch % Lines
...terface/test/kinematics_interface_common_tests.hpp 97.56% 0 Missing and 1 partial ⚠️
...e_pinocchio/src/kinematics_interface_pinocchio.cpp 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            jazzy     #364      +/-   ##
==========================================
+ Coverage   86.91%   87.81%   +0.89%     
==========================================
  Files           7        7              
  Lines         581      640      +59     
  Branches       78       83       +5     
==========================================
+ Hits          505      562      +57     
  Misses         40       40              
- Partials       36       38       +2     
Flag Coverage Δ
unittests 87.81% <96.96%> (+0.89%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...cchio/test/test_kinematics_interface_pinocchio.cpp 100.00% <100.00%> (ø)
...terface/test/kinematics_interface_common_tests.hpp 98.26% <97.56%> (-0.16%) ⬇️
...e_pinocchio/src/kinematics_interface_pinocchio.cpp 79.81% <95.23%> (+0.89%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@christophfroehlich
christophfroehlich merged commit 09ba1f3 into jazzy Dec 4, 2026
14 checks passed
@christophfroehlich
christophfroehlich deleted the mergify/bp/jazzy/pr-350 branch December 4, 2026 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants