Controlling Robots with your Brain (and Python!)

Alyssa M Batula

Audience level:


Brain-computer interfaces (BCIs) allow people to control computers (or robots) with only their thoughts, which could help handicapped individuals regain mobility or otherwise interact with their environment. This talk explores how Python is being used to build a BCI in order to control a humanoid robot.


This poster is an overview of how Python is being used to develop a brain-computer interface to control a mini-humanoid robot, the DARwIn-OP. What is a BCI? --- Brain-computer interfaces (BCIs) allow people to control computers (or robots) with only their thoughts. They are currently being studied as a means to allow people who are handicapped (especially those who are “locked-in” or totally unable to move) to interact with their environment and take care of their daily needs. Some are invasive, and require surgery to implant electronics in a patient's brain, while non-invasive BCIs typically use a cap placed on a patient's scalp to record brain signals. This particular non-invasive BCI uses infrared light to detect changes in blood flow, taking advantage of the fact that blood will typically flow to the areas of the brain actively being used. Why Python? --- Python was chosen for its ease of use in high-level applications as well as to get around issues with licenses and incorporating C code that had hindered previous MATLAB-based projects. Python 3 was chosen for the main BCI program to eliminate the need to eventually convert everything from 2 to 3. The DARwIn-OP robot is programmed using Python 2 in order to avoid installing extra packages on the robot (which runs Ubuntu). What does a BCI do, and how does Python help? --- Requirements for the BCI include real-time data collection and analysis, displaying prompts and feedback to guide subjects through the experiment, and high-level control of a robot. The program is able to run in real-time thanks to the multiprocessing module and queues for communication between its four processes (one to receive data, one to analyze the data, one to run the GUI, and one to control the experiment timing). It uses a Qt GUI to display instructions and Matplotlib feedback plots to the subject. All data received and communications between processes are noted in a time-stamped log, which has already prevented the loss of two hours worth of data due to a bug. Additionally, the program needs to send high-level commands to a robot over a network connection. The DARwIn-OP robot uses C++ to control motion by selecting high-level, preprogrammed poses or specifying walking parameters (left, straight, step size, etc). A Python wrapper created with Cython allows the robot to be controlled within a Python program, making it easier to pursue future developments in AI or advanced decision making.