Skip to content

Commit 03f059f

Browse files
...
1 parent 8083f0e commit 03f059f

2 files changed

Lines changed: 40 additions & 36 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ KIDA uses the V2 robot Hat from the [Freenove Tank Robot](https://github.com/Fre
162162
|-------------|----------|
163163
| Servo0 | 12 |
164164
| Servo1 | 13 |
165+
| Servo1 | 19 |
165166

166167
---
167168

scripts/tests/servo_test.py

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,49 @@
1-
#!/usr/bin/env python3
2-
31
from gpiozero import Servo
42
from time import sleep
53

64
# Hardware Configuration
7-
SERVO0_PIN = 12
8-
SERVO1_PIN = 13
5+
# Updated to include the new GPIO 19
6+
PINS = [12, 13, 19]
7+
servos = []
98

10-
# Initialize Servos
11-
# We use a standard pulse width range (min=1ms, max=2ms)
12-
servo0 = Servo(SERVO0_PIN)
13-
servo1 = Servo(SERVO1_PIN)
9+
print("--- KIDA Triple Servo Initialization ---")
1410

15-
def test_sweep(servo_obj, name):
16-
print(f"--- Testing {name} ---")
17-
18-
print("Moving to MIN position...")
19-
servo_obj.min()
20-
sleep(1)
21-
22-
print("Moving to MID position...")
23-
servo_obj.mid()
24-
sleep(1)
25-
26-
print("Moving to MAX position...")
27-
servo_obj.max()
28-
sleep(1)
29-
30-
print("Returning to MID...")
31-
servo_obj.mid()
32-
sleep(0.5)
11+
for pin in PINS:
12+
try:
13+
servos.append(Servo(pin))
14+
print(f"✅ Servo initialized on GPIO {pin}")
15+
except Exception as e:
16+
print(f"❌ Failed to initialize GPIO {pin}: {e}")
3317

34-
try:
35-
print("Starting Servo Test...")
36-
test_sweep(servo0, "Servo 0 (Pin 12)")
37-
test_sweep(servo1, "Servo 1 (Pin 13)")
38-
print("Test Complete!")
18+
def sweep_test():
19+
try:
20+
while True:
21+
for i, s in enumerate(servos):
22+
pin_num = PINS[i]
23+
print(f"\nTesting Servo on Pin {pin_num}")
24+
25+
print(" Moving to MIN...")
26+
s.min()
27+
sleep(0.8)
28+
29+
print(" Moving to MAX...")
30+
s.max()
31+
sleep(0.8)
32+
33+
print(" Centering...")
34+
s.mid()
35+
sleep(0.5)
36+
37+
print("\n--- Cycle Complete. Restarting in 2s... ---")
38+
sleep(2)
3939

4040
except KeyboardInterrupt:
41-
print("\nTest stopped by user.")
42-
41+
print("\nStopping tests...")
4342
finally:
44-
# Cleanup
45-
servo0.value = None
46-
servo1.value = None
43+
# Release the pins
44+
for s in servos:
45+
s.value = None
46+
print("Cleanup complete.")
47+
48+
if __name__ == "__main__":
49+
sweep_test()

0 commit comments

Comments
 (0)