Experiment Architecture (sbRIO) - GoldbergLab/RodentJoystick GitHub Wiki
Experiment Architecture
We have several mouse boxes placed on a Weill rack. The individual joystick is connected to a control board on the box itself that handles sensor inputs so that only a single DB15 cable is required to link a joystick box to the data acquisition system.
Each joystick unit is connected by a DB15 cable to an sbRIO rack mounted inside the server cart. Each of these sbRIO units is a U rack containing an sbRIO 9626/9636 with mounted ports for connecting to the joystick boxes. We are currently using two models, the sbRIO 9636 which can handle up to 4 boxes, and the sbRIO 9626, which can handle up to 8 boxes.
Each of these sbRIO units sends information via a network stream to a computing node, which stores the information as .dat files in the appropriate directory (See Post Processing Analysis for more information). Currently each sbRIO unit is assigned 1 node, but multiple sbRIO units can be linked to a single computing node.
##FPGA Code The FPGA code has three main tasks.
- It must acquire the Hall sensor's analog data and digital data from the touch sensors and IR beam (nose poke) sensor via the sbRIO.
- It must run contingency detection on the data. At a high level, this looks at the data streaming in at 1 kHz, and decides when to deliver a pellet. There is acquisition and contingency detection code for each mouse box.
- The FPGA code must also package and route data to the real-time processor, which then routes it to the host PC. All of the Boolean data, (Nose poke, touch 1, touch 2, Dispense, Laser, Lick) are packaged into a single fixed-point number. The x and y values are fixed point as well. Each joystick generates 3 fixed-point numbers per time step, which are sent to the RT code via direct memory access (DMA).
These three tasks run in the main loop of the FPGA code. Each box has its own pellet-dispensing loop. Dispensing a pellet requires sending a 100 ms TTL pulse through a digital output of the sbRIO. We generate this pulse in parallel in a separate loop to avoid stalling data acquisition or contingency detection.
The FPGA code's front panel displays the incoming sensor data and the outgoing pellet dispenser data for each mouse box. It also contains controls for setting contingencies, calibrating the joysticks, and automated pellet dispensal, through which pellets can be dispensed randomly, according to a Poisson distribution. It's important to note that the FPGA cannot generate random numbers itself, so we get them from the RT code via DMA.
Here are some screenshots of the code: images/fpga_main_2.png
Contingency detection: takes in raw X, Y voltages and combines with calibration info to give adjusted X-Y readings and compute other information necessary for calculation. images/fpga_cont_det.png
RT Code
The RT code serves mainly to route data between the FPGA and the host PC. It takes the fixed point data from the FPGA, converts it into double, and sends it to the host PC via network streams. It also generates the random numbers necessary for automated pellet dispensing.
images/rt_main_1.png images/rt_main_2.png images/rt_main_3.png
PC Code
The PC code conditionally saves data to disk.
Data is broken up by seconds. A second s is saved to disk if either s-1, s, or s+1, contain a nosepoke that went on. The user specifies a base directory, and the program saves data to:
base directory\box number\datecont\filename.dat
where the filename includes the time (to the nearest second) corresponding to the second of data that is saved. For more information, see the section Core Analysis
A common source of failure is that the writer IP address is not correctly set (See below).
images/pc_main_1.png
images/pc_main_2.png
#sbRIO Data Acquisition Setup & Debugging
- Attempt to connect to the sbRIO using NI Max - check that the sbRIO is visible on the left hand side browser. If this fails, connect the sbRIO to the router directly and attempt a connection. You may need to run NI Network Browser (from IE). Check to see that the sbRIO is not in safe mode, and restart if necessary.
- Once connected, if the sbRIO is new, you will need to configure the sbRIO software package. Use NI Max to configure sbRIO software. Make sure to add Network Stream and Web Access packages in addition to the default NI software components.
- Once software is added, you can connect to the computer, and compile the LabVIEW code to the sbRIO.
- Once compiled you should be able to run the software to acquire data. To run the code, first start the FPGA code, then the RT code, then the PC code. Make sure the box titled frame number is increasing. If it is not, you may need to restart the entire software suite for it to work. When you want to start saving data to disk, hit the acquire enable button on the FPGA code front panel. If upon a nosepoke trigger, the frame number suddenly stops increasing, this may indicate one of two things: (1) the directory is invalid and writing to that directory failed, or (2) the place where IP address is entered in PC main is incorrect, and writing fails because of that. These are the most likely possibilities.