loading
 
Problems with Calculate_Distance and If_Statement
BE from United States  [1 posts]
2 year
I am surprised that I'm having difficulty with what seem to be very simple modules.  The problems are with the Calculate_Distance and If_Statement.

In the attached robofiles, Calculate_Distance and the If_Statement work as expected in test_dist1.rbo, but do not work as expected in spectra_101.rbo.

In test_dist1.rbo, you click around the image window, and if you draw a long arrow, the screen text says "long", if you draw a short arrow, the screen text says "short".  Great, simple, just as expected.  The length of the arrow is determined by Calculate_Distance, and the test for long vs. short is done with the If_Statement.

In spectra_101.rbo, I attempt to find the area and centroid of a white rectangular blob (those work fine), then I calculate the centroid's deviation from an expected position (does not work) and check that the blob area meets a minimum criteria (does not work).    The deviation always comes back 133.124 regardless of the blob centroid, and the area test fails even though, for example, an area of 5682 is greater than 4000.

I hope I'm not overlooking something simple.

 

test_dist1.robo
program.robo
Steven Gentner from United States  [1446 posts] 2 year
BE,

It is something simple once you realize that the AREA variable is actually an array of areas even if there is only one blob that you are checking. In this case you need to specify the index as in

if area:0 < 4000 then ....

which will fix your particular issue.

Its a subtle point and one that tripped us up a bit too. Just add a ':' and the number next to an array variable to specify a particular value within that array. Note, we use [] to evaluate expressions so something like AREA[0] or AREA(0) does NOT work.

If you check the AREA variable in the Watch_Variables module and scroll to the right you can see the types of all variables. In your case AREA is indeed an array.

Sorry for the confusion!

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index