开发者

How to stream bot sensors with pyserial?

I am trying to stream an iRobot Create's sensors with pyserial. I import openinterface.py, setup the bot variable with the CreateBot function, and then call

bot.stream_sensors(6)

Then I receive this error - "Streaming thread error! tuple index out of range" The only reason I am calling the function with 6 is because thats what the example I am looking at used. I have also tried stream_sensors(0), stream_sensors(1), all the way up to 6. With any number less than 6, I get the same error plus "Illegal sensor id!". What is the parameter based on? Is it the specific sensor I want to stream (and if so, how do I get the number)? Any help w开发者_JAVA技巧ould be appreciated.


Looking through the openinterface.py source, it looks like your getting the "Illegal sensor id" error because the given ID value you use when you call stream_sensors() doesn't match against a dictionary with known sensor ID's. The sensor ID dictionary is specified in the class SensorPacketDecoderAPI:

class SensorPacketDecoderApi:
"""
Transform sensor data in the form of bytes (from a serial stream)
into a dictionary of sensor values.
"""

names = {'left-velocity' : 42,
         'right-velocity' : 41,
         'radius' : 40,
         'velocity' : 39,
         'n-stream-packets' : 38,
         'song-playing' : 37,
         'song-number' : 36,
         'oi-mode' : 35,
         'home-base?'        : 34,
         'internal-charger?' : 34,
         'user-analog-in-0' : 33,
         'baud-rate-change?' : 32,
         'user-digital-in-3' : 32,
         'user-digital-in-2' : 32,
         'user-digital-in-1' : 32,
         'user-digital-in-0' : 32,
         'cliff-right-signal' : 31,
         'cliff-right-front-signal' : 30,
         'cliff-left-front-signal' : 29,
         'cliff-left-signal' : 28,
         'wall-signal' : 27,
         'capacity' : 26,
         'charge' : 25,
         'temperature' : 24,
         'current' : 23,
         'voltage' : 22,
         'charging-state' : 21,
         'angle' : 20,
         'distance' : 19,
         'advance?' : 18,
         'play?'    : 18,
         'infrared-byte' : 17,
         'left-wheel-overcurrent?'       : 14,
         'right-wheel-overcurrent?'      : 14,
         'low-side-driver-2-overcurent?' : 14,
         'low-side-driver-0-overcurent?' : 14,
         'low-side-driver-1-overcurent?' : 14,
         'virtual-wall?' : 13,
         'cliff-right?' : 12,
         'cliff-front-right?' : 11,
         'cliff-front-left?' : 10,
         'cliff-left?' : 9,
         'wall?' : 8,
         'wheel-drop-caster?' : 7, 
         'wheel-drop-left?'   : 7,
         'wheel-drop-right?'  : 7,
         'bump-left?'         : 7,
         'bump-right?'        : 7,
         'all' : 6}

As to the reason why you're getting the "Streaming thread error!...", I'm not sure, all I can tell from my glance through the code is that it's originating in a function called _stream_sensors_worker inside the CreateBot class. There's also a function called _test_sensor_streaming that you could also try to get some debug info from _stream_sensors_worker.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜