Arduino Activation based on region of interest (ROI) and animal directionality

556 views
Skip to first unread message

Pedro Feliciano

unread,
May 9, 2017, 7:04:42 PM5/9/17
to Bonsai Users
Hi All,

Right now, I'm able to turn on/off an Arduino based on real-time tracking and ROI, however, I would like to add directionality as an additional criterion for activating the Arduino. For example, I want to turn on the Arduino only when the animal enters ROI A and goes from north to south. If the animal enters ROI A from South to North, the system is not activated. See Picture. I'll appreciate any suggestions.  Thanks.

Gonçalo Lopes

unread,
May 9, 2017, 7:16:09 PM5/9/17
to Pedro Feliciano, Bonsai Users
Hi Pedro,

Why not use a Condition to check the Y position at the time of ROI activation? If Y is smaller than the center of the ROI, the entry was from the north, if the Y is greater than the center, the entry was from the south.

Would this be enough?

--
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/e8dc818f-ee9f-4660-b523-3e5144b53223%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Pedro Feliciano

unread,
May 9, 2017, 8:02:48 PM5/9/17
to Bonsai Users, pdr...@gmail.com
Thank you for the quick response. Yes, I think it should be enough. If possible, could you provide with an example? Thanks. 


On Tuesday, May 9, 2017 at 7:16:09 PM UTC-4, goncaloclopes wrote:
Hi Pedro,

Why not use a Condition to check the Y position at the time of ROI activation? If Y is smaller than the center of the ROI, the entry was from the north, if the Y is greater than the center, the entry was from the south.

Would this be enough?
On 10 May 2017 at 00:04, Pedro Feliciano <pdr...@gmail.com> wrote:
Hi All,

Right now, I'm able to turn on/off an Arduino based on real-time tracking and ROI, however, I would like to add directionality as an additional criterion for activating the Arduino. For example, I want to turn on the Arduino only when the animal enters ROI A and goes from north to south. If the animal enters ROI A from South to North, the system is not activated. See Picture. I'll appreciate any suggestions.  Thanks.

--
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...@googlegroups.com.

Gonçalo Lopes

unread,
May 11, 2017, 7:20:30 PM5/11/17
to Pedro Feliciano, Bonsai Users
Sure, sorry for the delayed response. Here's a possible example (workflow also attached):


I'm not sure this fits in with how you were computing the ROI activations in your case, but it's one way to do it.

In general, the idea is to compute all the information you will need for the decisions in every frame and then define conditions to extract the events you are interested in.

Let me know if you would like me to explain any of the operations in more detail.

Hope this helps.

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

Pedro Feliciano

unread,
Jul 6, 2017, 12:10:19 PM7/6/17
to Bonsai Users, pdr...@gmail.com
Hi Goncalo,

Thanks for your response. I tried the workflow that you provided and I was able to detect entry from one side. However, the idea is to detect one side entry and to maintain the Arduino stimulation (output) in HIGH until the animal exit the region of interest (ROI-A).
Do you think it can be done? Attached a workflow that I started working on.What changes do you recommend?

Thank you for your time,
Best,
Pedro
PointGrey_Track_ROI_Trigger_Directionality_Arduino_v1.2.bonsai

Gonçalo Lopes

unread,
Jul 6, 2017, 8:05:09 PM7/6/17
to Pedro Feliciano, Bonsai Users
Hi Pedro,

I couldn't run the workflow you sent as there are many type incompatibilities. RoiActivityDetected can only be used with outputs coming from RoiActivity, so it cannot be used in this case.

I guess the difficulty here comes from the very specific stimulus activation rule (i.e. the centroid has to be above half of the ROI). Looking at this again, I was wondering why don't you simply define an ROI just for the north part of your region, rather than making a bigger ROI and then adding complex logic to the detection? You could simply define the ROI to be the area where you are exacly interested in, and then stimulation could match exactly activity in that area.

I guess maybe I don't yet fully understand what the goal is.
Hope this helps in any case.

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

Pedro Feliciano

unread,
Jul 11, 2017, 2:37:53 PM7/11/17
to Bonsai Users, pdr...@gmail.com

Hi Goncalo,

Sorry for the poor explanation. I have attached a picture explaining the protocol/goal. The general idea is to turn ON an Arduino based on two conditions: 1) when the animal is running in a specific direction and 2) while it remains in the region of interest (ROI). 

I have modified a workflow (see attachment) from another post (https://groups.google.com/forum/#!msg/bonsai-users/rMwPwl3pUiw/GLi3Tr-2AQAJ). This workflow works well on tracking and detecting directionality. The only problem is that the Arduino remains ON after the animal is outside of ROI. The last goal is to find a way to turn off the Arduino when the animal is exiting the ROI.
Any suggestions?

Thank you for your time,
Pedro


PointGrey_Track_ROI_Trigger_Directionality_Arduino_v4.0.bonsai

Pedro Feliciano

unread,
Jul 11, 2017, 3:35:46 PM7/11/17
to Bonsai Users
Attached a workflow that allows stimulating based on ROI and directionality. 
PointGrey_Track_ROI_Trigger_Directionality_Arduino_v4.1.bonsai

Gonçalo Lopes

unread,
Jul 12, 2017, 7:40:37 AM7/12/17
to Pedro Feliciano, Bonsai Users
Hi Pedro,

Looking at the workflow you attached, it looks like stimulation happens both when the animal enters and when it exits the ROI? Is this the intended behaviour? Basically if you follow the connections from the Entry and Exit nodes they go through the exact same sequence of operations. I guess for this to work one of them would have to be different?

Does this workflow work as expected?

--
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.

Pedro Feliciano

unread,
Jul 12, 2017, 9:58:09 AM7/12/17
to Bonsai Users, pdr...@gmail.com
Hi Goncalo,

Yes, you are right. For the workflow to work, the "exit node" has to be in "false" mode. So, I made a couple of changes to the "exit node" that were not included in the last workflow.

Thank you for all the help,
Pedro   


On Wednesday, July 12, 2017 at 7:40:37 AM UTC-4, goncaloclopes wrote:
Hi Pedro,

Looking at the workflow you attached, it looks like stimulation happens both when the animal enters and when it exits the ROI? Is this the intended behaviour? Basically if you follow the connections from the Entry and Exit nodes they go through the exact same sequence of operations. I guess for this to work one of them would have to be different?

Does this workflow work as expected?
On 11 July 2017 at 20:35, Pedro Feliciano <pdr...@gmail.com> wrote:
Attached a workflow that allows stimulating based on ROI and directionality. 

On Tuesday, May 9, 2017 at 7:04:42 PM UTC-4, Pedro Feliciano wrote:
Hi All,

Right now, I'm able to turn on/off an Arduino based on real-time tracking and ROI, however, I would like to add directionality as an additional criterion for activating the Arduino. For example, I want to turn on the Arduino only when the animal enters ROI A and goes from north to south. If the animal enters ROI A from South to North, the system is not activated. See Picture. I'll appreciate any suggestions.  Thanks.

--
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...@googlegroups.com.

Paolo Botta

unread,
Feb 28, 2018, 10:35:01 AM2/28/18
to Bonsai Users
Hi Pedro and Goncalo,

I was reading this message thread and I have the same issue.

I am able to trigger a change in arduino state (to trigger an LED) when the animal enters an ROI. However, if the animal stays in the ROI it will still get a stimulation. 
I would like to set a condition that ensures another stimulation at the entrance only when the animal has previously exited the ROI.

I came across the last post of Pedro as he set up the exit node to be a false node.

Is there a simple solution?

You can find my code attached.
Thanks,
Paolo
VideoTracking_optogeneticROIentranceExample.bonsai

Gonçalo Lopes

unread,
Mar 1, 2018, 11:34:03 AM3/1/18
to Paolo Botta, Bonsai Users
Hi Paolo,

What do you mean by "simple"? The solution to Pedro's problem was described in detail in this thread. Can you elaborate on what you would like to do differently?

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

Paolo Botta

unread,
Mar 2, 2018, 11:44:58 AM3/2/18
to Gonçalo Lopes, Bonsai Users
What I meant is that I need to trigger only at the entrance of the ROI. In this case, I do not want that the animal gets a stimulation when it seats inside the ROI but only at the entrance. 
The idea is that the animal has to go out from the ROI in order to get another stimulation upon entrance.
What I understood from the code of Pedro is that it will trigger a stimulation when the animal crosses the ROI until it leaves the ROI. In my case, I just need to trigger only upon the entrance with the condition that the animal has previously exited from the same ROI!




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

Gonçalo Lopes

unread,
Mar 2, 2018, 6:10:40 PM3/2/18
to Paolo Botta, Bonsai Users
Hi Paolo,

This looks like a different case from Pedro, since you are not worried about directionality.

Would you mind starting a new question thread with a more descriptive title, the diagram from the previous post, and your current workflow? This way it will be easier for future users to find it when they are in a similar situation.


Christopher Machle

unread,
Sep 1, 2019, 4:46:23 PM9/1/19
to Bonsai Users
Hi Goncalo!

The problem I am facing involves a workflow where Arduino coordinated events are triggered when mice move about a circular maze in the correct direction. I have used a similar strategy as delineated above, where I use entrances and exits from the previously occupied zone to evaluate whether the correct sequence occurred. Because of this, if the mice disappear and reappear from the camera's view after triggering the correct sequence, they can endlessly re-trigger an event that is supposed to occur once per correct sequence. Let me know if I should post the relevant info here, or open a new thread.

Thanks!
Christopher
To unsubscribe from this group and stop receiving emails from it, send an email to bonsai...@googlegroups.com.

--
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...@googlegroups.com.

Gonçalo Lopes

unread,
Sep 6, 2019, 9:49:03 PM9/6/19
to Christopher Machle, Bonsai Users
Hi Christopher,

If this is a direct adaptation of this workflow, go ahead and continue the thread. If your requirements for the task changed significantly, or you are facing different problems, it might be best to open a new thread. In any case, including the workflow, a description of the symptoms, and how to reproduce them would be really helpful.

Reply all
Reply to author
Forward
0 new messages