Custom Keyboard Teleop w/ Multi-joint capabilities

Hi all, trying to create my own keyboard teleop node right now, both to help me become more familiar with Stretch and ROS2, but also just to better serve my purposes.

I’m trying to run multiple joints at the same time, aka pressing multiple keys at the same time. So if I were to press i and j at the same time(And hold), the head would both look up and pan left.

The issue I’m facing right now, is that from what I can tell, detecting prolonged keypresses on the stretch without being root user(Which is a last resort) is not really possible.

Is there a way I can add the perms to hello-robot user to allow it access to /dev/input/* in order to use keyboard or pynput? Or just another solution in general?

Hey @byrnete, I use the pynput library regularly without root access. For example, here’s a small script that uses the four arrow keys to teleop the mobile base around (it includes long key-presses):

You might running into an issue on the ROS2 side. ROS2’s launch system takes over stdin/stdout, which causes issues for nodes that are reading keyboard input from stdin. There’s a few threads on the ROS forums where this issue is being actively discussed, but in the meantime, I’ve been using ros2 run <my_node> as a workaround because ROS2’s run command doesn’t take over stdin/stdout.

I think the main cause of the issue was actually just ignorance on my part.
I’m SSHing into the Stretch rather than developing directly on it. As far as I know, we don’t have the moonlight bridge connector for a remote desktop setup, but we got the stretch pretty early so it might not have come with it back then.

The real issue behind it was that when I ran pynput, because I was operating remotely, the stretch didn’t have a keyboard attached, and therefore pynput was throwing an error for not finding the device.

Even if I did have one attached, it wouldn’t have worked still since the SSH setup I use only sends the key presses, not the actual keyboard events.

If anyone does have this issue in the future, besides the moonlight connector and working directly on the stretch like mentioned, there is a possibility of using a terminal that also sends events. I haven’t tested it myself, but have used something similar before.

Either way, worked around the issue for now, and if I ever revisit it I’ll post it here!

1 Like