-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add root check Add Navio+ entry and add shield auto choice
- Loading branch information
Igor Anokhin
committed
Dec 21, 2017
1 parent
547a4cf
commit 0d1e765
Showing
1 changed file
with
24 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |