pybind11drake

How do I use RotaryEncoder and other templated sensor types in pydrake?


I'm getting an import error when I try to import RotaryEncoders or RotaryEncoders_ from pydrake.all or pydrake.systems.sensors. I feel like there's something obvious that I'm missing; all the templated sensor types are "missing" from sensors.pyi. What am I missing?

It's clearly doable, I just must be doing something wrong, c.f. this test: https://github.com/RobotLocomotion/drake/blob/03890722e4576c043192303a8270fd1bdf343653/bindings/pydrake/systems/test/sensors_test.py#L579

My setup

I suspect it doesn't matter, but I have pydrake version 1.30.0 installed via pip in a venv on Ubuntu 22.04

What I did

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pydrake.all import RotaryEncoders
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'RotaryEncoders' from 'pydrake.all' (/opt/drake/lib/python3.10/site-packages/pydrake/all.py)
>>> from pydrake.systems.sensors import RotaryEncoders
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'RotaryEncoders' from 'pydrake.systems.sensors' (/opt/drake/lib/python3.10/site-packages/pydrake/systems/sensors.cpython-310-x86_64-linux-gnu.so)
>>> from pydrake.systems.sensors import RotaryEncoders_
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'RotaryEncoders_' from 'pydrake.systems.sensors' (/opt/drake/lib/python3.10/site-packages/pydrake/systems/sensors.cpython-310-x86_64-linux-gnu.so)

What I expected

To not get an import error


Solution

  • Actually, the drake version does matter. I only very recently PR'd the python bindings for the RotaryEncoders class. They are not in v1.30.0, but will appear in v1.31.0, and are available now in the nightly pip wheels.