diff --git a/bindings/pydrake/BUILD.bazel b/bindings/pydrake/BUILD.bazel index c1c873bde91d..28caf4094098 100644 --- a/bindings/pydrake/BUILD.bazel +++ b/bindings/pydrake/BUILD.bazel @@ -227,7 +227,7 @@ drake_py_test( ) drake_py_test( - name = "math_test", + name = "test/math_test", size = "small", srcs = ["test/math_test.py"], main = "test/math_test.py", @@ -236,6 +236,11 @@ drake_py_test( ], ) +alias( + name = "math_test", + actual = "test/math_test", +) + drake_py_test( name = "symbolic_variables_test", size = "small", diff --git a/bindings/pydrake/systems/BUILD.bazel b/bindings/pydrake/systems/BUILD.bazel index 194ff56cdfa1..c8983987ae23 100644 --- a/bindings/pydrake/systems/BUILD.bazel +++ b/bindings/pydrake/systems/BUILD.bazel @@ -92,6 +92,7 @@ drake_pybind_library( drake_pybind_library( name = "controllers_py", cc_deps = [ + "//bindings/pydrake/util:wrap_function", "//systems/controllers:dynamic_programming", ], cc_so_name = "controllers", diff --git a/bindings/pydrake/systems/controllers_py.cc b/bindings/pydrake/systems/controllers_py.cc index d5c48e2bcca9..fbceecbb5e43 100644 --- a/bindings/pydrake/systems/controllers_py.cc +++ b/bindings/pydrake/systems/controllers_py.cc @@ -4,11 +4,34 @@ #include #include "drake/bindings/pydrake/pydrake_pybind.h" +#include "drake/bindings/pydrake/util/wrap_function.h" #include "drake/systems/controllers/dynamic_programming.h" namespace drake { namespace pydrake { +namespace { + +template +struct wrap_ptr : public wrap_arg_default {}; + +template +struct wrap_ptr&> { + using Type = systems::Context; + static auto wrap(const Type& arg) { return &arg; } + static auto unwrap(const Type* arg_wrapped) { return *arg_wrapped; } +}; + +// Ensures that `const Context&` is wrapped with `const Context*`. +// TODO(eric.cousineau): Replace this with general wrappper, place in +// `pydrake_pybind` or somewhere related. +template +auto WrapPtr(Func&& func) { + return WrapFunction(std::forward(func)); +} + +} // namespace + PYBIND11_MODULE(controllers, m) { // NOLINTNEXTLINE(build/namespaces): Emulate placement in namespace. using namespace drake::systems::controllers; @@ -21,7 +44,7 @@ PYBIND11_MODULE(controllers, m) { .def_readwrite("discount_factor", &DynamicProgrammingOptions::discount_factor); - m.def("FittedValueIteration", &FittedValueIteration); + m.def("FittedValueIteration", WrapPtr(&FittedValueIteration)); } } // namespace pydrake