Skip to content

Refactor JTC command interface assignment - #2489

Open
dlanov wants to merge 1 commit into
ros-controls:masterfrom
dlanov:refactor-jtc-command-assignment
Open

Refactor JTC command interface assignment#2489
dlanov wants to merge 1 commit into
ros-controls:masterfrom
dlanov:refactor-jtc-command-assignment

Conversation

@dlanov

@dlanov dlanov commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactor the JointTrajectoryController command-interface assignment logic to make the selected command sources explicit and reduce nested conditionals.

Changes

  • Rename tmp_command_ to closed_loop_pid_command_ to clarify that it stores preallocated closed-loop PID command output.
  • Select velocity and effort command sources through named constant references.
  • Preserve the existing position, velocity, acceleration, effort, and closed-loop PID command behavior.
  • Add no allocations or additional work to the real-time update path.

Testing

  • colcon build --symlink-install --packages-select joint_trajectory_controller --cmake-args -DBUILD_TESTING=ON
  • colcon test --packages-select joint_trajectory_controller --event-handlers console_cohesion+
  • colcon test-result --verbose
  • pre-commit run --files joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.hpp joint_trajectory_controller/src/joint_trajectory_controller.cpp
  • git diff --check

Results:

  • 850 tests
  • 0 errors
  • 0 failures
  • 0 skipped
  • All applicable pre-commit checks passed

Closes #326

AI assistance

Claude Code assisted with analyzing and preparing the narrowly scoped refactor. I manually reviewed the complete diff and verified the build, test, formatting, lint, and whitespace-check results.

Signed-off-by: Dennis Lanov <dennis.lanov@gmail.com>

@destogl destogl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good thanks!

Comment on lines +472 to 477
const std::vector<double> & velocity_command =
use_closed_loop_pid_adapter_ ? closed_loop_pid_command_ : command_next_.velocities;
const std::vector<double> & effort_command =
use_closed_loop_pid_adapter_ ? closed_loop_pid_command_ : state_desired_.effort;

if (has_position_command_interface_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the scope can be reduced inside the if-branches below, right? The ternary-if could even be used in assign_interface_from_point instead of assigning a new variable.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.83%. Comparing base (c7b97ca) to head (6a3c2d9).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2489   +/-   ##
=======================================
  Coverage   86.83%   86.83%           
=======================================
  Files         148      148           
  Lines       16273    16273           
  Branches     1368     1366    -2     
=======================================
  Hits        14131    14131           
  Misses       1635     1635           
  Partials      507      507           
Flag Coverage Δ
unittests 86.83% <100.00%> (ø)

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

Files with missing lines Coverage Δ
...jectory_controller/joint_trajectory_controller.hpp 62.50% <ø> (ø)
...ory_controller/src/joint_trajectory_controller.cpp 85.23% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

[JTC] This set of cascading if-s should be refactored into something more readable.

3 participants