Reporting of Active_Poke on SD card

113 views
Skip to first unread message

Laura Milton

unread,
Apr 22, 2022, 1:26:13 AM4/22/22
to FEDforum
Hey Lex,

Just want to bring up an issue with the recording of the Active_Poke in CSV files generated from sessions running the Random Ratio task menu.

I have collected the data from our latest experiment using the FEDs running the Random Ratio task menu that you helped us develop. I noticed that the Active_Poke (Column I) is not being recorded correctly on the CSV files (my python codes rely on this information for accuracy calculations so I need it to be correct in the raw CSV output). No matter what side of the FED is actually active, Active_Poke is always reported as Left. Thankfully this doesn't effect the functioning of the FED as it works as it is supposed to with the Right Port denoted as active in the Arduino code. I've attached an example CSV file for reference, as you can see the FED is functioning as expected delivering pellets after the required number of Right pokes are made but is reporting that the Left side is active. (For reference I have also attached the ino file, cpp file, and FED3.h file used to Flash the FED for this task).

I did some digging and from what I can gather it appears that there is a conflict between how the Active Port is determined in Arduino (and thus why the FED functions correctly) versus how it is reported in the CSV files based on code in the cpp and FED3.h files (and is therefore reported incorrectly although the FED functions correctly). I think there has been a change to the name of the variable in the ino file that has not been updated/accounted for in the cpp and FED3.h files? (I checked the example RandomRatio code in the FED3 Library and it doesn't have this new variable but the menu you created for us does).

In the ino file the variable to denote the active port is now:

bool LeftActive = false;                               //Set to false to make right poke active

and in the loops for the tasks it is called upon when determining the next steps following a poke: if (LeftActive == false) ...

Whereas in the cpp file for recording of the Active_Poke on the SD card it is:

/////////////////////////////////
  // Log Active poke side (left, right)
  /////////////////////////////////
  if (activePoke == 0)  logfile.print("Right"); //
  if (activePoke == 1)  logfile.print("Left"); //
  logfile.print(",");


Additionally, in the FED3.h file there is the following line:

// state variables
        bool activePoke = 1;  // 0 for right, 1 for left, defaults to left poke active


Given that this Arduino menu uses LeftActive = false rather than activePoke = 0 to signal that the right port is active (and activePoke is not used at all in this menu), I'm assuming this is why the Active_poke is always reported as Left?

I just wanted to clarify if the above is correct? Further, was this an intentional change in the variable name that is going to become standard (and requires updates to existing ino, cpp and FED3.h files) or is it just used for this menu? If it's the latter could you explain the difference between activePoke and LeftActive given they appear to me at face value to have the same function and i don't want to accidentally create conflicting codes in the future.

Depending on the above I can see two avenues to correcting the reporting of the Active_Poke in my CSV files. The first would simply be to swap out the LeftActive variable back to the activePoke one used before (if they are actually the same thing by different names).

Otherwise, I assume I would need to update the cpp and FED3.h files, would I change them as follows?

Change the cpp file lines to:

/////////////////////////////////
  // Log Active poke side (left, right)
  /////////////////////////////////
  if (LeftActive == false)  logfile.print("Right"); //
  if (LeftActive == true)  logfile.print("Left"); //
  logfile.print(",");


Change the FED3.h file to:

// state variables
        bool LeftActive = true;  // false for right, true for left, defaults to left poke active

I am hesitant to change the FED3.h file to test my theory out as I'm pretty new to Arduino and have learned exclusively by trial and error playing around with the ino and cpp files but don't understand the role of the FED3.h file nor the full relationship between all the files and how they mesh together to operate the FED.

Advice on whether my deductions are correct and on how to proceed to rectify the problem would be greatly appreciated.

Cheers,
FED3_random_LKM.cpp
FED3.h
FED027_041022_01.CSV
Random_Ratio_Menu_Right_LKM.ino

Lex Kravitz

unread,
May 16, 2022, 9:33:12 PM5/16/22
to FEDforum
Hi Laura! Good catch on the random ratio logging, this sort of thing can slip through when I write new programs, often they are only detected when someone uses the program for an actual experiment. You are correct in your analysis of the issue!  The variable LeftActive is only for the Arduino script, while the FED3 library is using activePoke to decide whether to write Left or Right  in the logfile.  I think a simple fix is to just stop using LeftActive and use fed3.activePoke in the Arduino code.  I'm attaching a modified Arduino sketch that does this. Can you check it out and see if it's working how you expect now?   Best, -Lex
Random_Ratio_Menu_Right_LKM_lex.ino
Reply all
Reply to author
Forward
0 new messages