Loop / Array / Raycast Error

Hey there :smiley:

I hope somebody can help me out with my issue.

I generated a 6x5 Array with the Boolean Values and another 6x5 Array with the Real Values.
Now I know if a spot is empty or not. Also, I know the height of the component.

So I created a while-for-if-else function for sorting the objects by height. After sorting it should look like this: First floor cylinder, second cone, third cube and fourth the weird pyramid.
On the picture I highlighted the spot 23 with the gray cylinder and the gripper moved it to spot 14. Everything ok.
Now look at the output panel: First it said spot 14 is empty, but after moving it is still empty :flushed:
The while loop checks every time at the beginning the new status of the sensors, but it only updates the sensor values, when clearing out the world and loading the project again.
I cannot find a python programming mistake in this, also I had a friend checked my python script.

That is my sorting function:
Question.txt (1.7 KB)

Am I missing something in my python programming?
That would be awesome if someone has a tip for that.

Thank you

Hi DrBro23,

Looks like your Create_Boolean() and Create_real() methods only return the signal value. Thus the Sort_Boolean and Sort_Real variables only contain the value (True / False / None) of the given signal at the time the variable was declared, and since there is no reference to the signal you need to call the function again to get new values.

To help with troubleshooting you should check if the raycast sensors are updating the signal values properly by going to the Signals view and seeing if the boolean values turn On / Off based on the robot sorting actions. If the signals do not update even in the signals view you should check if you have set the raycast sensor behaviour properties correctly. Note that having multiple raycast sensors with short sampling time has a drastic effect on the simulation performance.


1 Like

Hi Este,

Thank you for the tips :blush:
The Boolean signals are changing instantly, when the object gets picked.
So, I moved the python script from the gripper behaviours up to the shelf behaviours.
When picking, it is the same result.
When the first object gets moved and placed to the empty spot, the Boolean value changes to True.
When the next object gets picked the value changes to False; but after placing it to the next spot the Boolean value does not change to True.

My thoughts with the updating is:
When you look in the txt-File, Line 5 and 6. The functions Create_Boolean() and Create_Real() are getting called and assigned to Sort_Boolean and Sort_Real. So due to the while loop it runs the function again and writes the new parameter in the arrays or am I wrong with that?
Because now I changed it to:
Sort_Boolean = Create_Boolean()
Sort_Real = Create_Real()
So first it runs the functions and then assigns it, but still the same result.

Also I tried to create the array in the sort function and then assign the values to the arrays by calling the Create_Boolean() and Create_Real() functions at the beginning of the while loop. Note: I erased the return of the functions.

Hopefully you can help me again :sunglasses:
Sorry for my bad python programming skills :see_no_evil:


Hi DrBro23,

It does not matter if you have a value or reference for Sort_Boolean as long as you always call the Create_Boolean() again after changing the state of the shelf (moving objects from one place to another).

The logic itself seems ok as long as the values are refreshed every time you move something. You should figure out why the signal does not update to True after placing the object. If the Value is not updated in the signals view then there is something wrong with the behavior parameters. If you can’t find the issue then you could send the layout to VC support if you have active maintenance.


1 Like