Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 29, 2025

Description

Consolidates duplicated code patterns across kinematics solver modules into shared utility functions.

Changes:

  • TCP handling: Added _get_tcp_as_numpy() helper to SolverCfg base class, used by all 6 solver configs
  • Robot model reduction: Extracted build_reduced_pinocchio_robot() to solver_utils.py, replacing duplicate _get_reduce_robot() in PinocchioSolver and PinkSolver
  • Iteration param validation: Added validate_iteration_params() utility, shared by PinocchioSolver and PytorchSolver
  • Pinocchio FK: Added compute_pinocchio_fk() utility, replacing duplicate _get_fk() implementations
# Before: duplicated in each solver config
if isinstance(self.tcp, torch.Tensor):
    tcp = self.tcp.cpu().numpy()
else:
    tcp = self.tcp
solver.set_tcp(tcp)

# After: single helper in base class
solver.set_tcp(self._get_tcp_as_numpy())

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

N/A - refactoring with no functional changes

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.
Original prompt

Find and refactor duplicated code


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 29, 2025 14:52
- Add _get_tcp_as_numpy() helper method to SolverCfg base class
- Add build_reduced_pinocchio_robot() utility function to solver_utils
- Add validate_iteration_params() utility function to solver_utils
- Add compute_pinocchio_fk() utility function to solver_utils
- Update all solver init_solver methods to use _get_tcp_as_numpy()
- Update PinocchioSolver and PinkSolver to use build_reduced_pinocchio_robot()
- Update PinocchioSolver and PytorchSolver to use validate_iteration_params()
- Update PinocchioSolver and PinkSolver to use compute_pinocchio_fk()

Co-authored-by: yuecideng <[email protected]>
- Move numpy import to top of solver_utils.py
- Add validation for end_link_name in compute_pinocchio_fk()

Co-authored-by: yuecideng <[email protected]>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated code in solver modules Nov 29, 2025
Copilot AI requested a review from yuecideng November 29, 2025 14:58
@yuecideng yuecideng marked this pull request as ready for review December 3, 2025 16:24
@yuecideng yuecideng merged commit be5a951 into main Dec 3, 2025
4 checks passed
@yuecideng yuecideng deleted the copilot/refactor-duplicate-code branch December 3, 2025 16:36
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