mirror of
https://github.com/apirrone/Open_Duck_Mini_Runtime.git
synced 2025-09-03 03:33:54 +00:00
projector
This commit is contained in:
parent
f74f376a6a
commit
f28a3ad737
3 changed files with 67 additions and 1 deletions
29
mini_bdx_runtime/mini_bdx_runtime/projector.py
Normal file
29
mini_bdx_runtime/mini_bdx_runtime/projector.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
|
||||
PROJECTOR_GPIO = 25
|
||||
|
||||
class Projector:
|
||||
def __init__(self):
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setup(PROJECTOR_GPIO, GPIO.OUT)
|
||||
|
||||
GPIO.output(PROJECTOR_GPIO, GPIO.LOW)
|
||||
self.on = False
|
||||
|
||||
def switch(self):
|
||||
self.on = not self.on
|
||||
|
||||
if self.on:
|
||||
GPIO.output(PROJECTOR_GPIO, GPIO.HIGH)
|
||||
else:
|
||||
GPIO.output(PROJECTOR_GPIO, GPIO.LOW)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
p = Projector()
|
||||
while True:
|
||||
|
||||
p.switch()
|
||||
time.sleep(1)
|
|
@ -8,10 +8,19 @@ import time
|
|||
import pygame
|
||||
import numpy as np
|
||||
|
||||
|
||||
from mini_bdx_runtime.sounds import Sounds
|
||||
from mini_bdx_runtime.antennas import Antennas
|
||||
from mini_bdx_runtime.projector import Projector
|
||||
|
||||
sounds = Sounds(volume=1.0, sound_directory="../mini_bdx_runtime/assets/")
|
||||
antennas = Antennas()
|
||||
|
||||
eyes = Eyes()
|
||||
projector = Projector()
|
||||
hwi = HWI()
|
||||
|
||||
kps = [16] * 14
|
||||
kps = [8] * 14
|
||||
kds = [0] * 14
|
||||
|
||||
hwi.set_kps(kps)
|
||||
|
@ -36,13 +45,29 @@ l_x = 0
|
|||
l_y = 0
|
||||
r_x = 0
|
||||
r_y = 0
|
||||
left_trigger = 0
|
||||
right_trigger = 0
|
||||
while True:
|
||||
X_pressed = False
|
||||
A_pressed = False
|
||||
|
||||
for event in pygame.event.get():
|
||||
l_x = round(_p1.get_axis(0), 3)
|
||||
l_y = round(_p1.get_axis(1), 3)
|
||||
r_x = round(_p1.get_axis(2), 3)
|
||||
r_y = round(_p1.get_axis(3), 3)
|
||||
|
||||
|
||||
right_trigger = np.around((_p1.get_axis(4) + 1) / 2, 3)
|
||||
left_trigger = np.around((_p1.get_axis(5) + 1) / 2, 3)
|
||||
|
||||
if _p1.get_button(0): # A button
|
||||
A_pressed = True
|
||||
|
||||
|
||||
if _p1.get_button(3): # X button
|
||||
X_pressed = True
|
||||
|
||||
# print("l_x", l_x)
|
||||
# print("l_y", l_y)
|
||||
# print("r_x", r_x)
|
||||
|
@ -73,5 +98,14 @@ while True:
|
|||
hwi.set_position("neck_pitch", neck_pitch_pos_rad)
|
||||
|
||||
|
||||
antennas.set_position_left(right_trigger)
|
||||
antennas.set_position_right(left_trigger)
|
||||
|
||||
if X_pressed:
|
||||
sounds.play_random_sound()
|
||||
if A_pressed:
|
||||
projector.switch()
|
||||
|
||||
|
||||
pygame.event.pump() # process event queue
|
||||
time.sleep(1/60)
|
||||
|
|
|
@ -15,6 +15,7 @@ from mini_bdx_runtime.feet_contacts import FeetContacts
|
|||
from mini_bdx_runtime.eyes import Eyes
|
||||
from mini_bdx_runtime.sounds import Sounds
|
||||
from mini_bdx_runtime.antennas import Antennas
|
||||
from mini_bdx_runtime.projector import Projector
|
||||
|
||||
joints_order = [
|
||||
"left_hip_yaw",
|
||||
|
@ -84,6 +85,7 @@ class RLWalk:
|
|||
)
|
||||
|
||||
self.eyes = Eyes()
|
||||
self.projector = Projector()
|
||||
|
||||
self.feet_contacts = FeetContacts()
|
||||
|
||||
|
@ -229,6 +231,7 @@ class RLWalk:
|
|||
|
||||
if X_pressed:
|
||||
self.sounds.play_random_sound()
|
||||
self.projector.switch()
|
||||
|
||||
self.antennas.set_position_left(right_trigger)
|
||||
self.antennas.set_position_right(left_trigger)
|
||||
|
|
Loading…
Reference in a new issue