Skip to content

Commit

Permalink
python: Servo: add Navio+ support
Browse files Browse the repository at this point in the history
Add root check
Add Navio+ entry and add shield auto choice
  • Loading branch information
Igor Anokhin committed Dec 21, 2017
1 parent 361cc0e commit 4780e06
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions Python/Servo.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import sys
import time
import os;

import navio.pwm
import navio.util

navio.util.check_apm()
import navio.Common.util
import navio.Navio2.RCOutput
import navio.Navio.RCOutput

PWM_OUTPUT = 0
SERVO_MIN = 1.250 #ms
SERVO_MAX = 1.750 #ms

with navio.pwm.PWM(PWM_OUTPUT) as pwm:
pwm.set_period(50)
pwm.enable()
def get_pwm():
if (navio.Common.util.get_navio_version() == "NAVIO2"):
return navio.Navio2.RCOutput(PWM_OUTPUT)
else:
return navio.Navio.RCOutput(PWM_OUTPUT)

if (os.getuid() != 0):
print "Not root. Please, launch like this: sudo python Servo.py"
exit(-1)

navio.Common.util.check_apm()

with get_pwm() as pwm:
pwm.set_period(50)
pwm.enable()

while (True):
pwm.set_duty_cycle(SERVO_MIN)
time.sleep(1)
pwm.set_duty_cycle(SERVO_MAX)
time.sleep(1)
while (True):
pwm.set_duty_cycle(SERVO_MIN)
time.sleep(1)
pwm.set_duty_cycle(SERVO_MAX)
time.sleep(1)

0 comments on commit 4780e06

Please sign in to comment.