Welcome! Log In Create A New Profile

Advanced

Using Arduino to reward during eye calibrating

Posted by xiaoxu1107 
Using Arduino to reward during eye calibrating
December 16, 2022 03:00AM
Hello everyone,

I am using an Arduino to control the reward system in my task. To do this, I rewrote the goodmonkey function. The code in the function is to communicate with the Arduino to give a reward, and I put the function in the task folder to prevent the original goodmonkey function from being called.

Initially, I was just doing touch-screen tasks, but now I also need to track eye movements which require eye calibration. I found that a reward system should work during eye calibration. I'd like to know which file I should modify if I need to make my Arduino-controlled reward system work during eye calibrating.

I appreciate any help you can provide!
Re: Using Arduino to reward during eye calibrating
December 16, 2022 09:09AM
I need you to show me how you control your Arduino. Are you using the MATLAB Support Package for Arduino Hardware? Please provide your code lines to initialize Arduino and turn it on/off.
Re: Using Arduino to reward during eye calibrating
December 28, 2022 01:08AM
Yes, I'm using the MATLAB Support Package for Arduino Hardware. First, I started the commumication between Arduino and Matlab by editing the alert_function. The detail is showed up as following and in the attachment . Than I turned on the 'Alert On' buttern on the main menu. And I also attached the code of the goodmonkey function I modified. Thanks in advance! Look forward to your reply.



function alert_function(hook,MLConfig,TrialRecord)
switch hook
    case 'task_start'   % when the task starts by '[Space] Start' from the pause menu
           global a
           if isempty(a)
            a = arduino();  
           end
           disp("START!!!")
    case 'block_start'
        
    case 'trial_start'
        
    case 'trial_end'
        
    case 'block_end'
        
    case 'task_end'      % when the task finishes succesfully

    case 'task_aborted'  % when the task stops with an error
        
    case 'task_paused'   % when the task is paused with ESC during the task
        
    case 'task_resumed'  % when the task is resumed by '[Space] Resume' from the pause menu
        
end
end

function goodmonkey_xx(duration)

global a
writeDigitalPin(a, 'D8', 1);
pause(duration/1000); % reward duration
writeDigitalPin(a, 'D8', 0);
disp("reward!!")
end
Attachments:
open | download - alert_function.m (2 KB)
open | download - goodmonkey_xx.m (231 bytes)
Re: Using Arduino to reward during eye calibrating
January 08, 2023 05:34AM
See this post. You need to update your NIMH ML. Do not set the arduino variable as global in the alert function.
https://monkeylogic.nimh.nih.gov/board/read.php?2,1474,1474#msg-1474

Now you can call goodmonkey() like the following and there is no need of your own goodmonkey function.
goodmonkey(duration,'juiceline','D8');

Eye calibration tools have their own GUI menu to set the reward options. Change their JuiceLine to D8, too.
Re: Using Arduino to reward during eye calibrating
January 14, 2023 07:56AM
I really appreciate your help! The new goodmonkey function has driven my Arduino to trigger rewards during tasks successfully. But I don't know why triggering rewards during calibration still doesn't work. I found that the eye calibration GUI started with the message 'Reward I/O Not Assigned! (please see the attached figure 1).
Adding the command
MLConfig.DAQ.set_reward_object(MLConfig,'arduino')
to the mlcalibrate_origin_gain.m file made this eye calibration GUI work normally (Figure 2 in the attachment) and give rewards during calibration successfully. Could I modify it this way to give rewards for calibration?
By the way, when I calibrate in 2D spatial way, the error 'The equation matrix is insolvable' always showed up. How can I fix it? Thank you so much for your attention.
Attachments:
open | download - screenshot1.png (42.7 KB)
open | download - screenshot2.png (34.8 KB)
open | download - add the command.png (24.8 KB)
Re: Using Arduino to reward during eye calibrating
January 16, 2023 12:42AM
I found if I entered the calibration GUI by running the task, not by the eye calibration panel in the ML main GUI, giving rewards worked. Thank you very much!
Re: Using Arduino to reward during eye calibrating
January 17, 2023 08:27AM
I do not recommend modifying the core functions on your own. Then you will have to modify them every time when upgrading to a new version.

There were a few more things that needed to be patched, to make it work everywhere. Please download the package again. Sorry for the inconvenience.

The error message is shown because the calibration is incomplete. The number of the calibration points may be too small (less than 4) or they are all just on the same line. Or the registered voltage values may not be different between two calibration points.

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.