Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,

I have to measure a pallet full of pet food bags.
That pallet will travel along the X axis at a constant speed.
That pallet could not be perfectly aligned (slightly rotated).
I have been given 1 array of 100 sensors that is placed along the Y axis (perpendicular to the pallet movement).
There are 25mm between those sensors.
Each sensor emits a straight light beam, if nothing intercepts the beam I have a 0 from that sensor, if something intercepts the beam I have a 1 from that sensor.
Pallet will travel (in the X axis) across the sensors array (in the Y axis).

After the pallet travels from any point before getting under the sensors array to any point after the sensors array I will have an array full of data:

a[i].X (time based).
a[i].Y[j] (the active sensors, j goes from 1 to 100).

That data set should define the area occupied by the pallet (see x's in the next image) and the area occupied by badly placed bags in the pallet (see y's in the next "image").

  ________yy____
y|xxxxxxxxxxxxxx|
y|xxxxxxxxxxxxxx|
 |xxxxxxxxxxxxxx|y
 |xxxxxxxxxxxxxx|y
  ---yyy-------- 


At this point I need to find the best fitted rectangle for the x's points and the best fitted rectangle for the y's points.
After getting those two rectangles I should be able to get the differences between them, to know where (sides) food bags are placed incorrectly (and the maximum differences).

Any idea where I could find information and examples on how to solve this?

As always thank you in advance.

What I have tried:

Nothing, just trying to understand the issue, searching the Internet for alternatives and examples, but I am not being lucky finding them.
Posted
Updated 28-Feb-22 19:11pm
Comments
Richard MacCutchan 28-Feb-22 11:00am    
"Any idea where I could find information and examples on how to solve this?"
Within your brain. Seriously, this task has been set to get you to think about the issue and devise a solution. It is not designed to test your skill at using Google. So think about how the pallet travels, and which sensors will fire as it does so. From that you should be able to create an array of 1s and 0s. All of which should lead you to a solution.
Joan M 28-Feb-22 11:23am    
Thanks Richard... but in fact this is not homework, is about a customer that has no time nor knowledge to solve this and decided to contact me to help them as I have helped them in the past.
Clearly maths involved here are much more complicated than what I can do now... Years without doing this kind of things let the knowledge rust.
Google is not taking me to any good place and as I said my knowledge on this is not good enough now.
I can design and implement everything else, but I can't get the calculations done.
I thought, maybe in a community of 15M of developers some could lead me to the right place to get information (which is not my brain) :)
Richard MacCutchan 28-Feb-22 11:28am    
My apologies, but the question read just the same as most homework questions posted here. Like you my maths is rusty, but I would guess that given the speed of the pallet and the distance between sensors it should be possible to calculate the rectangle.
Joan M 28-Feb-22 11:34am    
Yes, it's really like those questions :D:D:D:D:D
Gosh, I'd love going back to the university, there a guy/girl explained you what he/she would ask you in the exam... sadly this never happens in real life...
Real life is more like bad specs, tight timelines, crazy customers and lately impossible to schedule calendars...
RedDk 28-Feb-22 13:30pm    
Is this that Calculus 101 problem that optimizes the volume of a container having dimensions width x height x length and given a flat piece of real estate (for the sake of IEEE engineers out there, in all fields, everywhere, including aliens from outer space who construct things out of unobtainium, which is not recognizable as feasible to earthlings) ... I leave the MATERIAL ______________ (blank)?

Then no. I have no idea how to run through the Riemann (pronounced as in Syngman Rhee) Sum, delta, epsilon approximation, limit producing solution.

But I could look up how to do that.

If I understand you correctly the sensor array can't discern bags and pallet, all you get is a matrix with zeroes and ones (representing "something" and "nothing").

If all the bags are within the bounds of the pallet, and assuming the pallet is rectangular, then the image will look very much like a rectangle.

What I would do is collect your matrix, then calculate its "convex hull" (Google!).
Ideally the hull would have four edges and be a rectangle, matching the pallet.
But poorly stacked pallets as well as discretization errors, will cause deviations.
Once you have the hull, the following pseudo-C# code could be used to check whether the image fits a pallet or not:

pseudo
bool palletOK=false
foreach(edge E of convex hull) {
    if (edge is very short with respect to pallet) continue
    bool goodEdge=true
    // width check
    foreach(point P of convex hull) {
        calculate orthogonal projection of P on (infinite line through) E
        if {orthogonal distance is > pallet width) goodEdge=false
    }
    // length check
    foreach(point P of convex hull) {
        calculate orthogonal projection of P on E
        identify first and last projected point on E
    }
    if (distance between first & last pt on E > length of pallet) goodEdge=false
    if (goodEdge) palletOK=true
}


What that code does is assume some edge E matches a long side of the pallet, and check if it is stacked properly then.

Notes:
- you can shortcircuit some of the code (as soon as goodEdge goes false, go test the next edge; and as soon as palltOK is true you're done)
- You may want to allow some tolerance (e.g. one sensor pitch) when comparing distances.
- Calculating a distance or a projection takes a little math, once again make Google your friend.
 
Share this answer
 
v8
Quote:
Where could I find information and examples to get the best fitting rectangle given a set of points?

The answer is always the same: you find information in your brain.
- Once you have the sensors data, how do you make it a 2D matrix ?
- How are you solving the problem by hand ?
- How are you doing it, what is your algorithm ?
- How to translate to code ?

first, you know that the solution is within the 2D matrix.
Then, how to reduce the area til only the pallet remains.
Quote:
a[i].X (time based).
a[i].Y[j] (the active sensors, j goes from 1 to 100).

Why do you need "a[i].X" ?
As far as i understand, you don't need it. "i" is enough to tell the time. You need a simple 2D array.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900