又一个Roomba控制器
yarc的Python项目详细描述
yarc:又一个roomba控制器
这是一个python库,允许您使用串行连接从irobot控制roomba和create。这需要python 3和pyserial库。这可以在许多设备上运行,如覆盆子PIS和普通PC。在Create2上测试,一些旧设备可能不支持所有操作或传感器。
这实现了iRobot的开放接口规范:http://www.irobot.com/~/media/MainSite/PDFs/About/STEM/Create/create_2_Open_Interface_Spec.pdf
这个库实现了规范中的每个操作码,并在一个易于使用的系统中提供了每个传感器。所有单个传感器都可以作为yarc.Roomba
对象和all_sensors
对象的属性使用,后者是所有传感器的namedtuple
其他组可以用sensor()
方法获得,自定义组可以用query_list()
方法获得单个值返回为int
s或bool
s,位字段返回为IntFlag
类型,值集合返回为namedtuple
实例
这可以从Github源或通过pip:pip install yarc
从源安装
示例
importyarc# Make the Roomba objectbot=yarc.Roomba('/dev/ttyUSB0')# Start the OI connection - must be the first callbot.start()# Switch to 'safe' mode# In this mode we can completely control the robot unless it 'senses danger'# in which case it will switch back to 'passive' mode. Danger could be# detection of a cliff, detection of a wheel drop, or charger plugged in.bot.safe()# Commandsbot.drive_distance(100)# drives 100 mm forwardbot.turn_angle(45)# rotates 45 degrees in-place...# more instructionsprint(bot.battery_charge/bot.battery_capacity)# print battery charge percentprint(bot.all_sensors)# print out all sensor data# Stop the OI connection - must be the last callbot.stop()