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 391e41a commit a84901b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 232 deletions.
22 changes: 5 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ install(DIRECTORY include/ DESTINATION include)
# Install shared resources
install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})

ament_export_targets(export_${PROJECT_NAME} rviz_visual_tools_binding_utilsTargets HAS_LIBRARY_TARGET)
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(geometry_msgs
shape_msgs
rclcpp
Expand Down Expand Up @@ -257,33 +257,21 @@ 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(rviz_visual_tools PACKAGE_DIR python/rviz_visual_tools)

add_library(rviz_visual_tools_binding_utils SHARED python/src/binding_utils.cpp)
ament_target_dependencies(rviz_visual_tools_binding_utils rclcpp pybind11)
target_include_directories(rviz_visual_tools_binding_utils PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/python/include>
$<INSTALL_INTERFACE:include/rviz_visual_tools>
)

pybind11_add_module(pyrviz_visual_tools python/src/rviz_visual_tools.cpp)
target_link_libraries(pyrviz_visual_tools PRIVATE rviz_visual_tools rviz_visual_tools_binding_utils)
target_link_libraries(pyrviz_visual_tools PRIVATE rviz_visual_tools py_binding_tools::py_binding_tools)
ament_target_dependencies(pyrviz_visual_tools pybind11)
install(
TARGETS
rviz_visual_tools_binding_utils
EXPORT
rviz_visual_tools_binding_utilsTargets
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

install(DIRECTORY python/include/ DESTINATION include/rviz_visual_tools)
install(TARGETS pyrviz_visual_tools
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}/rviz_visual_tools)
install(PROGRAMS
python/examples/rviz_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 @@ -38,6 +38,7 @@
<depend>visualization_msgs</depend>
<depend>std_msgs</depend>
<depend>trajectory_msgs</depend>
<depend>py_binding_tools</depend>

<build_depend>qtbase5-dev</build_depend>
<build_depend>eigen</build_depend>
Expand Down
5 changes: 3 additions & 2 deletions python/examples/rviz_visual_tools_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from threading import Thread
import numpy as np
from copy import deepcopy
import rclcpp

LOGGER = get_logger("rviz_visual_tools_demo")

rvt.init()
node = rvt.RvizVisualToolsNode("rviz_visual_tools_demo")
rclcpp.init()
node = rclcpp.Node("rviz_visual_tools_demo")
visual_tools = rvt.RvizVisualTools(node, "world", "/rviz_visual_tools")
visual_tools.load_marker_publisher(True)
visual_tools.delete_all_markers()
Expand Down
121 changes: 0 additions & 121 deletions python/include/rviz_visual_tools/binding_utils.hpp

This file was deleted.

3 changes: 0 additions & 3 deletions python/rviz_visual_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from rviz_visual_tools.pyrviz_visual_tools import (
init,
shutdown,
Scales,
Colors,
EulerConvention,
RvizVisualTools,
RvizVisualToolsNode,
)
57 changes: 0 additions & 57 deletions python/src/binding_utils.cpp

This file was deleted.

34 changes: 2 additions & 32 deletions python/src/rviz_visual_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <pybind11/eigen.h>
#include <pybind11/stl.h>
#include <rviz_visual_tools/rviz_visual_tools.hpp>
#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 @@ -11,36 +11,6 @@ namespace rviz_visual_tools
{
PYBIND11_MODULE(pyrviz_visual_tools, m)
{
py::class_<RvizVisualToolsNode, RvizVisualToolsNode::SharedPtr>(m, "RvizVisualToolsNode")
.def(py::init<const std::string&>(), "node_name"_a)
.def("spin_all", &RvizVisualToolsNode::spin_all, "timeout_millis"_a = 0)
.def("start_spin_thread", &RvizVisualToolsNode::start_spin_thread)
.def("stop_spin_thread", &RvizVisualToolsNode::stop_spin_thread);

/**Initialize ROS 2's global context.
This function decorates a `rclcpp::init` invocation.
*/
m.def(
"init",
[](std::vector<std::string> args) {
if (args.empty())
{
args = py::module::import("sys").attr("argv").cast<std::vector<std::string>>();
}
std::vector<const char*> raw_args;
raw_args.reserve(args.size());
for (const auto& arg : args)
{
raw_args.push_back(arg.c_str());
}
if (!rclcpp::ok())
{
rclcpp::init(raw_args.size(), raw_args.data());
}
},
py::arg("args") = std::vector<std::string>{});
m.def("shutdown", &rclcpp::shutdown);

py::enum_<Colors>(m, "Colors")
.value("BLACK", Colors::BLACK)
.value("BROWN", Colors::BROWN)
Expand Down Expand Up @@ -83,7 +53,7 @@ PYBIND11_MODULE(pyrviz_visual_tools, m)
.value("ZXZ", EulerConvention::ZXZ);

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

0 comments on commit a84901b

Please sign in to comment.