question

David VC avatar image
0 Likes"
David VC asked tannerp edited

How can I count "unique" collisions

Hi

I have following problem:

I have operators which can collide. Now I want to count the number of unique collisions. For example when the operators are loading at the same queue the Collision trigger Will fire several times, but in reality I want to count this as 1 Collision. Is there are a (simple) solution for this problem?

Best Regards

Choose One
collision
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Phil BoBo avatar image
2 Likes"
Phil BoBo answered Gabriel Morgante commented

The objects that can collide have a variable that stores whether they are currently in a collision. This variable is 0 when the collision first occurs. You can use this variable to only increment your counter at the beginning of each collision. Something like this:

double prevcollision = getvarnum(thisobject,"incollision");
if (prevcollision == 0)
	current.collisionCount++;

The "turn to the left" pick option in the Handle Collision trigger shows an example of using this variable.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Gabriel Morgante avatar image Gabriel Morgante commented ·

@phil.bobo

I am new to FlexSim so forgive me if this is a stupid question but how would I implement this code you shared?

I have 3 cranes working in the same frame on my model and I need to count their "unique" collisions as David said. So where should I implement this code so I can create the collision counter on a dashboard?

Thank you!

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Gabriel Morgante commented ·

You put the code into the Handle Collision trigger:

Here's a model showing that code implemented in that trigger. countcranecollisions.fsm

It also shows a Model Documentation dashboard widget that displays the current count on the label.

It also has a Statistics Collector that shows how you can record those values over time and plot them onto a line graph in the dashboard.

2 Likes 2 ·
Gabriel Morgante avatar image Gabriel Morgante Phil BoBo ♦♦ commented ·

@phil.bobo
Phill, my poor english isnt' enough to express how much I thank you... You are the MVP!

0 Likes 0 ·