Skip to content

Commit b3779ae

Browse files
author
Igor Anokhin
committed
python: Servo: add Navio+ support
Add root check Add Navio+ entry and add shield auto choice
1 parent 4f1e4b1 commit b3779ae

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

Python/Servo.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
1-
import sys
21
import time
2+
import os
33

4-
import navio.pwm
5-
import navio.util
4+
import navio.Common.util
65

7-
navio.util.check_apm()
6+
if navio.Common.util.get_navio_version() == "NAVIO2":
7+
import navio.Navio2.RCOutput as RCOutput
8+
else:
9+
import navio.Navio.RCOutput as RCOutput
810

11+
SERVO_MIN = 1.250 # ms
12+
SERVO_MAX = 1.750 # ms
913
PWM_OUTPUT = 0
10-
SERVO_MIN = 1.250 #ms
11-
SERVO_MAX = 1.750 #ms
1214

13-
with navio.pwm.PWM(PWM_OUTPUT) as pwm:
14-
pwm.set_period(50)
15-
pwm.enable()
15+
if (os.getuid() != 0):
16+
print "Not root. Please, launch like this: sudo python Servo.py"
17+
exit(-1)
1618

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)
19+
navio.Common.util.check_apm()
20+
21+
with RCOutput(PWM_OUTPUT) as pwm:
22+
pwm.set_period(50)
23+
pwm.enable()
24+
25+
while (True):
26+
pwm.set_duty_cycle(SERVO_MIN)
27+
time.sleep(1)
28+
pwm.set_duty_cycle(SERVO_MAX)
29+
time.sleep(1)

0 commit comments

Comments
 (0)