Mind-Controlled Magabot

Mind-Controlled Magabot

I recently brought Magabot to the Seattle Mini-Maker Faire to demonstrate controlling it with the Emotiv EPOC neuroheadset. I used the most affordable version of the EPOC, with no SDK, and a free application called Mind Your OSCs, which converts the EPOC data to Open Sound Control (OSC) data, which I read in Processing (using Andreas Schlegel’s oscP5 library) and convert to characters to send over a serial connection to the Magabot’s Arduino running the standard Magabot_SerialControl sketch (protocol = ‘H’). I mapped the EPOC’s four Cognitiv values for Push, Pull, Left, and Right, to the characters w, s, a, and d, respectively.

brain → EPOC → EPOC Control Panel → Mind Your OSCs → Processing (w/ oscP5) → Magabot (Arduino)

Here is the Processing sketch:

/**
 * NeuroMagabot
 * by Joshua Madara, hyperritual.com
 *
 * Transforms data from the Emotiv EPOC neuroheadset
 * to control data for the Magabot, via OSC.
 */

import processing.serial.*;
import oscP5.*;
import netP5.*;

Serial port;
OscP5 oscP5;

float thresh = 0.25; // one threshold for all Cognitiv values

void setup() {
  size(200, 200);
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 9600);
  
  //start oscP5, listening for incoming messages at port 7400
  //make sure this matches the port in Mind Your OSCs
  oscP5 = new OscP5(this, 7400);
  
  // plug the messages for the Cognitiv values
  oscP5.plug(this,"sendW","/COG/PUSH");
  oscP5.plug(this,"sendS","/COG/PULL");
  oscP5.plug(this,"sendA","/COG/LEFT");
  oscP5.plug(this,"sendD","/COG/RIGHT");
}

void draw() {
  // here you could graph the EPOC data, draw an animated face on the laptop screen, etc.
}

public void sendW(float val) {
  if (val >= thresh) {
    port.write('w'); // send move-forward command to Arduino
  } else {
    port.write('p'); // send stop command
  }
}

public void sendS(float val) {
  if (val >= thresh) {
    port.write('s'); // send move-reverse command to Arduino
  } else {
    port.write('p');
  }
}

public void sendA(float val) {
  if (val >= thresh) {
    port.write('a'); // send turn-left command to Arduino
  } else {
    port.write('p');
  }
}

public void sendD(float val) {
  if (val >= thresh) {
    port.write('d'); // send turn-right command to Arduino
  } else {
    port.write('p');
  }
}