Last active
March 1, 2016 01:04
-
-
Save freeman-lab/8130e55a1b520a870db3 to your computer and use it in GitHub Desktop.
redux-style experiment control system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api | |
var task = require('2AFC') | |
var runner = require('runner') | |
var johnny = require('johnny-five') | |
var board = new johnny({type: 'arduino'}) | |
var input = require('track-ball')(board, opts) | |
var output = require('lick-port')(board, opts) | |
var experiment = runner(task, [input], [output]) | |
board.on('ready', function () { | |
experiment.start() | |
}) | |
-------------------------------------------------- | |
// 2afc.js | |
var movement = require('movement') | |
var reward = require('reward') | |
function (state, action, output) { | |
switch (action.type) { | |
case movement.MOVE: | |
if (state > 10) { | |
output.emit(reward.DELIVER, { | |
value: 10 | |
}) | |
} | |
state = state + 1 | |
return | |
case movement.STOP: | |
outputs.emit(reward.DELIVER, { | |
value: 5 | |
}) | |
state = 0 | |
return | |
} | |
} | |
-------------------------------------------------- | |
// movement.js | |
module.exports = { | |
MOVE: 'MOVE', | |
STOP: 'STOP' | |
} | |
-------------------------------------------------- | |
// reward.js | |
module.exports = { | |
DELIVER: 'DELIVER' | |
} | |
-------------------------------------------------- | |
// runner.js | |
inputs.forEach(function (input) { | |
input.on('action', function (action) { | |
outputs.forEach(function (output) { | |
task(state, action, output) | |
}) | |
}) | |
}) | |
OR | |
runner = create(task) | |
input.on('action', function (action) { | |
runner.dispatch(action) | |
}) | |
-------------------------------------------------- | |
//modules to be written (X is the umbrella project name): | |
'X' | |
'X-movement' | |
'X-reward' | |
'X-track-ball' | |
'X-lick-port' | |
'X-2afc' | |
'X-wall-task' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment