I'm working on sending input from a gamepad over rosbridge, using the inputs python module to get input from the gamepad. Each gamepad event has three pieces of information, the event type (afaik for telling between analog vs button input), the event code (the name of the button/joystick), and event state (analog values). If I send each of these pieces of information separately as their own Messages things work fine, but I'm trying to send all three in one message. Roslibpy's source and readthedocs both claim that messages are just dictionaries and can be treated as such, but if I try to send a message with more than on keyvalue pair I get error messages on the rosbridge server's console. EDIT: I'm using roslibpy because the talker node is on windows 7 and I'm sending information to a ROS Melodic server on ubuntu 18.04 via rosbridge.
In the example below, if I call talker.publish() with a Message containing a single keyvalue pair dictionary, the message sends successfully. With multiple pairs in the dictionary as shown below, I get errors.
the talker node:
from __future__ import print_function
import time
import roslibpy
from inputs import get_gamepad
def main():
client = roslibpy.Ros(host='localhost', port=9090)
client.run()
talker = roslibpy.Topic(client, '/chatter', 'std_msgs/String')
while client.is_connected:
events = get_gamepad()
for event in events:
talker.publish(roslibpy.Message({'data': str(event.ev_type), 'btype': str(event.code), 'value': str(event.state) }))
print('Sending message...\n')
talker.unadvertise()
client.terminate()
if __name__ == "__main__":
main()
the listener node:
from __future__ import print_function
import roslibpy
def main():
client = roslibpy.Ros(host='localhost', port=9090)
client.run()
listener = roslibpy.Topic(client, '/chatter', 'std_msgs/String')
listener.subscribe(lambda message: out(message))
try:
while True:
pass
except KeyboardInterrupt:
client.terminate()
def out( dict ):
print('input type: ' + dict['data'])
print('input button: ' + dict['btype'])
print('button value: ' + dict['value'])
if __name__ == "__main__":
main()
The error messages (there are many of them but the only thing that changes is publish:/chatter[a counter]):
[ERROR] [1570653818.070547]: [Client 26] [id: publish:/chatter:35] publish: Message type std_msgs/String does not have a field btype
[ERROR] [1570653818.070547]: [Client 26] [id: publish:/chatter:36] publish: Message type std_msgs/String does not have a field btype
Is this an exercise in futility and I should just try concatenating all of the gamepad event information into a single string, or is there something I'm missing and it really is possible to use a dictionary with more than one pair in a ros message?