Skip to content

Commit

Permalink
quadrotor example: add getter for geometry frame
Browse files Browse the repository at this point in the history
  • Loading branch information
RussTedrake committed May 15, 2021
1 parent 2c3d6de commit 49e892b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bindings/pydrake/examples/quadrotor_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ PYBIND11_MODULE(quadrotor, m) {

py::class_<QuadrotorGeometry, LeafSystem<double>>(
m, "QuadrotorGeometry", doc.QuadrotorGeometry.doc)
.def("get_frame_id()", &QuadrotorGeometry::get_frame_id,
doc.QuadrotorGeometry.get_frame_id.doc)
.def_static("AddToBuilder", &QuadrotorGeometry::AddToBuilder,
py::arg("builder"), py::arg("quadrotor_state_port"),
py::arg("scene_graph"), py::return_value_policy::reference,
Expand Down
3 changes: 2 additions & 1 deletion bindings/pydrake/examples/test/quadrotor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ def test_geometry(self):
quadrotor = builder.AddSystem(QuadrotorPlant())
scene_graph = builder.AddSystem(SceneGraph())
state_port = quadrotor.get_output_port(0)
QuadrotorGeometry.AddToBuilder(builder, state_port, scene_graph)
geom = QuadrotorGeometry.AddToBuilder(builder, state_port, scene_graph)
self.assertTrue(geom.get_frame_id().is_valid())
4 changes: 4 additions & 0 deletions examples/quadrotor/quadrotor_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class QuadrotorGeometry final : public systems::LeafSystem<double> {
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(QuadrotorGeometry);
~QuadrotorGeometry() final;

/// Returns the frame of the geometry registered with a SceneGraph. This can
/// be useful, e.g., if one would like to add a camera to the quadrotor.
geometry::FrameId get_frame_id() const { return frame_id_; }

/// Creates, adds, and connects a QuadrotorGeometry system into the given
/// `builder`. Both the `quadrotor_state.get_system()` and `scene_graph`
/// systems must have been added to the given `builder` already.
Expand Down
2 changes: 2 additions & 0 deletions examples/quadrotor/test/quadrotor_geometry_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ GTEST_TEST(QuadrotorGeometryTest, AcceptanceTest) {
&builder, plant->get_output_port(0), scene_graph);
auto diagram = builder.Build();
ASSERT_NE(geom, nullptr);

EXPECT_TRUE(geom->get_frame_id().is_valid());
}

} // namespace
Expand Down

0 comments on commit 49e892b

Please sign in to comment.