Integrating "Identification" into MonkeyLogic Setup
April 23, 2024 02:22PM
Hi,

We're using MonkeyLogic on a tablet to run experiments in a setup that's installed in the cage, and multiple monkeys use the same setup.
We deliver rewards through Bluetooth (HC05) connected to an Arduino.

We're looking to identify which monkey is interacting with the setup to customize the difficulty level of tasks accordingly.
Does anyone know of existing methods or has anyone implemented something similar for such identification?

Here's an idea we had:
- Integrate an RFID module with the existing Arduino setup.
- Upon detection of a new RFID tag, send the ID via Bluetooth to MonkeyLogic.
- Modify the reward function (which already communicates with Arduino via Bluetooth) to read the ID.
- Use this ID to trigger quit and load functions in MonkeyLogic, adjusting the experiment setup for the specific monkey.

I'm relatively new to the functionalities of MonkeyLogic, so any advice on whether this approach is feasible, or how to better integrate an identification method would be hugely appreciated.
Thanks in advance for your help and insights!
Re: Integrating "Identification" into MonkeyLogic Setup
April 23, 2024 06:17PM
The ID method is not something covered by NIMH ML, although some users may be able to share their experience here. You can use RFID, face detection or any ID method that you like, as long as it returns some unique number or string for each individual to NIMH ML.

Arduino cannot run multiple sketches. You may need more than one Arduino device, if your ID method is also Arduino-based. You can create multiple arduino objects that represent difference devices with additional parameters. See the MATLAB arduino documentation.

You probably want to learn how to use the userloop. You can integrate the ID method and adjust task parameters in it, before starting the next trial.
https://monkeylogic.nimh.nih.gov/docs_CreatingTask.html#Userloop
Re: Integrating "Identification" into MonkeyLogic Setup
May 14, 2024 01:13PM
Hi Jaewon,


I'm adjusting the user loop for our experiments and have a few questions:

1) When loading a new timing script for a different monkey, should I quit the trial record? If so, how should I manage opening a new behavior file?

2) I've saved the RFID IDs as MATLAB variables, but I'm unsure how to import them into ML. I'm sorry if this is a simple matter that I'm missing; could you provide some guidance on this?

Thanks for your patience and assistance.

function [C,timingfile,userdefined_trialholder] = task_userloop(MLConfig,TrialRecord)

C = [];
timingfile = {'ID1.m','ID2.m','ID3.m'};
userdefined_trialholder = '';


% I save the ID of the first Monkey using the device, to check for the changes in the upcoming trials.

persistent timing_filename_returned
if isempty(timing_filename_returned)
    timing_filename_returned = true;
    TrialRecord.User.CurrentMonkey = TrialRecord.User.monkeyID;
    return
end


if TrialRecord.User.CurrentMonkey ~= TrialRecord.User.monkeyID
    switch TrialRecord.User.monkeyID
        case 1
            timingfile = 'ID1.m';
            TrialRecord.User.CurrentMonkey = TrialRecord.User.monkeyID;
            TrialRecord.Quit = true;
        case 2
            timingfile = 'ID2.m';
            TrialRecord.User.CurrentMonkey = TrialRecord.User.monkeyID;
        case 3
            timingfile = 'ID3.m';
            TrialRecord.User.CurrentMonkey = TrialRecord.User.monkeyID;
    end
end
end
Re: Integrating "Identification" into MonkeyLogic Setup
May 14, 2024 02:28PM
1) When multiple timing scripts are used in a task, a different script is called in each trial, like Trial 1 → ID1.m, Trial2 → ID3.m, etc. Everything is still stored in one single datafile. You just need to group trials later, according to the subject IDs.
By the way, you know that the TrialRecord structure has nothing to do with data saving, don't you?

2) What do you mean by saving the RFID IDs as MATLAB variables? The ID is supposed to be read from the RFID reader before each trial.
function [C,timingfile,userdefined_trialholder] = task_userloop(MLConfig,TrialRecord)

C = [];
timingfile = {'ID1.m','ID2.m','ID3.m'};
userdefined_trialholder = '';

persistent timing_filename_returned
if isempty(timing_filename_returned)
    timing_filename_returned = true;
    TrialRecord.User.CurrentMonkey = TrialRecord.User.monkeyID;
    return
end

% run a command or call a function to get the RFID from the reader
ID = readRFID();  % this is an example

switch ID
    case 1, timingfile = 'ID01.m';
    case 2, timingfile = 'ID02.m';
    case 3, timingfile = 'ID03.m';
end

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.