News for hackers. Stuff that matters.
Re:Show HN: Sorting Two Metric Tons of Lego by jacquesm on Saturday April 29, 2017 @01:48PM (#14227731)
Hopper belt to camera belt is just a speed difference that causes the parts to become nicely spread out (at least, you hope so!), the camera stitches together frames to scan the part so a part larger than a frame can be scanned. Once the end of the part is detected it gets fed into the classifier which returns part id, category and color. Depending on what sort is set up a part then gets pushed into one of 7 bins, these periodically are emptied into larger bins and bags.

If necessary a lot can be pushed through the machine twice for instance to sort parts by length or to pick out sets (that last bit works in theory but in practice there are a lot of problems to overcome because of the limited number of bins to deposit into).

As for the hardware, there is a nifty little camera with a macro lens that connects to the USB port (noname Asian stuff), it has a 10x magnifying lens, a pololu servo/gpio to USB card to drive the relays and a Sainsmart 16 port relay board to drive the solenoids for the air valves.

The software is all in python with a generous amount of help from the people who wrote numpy, opencv, keras and theano.

The error rate is between 3 and 5% depending on how fast I set the machine, there are a number of sources for the errors, obviously classification errors, also sometimes two parts are too close to each other and even if the classifier got them right the airpuff for one pushes the other of the belt as well. To minimize this effect I keep the airpuff super short, on the order of 10 ms, which is about as fast as the solenoids can open and close reliably, but it does mean that if it misses even by a bit there is nothing to be done about it and that part will land in the 'other' bin.

That error rate is still too high but with every run the classification errors go down and that's the main component.

One nasty little problem was that I spaced the puffers too regular in the first iteration which meant that sometimes the parts would line up just so in the order in which they came under the camera so that more than one puffer would be active at once leading to a reduction on pressure and no parts would be pushed off the belt. That was a tricky one!

Re:Show HN: Sorting Two Metric Tons of Lego by aidos on Saturday April 29, 2017 @03:17PM (#14228210)
This is one of the greatest, most HN comments of all time! I'd love to do some hardware stuff but it always seems so inapproachable for a software-only person.

"more than one puffer would be active at once" — sounds like a job for prime numbers!

Re:Show HN: Sorting Two Metric Tons of Lego by jacquesm on Saturday April 29, 2017 @03:23PM (#14228238)
> sounds like a job for prime numbers!

And that's exactly how it was solved. The puffers are now spaced prime distances apart and that took care of that, it would be harder for a longer belt because then you'd start wasting an awful lot of space next to the belt.

Re:Show HN: Sorting Two Metric Tons of Lego by hedgehog on Saturday April 29, 2017 @03:26PM (#14228253)
I think a Golomb ruler would be a good start for spacing.
Re:Show HN: Sorting Two Metric Tons of Lego by jacquesm on Saturday April 29, 2017 @03:31PM (#14228273)
Interesting I had never heard of the term. Thank you for the pointer!
Re:Show HN: Sorting Two Metric Tons of Lego by neonkiwi on Sunday April 30, 2017 @12:11AM (#14230129)
This is an interesting problem. I'm trying to visualize this and I must be thinking about the problem incorrectly; perhaps you can help me wrap my head around it.

Since the pieces fall onto the faster conveyor belt with random spacing, isn't it possible that two consecutive pieces will have the spacing of the puffers they are destined for (within margins), regardless of the puffer placements?

Re:Show HN: Sorting Two Metric Tons of Lego by jacquesm on Sunday April 30, 2017 @12:31AM (#14230167)
The spacing of the conveyor 'traps' is equal, the conveyor belt speeds are a constant. If the puffers are equidistant the chances of overlap are substantially higher than if they don't. Most conveyor traps take only one or two parts along. If there are many more parts they tend to fall in a clump and won't be classified so then there also is no problem.

In the end the error rate went down a lot because of a less predictable spacing. But you are right that if the pieces would fall with random spacings that it would not matter what the distance between the puffer stations would be.

The funny thing is that I spent a lot of time measuring out the vertical spacing on the conveyor in the hopper. If I had done that more sloppily it would have worked better :)

Re:Show HN: Sorting Two Metric Tons of Lego by aws_ls on Monday May 01, 2017 @05:11AM (#14236380)
I had to think for some time on this one. Finally it occurred to me, that the pieces are some x distance apart on an average.

At any snapshot, the pieces are lying with a Gaussian distribution around x multiples along the belt i.e having sigma at x, 2x, 3x,...nx....

So for the bins to not overlap:

1) their width/span-along-the-belt should be lesser than x

2) And they can be placed at x, 3x/2, 5x/2, 7x/2 (i.e. prime multiples of x/2)

Wow! Learnt something useful today. Thank you. :)

Edit: I realize after posting that, my solution won't work! If somebody can explain how the prime thing works will be great. I can imagine, though, that the bin placements should be such that, at any given time the piece is only in front of a single bin. Meaning, no pair of bins should have a distance of x-multiple. I can guess, perhaps heuristics which work well, can be devised. But it will be great to know the mathematical solution for this.

Re:Show HN: Sorting Two Metric Tons of Lego by sprocket on Saturday April 29, 2017 @02:23PM (#14227906)
What is the name of the hardware parts that are connected to the relay? I think you've called them "puffers", but searching on that didn't bring up any results. Are you able to provide a link to where I might purchase a couple?
Re:Show HN: Sorting Two Metric Tons of Lego by jacquesm on Saturday April 29, 2017 @02:41PM (#14228023)
They're simply 12V solenoids with an air valve attached, to that I've run a small 1/8th" tube to a piece of thin copper tubing that's open on one end. Nothing fancy or branded, the air valves are all attached to a manifold that divides the pressure from the compressor across all the valves.

12V on the valve -> air streams out of the corresponding tube.

Re:Show HN: Sorting Two Metric Tons of Lego by sprocket on Saturday April 29, 2017 @08:11PM (#14229510)
Ah, yes; it was the manifold that I was looking at and wondering what it was. Thanks for the explanation!