Skip to content

Pr humble python bindings #3487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 30 commits into
base: humble
Choose a base branch
from

Conversation

SamueleSandrini
Copy link
Contributor

@SamueleSandrini SamueleSandrini commented May 29, 2025

Description

This PR introduces Python bindings (MoveItPy) for MoveIt 2 Humble. The implementation was mainly adapted by copying existing code from the Jazzy and Main branches and adjusting for interface differences in Humble (see attached notes from the porting process).
Notably, in planning_component.hpp/.cpp, the return type of plan() changed from planning_interface::MotionPlanResponse to moveit_cpp::PlanningComponent::PlanSolution. To maintain consistency with the existing C++ structure (similar to Jazzy’s treatment in moveit_core), I placed the Python bindings within planning_component.hpp/.cpp. Feedback on this placement is welcome if changes are preferred.

During testing with colcon test, I encountered import issues where the moveit.planning and related Python modules were not found, even though they work fine when sourcing the workspace, and thus using the installed modules. The cause has not yet been identified (I suspected it was due to the location of the build folder of the __init__.py together with modules file inside the build folder under test_moveit rather than test_moveit/moveit, but that turned out not to be the issue).

For initial testing, I also forked moveit2_tutorials available here.

Additional example tests I tried can be found here, which uses this UR-robot cell. Let me know if it is required to provide a docker.

Related issues: #3454 #3473

Checklist

  • Required by CI: Code is auto formatted using clang-format
  • Extend the tutorials / documentation reference (Partially)
  • Document API changes relevant to the user in the MIGRATION.md notes
  • Create tests, which fail without this PR reference
  • Include a screenshot if changing a GUI
  • While waiting for someone to review your request, please help review another open pull request to support the maintainers

@SamueleSandrini SamueleSandrini changed the base branch from humble to main May 29, 2025 00:32
@sea-bass sea-bass changed the base branch from main to humble May 29, 2025 01:19
@moveit moveit deleted a comment from mergify bot May 29, 2025
@moveit moveit deleted a comment from mergify bot May 29, 2025
@moveit moveit deleted a comment from mergify bot May 29, 2025
Copy link
Contributor

@rhaschke rhaschke left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution. I noticed that the .pyi files deviate from the main branch.
As you copied the stuff from there, why did you change those files?
We should also remove old/unused python code from ROS1. I prepared corresponding commits here. This also fixes the tests.
Finally, copying files is not authoring. Hence, you should remove yourself from the authors list of the copied files. Ideally, the added files should have minimal changes w.r.t. the main branch.

static py::handle cast(const rclcpp::Time& src, return_value_policy /* policy */, py::handle /* parent */)
{
py::module rclpy_time = py::module::import("rclpy.time");
py::object Time = rclpy_time.attr("Time");
Copy link
Contributor

@rhaschke rhaschke May 30, 2025

Choose a reason for hiding this comment

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

This should fix the clang-tidy issue:

Suggested change
py::object Time = rclpy_time.attr("Time");
py::object Time = rclpy_time.attr("Time"); // NOLINT(readability-identifier-naming)

Copy link

codecov bot commented May 30, 2025

Codecov Report

Attention: Patch coverage is 46.79245% with 423 lines in your changes missing coverage. Please review.

Project coverage is 50.87%. Comparing base (a60ed9f) to head (5c098a2).
Report is 1 commits behind head on humble.

Files with missing lines Patch % Lines
...py/src/moveit/moveit_py_utils/src/copy_ros_msg.cpp 0.00% 182 Missing ⚠️
...src/moveit/moveit_core/robot_state/robot_state.cpp 57.90% 72 Missing ⚠️
...moveit/moveit_core/kinematic_constraints/utils.cpp 17.47% 52 Missing ⚠️
...veit/moveit_core/planning_scene/planning_scene.cpp 75.00% 29 Missing ⚠️
.../moveit_py/moveit_py_utils/ros_msg_typecasters.hpp 42.86% 20 Missing ⚠️
...y/src/moveit/moveit_core/transforms/transforms.cpp 0.00% 17 Missing ⚠️
...veit_core/collision_detection/collision_matrix.cpp 51.73% 14 Missing ⚠️
...veit_core/planning_interface/planning_response.cpp 55.00% 9 Missing ⚠️
...veit/moveit_core/robot_model/joint_model_group.cpp 61.91% 8 Missing ⚠️
.../moveit_core/robot_trajectory/robot_trajectory.cpp 72.42% 8 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##           humble    #3487      +/-   ##
==========================================
- Coverage   50.96%   50.87%   -0.08%     
==========================================
  Files         390      407      +17     
  Lines       32520    33323     +803     
==========================================
+ Hits        16569    16950     +381     
- Misses      15951    16373     +422     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SamueleSandrini
Copy link
Contributor Author

Thanks for this contribution. I noticed that the .pyi files deviate from the main branch. As you copied the stuff from there, why did you change those files? We should also remove old/unused python code from ROS1. I prepared corresponding commits here. This also fixes the tests. Finally, copying files is not authoring. Hence, you should remove yourself from the authors list of the copied files. Ideally, the added files should have minimal changes w.r.t. the main branch.

Thanks for the feedback, I'll fix the names.
As for the stub files, I had thought of regenerating them based on the info in the README (stubgen -p moveit) to make sure they're aligned with the small changes I made, like to MotionPlanResponse, RobotTrajectory, PlanningSceneMonitor, TrajectoryExecutionManager classes.
However, I noticed that with this approach there are some differences respect main branch files, like Incomplete instead of Any, and some imports.
Would it be better if I took the files from main and just fixed the properties and methods where needed? Otherwise, how can I avoid those differences in automatic generation with stub?

@rhaschke
Copy link
Contributor

rhaschke commented Jun 1, 2025

Would it be better if I took the files from main and just fixed the properties and methods where needed?

Yes, that's what I suggest. I have further reduced the differences to main here.

Comment on lines 21 to 22
copyright = "2022, Peter David Fagan; 2025, Samuele Sandrini"
author = "Peter David Fagan, Samuele Sandrini"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, authorship doesn't apply here as well.

Suggested change
copyright = "2022, Peter David Fagan; 2025, Samuele Sandrini"
author = "Peter David Fagan, Samuele Sandrini"
copyright = "2022, Peter David Fagan"
author = "Peter David Fagan"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thanks! I missed that. I had only checked in src

def process_planning_scene_world(self, *args, **kwargs) -> Any: ...
def remove_all_collision_objects(self, *args, **kwargs) -> Any: ...
def set_object_color(self, *args, **kwargs) -> Any: ...
def save_geometry_to_file(self, file_name_and_path) -> Any: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't be file_path_and_name here (and also in the next line)? (also in the main branch).

def read_write(self, *args, **kwargs) -> Any: ...
def request_planning_scene_state(self, *args, **kwargs) -> Any: ...
def start_scene_monitor(self, *args, **kwargs) -> Any: ...
def start_state_monitor(self, *args, **kwargs) -> Any: ...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this might be a duplication. It also appears in the main branch.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please file a PR to fix those issues on the main branch as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had seen wrong, they are different. Instead, in the previous comment, there is indeed a mismatch between stub file and args in the bindings.

@rhaschke
Copy link
Contributor

rhaschke commented Jun 2, 2025

Looks like the ROS docker images are broken and need to be upgraded to the latest ROS install procedure.
Unfortunately, the correspondig PR is not yet merged: docker-library/official-images#19162

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