Josh
Dear Josh,
Thank you. I setup Rp2 and now it sends TTL to Bpod. I didn't find examples which command I have to write in Bpod for first state that wait for TTL. Could you please advise me about this.
Best Regards,
Saleh
Josh
Dear Josh,
Thank you. I setup Rp2 and now it sends TTL to Bpod. I didn't find examples which command I have to write in Bpod for first state that wait for TTL. Could you please advise me about this.
Best Regards,
Saleh
Hello Saleh,
You can start with the one-state example here.
In the StateChangeConditions section, add:
{'BNC1High', MyNextState}
if the RP2.1 is patched to a BNC input channel{'Port1In', MyNextState}
if the RP2.1 is patched to a port input channelYou don't need to install anything special to use the valves. In the OutputActions section, add:
{'Valve2', 1}
to open valve 2
I hope this helps,
Josh
Thank you Josh,
I want to generate sound with Rp2 (with 2 sec pulse width) and send TTL to Bpod for delivering airpuf (for 1 sec) for each sound pulse. Could you please check this script is fine or not?
function Airpuf
sma = NewStateMachine;
sma = AddState(sma, 'Name', 'TTL1', ...
'Timer', 0,...
'StateChangeConditions', {'BNC1High', Delay},...
'OutputActions', {'Valve2', 1});
sma = AddState(sma, 'Name', 'Delay', ...
'Timer', 1,...
'StateChangeConditions', {'BNC1High', 'end'},...
'OutputActions', {'Valve2', 1});
SendStateMatrix(sma);
RawEvents = RunStateMatrix;
end
How does the RP2 know when to play the sound?
The code you wrote opens valve 2 immediately, because {'Valve2', 1} is in the output actions of the first state.
Output actions are executed on entering a state.
The second state also has {'Valve2', 1} so the valve would remain open until a second TTL pulse arrives from RP2, ending the trial.
-Josh
Josh
Thank you Josh,
I defined by Pulsedtrain in RPvdsx. I changed script. Is it correct?
In this script solenoid deliver puf until get TTL or finished in first pulse and I have to consider loop in my script?
function Airpuf
sma = NewStateMachine;
sma = AddState(sma, 'Name', 'Openvalve', ...
'Timer', 0.1,...
'StateChangeConditions', {'BNC1High', Closevalve},...
'OutputActions', {'Valve2', 1});
sma = AddState(sma, 'Name', 'Closevalve', ...
'Timer', 1,...
'StateChangeConditions', {'BNC1High', 'end'},...
'OutputActions', {'Valve2', 2});
SendStateMatrix(sma);
RawEvents = RunStateMatrix;
end
Hello Saleh,
If you want to close the valve in the 'Closevalve' state, you'd use:
{'Valve2', 0}
or leave it blank, as the default state is closed.
-Josh
Josh
Hello Jon,
Thank you.
Dear Josh,
I ran above protocol and faced these errors. Could you please advise me about that.
thank you
Error using SendStateMachine
Please define the following states using the AddState function before sending the state machine: end
Error in SendStateMatrix (line 2)
Confirmed = SendStateMachine(sma);
Error in Airpuf (line 13)
SendStateMatrix(sma);
Error in run (line 91)
evalin('caller', strcat(script, ';'));
Error in LaunchManager>launch_protocol (line 843)
run(protocolPath);
Error while evaluating DestroyedObject Callback.
To exit the trial, in StateChangeConditions, you should use '>exit', not 'end'
-Josh
Thank you
Hello Josh,
I run Bpod with this protocol but it delivers airpuf continuously until I stop Bpod. Could you please advise me about that.
Best Regards,
Saleh
Hello Saleh,
Can you please share the updated version of your code?
Thanks,
Josh
My last script:
function Airpuf
sma = NewStateMachine;
sma = AddState(sma, 'Name', 'Openvalve', ...
'Timer', 0.1,...
'StateChangeConditions', {'BNC1High', Closevalve},...
'OutputActions', {'Valve2', 1});
sma = AddState(sma, 'Name', 'Closevalve', ...
'Timer', 1,...
'StateChangeConditions', {'BNC1High', 'exit'},...
'OutputActions', {'Valve2', 2});
SendStateMatrix(sma);
RawEvents = RunStateMatrix;
end
When I run Bpod the icon of BNC1 in Bpod console is not green and I think Bpod didn't identify input TTL. I also turned off RP2. I run the code again and Bpod opened valve without input TTL signal untill I stop Bpod.
Best Regards,
Saleh
Hello Saleh,
Output actions are set when you enter a state. You need to remove {'Valve2', 1} from the output actions of your first state.
Also, the syntax is {'Valve2', 1} to open the valve, and {'Valve2', 0} to close it. {'Valve2', 2} isn't a valid instruction. In your 'CloseValve' state, change 2 to 0.
Please let me know if this works for you.
Thanks,
Josh
Sorry my last script was:
My last script:
function Airpuf
sma = NewStateMachine;
sma = AddState(sma, 'Name', 'Openvalve', ...
'Timer', 0.1,...
'StateChangeConditions', {'BNC1High', Closevalve},...
'OutputActions', {'Valve2', 1});
sma = AddState(sma, 'Name', 'Closevalve', ...
'Timer', 1,...
'StateChangeConditions', {'BNC1High', 'exit'},...
'OutputActions', {'Valve2', 0});
SendStateMatrix(sma);
RawEvents = RunStateMatrix;
end
for first state which command I have to replace with {'Valve 2',1}? Previously (in post 6) you told me In the OutputActions section, add:
{'Valve2', 1} to open valve 2
Best Regards
In my earlier post I recommended to add it, but I didn't specify which state.
Here's the updated version:
sma = NewStateMachine;
sma = AddState(sma, 'Name', 'Openvalve', ...
'Timer', 0.1,...
'StateChangeConditions', {'BNC1High', Closevalve},...
'OutputActions', {});
sma = AddState(sma, 'Name', 'Closevalve', ...
'Timer', 1,...
'StateChangeConditions', {'BNC1High', 'exit'},...
'OutputActions', {'Valve2', 1});
Josh
Thank you Josh.
Hello Josh,
I couldn't run that script. Now I set circuit in RP2 to get TTL from Bpod. I connect BNC out 1 Bpod to BNC in RP2. I wrote this script bu didnt consider TTL to only open and close Valve:
function Airpuf
global BpodSystem
MaxTrials = 5;
for currentTrial = 1:MaxTrials
sma = NewStateMachine;
sma = AddState(sma, 'Name', 'Openvalve', ...
'Timer',3,...
'StateChangeConditions', {'Tup', 'Closevalve'},...
'OutputActions', {'Valve1',1});
sma = AddState(sma, 'Name', 'Closevalve', ...
'Timer', 2,...
'StateChangeConditions', {'Tup', 'exit'},...
'OutputActions', {'Valve1',0});
SendStateMatrix(sma);
RawEvents = RunStateMatrix;
end
end
But when I run this script RP2 also generate sound for each iteration. Could you please advise me about that.
Best Regards
Hello Saleh,
Why couldn't you run the script? If you got an error message, please share it here.
In your new setup, is the RP2 configured to play sound when it gets a TTL from Bpod?
The script you shared shouldn't send a TTL. Can you please confirm this with an oscilloscope?
Thanks,
Josh