Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4824

Automation, sensing and robotics • Re: Arcade Claw Machine Automation [SOLVED]

$
0
0
PROGRESS UPDATE:

Qapla'! I am now able to use the Raspberry Pi's GPIO to trigger the coin sensor and also simulate the gantry controls and claw catch button.

https://youtube.com/shorts/AJVe_EAvx9k

Here is my setup: Please pardon the mess...this is just for proof-of-concept. I will tidy everything up once I have everything certain:

Image

The green bank of relays are to block local playback inputs while a remote player is playing. The blue bank of relays simulate local inputs by "shorting" the runs going into the main board by connecting them to ground.

Here is the code I'm using:

Code:

import RPi.GPIO as GPIOimport pygameimport sysimport timefrom threading import TimerGPIO.setwarnings(False)GPIO.setmode(GPIO.BCM)prize_pin = 2GPIO.setup(prize_pin,GPIO.IN)blocking_relay = 3GPIO.setup(blocking_relay,GPIO.OUT)GPIO.output(blocking_relay,GPIO.LOW) #ensures default statecoin_drop = 4GPIO.setup(coin_drop,GPIO.OUT) GPIO.output(coin_drop,GPIO.HIGH) #ensures default statecatch_button = 17GPIO.setup(catch_button,GPIO.OUT)GPIO.output(catch_button,GPIO.HIGH) #ensures default statejoystick_up = 27GPIO.setup(joystick_up,GPIO.OUT)GPIO.output(joystick_up,GPIO.HIGH) #ensures default statejoystick_down = 22GPIO.setup(joystick_down,GPIO.OUT)GPIO.output(joystick_down,GPIO.HIGH) #ensures default statejoystick_left = 10GPIO.setup(joystick_left,GPIO.OUT)GPIO.output(joystick_left,GPIO.HIGH) #ensures default statejoystick_right = 9GPIO.setup(joystick_right,GPIO.OUT)GPIO.output(joystick_right,GPIO.HIGH) #ensures default statedisplay = pygame.display.set_mode((300, 300))pygame.init()# block spurious inputs credit = Falsecatching = Falsedirections = {"up": False,"down": False,"left": False,"right": False}def end_game():global creditglobal catchingGPIO.output(coin_drop,GPIO.LOW) #reset to default stateGPIO.output(blocking_relay,GPIO.LOW) #reset to default statecredit = Falsecatching = Falseprint("Game Over!")try:while True:for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()GPIO.cleanup()sys.exit()if event.type == pygame.KEYDOWN:if event.key == pygame.K_RETURN:if not credit:credit = TrueGPIO.output(blocking_relay,GPIO.HIGH) #turn on relay to block local playback inputstime.sleep(50/1000.0)GPIO.output(coin_drop,GPIO.HIGH)time.sleep(50/1000.0) #trick the coin sensor with a pulseGPIO.output(coin_drop,GPIO.LOW)timer = Timer(40,end_game)timer.start()print("CREDIT!")if credit:if not catching:if event.key == pygame.K_UP:if not directions["up"]:directions["up"] = TrueGPIO.output(joystick_up,GPIO.LOW)print("UP Keyboard Arrow Pressed")if event.key == pygame.K_DOWN:if not directions["down"]:directions["down"] = TrueGPIO.output(joystick_down,GPIO.LOW)print("DOWN Keyboard Arrow Pressed")if event.key == pygame.K_LEFT:if not directions["left"]:directions["left"] = TrueGPIO.output(joystick_left,GPIO.LOW)print("LEFT Keyboard Arrow Pressed")if event.key == pygame.K_RIGHT:if not directions["right"]:directions["right"] = TrueGPIO.output(joystick_right,GPIO.LOW)print("RIGHT Keyboard Arrow Pressed")if event.key == pygame.K_SPACE:catching = Truetimer.cancel()timer = Timer(15,end_game)timer.start()GPIO.output(catch_button,GPIO.LOW)time.sleep(50/1000.0)GPIO.output(catch_button,GPIO.HIGH)print("CATCH!")if event.type == pygame.KEYUP:if event.key == pygame.K_UP:if directions["up"]:directions["up"] = FalseGPIO.output(joystick_up,GPIO.HIGH)print("UP Keyboard Arrow Released")if event.key == pygame.K_DOWN:if directions["down"]:directions["down"] = FalseGPIO.output(joystick_down,GPIO.HIGH)print("DOWN Keyboard Arrow Released")if event.key == pygame.K_LEFT:if directions["left"]:directions["left"] = FalseGPIO.output(joystick_left,GPIO.HIGH)print("LEFT Keyboard Arrow Released")if event.key == pygame.K_RIGHT:if directions["right"]:directions["right"] = FalseGPIO.output(joystick_right,GPIO.HIGH)print("RIGHT Keyboard Arrow Released")except KeyboardInterrupt:GPIO.cleanup()

My next steps will be to create a web interface for the controls. I already have the web server up-and-running (apache2), and I'm currently investigating how I will get a live video feed from within the cabinet itself; at least one with an orthogonal view of the interior of the cabinet, and perhaps another mounted directly onto the claw gimbal pointing face-down into the prize bin to assist with aiming.

In the meantime, thanks again to everyone for your help, feedback, and interest in my little project here! :D

Statistics: Posted by lincolnberryiii — Fri Mar 01, 2024 3:06 pm



Viewing all articles
Browse latest Browse all 4824

Trending Articles