Skip to content

Commit 29d1219

Browse files
committed
Reenable python bindings
1 parent 98000f3 commit 29d1219

File tree

16 files changed

+29
-162
lines changed

16 files changed

+29
-162
lines changed

core/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ find_package(moveit_core REQUIRED)
1212
find_package(moveit_ros_planning REQUIRED)
1313
find_package(moveit_ros_planning_interface REQUIRED)
1414
find_package(moveit_task_constructor_msgs REQUIRED)
15+
find_package(py_binding_tools REQUIRED)
1516
find_package(rclcpp REQUIRED)
1617
find_package(rviz_marker_tools REQUIRED)
1718
find_package(tf2_eigen REQUIRED)
@@ -26,8 +27,8 @@ add_compile_options(-fvisibility-inlines-hidden)
2627
set(PROJECT_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include/moveit/task_constructor)
2728

2829
add_subdirectory(src)
29-
# TODO: enable python wrapper
30-
#add_subdirectory(python)
30+
ament_python_install_package(moveit PACKAGE_DIR python/moveit)
31+
add_subdirectory(python)
3132
add_subdirectory(test)
3233

3334
install(DIRECTORY include/ DESTINATION include
@@ -42,6 +43,7 @@ ament_export_dependencies(moveit_core)
4243
ament_export_dependencies(moveit_ros_planning)
4344
ament_export_dependencies(moveit_ros_planning_interface)
4445
ament_export_dependencies(moveit_task_constructor_msgs)
46+
ament_export_dependencies(py_binding_tools)
4547
ament_export_dependencies(rclcpp)
4648
ament_export_dependencies(rviz_marker_tools)
4749
ament_export_dependencies(tf2_eigen)

core/include/moveit/python/python_tools/ros_types.h

Lines changed: 0 additions & 90 deletions
This file was deleted.

core/include/moveit/python/task_constructor/properties.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class PropertyConverter : protected PropertyConverterBase
3535
static boost::any fromPython(const pybind11::object& po) { return pybind11::cast<T>(po); }
3636

3737
template <class Q = T>
38-
typename std::enable_if<ros::message_traits::IsMessage<Q>::value, std::string>::type rosMsgName() {
39-
return ros::message_traits::DataType<T>::value();
38+
typename std::enable_if<rosidl_generator_traits::is_message<Q>::value, std::string>::type rosMsgName() {
39+
return rosidl_generator_traits::name<Q>();
4040
}
4141

4242
template <class Q = T>
43-
typename std::enable_if<!ros::message_traits::IsMessage<Q>::value, std::string>::type rosMsgName() {
43+
typename std::enable_if<!rosidl_generator_traits::is_message<Q>::value, std::string>::type rosMsgName() {
4444
return std::string();
4545
}
4646
};

core/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<depend>moveit_ros_planning</depend>
2121
<depend>moveit_ros_planning_interface</depend>
2222
<depend>moveit_task_constructor_msgs</depend>
23+
<depend>py_binding_tools</depend>
2324
<depend>rclcpp</depend>
2425
<depend>rviz_marker_tools</depend>
2526
<depend>tf2_eigen</depend>

core/python/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ add_subdirectory(pybind11)
2424
# C++ wrapper code
2525
add_subdirectory(bindings)
2626

27-
ament_python_install_package("src")
2827

2928
if(BUILD_TESTING)
3029
find_package(ament_cmake_pytest REQUIRED)
Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
# python tools support lib
2-
set(TOOLS_LIB_NAME moveit_python_tools)
3-
set(INCLUDES ${PROJECT_SOURCE_DIR}/include/moveit/python/python_tools)
4-
add_library(${TOOLS_LIB_NAME} SHARED
5-
${INCLUDES}/ros_init.h
6-
${INCLUDES}/ros_types.h
7-
src/ros_init.cpp
8-
src/ros_types.cpp
9-
)
10-
target_include_directories(${TOOLS_LIB_NAME}
11-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
12-
PUBLIC $<INSTALL_INTERFACE:include>
13-
)
14-
target_link_libraries(${TOOLS_LIB_NAME} PUBLIC pybind11::pybind11 ${Boost_LIBRARIES} rclcpp::rclcpp)
15-
16-
install(TARGETS ${TOOLS_LIB_NAME}
17-
ARCHIVE DESTINATION lib
18-
LIBRARY DESTINATION lib
19-
)
20-
21-
# moveit.python_tools
22-
pybind11_add_module(pymoveit_python_tools src/python_tools.cpp)
23-
target_link_libraries(pymoveit_python_tools PRIVATE ${TOOLS_LIB_NAME})
24-
251
# moveit.task_constructor
262
set(INCLUDES ${PROJECT_SOURCE_DIR}/include/moveit/python/task_constructor)
273
pybind11_add_module(pymoveit_mtc
@@ -34,9 +10,9 @@ pybind11_add_module(pymoveit_mtc
3410
src/module.cpp
3511
)
3612
target_include_directories(pymoveit_mtc PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>)
37-
target_link_libraries(pymoveit_mtc PUBLIC ${PROJECT_NAME} ${PROJECT_NAME}_stages ${TOOLS_LIB_NAME})
13+
target_link_libraries(pymoveit_mtc PUBLIC ${PROJECT_NAME} ${PROJECT_NAME}_stages py_binding_tools::py_binding_tools)
3814

3915
# install python libs
40-
install(TARGETS pymoveit_python_tools pymoveit_mtc
41-
LIBRARY DESTINATION "${PYTHON_INSTALL_DIR}/${PROJECT_NAME}"
16+
install(TARGETS pymoveit_mtc
17+
LIBRARY DESTINATION "${PYTHON_INSTALL_DIR}"
4218
)

core/python/bindings/src/core.cpp

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ void export_core(pybind11::module& m) {
412412
.def_property_readonly("failures", &Task::failures, "Solutions: Failed Solutions of the stage (read-only)")
413413
.def_property("name", &Task::name, &Task::setName, "str: name of the task displayed e.g. in rviz")
414414

415-
.def("loadRobotModel", &Task::loadRobotModel, "robot_description"_a = "robot_description",
415+
.def("loadRobotModel", &Task::loadRobotModel, "node"_a, "robot_description"_a = "robot_description",
416416
"Load robot model from given ROS parameter")
417417
.def("getRobotModel", &Task::getRobotModel)
418418
.def("enableIntrospection", &Task::enableIntrospection, "enabled"_a = true,
@@ -471,30 +471,7 @@ void export_core(pybind11::module& m) {
471471
"publish",
472472
[](Task& self, const SolutionBasePtr& solution) { self.introspection().publishSolution(*solution); },
473473
"solution"_a, "Publish the given solution to the ROS topic ``solution``")
474-
.def_static(
475-
"execute",
476-
[](const SolutionBasePtr& solution) {
477-
using namespace moveit::planning_interface;
478-
PlanningSceneInterface psi;
479-
MoveGroupInterface mgi(solution->start()->scene()->getRobotModel()->getJointModelGroupNames()[0]);
480-
481-
MoveGroupInterface::Plan plan;
482-
moveit_task_constructor_msgs::msg::Solution serialized;
483-
solution->toMsg(serialized);
484-
485-
for (const moveit_task_constructor_msgs::msg::SubTrajectory& traj : serialized.sub_trajectory) {
486-
if (!traj.trajectory.joint_trajectory.points.empty()) {
487-
plan.trajectory_ = traj.trajectory;
488-
if (!mgi.execute(plan)) {
489-
ROS_ERROR("Execution failed! Aborting!");
490-
return;
491-
}
492-
}
493-
psi.applyPlanningScene(traj.scene_diff);
494-
}
495-
ROS_INFO("Executed successfully");
496-
},
497-
"solution"_a, "Send given solution to ``move_group`` node for execution");
474+
.def("execute", &Task::execute, "solution"_a, "Send given solution to ``move_group`` node for execution");
498475
}
499476
} // namespace python
500477
} // namespace moveit

core/python/bindings/src/properties.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,15 @@ py::object PropertyConverterRegistry::toPython(const boost::any& value) {
119119

120120
std::string rosMsgName(PyObject* object) {
121121
py::object o = py::reinterpret_borrow<py::object>(object);
122-
try {
123-
return o.attr("_type").cast<std::string>();
124-
} catch (const py::error_already_set& e) {
122+
auto cls = o.attr("__class__");
123+
auto name = cls.attr("__name__").cast<std::string>();
124+
auto module = cls.attr("__module__").cast<std::string>();
125+
auto pos = module.find(".msg");
126+
if (pos == std::string::npos)
125127
// object is not a ROS message type, return it's class name instead
126-
return o.attr("__class__").attr("__name__").cast<std::string>();
127-
}
128+
return module + "." + name;
129+
else
130+
return module.substr(0, pos) + "/msg/" + name;
128131
}
129132

130133
boost::any PropertyConverterRegistry::fromPython(const py::object& po) {

core/python/bindings/src/solvers.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include <moveit/task_constructor/solvers/pipeline_planner.h>
3838
#include <moveit/task_constructor/solvers/joint_interpolation.h>
3939
#include <moveit/task_constructor/solvers/multi_planner.h>
40-
#include <moveit_msgs/WorkspaceParameters.h>
40+
#include <moveit_msgs/msg/workspace_parameters.hpp>
4141
#include "utils.h"
4242

4343
namespace py = pybind11;
@@ -69,19 +69,18 @@ void export_solvers(py::module& m) {
6969
from moveit.task_constructor import core
7070
7171
# Create and configure a planner instance
72-
pipelinePlanner = core.PipelinePlanner()
73-
pipelinePlanner.planner = 'PRMkConfigDefault'
72+
pipelinePlanner = core.PipelinePlanner(node, 'ompl', 'PRMkConfigDefault')
7473
pipelinePlanner.num_planning_attempts = 10
7574
)")
76-
.property<std::string>("planner", "str: Planner ID")
7775
.property<uint>("num_planning_attempts", "int: Number of planning attempts")
7876
.property<moveit_msgs::msg::WorkspaceParameters>(
7977
"workspace_parameters",
8078
":moveit_msgs:`WorkspaceParameters`: Specifies workspace box to be used for Cartesian sampling")
8179
.property<double>("goal_joint_tolerance", "float: Tolerance for reaching joint goals")
8280
.property<double>("goal_position_tolerance", "float: Tolerance for reaching position goals")
8381
.property<double>("goal_orientation_tolerance", "float: Tolerance for reaching orientation goals")
84-
.def(py::init<const std::string&>(), "pipeline"_a = std::string("ompl"));
82+
.def(py::init<const rclcpp::Node::SharedPtr&, const std::string&, const std::string&>(), "node"_a,
83+
"pipeline"_a = std::string("ompl"), "planner_id"_a = std::string(""));
8584

8685
properties::class_<JointInterpolationPlanner, PlannerInterface>(
8786
m, "JointInterpolationPlanner",

core/python/bindings/src/stages.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <moveit/task_constructor/stages/pick.h>
3939
#include <moveit/task_constructor/stages/simple_grasp.h>
4040
#include <moveit/planning_scene/planning_scene.h>
41-
#include <moveit_msgs/PlanningScene.h>
41+
#include <moveit_msgs/msg/planning_scene.hpp>
4242
#include <pybind11/stl.h>
4343
#include <py_binding_tools/ros_msg_typecasters.h>
4444

@@ -357,7 +357,7 @@ void export_stages(pybind11::module& m) {
357357
str: Name of the object in the planning scene, attached to the robot which should be placed
358358
)")
359359
.property<std::string>("eef", "str: Name of the end effector that should be used for grasping")
360-
.property<geometry_msgs::msg::msg::PoseStamped>("pose", R"(
360+
.property<geometry_msgs::msg::PoseStamped>("pose", R"(
361361
PoseStamped_: The pose where the object should be placed, i.e. states should be sampled
362362
363363
.. _PoseStamped: https://docs.ros.org/en/api/geometry_msgs/html/msg/PoseStamped.html
@@ -393,7 +393,7 @@ void export_stages(pybind11::module& m) {
393393
for an implementation of a task hierarchy that makes use of the
394394
``GeneratePose`` stage.
395395
)")
396-
.property<geometry_msgs::msg::msg::msg::PoseStamped>("pose", R"(
396+
.property<geometry_msgs::msg::PoseStamped>("pose", R"(
397397
PoseStamped_: Set the pose, which should be spawned on each new solution of the monitored stage.
398398
399399
.. _PoseStamped: https://docs.ros.org/en/api/geometry_msgs/html/msg/PoseStamped.html

0 commit comments

Comments
 (0)