Trigger a TTL with a threshold range

383 views
Skip to first unread message

Paolo Botta

unread,
May 22, 2018, 3:16:40 PM5/22/18
to Bonsai Users
Hi Goncalo,

I am doing a closed-loop experiment in order to track the speed and trigger a TTL only after the speed crosses a threshold value. I can easily do this by adding a GreaterThan after the node Speed.

What I am struggling with is to have a second speed's threshold. Ideally, I would like to have two thresholds for the speed where I stimulate ONLY if they reach the first threshold but they do not reach the second threshold.

I have tried to put a LessThan node after the GreaterThan but  it does not work. I am attaching the code where I have tried to subtract two times the speed values of two consecutive frames. When I put the LessThan node it takes too many values below 1. 

Do you have any recommendation how to setup a second threshold in order to have a TTL output ONLY within a range of speeds?

Thanks,
Paolo
VideoTracking_optogeneticSpeedTest2.bonsai
VideoTracking_optogeneticSpeedTest2.bonsai.layout

Gonçalo Lopes

unread,
May 23, 2018, 8:22:41 PM5/23/18
to Paolo Botta, Bonsai Users
Hi Paolo,

You can do each of the tests in different branches and combine them with LogicalAnd, like so:



Even easier might be to just use ExpressionTransform and plug in the expression (for example):
it > 100 && it < 200

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "Bonsai Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/bonsai-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/bonsai-users/ae3ee6db-2477-47da-b3ec-8a278f0a5024%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paolo Botta

unread,
May 25, 2018, 9:13:47 AM5/25/18
to Gonçalo Lopes, Bonsai Users
Thanks a lot Goncalo. It works! I have managed also to add a second threshold for the acceleration.

Now another small problem occurred. This is related by the fact that the animal crosses multiple times that speed and acceleration. I want to avoid that the animal gets too many stimuli and filter only the first output (from false to true) followed by a refractory time of 10 seconds. During this time, the animal should not get any further stimulus even though it crosses the thresholds. I have checked this post but did not manage.

Please let me know also if I should include this under another question.

Thanks,
Paolo

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman Institute
Columbia University
Tel. +1 3475253666 | Skype paolo...@gmail.comLinkedIn

Gonçalo Lopes

unread,
May 28, 2018, 5:12:22 AM5/28/18
to Paolo Botta, Bonsai Users
Hi Paolo,

You can implement a simple refractory period with DistinctUntilChanged > Condition > GateInterval.
This will filter for the first rising edge and then ignore any triggers for the specified amount of time.

Hope this helps.

Paolo Botta

unread,
Jun 1, 2018, 4:18:07 PM6/1/18
to Bonsai Users
Thanks a lot Goncalo, that helps part of the problem.

After your suggestion, I had a a new problem

In an openfield, when an animal reaches a certain velocity we turn on a laser with 50% probability. Using your suggestion we now have solved the delay thing. Now, after the gate interval, we have a node that calculates a probability of 50%. The thing is that, when the output is True True, the Digital Output node does not "write" the second true. It only write differences from False to True. Any suggestion on how to go around this?

Thanks a lot
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users...@googlegroups.com.
MouseTracking_optogeneticSpeedTest_GAteInterval2.bonsai
MouseTracking_optogeneticSpeedTest_GAteInterval2.bonsai.layout

Gonçalo Lopes

unread,
Jun 17, 2018, 7:04:45 AM6/17/18
to Paolo Botta, Bonsai Users
Hi Paolo,

What do you mean by "the Digital Output node does not "write" the second true"? If you set a digital line that is already high, then no change is expected. Are you somehow setting the line LOW using some other process? If you need to generate a rising edge, you need to write a False before you write the second True.

Hope this helps.

To unsubscribe from this group and stop receiving emails from it, send an email to bonsai-users+unsubscribe@googlegroups.com.

Paolo Botta

unread,
Jun 22, 2018, 12:11:20 PM6/22/18
to Gonçalo Lopes, Paolo Botta, Bonsai Users
Hi Gocalo,

We have tried to put a False. Can you suggest where to add it in the code that I sent you?

Thanks
Paolo

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman institute
Columbia University
Tel. +1 (347) 525-3666 | Skype paolobotta | LinkedIn

Gonçalo Lopes

unread,
Jul 7, 2018, 6:17:04 PM7/7/18
to Paolo Botta, Paolo Botta, Bonsai Users
Hi Paolo,

That depends on the protocol you want. If you just need the rising edge and you don't require any delay, you can simply insert the False immediately after you send the True.

Paolo Botta

unread,
Jul 9, 2018, 1:10:22 PM7/9/18
to Gonçalo Lopes, Paolo Botta, Bonsai Users
Hi Goncalo,

We have problems in integrating the False node in our workflow. We have tried to add the False at the end of the sequence (and many more things) but it is not working!

As you can see from the workflow, the random decision node is generating 0 and 1 values. This is good until the sequence generated by the random decision is 011 for example. In the latest case, we are skipping the stimulation.

Would you mind to check our BONSAI code please and let us understand where to add the False node & how should be done in that way?

Thanks for checking & best,
Paolo

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman institute
Columbia University
Tel. +1 (347) 525-3666 | Skype paolobotta | LinkedIn

On Sat, Jul 7, 2018 at 6:17 PM, Gonçalo Lopes <goncal...@gmail.com> wrote:
Hi Paolo,

That depends on the protocol you want. If you just need the rising edge and you don't require any delay, you can simply insert the False immediately after you send the True.

Gonçalo Lopes

unread,
Aug 14, 2018, 5:34:05 AM8/14/18
to Paolo Botta, Paolo Botta, Bonsai Users
Hi Paolo,

Can you send us a smaller workflow just for the stimulation part, and point out what is not working? It would really help a lot to understand what it is you are trying to do and to isolate the problem.

On 9 July 2018 at 18:09, Paolo Botta <paolo...@neuro.fchampalimaud.org> wrote:
Hi Goncalo,

We have problems in integrating the False node in our workflow. We have tried to add the False at the end of the sequence (and many more things) but it is not working!

As you can see from the workflow, the random decision node is generating 0 and 1 values. This is good until the sequence generated by the random decision is 011 for example. In the latest case, we are skipping the stimulation.

Would you mind to check our BONSAI code please and let us understand where to add the False node & how should be done in that way?

Thanks for checking & best,
Paolo

Paolo Botta
Postdoctoral fellow, Costa lab
Zuckerman institute
Columbia University
Tel. +1 (347) 525-3666 | Skype paolobotta | LinkedIn

On Sat, Jul 7, 2018 at 6:17 PM, Gonçalo Lopes <goncal...@gmail.com> wrote:
Hi Paolo,

That depends on the protocol you want. If you just need the rising edge and you don't require any delay, you can simply insert the False immediately after you send the True.
Reply all
Reply to author
Forward
0 new messages