Skip to content

Commit

Permalink
Merge pull request RobotLocomotion#8690 from ekumenlabs/add_simple_ca…
Browse files Browse the repository at this point in the history
…r_state_bindings

Add python bindings for SimpleCarState
  • Loading branch information
EricCousineau-TRI authored Apr 27, 2018
2 parents aa70a7d + ecfab67 commit d78dc06
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bindings/pydrake/automotive_py.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ PYBIND11_MODULE(automotive, m) {
py_reference_internal);

// TODO(eric.cousineau) Bind this named vector automatically (see #8096).
py::class_<SimpleCarState<T>, BasicVector<T>>(m, "SimpleCarState");
py::class_<SimpleCarState<T>, BasicVector<T>>(m, "SimpleCarState")
.def(py::init<>())
.def("x", &SimpleCarState<T>::x)
.def("y", &SimpleCarState<T>::y)
.def("heading", &SimpleCarState<T>::heading)
.def("velocity", &SimpleCarState<T>::velocity)
.def("set_x", &SimpleCarState<T>::set_x)
.def("set_y", &SimpleCarState<T>::set_y)
.def("set_heading", &SimpleCarState<T>::set_heading)
.def("set_velocity", &SimpleCarState<T>::set_velocity);

py::class_<SimpleCar<T>, LeafSystem<T>>(m, "SimpleCar")
.def(py::init<>())
Expand Down
17 changes: 17 additions & 0 deletions bindings/pydrake/test/automotive_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,23 @@ def test_pure_pursuit(self):
self.assertEqual(len(steering.get_value()), 1)
self.assertTrue(steering.get_value() < 0.)

def test_simple_car_state(self):
simple_car_state = SimpleCarState()
self.assertTrue(isinstance(simple_car_state, framework.BasicVector))
self.assertEqual(simple_car_state.size(), 4)
self.assertNotEqual(simple_car_state.x(), 5.)
simple_car_state.set_x(5.)
self.assertEqual(simple_car_state.x(), 5.)
self.assertNotEqual(simple_car_state.y(), 2.)
simple_car_state.set_y(2.)
self.assertEqual(simple_car_state.y(), 2.)
self.assertNotEqual(simple_car_state.heading(), 14.)
simple_car_state.set_heading(14.)
self.assertEqual(simple_car_state.heading(), 14.)
self.assertNotEqual(simple_car_state.velocity(), 52.)
simple_car_state.set_velocity(52.)
self.assertEqual(simple_car_state.velocity(), 52.)

def test_idm_controller(self):
rg = make_two_lane_road()
idm = IdmController(
Expand Down

0 comments on commit d78dc06

Please sign in to comment.