From 49e892b04f32eaf659a1d87bcd6ff24f152a1268 Mon Sep 17 00:00:00 2001 From: Russ Tedrake Date: Fri, 14 May 2021 22:12:12 -0400 Subject: [PATCH] quadrotor example: add getter for geometry frame --- bindings/pydrake/examples/quadrotor_py.cc | 2 ++ bindings/pydrake/examples/test/quadrotor_test.py | 3 ++- examples/quadrotor/quadrotor_geometry.h | 4 ++++ examples/quadrotor/test/quadrotor_geometry_test.cc | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bindings/pydrake/examples/quadrotor_py.cc b/bindings/pydrake/examples/quadrotor_py.cc index 63229cc12c50..8ed671d00654 100644 --- a/bindings/pydrake/examples/quadrotor_py.cc +++ b/bindings/pydrake/examples/quadrotor_py.cc @@ -38,6 +38,8 @@ PYBIND11_MODULE(quadrotor, m) { py::class_>( 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, diff --git a/bindings/pydrake/examples/test/quadrotor_test.py b/bindings/pydrake/examples/test/quadrotor_test.py index b82e90d46b4a..908247e7b4ec 100644 --- a/bindings/pydrake/examples/test/quadrotor_test.py +++ b/bindings/pydrake/examples/test/quadrotor_test.py @@ -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()) diff --git a/examples/quadrotor/quadrotor_geometry.h b/examples/quadrotor/quadrotor_geometry.h index 87183af40926..3613faa3df22 100644 --- a/examples/quadrotor/quadrotor_geometry.h +++ b/examples/quadrotor/quadrotor_geometry.h @@ -25,6 +25,10 @@ class QuadrotorGeometry final : public systems::LeafSystem { 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. diff --git a/examples/quadrotor/test/quadrotor_geometry_test.cc b/examples/quadrotor/test/quadrotor_geometry_test.cc index 840a3f93d8ef..2fbeb340346b 100644 --- a/examples/quadrotor/test/quadrotor_geometry_test.cc +++ b/examples/quadrotor/test/quadrotor_geometry_test.cc @@ -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