如何使用 pyserial 传输机器人传感器?
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 openinterface.py 源代码,您似乎收到了“非法传感器 id”错误,因为调用 stream_sensors() 时使用的给定 ID 值与具有已知传感器 ID 的字典不匹配。传感器 ID 字典在 SensorPacketDecoderAPI 类中指定:
至于您收到“流线程错误!...”的原因,我不确定,我只能从我的浏览代码可以发现它源自 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:
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.