Skip to content

Commit

Permalink
Use py_binding_tools
Browse files Browse the repository at this point in the history
  • Loading branch information
JafarAbdi committed Nov 13, 2024
1 parent 34ed825 commit 86446dc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,19 @@ endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_package(pybind11_vendor REQUIRED)
find_package(pybind11 REQUIRED)
find_package(py_binding_tools REQUIRED)

ament_python_install_package(moveit_visual_tools PACKAGE_DIR python/moveit_visual_tools)

pybind11_add_module(pymoveit_visual_tools python/src/moveit_visual_tools.cpp)
target_link_libraries(pymoveit_visual_tools PUBLIC moveit_visual_tools)
target_link_libraries(pymoveit_visual_tools PUBLIC moveit_visual_tools py_binding_tools::py_binding_tools)
ament_target_dependencies(pymoveit_visual_tools PUBLIC pybind11 rviz_visual_tools)
install(TARGETS pymoveit_visual_tools
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}/moveit_visual_tools)
install(PROGRAMS
python/examples/moveit_visual_tools_demo.py
DESTINATION lib/${PROJECT_NAME}
)
ament_export_dependencies(py_binding_tools)

ament_package()
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<depend>tf2_ros</depend>
<depend>trajectory_msgs</depend>
<depend>visualization_msgs</depend>
<depend>py_binding_tools</depend>

<build_depend>pybind11_vendor</build_depend>

Expand Down
8 changes: 5 additions & 3 deletions python/examples/moveit_visual_tools_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import moveit_visual_tools as mvt
import rviz_visual_tools as rvt
import rclcpp
import sys
import time
from rclpy import logging
Expand All @@ -13,12 +14,11 @@

from geometry_msgs.msg import Pose, Point, Quaternion

rvt.init()
rclcpp.init()

PLANNING_GROUP_NAME = "arm"

node = rvt.RvizVisualToolsNode("moveit_visual_tools_demo")
node.start_spin_thread()
node = rclcpp.Node("moveit_visual_tools_demo")
visual_tools = mvt.MoveItVisualTools(node, "world", "/moveit_visual_tools")
visual_tools.load_planning_scene_monitor()
visual_tools.load_marker_publisher(True)
Expand Down Expand Up @@ -129,3 +129,5 @@
cylinder_pose.position.x += 0.1 + i
visual_tools.trigger_planning_scene_update()
time.sleep(1.0)

rclcpp.shutdown()
7 changes: 3 additions & 4 deletions python/src/moveit_visual_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <pybind11/stl.h>
#include <rviz_visual_tools/rviz_visual_tools.hpp>
#include <moveit_visual_tools/moveit_visual_tools.h>
#include <rviz_visual_tools/binding_utils.hpp>
#include <py_binding_tools/ros_msg_typecasters.h>

namespace py = pybind11;
using py::literals::operator""_a;
Expand All @@ -18,9 +18,8 @@ PYBIND11_MODULE(pymoveit_visual_tools, m)
py::module::import("moveit.core.planning_scene");

py::class_<MoveItVisualTools, rviz_visual_tools::RvizVisualTools>(m, "MoveItVisualTools")
.def(py::init(
[](const rviz_visual_tools::RvizVisualToolsNode::SharedPtr& node) { return MoveItVisualTools(node); }))
.def(py::init([](const rviz_visual_tools::RvizVisualToolsNode::SharedPtr& node, const std::string& base_frame,
.def(py::init([](const rclcpp::Node::SharedPtr& node) { return MoveItVisualTools(node); }))
.def(py::init([](const rclcpp::Node::SharedPtr& node, const std::string& base_frame,
const std::string& marker_topic) { return MoveItVisualTools(node, base_frame, marker_topic); }),
"node"_a, "base_frame"_a, "marker_topic"_a = rviz_visual_tools::RVIZ_MARKER_TOPIC)
.def("set_robot_state_topic", &MoveItVisualTools::setRobotStateTopic)
Expand Down

0 comments on commit 86446dc

Please sign in to comment.