I made gogo_keyboard to simply get keyboard events in ROS 2 (… and asyncio, and Zenoh). gogo_keyboard creates a new independent SDL2 window (with a ) that captures the key presses and releases. Then sends the key information onto a ROS topic.
Oh, but the same can happen even on a single topic (and it actually does quite often when using DDS (not sure if also with these small messages)).
I strongly suggest adding a timestamp to the messages so that the receivers can cache and order the messages accordingly (bringing in a small latency).
Otherwise, creating a custom and suitable message type should not be felt as a disadvantage in the ROS world. I understand your strive to get it as simple as possible, but if it were for me, I’d go with a custom message.
In some cases, RViz can also be used as a source of keyboard events. Not sure if it matches your use-case, but if it does, you can have a look into it.
Thanks, I will add this, I’ve been thinking about TCP too much lately. This is critical even though I never used it. I will also add a counter, so the user can know when something went wrong.
That’s what I am using actually (or at least what I think I am doing), correct me if I am wrong:
# gogo_keyboard/ros_node.py
pub = node.create_publisher(
String,
topic,
QoSProfile( # no message lost (hopefuly)
reliability=ReliabilityPolicy.RELIABLE,
history=HistoryPolicy.KEEP_ALL,
durability=DurabilityPolicy.VOLATILE,
),
)
My main worry is about the ordering (losing messages is also bad, but DDS should not), I want to avoid key pressed and key released being out of order. This can have terrible consequences in a setup where the robot moves while the key pressed, then stops once the key is released.
That should be done using a Time Sequencer . If you’re looking at sequence numbers, you’re basically reimplementing what the time sequencer does (or not? maybe you want a more sophisticated logic). But I see that TimeSequencer introduces a constant delay, whereas sequence numbers allow you to process the event immediately if you know that the incoming message has the expected sequence number… So maybe I convinced myself that sequence numbers are a good thing here
Wow I didn’t know about this little guy. Cool. In the end I will let the user do whatever he needs to not mess this up on the receiving side. He should have all the necessary data to make a decision using the timestamp and the sequence number. (And I think most user will never think of this for their keyboard).
Later I might make a ros package with this lib and a custom message so the Time Sequencer and such tools work. But right now, I don’t need it and I have other things to work on.