Skip to content

Commit

Permalink
Modified pybind components to conform to previous binds
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth authored and sloretz committed Apr 21, 2022
1 parent ec8663d commit 2a23ddb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
6 changes: 3 additions & 3 deletions drake_ros_viz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ install(
# Python bindings
###
pybind11_add_module(py_drake_ros_viz SHARED
src/python_bindings/module_drake_ros_viz.cpp
src/python_bindings/drake_ros_viz.cc
)
set_target_properties(py_drake_ros_viz PROPERTIES OUTPUT_NAME "drake_ros_viz")
target_link_libraries(py_drake_ros_viz PRIVATE drake_ros_viz)
Expand All @@ -84,11 +84,11 @@ target_include_directories(py_drake_ros_viz
)

# Sets PYTHON_INSTALL_DIR
_ament_cmake_python_get_python_install_dir()
ament_get_python_install_dir(python_install_dir)

install(
TARGETS py_drake_ros_viz
DESTINATION "${PYTHON_INSTALL_DIR}"
DESTINATION "${python_install_dir}"
)
### End Python bindings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
// limitations under the License.
#include <memory>

#include "drake_ros_viz/rviz_visualizer.hpp"
#include <drake/systems/framework/leaf_system.h>
#include "drake_ros_core/drake_ros.h"
#include <drake/systems/framework/diagram.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include "drake_ros_viz/rviz_visualizer.h"

namespace py = pybind11;

using drake::systems::Diagram;
using drake::systems::TriggerType;

using drake_ros_core::DrakeRosInterface;
using drake_ros_core::DrakeRos;
using drake_ros_viz::RvizVisualizer;
using drake_ros_viz::RvizVisualizerParams;

Expand All @@ -34,23 +36,26 @@ PYBIND11_MODULE(drake_ros_viz, m) {
py::module::import("pydrake.systems.framework");
py::module::import("pydrake.multibody.plant");

const RvizVisualizerParams default_params{};
py::class_<RvizVisualizerParams>(m, "RvizVisualizerParams")
.def(py::init([](py::kwargs kwargs) {
RvizVisualizerParams obj{};
py::object pyobj = py::cast(&obj, py::return_value_policy::reference);
for (auto& item : kwargs) {
py::setattr(pyobj, item.first, item.second);
}
return obj;
}))
.def(py::init([](const std::unordered_set<drake::systems::TriggerType>&
publish_triggers,
double publish_period, bool publish_tf) {
return RvizVisualizerParams{publish_triggers, publish_period,
publish_tf};
}),
py::kw_only(),
py::arg("publish_triggers") = default_params.publish_triggers,
py::arg("publish_period") = default_params.publish_period,
py::arg("publish_tf") = default_params.publish_tf)
.def_readwrite("publish_triggers",
&RvizVisualizerParams::publish_triggers)
.def_readwrite("publish_period", &RvizVisualizerParams::publish_period)
.def_readwrite("publish_tf", &RvizVisualizerParams::publish_tf);

py::class_<RvizVisualizer, Diagram<double>>(m, "RvizVisualizer")
.def(py::init<std::shared_ptr<DrakeRosInterface>, RvizVisualizerParams>(),
py::arg("ros_interface"), py::arg("params") = RvizVisualizerParams{})
.def(py::init<DrakeRos*, RvizVisualizerParams>(), py::arg("ros"),
py::arg("params") = RvizVisualizerParams{})
.def("RegisterMultibodyPlant", &RvizVisualizer::RegisterMultibodyPlant)
.def("get_graph_query_port", &RvizVisualizer::get_graph_query_port,
py::return_value_policy::reference_internal);
Expand Down

0 comments on commit 2a23ddb

Please sign in to comment.