mirror of
https://github.com/apirrone/Open_Duck_Mini_Runtime.git
synced 2025-09-02 19:23:54 +00:00
antennas test
This commit is contained in:
parent
f99abfc078
commit
5a8b057019
2 changed files with 13 additions and 15 deletions
|
@ -1,4 +1,5 @@
|
|||
import RPi.GPIO as GPIO
|
||||
import numpy as np
|
||||
import time
|
||||
|
||||
LEFT_ANTENNA_PIN = 13
|
||||
|
@ -6,6 +7,7 @@ RIGHT_ANTENNA_PIN = 12
|
|||
LEFT_SIGN = 1
|
||||
RIGHT_SIGN = -1
|
||||
|
||||
|
||||
class Antennas:
|
||||
def __init__(self):
|
||||
|
||||
|
@ -28,7 +30,6 @@ class Antennas:
|
|||
def set_position_right(self, position):
|
||||
self.set_position(2, position, RIGHT_SIGN)
|
||||
|
||||
|
||||
def set_position(self, servo, value, sign=1):
|
||||
"""
|
||||
Moves the servo based on an input value in the range [-1, 1].
|
||||
|
@ -57,15 +58,13 @@ class Antennas:
|
|||
self.pwm2.stop()
|
||||
GPIO.cleanup()
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# servo_control = Antennas()
|
||||
|
||||
# try:
|
||||
# while True:
|
||||
# servo_num = int(input("Enter servo number (1 or 2): "))
|
||||
# value = float(input("Enter position (-1 to 1): "))
|
||||
# servo_control.set_position(servo_num, value)
|
||||
if __name__ == "__main__":
|
||||
antennas = Antennas()
|
||||
|
||||
# except KeyboardInterrupt:
|
||||
# print("Stopping servos...")
|
||||
# servo_control.stop()
|
||||
s = time.time()
|
||||
while True:
|
||||
antennas.set_position_left(np.sin(2 * np.pi * 1 * time.time()))
|
||||
antennas.set_position_right(np.sin(2 * np.pi * 1 * time.time()))
|
||||
|
||||
time.sleep(1 / 50)
|
||||
|
|
|
@ -8,12 +8,11 @@ antennas = Antennas()
|
|||
|
||||
|
||||
while True:
|
||||
_, _, _, left_trigger, right_trigger = (
|
||||
controller.get_last_command()
|
||||
)
|
||||
|
||||
_, _, left_trigger, right_trigger = controller.get_last_command()
|
||||
|
||||
antennas.set_position_left(right_trigger)
|
||||
antennas.set_position_right(left_trigger)
|
||||
|
||||
# print(left_trigger, right_trigger)
|
||||
time.sleep(1/50)
|
||||
time.sleep(1 / 50)
|
||||
|
|
Loading…
Reference in a new issue