This is a Python library that allows you to control Roomba's and Create's from iRobot using the serial connection. This requires Python 3 and the pyserial library. This can run on many devices such as Raspberry Pis and regular PCs. Tested on the Create 2, some older devices may not support all operations or sensors.
This implements the Open Interface specification by iRobot: http://www.irobot.com/~/media/MainSite/PDFs/About/STEM/Create/create_2_Open_Interface_Spec.pdf
This library implements every single opcode in the specification and provides every sensor in an easy-to-use system. All single sensors are available as attributes on a yarc.Roomba object along with all_sensors which is a namedtuple of all of the sensors. Other groups can be obtained with the sensor() method and custom groups can be acquired with query_list() method. Single values are returned as ints or bools, bit fields are returned as IntFlag types, and collections of values are returned as namedtuple instances.
This can be installed from source from the Github source or through 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()