Skip to content

Commit 4780e06

Browse files
author
Igor Anokhin
committed
python: Servo: add Navio+ support
Add root check Add Navio+ entry and add shield auto choice
1 parent 361cc0e commit 4780e06

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

Python/Servo.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
1-
import sys
21
import time
2+
import os;
33

4-
import navio.pwm
5-
import navio.util
6-
7-
navio.util.check_apm()
4+
import navio.Common.util
5+
import navio.Navio2.RCOutput
6+
import navio.Navio.RCOutput
87

98
PWM_OUTPUT = 0
109
SERVO_MIN = 1.250 #ms
1110
SERVO_MAX = 1.750 #ms
1211

13-
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
14-
pwm.set_period(50)
15-
pwm.enable()
12+
def get_pwm():
13+
if (navio.Common.util.get_navio_version() == "NAVIO2"):
14+
return navio.Navio2.RCOutput(PWM_OUTPUT)
15+
else:
16+
return navio.Navio.RCOutput(PWM_OUTPUT)
17+
18+
if (os.getuid() != 0):
19+
print "Not root. Please, launch like this: sudo python Servo.py"
20+
exit(-1)
21+
22+
navio.Common.util.check_apm()
23+
24+
with get_pwm() as pwm:
25+
pwm.set_period(50)
26+
pwm.enable()
1627

17-
while (True):
18-
pwm.set_duty_cycle(SERVO_MIN)
19-
time.sleep(1)
20-
pwm.set_duty_cycle(SERVO_MAX)
21-
time.sleep(1)
28+
while (True):
29+
pwm.set_duty_cycle(SERVO_MIN)
30+
time.sleep(1)
31+
pwm.set_duty_cycle(SERVO_MAX)
32+
time.sleep(1)

0 commit comments

Comments
 (0)