如何使用 pyserial 传输机器人传感器?

发布于 2024-10-03 15:48:14 字数 380 浏览 4 评论 0原文

我正在尝试使用 pyserial 传输 iRobot Create 的传感器。我导入 openinterface.py,使用 CreateBot 函数设置 bot 变量,然后调用

bot.stream_sensors(6)

然后我收到此错误 - “流线程错误!元组索引超出范围”我调用该函数的唯一原因6 是因为这就是我正在查看的示例所使用的。我还尝试了 stream_sensors(0)stream_sensors(1),一直到 6。对于任何小于 6 的数字,我都会收到相同的错误加上“< code>非法传感器 ID!”。参数是基于什么?这是我想要传输的特定传感器(如果是,我如何获取该号码)?任何帮助将不胜感激。

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 would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2024-10-10 15:48:14

查看 openinterface.py 源代码,您似乎收到了“非法传感器 id”错误,因为调用 stream_sensors() 时使用的给定 ID 值与具有已知传感器 ID 的字典不匹配。传感器 ID 字典在 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}

至于您收到“流线程错误!...”的原因,我不确定,我只能从我的浏览代码可以发现它源自 CreateBot 类中名为 _stream_sensors_worker 的函数。还有一个名为 _test_sensor_streaming 的函数,您也可以尝试从 _stream_sensors_worker 获取一些调试信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文