33#include < pybind11/pybind11.h>
44#include < pybind11/stl.h>
55
6+ #include " dairlib/lcmt_robot_output.hpp"
67#include " systems/framework/lcm_driven_loop.h"
78#include " systems/framework/output_vector.h"
89#include " systems/framework/timestamped_vector.h"
910
10- #include " dairlib/lcmt_robot_output.hpp"
11-
1211#include " drake/bindings/pydrake/pydrake_pybind.h"
1312
1413namespace py = pybind11;
@@ -20,53 +19,50 @@ using drake::pydrake::make_unowned_shared_ptr_from_raw;
2019using LcmOutputDrivenLoop = systems::LcmDrivenLoop<dairlib::lcmt_robot_output>;
2120
2221PYBIND11_MODULE (framework, m) {
22+ py::class_<LcmOutputDrivenLoop>(m, " LcmOutputDrivenLoop" )
23+ .def (py::init ([](drake::lcm::DrakeLcm* drake_lcm,
24+ drake::systems::Diagram<double >& diagram,
25+ const drake::systems::LeafSystem<double >* lcm_parser,
26+ const std::string& input_channel,
27+ bool is_forced_publish) {
28+ // The C++ constructor doesn't offer a bare-pointer overload,
29+ // only shared_ptr. Because object lifetime is already
30+ // handled by the ref_cycle annotation below (as required for
31+ // all subclasses of Diagram), we can pass the `plant` as an
32+ // unowned shared_ptr.
33+ // (comment taken from Drakes controllers_py.cc)
34+ return std::make_unique<LcmOutputDrivenLoop>(
35+ drake_lcm, make_unowned_shared_ptr_from_raw (&diagram),
36+ lcm_parser, input_channel, is_forced_publish);
37+ }),
38+ py::arg (" drake_lcm" ), py::arg (" diagram" ), py::arg (" lcm_parser" ),
39+ py::arg (" input_channel" ), py::arg (" is_forced_publish" ))
40+ .def (" Simulate" , &LcmOutputDrivenLoop::Simulate,
41+ py::arg (" end_time" ) = std::numeric_limits<double >::infinity ());
2342
24- py::class_<LcmOutputDrivenLoop>(m, " LcmOutputDrivenLoop" )
25- .def (py::init (
26- [](drake::lcm::DrakeLcm* drake_lcm,
27- drake::systems::Diagram<double >& diagram,
28- const drake::systems::LeafSystem<double >* lcm_parser,
29- const std::string& input_channel, bool is_forced_publish) {
30- // The C++ constructor doesn't offer a bare-pointer overload,
31- // only shared_ptr. Because object lifetime is already
32- // handled by the ref_cycle annotation below (as required for
33- // all subclasses of Diagram), we can pass the `plant` as an
34- // unowned shared_ptr.
35- // (comment taken from Drakes controllers_py.cc)
36- return std::make_unique<LcmOutputDrivenLoop>(
37- drake_lcm, make_unowned_shared_ptr_from_raw (&diagram),
38- lcm_parser, input_channel, is_forced_publish);
39-
40- }),
41- py::arg (" drake_lcm" ),
42- py::arg (" diagram" ), py::arg (" lcm_parser" ),
43- py::arg (" input_channel" ), py::arg (" is_forced_publish" ))
44- .def (" Simulate" , &LcmOutputDrivenLoop::Simulate,
45- py::arg (" end_time" ) = std::numeric_limits<double >::infinity ());
46-
47- py::class_<systems::TimestampedVector<double >,
48- drake::systems::BasicVector<double >>(m, " TimestampedVector" )
49- .def (py::init<int >(), py::arg (" data_size" ))
50- .def (" set_timestamp" , &systems::TimestampedVector<double >::set_timestamp,
51- py::arg (" timestamp" ))
52- .def (" get_timestamp" , &systems::TimestampedVector<double >::get_timestamp)
53- .def (" get_data" , &systems::TimestampedVector<double >::get_data)
54- .def (" SetDataVector" , &systems::TimestampedVector<double >::SetDataVector,
55- py::arg (" value" ));
43+ py::class_<systems::TimestampedVector<double >,
44+ drake::systems::BasicVector<double >>(m, " TimestampedVector" )
45+ .def (py::init<int >(), py::arg (" data_size" ))
46+ .def (" set_timestamp" , &systems::TimestampedVector<double >::set_timestamp,
47+ py::arg (" timestamp" ))
48+ .def (" get_timestamp" , &systems::TimestampedVector<double >::get_timestamp)
49+ .def (" get_data" , &systems::TimestampedVector<double >::get_data)
50+ .def (" SetDataVector" , &systems::TimestampedVector<double >::SetDataVector,
51+ py::arg (" value" ));
5652
57- py::class_<systems::OutputVector<double >,
58- drake::systems::BasicVector<double >>(m, " OutputVector" )
59- .def (py::init<int ,int ,int >(), py::arg (" num_positions" ),
60- py::arg (" num_velocities" ), py::arg (" num_efforts" ))
61- .def (" SetPositions" , &systems::OutputVector<double >::SetPositions,
62- py::arg (" positions" ))
63- .def (" SetVelocities" , &systems::OutputVector<double >::SetVelocities,
64- py::arg (" velocities" ))
65- .def (" SetState" , &systems::OutputVector<double >::SetState,
66- py::arg (" state" ))
67- .def (" GetPositions" , &systems::OutputVector<double >::GetPositions)
68- .def (" GetVelocities" , &systems::OutputVector<double >::GetVelocities)
69- .def (" GetState" , &systems::OutputVector<double >::GetState);
53+ py::class_<systems::OutputVector<double >,
54+ drake::systems::BasicVector<double >>(m, " OutputVector" )
55+ .def (py::init<int , int , int >(), py::arg (" num_positions" ),
56+ py::arg (" num_velocities" ), py::arg (" num_efforts" ))
57+ .def (" SetPositions" , &systems::OutputVector<double >::SetPositions,
58+ py::arg (" positions" ))
59+ .def (" SetVelocities" , &systems::OutputVector<double >::SetVelocities,
60+ py::arg (" velocities" ))
61+ .def (" SetState" , &systems::OutputVector<double >::SetState,
62+ py::arg (" state" ))
63+ .def (" GetPositions" , &systems::OutputVector<double >::GetPositions)
64+ .def (" GetVelocities" , &systems::OutputVector<double >::GetVelocities)
65+ .def (" GetState" , &systems::OutputVector<double >::GetState);
7066}
7167
7268} // namespace pydairlib
0 commit comments