ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Other Software > Developer's Corner

Dice analyzer machine project

<< < (15/19) > >>

mouser:
Here's something cool.. I ran the autoclusterer function on a D20, and was unpleasantly surprised to see it was mistakenly creating two clusters of the 19 face..
Then i studied the die images closer and realized that the "18" label is worn off to make it look like a "19", and in fact the clusterer HAD successfully distinguished the two very similar looking sides:

The topmost cluster is the worn-out "18" side:


You can see how it looks on the die here:


Pretty cool!

mouser:
For those who might be curious, here is how i wired up the Arduino and Dice Roller:

First, as I posted here, I ordered a $10 battery (2xAA) powered dice spinner from Amazon.  You push a button and the base spins for a second or so, throwing the dice out to the edge where it tumbles against a sloped incline; the friction of the base and the angle of the edge seems to do quite a good job of randomly spinning dice of various shapes.

Next, I got an Arduino (R3) and a Sainsmart single channel Relay. A relay is a switch that allows an external source of power through it when it is closed.
I soldered an additional (parallel) connection from battery to motor through the relay -- basically acting as a parallel way to complete the circuit that the existing button on the device provides.  Now you can push the button to spin the dice, OR activate the relay.

Next a tiny script(sketch) was written for the Arduino, which just loops and listens to serial (usb) connection for a simple signal telling it to spin the die for a certain amount of time.  When the signal arrives, it turns on the relay (a simple command to the pin on the Arduino that drives the relay) briefly, and then turns it off.

Next, my python dice control code uses the PySerial library to send the signal to the Arduino when it wants the dice rolled.  The script already has code that notices when the dice are moving, and waits until they settle before performing another cycle of processing, so everything proceeds automatically once they die settles.

It can perform a roll and visual processing of a die about once every 1.5 seconds.

Complications:
The only real complication I've had is that the Arduino seems to sometimes loose connection with the serial communication. So my code has to check that the Arduino confirms it has received the command, and if not, occasionally disconnect and reconnect.  This works most of the time but occasionally the Arduino just won't wake up and requires a hardware reset.  This would not be acceptable for a setup that required a high-level of uptime, but for this project it's not a show stopper.

Deozaan:
Then i studied the die images closer and realized that the "18" label is worn off to make it look like a "19", and in fact the clusterer HAD successfully distinguished the two very similar looking sides

Pretty cool!
-mouser (February 24, 2016, 11:27 PM)
--- End quote ---

That is pretty cool. It's a case where human error may have mistaken the die value as a "19" but the computer was able to distinguish the subtle differences.  :Thmbsup:

Ath:
I have ordered raspberry pi and motor control hat and ...
-mouser (February 08, 2016, 04:42 PM)
--- End quote ---
Why didn't you use that motor control hat to turn on the dice-roller? Or doesn't it have a relay for switching something external? (probably depends on the model, but a separate relay-hat isn't that expensive) Your python code on the RPi can then directly control the dice-roller without further external devices.

mouser:
Why didn't you use that motor control hat to turn on the dice-roller? Or doesn't it have a relay for switching something external? (probably depends on the model, but a separate relay-hat isn't that expensive) Your python code on the RPi can then directly control the dice-roller without further external devices.
--- End quote ---

Excellent question.

My original plan was to run the dicer software on the standalone Raspberry Pi as planned, and have the motor hat on the Raspberry Pi directly drive the motor in the dicer roller (or indeed a better replacement motor).

There were three reasons I did not go forward with this plan:

* The first was that the Raspberry Pi is 30x slower than my PC, and my recognition code is quite slow (I need to find ways to be more clever and take a less brute force approach to image rotation alignment).  Because of this I wanted to go back to doing most of my development at least on my desktop PC.
* The second was that the camera on the Raspberry Pi, while high resolution, has absolutely no focus control and would not focus well on anything shorter than about 24 inches from it.  This caused real trouble and I tried a bunch of kludges to fix this including misc. lens and even reading glass lenses, etc.  But I just couldnt get something working reliably.  It's really a shame the RPi camera doesnt have a focus ring.  Trying to use a standard webcam on Rpi was untsable/unsatisfactory.
* The third was that I wanted to do minimal surgery on the $10 die roller that was made in China but shipped from Germany, because if I messed it up, it would be another month before I got a replacement.  And I wanted to still be able to engage it manually.
So right now I'm actually controlling the Arduino from my DESKTOP (windows) python code.  The Raspberry Pi version of the software can also control it (Raspberry Pi controlling an Arduino is kind of like a Turducken, but it does work).

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version