-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleservo.py
More file actions
45 lines (34 loc) · 727 Bytes
/
simpleservo.py
File metadata and controls
45 lines (34 loc) · 727 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import time
from lx16a import LX16A
# Setup:
try:
LX16A.initialize("/dev/ttyUSB0")
except Exception as e:
print("Initialisation ERROR")
print(e)
quit()
motor1 = LX16A(1)
motor2 = LX16A(2)
motor1.enable_torque()
motor1.servo_mode()
motor2.enable_torque()
motor2.servo_mode()
# Main loop:
try:
while True:
angle = motor1.get_physical_angle()
time.sleep(0.05)
print(f"angle: {angle:.2f}")
motor1.move(240)
time.sleep(1)
motor2.move(240)
time.sleep(2)
angle = motor1.get_physical_angle()
time.sleep(0.05)
print(f"angle: {angle:.2f}")
motor1.move(0)
time.sleep(1)
motor2.move(0)
time.sleep(2)
except KeyboardInterrupt:
print("Program stopped.")