Creating a Simple Output Module¶
An output module listens for selections from the MindAffect decoder and acts on them to create some output. By the end of this tutorial you will be able to: * make a simple output module which prints “Hello World” when the presentation ‘button’ with ID=1 is selected. * know how to make your own output modules to perform arbitary actions under brain control
Before starting this tutorial please read the how an evoked bci works **tutorial to gain a general understanding of the components of this BCI. And the quickstart tutorial or DIY Brain Computer Interface for how they are used in the mindaffectBCI. **
The non-Jupyter Notebook version of this code and other output examples can be found in the examples/output directory
First, we import the module responsible for translating selections to output, and create the utopia2output object:
[1]:
# Import the utopia2output module
from mindaffectBCI.utopia2output import Utopia2Output
u2o=Utopia2Output()
Defining the Output function¶
Now we define a function to print hello-world.
[2]:
def helloworld(objID):
print("hello world")
Connecting the Output function¶
And connect it so it is run when the object with ID=1 is selected. You can create as many output functions as needed, and connect them to different object ID’s by simply adding them to the dictionary as key-value pairs.
[3]:
# set the objectID2Action dictionary to use our helloworld function if 1 is selected
u2o.objectID2Action={ 1:helloworld }
Start the BCI decoder in the background.¶
N.B. if you run directly in this notebook, don’t forget to shutdown the decoder at the end.
[ ]:
import mindaffectBCI.online_bci
config = mindaffectBCI.online_bci.load_config('fake_recogniser.json')
mindaffectBCI.online_bci.run(**config)
Alternatively you can run this config from the command line with:
python3 -m mindaffectBCI.online_bci --config_file fake_recogniser.json
Or from you Anaconda environment:
python -m mindaffectBCI.online_bci --config_file fake_recognizer.json
See our tutorial Running Custom Presentation to set-up a BCI using your own Presentation module
Connect and Run¶
We now connect our output module to a running decoder and run the main loop. Selection of ID=1 will result in printing “Hello World” to this prompt.
[ ]:
# connect
u2o.connect()
# run the main loop
u2o.run()