Med_Support
Forum Replies Created
-
AuthorPosts
-
Med_Support
ModeratorDevan
Thank you for your reply.
I actually have it working now and would only need one additional thing added, which is a flush command recording the responses from each input device every 30 minutes (eventually this program will be used for 23 hr access). This would be in addition to the total responses displayed in the show rows. I would also like the data sent to MATLAB and am not sure how to do accomplish this.
I’ve attached the working program to this post.
Thanks again
January 21, 2016 at 4:47 pm in reply to: Dual lever- with different punishment time and reward amount #12775Med_Support
ModeratorJon Beyor
Do you have any code so far? Make 2 State Sets each extending the appropriate lever and then each progressing in their own scenario.
Med_Support
ModeratorMed_Support
ModeratorJim Frei
Glad to help.
Med_Support
ModeratorWelcome2Machine
Hello Jim! Thank you for your feedback, it was extremely helpful and now the program is working great!
Thanks again.
Welcome2Machine

Med_Support
ModeratorJim Frei
You would use a variable to track the lever’s state. For example, when the lever is retracted set S = 0, when it’s extended set S = 1. Then, in the state where you are watching for lever presses use an IF statement to check the levers state and only increment your counter when S = 1. Ie:
#R^lever: IF S = 1 [@T, @F] @T: ADD A; SHOW 1, Lever Presses, A ---> SX @F: ---> SX
If you need more help just let me know.
Jim
Med_Support
Moderatortimedwards233
Re: Interfacing Med-PC with non-Med Associates Hardware
« Reply #2 on: June 12, 2015, 10:25:00 am »Hi Jim,
Thank you for the quick reply! This looks like the tool we need. I will forward the information to our programmer and see what he can do with it.
Tim
Med_Support
ModeratorJim Frei
Re: Interfacing Med-PC with non-Med Associates Hardware
June 12, 2015, 08:21:40 amHi Tim, You could use our software API to talk to Med-PC gear with other languages.
Please see: https://mednr.com/product/control-of-med-inputoutput-from-other-languages/
You can reach our sales & applications folks at 802-527-2343 for more information.
Jim
Med_Support
ModeratorFlienard
I do not understand why the first program you sent us does not work, do you have any idea?
Fabienne
…
Hi Jim,
Your first program works well now. Our Superport input settings JP3 and JP4 were placed on the level mode. I have changed for the transition mode and it works well now.Fabienne
Med_Support
ModeratorJim Frei
Fabienne see my second post above please.
Jim
Med_Support
ModeratorFlienard
Hi Jim,
You are right we need the time when the licks occur. But when I use the program you send us it gives me plenty of values for one lick and the array of irt is plenty of “0” and “0.01”, I do not understand why. This is why I thought the beam break code should ameliorate the result but I do not know if it is correct, if you said that the beam break code is used to measure the time spend by the animal in the dispenser.Fabienne
Med_Support
ModeratorJim Frei
Hi Fabienne,
I misunderstood your question, when you said time of licks I thought you meant at what point in time the lick occurs, not how long the animal’s head is in the dispenser. Give me a little bit and I’ll see if I can adjust the code.
Jim
…
Hi Fabienne,
Here’s some sample code on how to time the length of an input. If you need more help let us know.
How to time the length of an input \*************************************************** \ RESPONSE DEFINED - 20ms BREAK, 20ms RELEASE \*************************************************** S.S.2, S1, \ Inputs in Level Mode generate an input "count" on each \ interrupt. With a 10 ms system resolution 2 counts \ will be reached in 20 ms. The Z3 pulse is used to \ signal a completed Response. The second statement \ resets the counter every 20 ms so that a partial \ Response of less than 20 ms will not be counted. #R1: ADD Y; IF Y >= 2 [@Response, @NoResponse] @Response: SET Y = 0; Z3 ---> S2 @NoResponse: ---> SX 0.02": SET Y = 0 ---> S1 S2, \ As long as the input is broken the second statement \ causes a re-entry to this State. This resets the \ internal 20 ms timer so it never times out. When the \ input is released for 20 ms the timer times out and a \ Z4 pulse signals the release. 0.02": Z4 ---> S1 #R1: ---> S2 \*************************************************** \ RESPONSE TIMER \*************************************************** S.S.3, S1, #START: SET Z(I) = -987.987 ---> S2 S2, \ Wait for a signal that the input has been broken. #Z3: SET T = 0 ---> S3 S3, \ Wait for signal that the input has been released. \ Record the length of the Response. 0.01": SET T = T + 0.01 ---> S3 #Z4: SET Z(I) = T; ADD I; SET Z(I) = -987.987 ---> S2Med_Support
ModeratorFlienard
Hi, Jim
Thank you so much
I will test your program now. And sure it will help me;
Thank you again
Fabienne…
Hi Jim,
We are using ENV-251L with photobeam sensor, I wonder if I should use beambreak code?Fabienne
Med_Support
ModeratorJim Frei
Hi Fabienne,
This code should do what you want or get you started at least:
\Inputs ^rightLick = 1 ^leftLick = 2 \Control variables VAR_ALIAS Session Timer (sec) = A(0) \Default = 600 VAR_ALIAS Bin Timer (sec) = A(1) \Default = 60 ^sessionTimer = 0 ^binTimer = 1 \Data variables \B(E) = Right licks/bin \C(E) = Left licks/bin \D(F) = Time of each right lick \G(H) = Time of each left lick \I(J) = Array of ITR times DIM A = 1 DIM B = 100 DIM C = 100 DIM D = 10000 DIM G = 10000 DIM I = 10000 \Working variables \E = Bin number \F = Total right licks \H = Total left licks \J = I() index \R = IRT timer \S = Session timer \T = Bin timer \Z-Pulses \Z1 = Start program \Z2 = End program \********************************************* \ Initialize values \********************************************* S.S.1, S1, 0.001": SET A(^sessionTimer) = 600, A(^binTimer) = 60; SET E = 1, J = 1; SET B(E+1) = -987.987, C(E+1) = -987.987; SET D(F+1) = -987.987; SET G(H+1) = -987.987; SET I(J) = -987.987 ---> S2 S2, #START: Z1 ---> SX \******************************************** \ Session timer \******************************************** S.S.2, S1, #Z1: ---> S2 S2, 0.01": SET S = S + 0.01; SHOW 1, Session Timer, S; IF S >= A(^sessionTimer) [@T, @F] @T: Z2 ---> S1 @F: ---> SX \********************************************** \ Bin timer \********************************************** S.S.3, S1, #Z1: ---> S2 S2, 0.01": SET T = T + 0.01; SHOW 6, Bin Timer, T; IF T >= A(^binTimer) [@T, @F] @T: ADD E; SET T = 0; SET B(E) = 0, C(E) = 0; SET B(E+1) = -987.987, C(E+1) = -987.987---> S2 @F: ---> SX \********************************************* \ Record licks & IRT timer \********************************************* S.S.4, S1, #Z1: ---> S2 S2, \Record right licks #R^rightLick: ADD F; SET D(F) = S; SET D(F+1) = -987.987; ADD B(E); SET I(J) = R; ADD J; SET I(J) = -987.987; SET R = 0 ---> S2 \Record left licks #R^leftLick: ADD H; SET G(H) = S; SET G(H+1) = -987.987; ADD C(E); SET I(J) = R; ADD J; SET I(J) = -987.987; SET R = 0 ---> S2 0.01": SET R = R + 0.01; SHOW 8, IRT Timer, R ---> SX \****************************************** \ Update the display \******************************************** S.S.31, S1, 0.1": SHOW 2, Total Right Licks, F; SHOW 3, Total Left Licks, H; SHOW 7, Bin Number, E ---> SX \********************************************* \ End program \******************************************** S.S.32, S1, #Z2: ---> S2 S2, 1": ---> STOPABORTFLUSHMed_Support
ModeratorJim Frei
Hi Blee,
The command is VAR_ALIAS, not VARS_ALIAS.
To save you some typing, by default all variables will show up in your data file, you don’t need to type DISKVARS A-Z. You can use the DISKVARS command to limit what appears in the data file if you’d like to.
Jim
Med_Support
ModeratorJim Frei
Glad to help.
Jim
Med_Support
ModeratorSarah Delcourte
Everything is perfect ,
Thank you again Jim.
Kind regards,
Sarah
Med_Support
ModeratorJim Frei
Hi Sarah,
A few things needed to be changed so I made the changes. Please save the attached file, change the extension to .mpc, compile in Trans IV and then try the program. Let me know.
Take care,
JimMed_Support
ModeratorSarah Delcourte
A HUGE thank you for what you’ve sent me, I tried the program this morning and it worked perfectly, you saved my life !!
I just have one (last) question. I tried to understand what you’ve written but I am far from being an expert, so I didn’t understand, and can’t make few changes.
When the non target tone is played, and the rat doesn’t respond, in the program, it is an omission. I would like to add another variable to caracterize this particular response. Can I just add the variable or do I have to change other things ( the value of “DIM B”, of B(I) etc ?)
Sorry to bother you with all my questions but I really don’t know nothing about programing
Thanks again for your help, without you I would be lost.
Sarah
Med_Support
ModeratorJim Frei
Hi Sarah,
Save the attached file to your MPC folder and change the file extension to .mpc. Then read the program to see what values are what and then try the program, I think it does what you’re looking for. Start it with the wizard in Med-PC IV to see your options. If you have questions let me know.
Med_Support
ModeratorIan
Hi Gary,
I really appreciate your help. The program is now working exactly as I wanted, and you’ve helped me understand a lot more about MedState notation in the process. Thank you for all your help! 🙂
Ian
Med_Support
ModeratorSarah Delcourte
Hi Jim,
Thank you for your quick answer,
A response is correct when the rat nose-poke within 5 seconds of presentation of the target tone ( 2000Hz).
If the rat doesn’t respond within the 5 seconds, the response is missed.
If the rat respond to the non target tone, the response is incorrect.
A premature response occurs during the ITI , or during the beginning of the presentation of the sound .
When the sound is ON, there is a cue light in the hole where the rat has to nose poke. This light turns off when the rat nose-poke (if he does it within the 5 seconds after the tone presentation), or 5 seconds after the tone presentation , indicating that the time has passed.
When the rat makes a correct response, the light in the pellet receptacle turns on during 1 second ( I forgot to change this part on the program code I’ve posted).
I removed the “Hz” following “2000” and “1000” in the “LIST A”, and no more errors occured, but when I launch the program, the sound does not work. I don’t know why.
I’m sorry my english isn’t really good, I hope you will understand what I’m trying to explain.
To summarise :
2 tones ( a traget and a non-target one) are randomly presented to the rat, the rat has to answer, by nose-poking within the 5 seconds following the presentation of the target tone (2000Hz). When the target tone is on, a cue light turns on . If the rat nose poke within the 5 seconds, the cue light turns off, the pellet receptacle light turns on dring 1 second to let the rat know that a pellet has benn dispensed.
Thanks again, if you could help me, it would be so great !
Sarah
Med_Support
ModeratorGary Bamberger
Hi Ian,
The problem is that A(6) is pulling double duty:
^RewardTime = 3 ^RewardTicks = 6 S2, #START: CLEAR 1,200; SET A(^RewardTicks) = A(^RewardTime) * 1"; The Reward Time is 0.05 when multiplied by 1" the Reward Ticks becomes 5. SET A(6) = A(3) * 1" SET A(6) = 0.05 * 100 SET A(6) = 5We need to modify the code so that it is using a variable that is available:
Var_Alias Number of Pellets to Dispense = A(8) \ Default = 2 DIM A = 8 S.S.3, S1, 0.01": SET A(8) = 2 ---> S2 S2, \ Wait for Reinforcement Signal #Z^Z_Reward: ON ^Pellet; ADD N ---> S3 S3, \ Check if delivered desired Number of Pellets 0.15": OFF ^Pellet; IF N >= A(8) [@Done, @More]I hope that this information helps.
GaryMed_Support
ModeratorIan
Hi Gary. Thanks for your response. Here’s the entire program:
\ Copyright (c) 2013 MEDState Notation Repository, All rights reserved. \ ProgressiveRatio_v2.mpc \ \ When the program is started it will turn on the HouseLight and the lights over \ both Levers, and the current PR Value will be set to the first value drawn in \ order from List Z. The program will then wait for the Animal to respond on \ the Correct Lever enough times to meet the current PR Value. \ \ When the current PR Value has been met the program will turn on the Reward \ Device for the Reward Time. At the end of the Reward Time the program will \ time the Time Out Following Reward. \ \ When the Time Out Following Reward has been completed the program set the \ current PR Value to the next value drawn in order from List Z. \ \ The program will then once again wait for the Animal to respond on the Correct \ Lever enough times to meet the current PR Value. \ \ Responses on the Incorrect Lever will be recorded, but have no adverse affect. \ \ The program will end when the Session Length has been reached. \ Inputs ^LeftLever = 1 ^RightLever = 2 \ Outputs ^Pellet = 3 ^Dipper = 3 \ If both Pellet and Dipper are ordered \ It will be necessary to change one of these ^LeftLight = 4 ^RightLight = 5 ^HouseLight = 7 ^Pump = 8 \ A() = Control Variables with Assigned Aliases as Defined Var_Alias Session Length (min) = A(0) \ Default = 10 minutes Var_Alias Correct Lever (1=Left 2=Right) = A(1) \ Default = 1-Left Var_Alias Reward Device (1=Pellet 2=Dipper 3=Pump) = A(2) \ Default = 1-Pellet Var_Alias Reward Time (sec) = A(3) \ Default = 0.05 seconds Var_Alias Time Out Following Reward (sec) = A(4) \ Default = 0 seconds Var_Alias SoftCR Data Array (1=Yes 0=No) = A(5) \ Default = 1-Yes Var_Alias Number of Pellets to Dispense = A(6) \ Default = 2 ^Session = 0 ^CorrectLev = 1 ^RewardDevice = 2 ^RewardTime = 3 ^TimeOut = 4 ^SoftCR = 5 ^RewardTicks = 6 ^TimeOutTicks = 7 \ List Data Variables Here \ B() = Response Counts \ B(0) = Total Responses \ B(1) = Total Correct Response Count \ B(2) = Total Incorrect Response Count \ B(3) = Total Rewards \ B(4) = % Correct \ B(5) = % Incorrect \ B(6) = Last PR Value that was Met \ List Working Variables Here \ I = Subscript for the IRT Array C \ N = Counter to count how many pellets have been dispensed this reward. \ P = Current PR Value \ R = Ratio Response Counter \ S = Elapsed Time in Session \ X = Subscript for Progressive Ratio List Z \ Z() = Progressive Ratio Default List DIM A = 7 DIM B = 6 LIST Z = 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 44, 48, 52, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, 464 \ Z-Pulses Used in this Program ^Z_Pellet = 1 \ Signal Pellet Reinforcement ^Z_Dipper = 2 \ Signal Dipper Reinforcement ^Z_Pump = 3 \ Signal Pump Reinforcement ^Z_EndReward = 4 \ Signal End of Reward ^Z_End = 32 \ Signal End of Session ^Z_Reward = 1 \ Z1 = Signal Reward \*************************************************** \ Progressive Ratio Schedule \ S1 - Set Default Values \ Session Length (10 minutes) \ Correct Lever (1-Left) \ Reward Device (1-Pellet) \ Reward Time (0.05 seconds) \ Time Out Following Reward (0 seconds) \ SoftCR Data Array (1-Yes) \*************************************************** S.S.1, S1, 0.01": SET A(^Session) = 10, A(^CorrectLev) = 2, A(^RewardDevice) = 1; SET A(^RewardTime) = 0.05, A(^TimeOut) = 0, A(^SoftCR) = 1 ---> S2 S2, \ First Statement: Wait for START signal, turn HouseLight ON \ and turn associated stimulus ON. \ \ Second Statement: Update screen display with default values \ for Control Variables. This will show any changes made via \ the "Configure | Change Variables" Window prior to START. #START: CLEAR 1,200; SET A(^RewardTicks) = A(^RewardTime) * 1"; SET A(^TimeOutTicks) = A(^TimeOut) * 1"; ON ^HouseLight, ^LeftLight, ^RightLight; SHOW 1,Session,S/60 ---> S3 1": SHOW 1,Session Length,A(^Session), 2,Correct Lever,A(^CorrectLev), 3,Reward Device,A(^RewardDevice); SHOW 4,Reward Time,A(^RewardTime), 5,Time Out,A(^TimeOut), 6,SoftCR Code,A(^SoftCR) ---> SX S3, \ Time Session Length 0.01": SET S = S + 0.01; SHOW 1,Session,S/60; IF S/60 >= A(^Session) [@EndSession, @ContinueTiming] @End: Z^Z_End ---> S4 @Cont: ---> SX S4, \ Wait for Screen Update and end with \ STOPABORTFLUSH for Automatic Data Saving 2": ---> STOPABORTFLUSH \*************************************************** \ MAIN PROGRAM \*************************************************** S.S.2, S1, \ Draw first Progressive Ratio from List Z #START: LIST P = Z(X) ---> S2 S2, \ Test for Correct Lever #RA(^CorrectLev): ADD B(0), B(1), R; IF R >= P [@PR_Value_Met, @False] @PR_Met: ADD B(3); SET B(6) = P, R = 0; ZA(^RewardDevice) ---> S3 @False: ---> SX #R^LeftLever: ADD B(0), B(2) ---> SX #R^RightLever: ADD B(0), B(2) ---> SX #Z^Z_End: ---> S5 S3, \ Wait for End of Reward Signal #Z^Z_End: ---> S5 #Z^Z_EndReward: ---> S4 S4, \ Time Out Interval Following Reward \ Update Progressive Ratio P from LIST Z A(^TimeOutTicks)#T: LIST P = Z(X) ---> S2 #Z^Z_End: ---> S5 S5, \ End of Session - Turn Lights Off \ Calculate % Correct and % Incorrect 0.01": OFF ^HouseLight, ^LeftLight, ^RightLight; IF B(0) = 0 [@NoCalc, @Calculate] @NoCalc: ---> S6 @Calculate: SET B(4) = B(1) / B(0) * 100; SET B(5) = B(2) / B(0) * 100; SHOW 7,% Correct,B(4), 8,% Incorrect,B(5), 10,Last PR Met,B(6) ---> S6 S6, \ Holding State at End of Session 1': ---> SX \*************************************************** \ REWARD CONTROL TIMER \*************************************************** S.S.3, S1, 0.01": SET A(6) = 2 ---> S2 S2, \ Wait for Reinforcement Signal #Z^Z_Reward: ON ^Pellet; ADD N ---> S3 S3, \ Check if delivered desired Number of Pellets 0.15": OFF ^Pellet; IF N >= A(6) [@Done, @More] @Done: SET N = 0; Z^Z_EndReward ---> S2 @More: ---> S4 S4, \ Must wait a certain amount of time before \ trying to dispense the next pellet. This \ delay can be shortened for some Pellet \ Dispensers. 0.15": ON ^Pellet; ADD N ---> S3 \*************************************************** \ UPDATE DISPLAY \*************************************************** S.S.4, S1, #START: SHOW 2,Correct Rsp,B(1), 3,Incorrect Rsp,B(2), 4,Rewards,B(3), 5,PR Value,P ---> S2 S2, 1": SHOW 2,Correct Rsp,B(1), 3,Incorrect Rsp,B(2), 4,Rewards,B(3), 5,PR Value,P ---> S2
Med_Support
ModeratorJim Frei
Hi Sarah,
I can offer more help if you supply more information about how the program is to work.
After the tone plays for 50ms how do you determine whether the response is premature, correct or incorrect?
Does the rat have a certain amount of time to respond or not respond within?
Is a premature response one that happens during the ITI?
Are there any other lights or indicators to the rat when he’s correct and the pellet is dispensed?
The more details you can supply the better I can try to help you.
Take care,
JimMed_Support
ModeratorGary Bamberger
I’m going to need to see the entire program as you currently have it written in order to try and find out why it is not working for you.
Gary
Med_Support
ModeratorIan
Hi Gary,
Thanks again for your continued help! I have included your changes, and also included a Z^Z_EndReward term to interface appropriately with the rest of the program. Unfortunately, I seem to get 5 pellets every time, and setting A(6) to a different value has no impact. Do you know what this could be? Once again, I really value the help you’re giving me!
\*************************************************** \ REWARD CONTROL TIMER \*************************************************** S.S.3, S1, 0.01": SET A(6) = 2 ---> S2 S2, \ Wait for Reinforcement Signal #Z^Z_Reward: ON ^Pellet; ADD N ---> S3 S3, \ Check if delivered desired Number of Pellets 0.05": OFF ^Pellet; IF N >= A(6) [@Done, @More] @Done: SET N = 0; Z^Z_EndReward ---> S2 @More: ---> S4 S4, \ Must wait a certain amount of time before \ trying to dispense the next pellet. This \ delay can be shortened for some Pellet \ Dispensers. 0.5": ON ^Pellet; ADD N ---> S3
Med_Support
ModeratorGary Bamberger
Hi Ian,
I have to apologize, but there was a bug in my sample code.
S4, \ Must wait a certain amount of time before \ trying to dispense the next pellet. This \ delay can be shortened for some Pellet \ Dispensers. 0.5" ON ^Pellet; ADD N ---> S3
There is a colon missing after the 0.5″. The following will compile.
S4, \ Must wait a certain amount of time before \ trying to dispense the next pellet. This \ delay can be shortened for some Pellet \ Dispensers. 0.5": ON ^Pellet; ADD N ---> S3
Remember that this new State Set is replacing S.S.3 in your existing code. You don’t want both State Sets trying to dispense a pellet.
Gary
Med_Support
ModeratorIan
Thanks Gary!
I have read and understood the code you wrote posted. Thank you for doing so! I added your code into the progressive ratio program, changing A(0) to A(6), S.S.2 to S.S.5, and variable P to N (as these were already in use by the ProgressiveRatio_v2.mpc program). However, when I run this through Trans IV, I get the following error message:
ERROR # 8 0.5"ON^Pellet;ADDN--->S3 Offending test: "and/or ON^Pellet, ADDN Illegal input statement - ! may be missing
I’ve tinkered with a few things, but have been unable to get past this error. Do you know if it’s down to something I changed?
Once again, thank you for any help that you’re able to give!
Med_Support
ModeratorGary Bamberger
Hi Ian,
Here is some sample code that shows how to dispense more than one pellet:
\ Outputs ^Pellet = 3 \ A() = Control Variable with Assigned Aliases as Defined Var_Alias Number of Pellets to Dispense = A(0) \ Default = 2 \ Z-Pulses Used in this Program ^Z_Reward = 1 \ Z1 = Signal Reward \*************************************************** \ PELLET DISPENSER CONTROL \*************************************************** S.S.2, S1, 0.01": SET A(0) = 2 ---> S2 S2, \ Wait for Reinforcement Signal #Z^Z_Reward: ON ^Pellet; ADD P ---> S3 S3, \ Check if delivered desired Number of Pellets 0.05": OFF ^Pellet; IF P >= A(0) [@Done, @More] @Done: SET P = 0 ---> S2 @More: ---> S4 S4, \ Must wait a certain amount of time before \ trying to dispense the next pellet. This \ delay can be shortened for some Pellet \ Dispensers. 0.5" ON ^Pellet; ADD P ---> S3
Med_Support
ModeratorJim Frei
Depends on which lever you have. Some like the ultra-sensitive levers are set at the factory and are not adjustable. Others have a little spring and nut that can be used to adjust the tension on the spring which adjusts the force needed to press the lever. With this type of user adjustable lever you could probably set (don’t drop) a small weight of the value you desire and it would be close enough. Ie: you need 2g of force, place a 2g weight on the lever and see if an input is recorded.
Med_Support
Moderatorandersem
That’s all it needed, thanks!
Now for a non coding question:
Is there a specific protocol to tell how much weight it takes for the lever to consider a press? Do I set a weight on it or drop a weight from a certain height?Med_Support
ModeratorJim Frei
Hi Andersem,
Jon had to leave early today so he asked me to check in. He gave me some code but I’m not sure if it’s the same as the one you’re working from. The last reward timer shows up fine in the version I have. You need to make sure you have enough rows showing in your display. Look near the top of Med-PC and you’ll see “Summary Show Rows”, make sure you have this set to at least 2 if your reward timer is in block 7.
If you’re still having trouble please post the code you’re working from and I’ll take a look.
j -
AuthorPosts
