Compare commits

...

7 Commits

Author SHA1 Message Date
47fc81eab1 a 2024-12-28 20:17:25 +01:00
e7e2be6c6a a 2024-12-28 20:16:44 +01:00
573a15ffdc a 2024-12-28 20:15:35 +01:00
9defed0f3e a 2024-12-28 20:08:21 +01:00
5584b058db a 2024-12-28 20:04:42 +01:00
9efa31daf8 a 2024-12-28 20:03:55 +01:00
064fc6befa a 2024-12-28 19:55:12 +01:00

View File

@@ -9,7 +9,7 @@ from adafruit_servokit import ServoKit # type: ignore
kit = ServoKit(channels=16) kit = ServoKit(channels=16)
# Constants for delay # Constants for delay
DELAY = 0.25 DELAY = 0.15
# Servo angle configurations # Servo angle configurations
FORWARD = { FORWARD = {
@@ -27,7 +27,22 @@ FORWARD = {
11: (110, 10, 90), 11: (110, 10, 90),
} }
ROTATE_RIGHT = { # Placeholder, update values later BACK = {
0: (0, 110, 70),
1: (0, 110, 70),
2: (0, 110, 70),
3: (0, 110, 70),
4: (0, 110, 70),
5: (0, 110, 70),
6: (110, 10, 90),
7: (120, 10, 65),
8: (170, 70, 90),
9: (70, 170, 90),
10: (10, 120, 65),
11: (10, 110, 90),
}
ROTATE_RIGHT = {
0: (0, 110, 70), 0: (0, 110, 70),
1: (0, 110, 70), 1: (0, 110, 70),
2: (0, 110, 70), 2: (0, 110, 70),
@@ -42,19 +57,19 @@ ROTATE_RIGHT = { # Placeholder, update values later
11: (10, 170, 90), 11: (10, 170, 90),
} }
ROTATE_LEFT = { # Placeholder, update values later ROTATE_LEFT = {
0: (0, 110, 70), 0: (0, 110, 70),
1: (0, 110, 70), 1: (0, 110, 70),
2: (0, 110, 70), 2: (0, 110, 70),
3: (0, 110, 70), 3: (0, 110, 70),
4: (0, 110, 70), 4: (0, 110, 70),
5: (0, 110, 70), 5: (0, 110, 70),
6: (10, 110, 90), 6: (170, 10, 90),
7: (10, 120, 65), 7: (120, 10, 65),
8: (70, 170, 90), 8: (170, 10, 90),
9: (170, 70, 90), 9: (170, 10, 90),
10: (120, 10, 65), 10: (120, 10, 65),
11: (110, 10, 90), 11: (170, 10, 90),
} }
# Movement functions # Movement functions
@@ -71,7 +86,7 @@ def move_leg(servo1, servo2, servo_angles):
time.sleep(DELAY) time.sleep(DELAY)
kit.servo[servo2].angle = back kit.servo[servo2].angle = back
time.sleep(DELAY) time.sleep(DELAY*2)
kit.servo[servo1].angle = up kit.servo[servo1].angle = up
time.sleep(DELAY) time.sleep(DELAY)
@@ -129,7 +144,7 @@ def is_input_available():
# Main execution # Main execution
if __name__ == "__main__": if __name__ == "__main__":
print("Press 'w' for FORWARD, 'a' for LEFT, 'd' for RIGHT. Press 'q' to quit.") print("Press 'w' for FORWARD, 'a' for LEFT, 'd' for RIGHT, 's' for BACK. Press 'q' to quit.")
command_queue = queue.Queue() command_queue = queue.Queue()
@@ -137,7 +152,7 @@ if __name__ == "__main__":
while True: while True:
if is_input_available(): if is_input_available():
input_char = sys.stdin.read(1).strip() input_char = sys.stdin.read(1).strip()
if input_char in ['w', 'a', 'd']: if input_char in ['w', 'a', 'd', 's']:
command_queue.put(input_char) command_queue.put(input_char)
elif input_char == 'q': elif input_char == 'q':
print("Exiting...") print("Exiting...")
@@ -157,7 +172,11 @@ if __name__ == "__main__":
print("Executing RIGHT movement...") print("Executing RIGHT movement...")
group_1(ROTATE_RIGHT) group_1(ROTATE_RIGHT)
group_2(ROTATE_RIGHT) group_2(ROTATE_RIGHT)
elif command == 's':
print("Executing BACK movement...")
group_1(BACK)
group_2(BACK)
time.sleep(0.1) # Idle loop time.sleep(0.1) # Idle loop
except KeyboardInterrupt: except KeyboardInterrupt:
print("\nProgram terminated.") print("\nProgram terminated.")