Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Real-time data logging and event triggering
#1
Hello everyone,

There are two parts to my question:
1. Does BPOD allows for real-time data acquisition through the AnalogInput module, as opposed to recording data for a certain amount of time and then analyzing it later?
2. Can I create a state-change trigger off of this analog signal, as opposed to a TTL pulse on a given behavioral port.

In short, I would like to record from a sensor (analog load cell + amplifier) that is connected to the AnalogInput module.  I would then like to trigger a reward (say from a water spout) based on this analog signal reaching a certain (perhaps user-specified) value and staying there for a certain period of time.  It is important to note that a simple threshold crossing will not satisfy my requirements, as I want to continuously monitor the analog signal and prescribe it to stay within a certain range over a brief period of time.

I can only seem to find documentation and examples of state-changes based on binary "on/off" event types on a specified channel.  I would like to create a state-change based on calculations performed in software during the "Main Loop" protocol phase.  Is triggering events possible in software, or only with hardware TTL pulses?

Thanks a bunch!
Reply
#2
Hi MJDubs,

The analog input module has a software GUI to verify the signals and set up thresholds, but the GUI does not log data. In a typical setup, each trial's analog signal is logged to the module's microSD card. The logged data from each trial can then be loaded to the PC during the dead-time between trials. Technically it is possible to read data sent back over USB as discussed later on below.

Each analog input channel has a pair of thresholds you can set. When the primary threshold is crossed, an event is sent to the state machine and timestamped like any other event. The secondary threshold is a "reset" threshold, that must be crossed to re-enable the primary threshold. Setting these thresholds properly should give some ability to detect analog events, and reject noise.

Analog threshold events are sent to the state machine digitally over the module's CAT5 cable - so technically they aren't TTL pulses.

Unfortunately the current firmware does not support a time interval criterion, where the signal must stay between two values for a fixed amount of time. If I understand correctly, your idea was to work around this by having the analog input module stream data back to the PC, and have the PC generate an event when a criterion is met. This is technically possible using the BpodAnalogIn class (see the startUSBStream() method here). To make it run in parallel with Bpod software, you'd need to set up a MATLAB timer object, and have its callback function read bytes from the BpodAnalogIn object's serial port, determine any events, and send the events back to the state machine using SendBpodSoftCode() as in the code example here. The disadvantage of having the PC detect the events (as opposed to modding the firmware) is that MATLAB is running on a non-realtime operating system, so the analog events will arrive at the state machine with significant latency and jitter, probably tens or hundreds of milliseconds.

I hope this helps!
-Josh
Reply
#3
Hi Josh,

Thanks for the response!  I have a couple follow-up questions concerning thresholds for the analog input module:

What is the syntax for using the threshold as a state-change for the state machine?  Is it something like 'AnalogInput1_1', 'AnalogInput1_2', etc. for the thresholds on each channel, respectively?

Can I set a 'goal state' and then have a timer run within that state, so that the trial will terminate when that timer is up?

Can I connect my analog signal to multiple analog input channels so I can essentially set multiple thresholds for the same signal?  Like say I want to trigger a threshold crossing of both 5V and 6V.  Can this be accomplished by simply connecting the same analog signal to two input channels and setting a 5V threshold on the first channel and a 6V on the other?

When I call the function 'getData()', does it only return data between the most recent 'startLogging()' and 'stopLogging()' commands?

Thanks a lot for all your help!
--Matt
Reply
#4
Hi Matt,

Reponses in-line below:

What is the syntax for using the threshold as a state-change for the state machine?  Is it something like 'AnalogInput1_1', 'AnalogInput1_2', etc. for the thresholds on each channel, respectively?

Threshold crossing events are named AnalogIn1_N, where N is the channel. In general, the 'magnifying glass' icon on the Bpod console will show you a table of valid events, given the state machine model and its detected modules.

Can I set a 'goal state' and then have a timer run within that state, so that the trial will terminate when that timer is up?

Yes, I don't see why not. Is the question about how to implement this while the state is waiting for something else to happen?

Can I connect my analog signal to multiple analog input channels so I can essentially set multiple thresholds for the same signal?  Like say I want to trigger a threshold crossing of both 5V and 6V.  Can this be accomplished by simply connecting the same analog signal to two input channels and setting a 5V threshold on the first channel and a 6V on the other?

I did a basic test and it looks like this works. The input channels are high impedance. Please note that the channels do not have channel-to-channel isolation, and share a ground plane - so for this application you can make a single connection from the signal's ground to one of the 8 ground terminals, and jump the signal between the remaining input channels.

When I call the function 'getData()', does it only return data between the most recent 'startLogging()' and 'stopLogging()' commands?

Yes. To make the timing of the samples match the timing of each trial's events, you can have your first state start the logging by using the following output action: {'AnalogIn1', ['L' 1]};
To stop the logging from the state machine (e.g. at the end of the trial) you can use:
{'AnalogIn1', ['L' 0]} - or you can stop it from the PC with the BpodAnalogIn class.
In general, byte commands from the state machine to its modules are documented in the 'Module Serial Interfaces' pages here.

I hope this helps!
-Josh
Reply


Forum Jump: