is it possible to code two inputs to happens concomitant?
MEDState Notation Repository › Forums › Coding Help Archive › is it possible to code two inputs to happens concomitant?
- This topic has 7 replies, 1 voice, and was last updated 8 years, 9 months ago by
Med_Support.
-
AuthorPosts
-
May 12, 2011 at 1:16 pm #13087
Med_Support
Moderatorlianedahas
I need two inputs occurring concomitant, in the same time, in order to give a determined consequence. Is that possible? I tried already #R1#R2,#R1,R2 and all variations.
May 12, 2011 at 3:15 pm #13088Med_Support
ModeratorGary Bamberger
Hello Liane,
Now that is tricky, but it is possible. I guess the first thing you would need to do is change the inputs so that they are in Level Mode. Once you have done that the code below should work:
DIM Y = 1 \ Z-Pulses Used in this Program \ Z1 = Signal Both Inputs are on \ Z3 = Input 1 Response \ Z4 = Input 1 Release \ Z5 = Input 2 Response \ Z6 = Input 2 Release \*************************************************** \ INPUT 1 DETECTION \*************************************************** S.S.1, S1, #START: ---> S2 S2, \ Wait for Input 1 Response Signal \ Check for Input 2 Response #Z3: IF S.S.2 = 3 [@Both, @One] @Both: Z1 ---> S3 \ Tell the rest of the program @One: ---> S3 S3, \ Wait for Input 1 Release Signal #Z4: ---> S2 \*************************************************** \ INPUT 2 DETECTION \*************************************************** S.S.2, S1, #START: ---> S2 S2, \ Wait for Input 2 Response Signal \ Check for Input 1 Response #Z5: IF S.S.1 = 3 [@Both, @One] @Both: Z1 ---> S3 \ Tell the rest of the program @One: ---> S3 S3, \ Wait for Input 2 Release Signal #Z6: ---> S2 \*************************************************** \ INPUT 1 DEFINED - 20ms RESPONSE, 20ms RELEASE \*************************************************** S.S.3, 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 constitute a Response. #R1: ADD Y(0); IF Y(0) >= 2 [@BeamBreak, @NoBeamBreak] @Break: Z3; SET Y(0) = 0 ---> S2 @NoBreak: ---> SX 0.02": SET Y(0) = 0 ---> S1 S2, \ As long as the Input is on the second statement \ causes a re-entry to this State. This resets the \ 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 \*************************************************** \ INPUT 2 DEFINED - 20ms RESPONSE, 20ms RELEASE \*************************************************** S.S.4, S1, #R2: ADD Y(1); IF Y(1) >= 2 [@BeamBreak, @NoBeamBreak] @Break: Z5; SET Y(1) = 0 ---> S2 @NoBreak: ---> SX 0.02": SET Y(1) = 0 ---> S1 S2, 0.02": Z6 ---> S1 #R2: ---> S2
I hope that this helps.
GaryMay 13, 2011 at 10:03 am #13091Med_Support
Moderatorlianedahas
Thank you, Gary!
I am a new user of WMPC, and I am not understanding in this code you made where is the unique consequence for both inputs, i.e., I need to guarantee that both inputs occurs in the same time and then, give one consequence (output) for them. Is it possible?May 16, 2011 at 1:59 pm #13093Med_Support
ModeratorGary Bamberger
Not certain what you mean by the same time?
If you mean that they must start at the exact same interrupt, then that will almost never happen. For two inputs to be started within less than 10ms of each other is pretty much impossible for a human much less an animal. Now it is possible that they could happen within less than 1s of each other.
The code sample that I provided looks to see if there is a response on both inputs at the same time. If both inputs are showing a response, then the code issues a Z1 pulse. Your program must then respond to that input and do whatever the consequence is supposed to be. Example:
S.S.5, S1, \ Turn on Shock output as a consequence \ of both inputs happening at same time. #Z1: ON 5 ---> S2 S2, 1": OFF 5 ---> S1
There is one feature with my code sample that may not meet your needs. The animal could respond and hold input 1 for 10s before responding on input 2. So the inputs did not start at the same time, but there was a point where they were happening at the same time.
If you need the inputs to always start at the same time, I don’t think it is possible to write code to check for that. I also don’t think it is generally possible for the animals to do that.
Please let me know if this helps answer your questions or if there is some detail about what you are trying to do that I am missing.
Gary
June 2, 2011 at 9:46 am #13095Med_Support
Moderatorlianedahas
Gary, I am really grateful for your help.
What I am trying to do is to demand that a rat nose break two light beams in the same time (that will provide a response – in fact, a single one, but two inputs for Med programation – more precise than using only one beam).
Perhaps, the short time between one and other response, needed in your code, will not disturb my intentions, I will try.
But I am not having success in translate your code, it appears an ERROE 89:”)” expected. What may be wrong?
And I would like to understand what “s.s.1=3” means. How can I quantify a state set?
…
Does somebody understood what I am triyng yo do?
June 17, 2011 at 11:26 am #13097Med_Support
ModeratorGary Bamberger
Hello Liane,
Sorry for taking so long in getting back to you.
The IF S.S.1 = 3 checks which State that S.S.1 is currently in. If S.S.1 is in State 3, then input 1 must already be broken. The only reason that S.S.1 would be in S3 is if input 1 was currently broken.
If input 1 is already broken as indicated by S.S.1 being in S3 and we just received a Z pulse telling us that input 2 is broken, then both beams are broken at the same time and your code can continue on with the reward or punishment.
The ERROR 89:”)” expected is probably something to do with an IF statement or an array variable, but without the actual program I cannot give you a better answer. If you want to email me a copy of the program I will be able to tell you exactly why it can’t compile and how to fix it.
Gary
July 12, 2011 at 12:27 pm #13100Med_Support
Moderatorlianedahas
Gary,
I think I was having problems in copying your code. Now, the code was translate without problems. Unfortunately, I am not able to use my lab this week, but when I test it, I will tell you what happens.
Thanks a lot,
Liane…
Gary, now I was able to try it, and your code is doing very well!
Thank you,
LianeJuly 13, 2011 at 8:16 am #13102Med_Support
ModeratorGary Bamberger
Thank you for letting me know and I’m glad that it is working for you.
Gary -
AuthorPosts
- You must be logged in to reply to this topic.