Jump to content
  • entries
    3
  • comments
    17
  • views
    2,719

Homemade Claw Machine Pt. 2


dogcow

1,164 views

blog-0321895001348591269.jpgOne thing i noticed when connecting the arcade controls, the ground is common but each 5v line coming to the board....but to make the inputs go high,wwhen the button is pressed how do i pull the voltage up on those lines? I couldnt figure it out, so i rewired it so that the pins on the shift register are pulled high, and then when the button is pressed they are pulled low. this made sense, i figured i must be missinng something...

Well I got the arcade stick , button and coin mech connected to the board. So now its time to look at the code, Right now its a bit sluggish to respond to controls. The reason is i am using a simple event loop to handle input. Basically the code looks like this:


LOOP {
FOR ( i = 1 TO 7 ) {
// i is the number of each input line
input_status = READ INPUT i

if ( i = 0 ) {
HANDLE THE EVENT FOR WHAT EVER BUTTON IS PRESSED
}
}
}

hope this makes sense to any non-programmer reading this. The problems with this approach should
be immediately obvious, though.

1) button events are handled in the order they are connected to the board, not in the order of importance

2) if an event handler takes a long time, any inputs that happen while in the event handler routine
get missed

3) any inputs that happen on a pin while checking a another pin get missed. For example lets say we check pin 0 and its high ( inputs on the shift register are pulled up to +5v and brought low when the inputs are in use), so we move on to the next pin, but then pin 0 changes to low, we have to wait until we've checked all the rest of the pins and hope that the button connected to pin 0 is still being pressed when we get back to it.

All of this causes problems mainly causing the program to be slow to respond to input or possibly miss inputs. for something like a coin drop, that could be really bad.

So as an experienced programmer I know the best way to handle this would be to use "interrupts". An interrupt is a function of a microprocessor that interrupts program flow in response to some kind of event. It causes control to be passed to another part of the code which is designated as the "interrupt handler" once this completes the program goes back to where it was before the interrupt was "raised".

The arudino controller has only two interrupt pins, both of which im using for the shift register. furthermore the shift register has no ability to raise an interrupt when the pin status changes. now im starting to understand why they are used for dip switches and not user input, very inefficient.

so someone points me to the MCP23017 which is an I/O expansion IC that works sort of similar to the shift register but is more complex and can raise an interrupt when one of the inputs change.

I havent got one yet, so i continue on with the code for when it arrives. Now the problem with interrupts is bounce, when a switch is thrown it wont go exactly from high to low, it will "bounce" a bit
first, vacillating back from low to high a few times before settling. in the loop (polling) model shown above this doesnt matter, we just make a small delay before reading the input to wait for it to settle down. in an interrupt handler the problem is each one of these will
raise the interrupt, thats no good, 1 coin bounce could cause a bunch of credits on the machine. You dont want to put in a delay because interrupt handlers need to be executed as fast as possible to prevent them from blocking other parts of the code or even blocking other interrupts from firing.

So to fix that you add a capacitor across the switch (which the folks at united textiles have thoughtfully already done for me). Doing a little digging on that problem I came across a tutorial that discussed an inverter chip called a inverting schmitt trigger that will take whatever logical value passed in and invert it. so if you have a high value being pulled low, the schmitt trigger will return 0->1 instead of 1->0

ah ha! that explains why the controls are wired that way, because its how to fix the "bounce " problem
using the microcontroller interrupt. OK things are starting to make sense

6 Comments


Recommended Comments

I have rigged up a lot of different type cranes to accept the feiloli board and its a big pain...i would order the gantry,wires and board from feiloli for about 300 and then put them in some chinese cranes or broken down cranes i picked up at auctions for free....

the problems i had with running one board on another cranes controls where speed.. I don't think any two cranes use same speed motors...

for example look at a toy soldier operating,, when you move joystick the gantry jerks and jumps because the motors are so fast...then look at a toy chest and its a lot slower...so when i put board from toy chest into a toy soldier it gets wild... you can move crane around but when you push drop button and the little music sounds like a bomb dropping it will go all the way and give a error code because it thinkgs the down switch is broken because it timed out..

so when i switch a machine over i have to swap gantry and motherboard so they match speeds with program..

sounds like you are working on some antique cranes so it might not be the case, i can't wait to you get this all figured out so i can just call you and order the "dog cow master crane controller"!!!

ron..

ps..oh yeah,, can you hack the music chip on the cranes?? i had a guy that was gonna do this for me but he dropped the ball.. i wanna be able to change the eprom out with the seasons or plush,,like christmas music at christmas, halloween music(like vincent price laughing), or themed music for different themed plush..
Link to comment
[quote name='ronsidney' timestamp='1348662898']
I have rigged up a lot of different type cranes to accept the feiloli board and its a big pain...i would order the gantry,wires and board from feiloli for about 300 and then put them in some chinese cranes or broken down cranes i picked up at auctions for free....

the problems i had with running one board on another cranes controls where speed.. I don't think any two cranes use same speed motors...

for example look at a toy soldier operating,, when you move joystick the gantry jerks and jumps because the motors are so fast...then look at a toy chest and its a lot slower...so when i put board from toy chest into a toy soldier it gets wild... you can move crane around but when you push drop button and the little music sounds like a bomb dropping it will go all the way and give a error code because it thinkgs the down switch is broken because it timed out..

so when i switch a machine over i have to swap gantry and motherboard so they match speeds with program..

sounds like you are working on some antique cranes so it might not be the case, i can't wait to you get this all figured out so i can just call you and order the "dog cow master crane controller"!!!

ron..

ps..oh yeah,, can you hack the music chip on the cranes?? i had a guy that was gonna do this for me but he dropped the ball.. i wanna be able to change the eprom out with the seasons or plush,,like christmas music at christmas, halloween music(like vincent price laughing), or themed music for different themed plush..
[/quote]

yeah im trying to design a universal replacement
so i will be including external motor speed controls on the board using dials. my guess is all the motors on cranes are controlled using pulse width modulation. i would just have a dial, and then read the setting off tha dial and use that to control the pwm.

also im wondering if there is really a point of having forward/back right/left limit switches, maybe just for diagnostic purposes? i cant figure out why they are really needed. i guess someone could potentially burn out the motors if they wanted to but that seems unlikely and the limit switches seem to cause more trouble when they go bad or something gets stuck in front of them like a cable or something... do you know?

, dont know if i can actually get them manufactured because the microcontroller im using has a decent cost to it, though i hear u can just buy the chip and load it with the program for a dollar or two per chip. not thinking that far ahead. really if i actually get this working i will probably just post it so anyone can copy the design and software.

as for the music,maybe if i had a schematic or something , i am just a hacker with electronics i really never studied my main knowledge is in software
Link to comment
how would the machine know when it was in home position to release the claw then??

i do have cranes with only left and front home prox switches and they work fine,,but I've had a occasion when the joystick would get stuck and it would continually go to say right and the motor would just spin and spin until time ran out because it never knew it was all the way there..

I do know guan shin used to sell a "universal" crane board kit,,you could buy entire gantry, board etc for 250 to build your own crane...i order 2 and rebuilt two Macrown cranes i got that where junk, i had bought them as samples..

ron
Link to comment
good point,also reminds me,sometimes the home pos. needs to be back left , have to make that a option. i tried to contact GS but they dont seem to be in business for $250 i would definitely buy a kit for most of my cranes. unless it used that strong/weak timer system i cant figure that out lol
Link to comment
Hey Dogcow nice work! I cam across this post through a google search as I am looking for some expertise in hacking or controlling a claw / grabber machine. But need to allow people to post commands online that it then performs to try and attempt a toy pick up.

Do you reckon that is something you could do? The user commands will need to come through an existing platform with it's own API.

Let me know best way to get in touch with you
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...