Last active
August 29, 2015 14:12
-
-
Save gustafsson/d178b4ce431406e50328 to your computer and use it in GitHub Desktop.
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
mypi |
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
#!/bin/bash | |
set -e | |
if [ ! -f mypi ]; then | |
echo 'Create a file named "mypi" with the user name and ip adress of your pi. Like pi@192.168.0.21' | |
false | |
fi | |
mypi=$(cat mypi) | |
scp piservo.py ${mypi}:~/dev/piservo | |
ssh ${mypi} 'cd ~/dev/piservo;sudo python piservo.py' |
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
#sudo apt-get install python-setuptools | |
#easy_install -U RPIO | |
import time | |
from RPIO import PWM | |
servo = PWM.Servo() | |
#min 600, max 2500 | |
#servo.set_servo(18, 2500) | |
#delay_period = 0.02 | |
delay_period = 0.035 | |
while True: | |
for angle in range(7, 24): | |
#servo.set_servo(18, (31-angle)*100) | |
servo.set_servo(18, angle*100) | |
time.sleep(delay_period) | |
for angle in range(7, 24): | |
servo.set_servo(18, (31-angle)*100) | |
time.sleep(delay_period) |
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
#sudo apt-get install python-setuptools | |
#easy_install -U RPIO | |
import time | |
import datetime as dt | |
n1=dt.datetime.now() | |
from RPIO import PWM | |
servo = PWM.Servo() | |
#min 600, max 2500 | |
#servo.set_servo(18, 2500) | |
#delay_period = 0.02 | |
delay_period = 0.035 | |
def angle_t( a ): | |
min_a = 0 | |
max_a = 160 | |
min_t = 1000 | |
max_t = 2000 | |
if a < min_a: | |
a = min_a | |
if a > max_a: | |
a = max_a | |
return (a-min_a)/(max_a-min_a)*(max_t-min_t) + min_t; | |
def elasped_since_start(): | |
n2=dt.datetime.now() | |
return (n2-n1).microseconds/1e6 | |
def set_servo_angle(a): | |
t = angle_t(a) | |
print "Angle: " + repr(a) + ", pulse width = " + repr(t) + " us" | |
servo.set_servo(18, t) | |
while elasped_since_start()<1: | |
set_servo_angle(0) | |
#while elasped_since_start()<2: | |
# set_servo_angle(160) | |
#for a in range(0, 1600): | |
# set_servo_angle(a/10) | |
#for a in range(1600, 0, -1): | |
# set_servo_angle(a/10) |
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
import RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(18, GPIO.OUT) | |
pwm = GPIO.PWM(18, 100) | |
pwm.start(5) | |
def set_angle(angle): | |
if angle<20: | |
angle=20 | |
if angle>90: | |
angle=90 | |
duty = float(angle) / 10.0 + 2.5 | |
pwm.ChangeDutyCycle(duty) | |
set_angle(0) | |
time.sleep(1) | |
set_angle(180) | |
time.sleep(1) | |
#def elasped_since_start(): | |
# n2=dt.datetime.now() | |
# return (n2-n1).microseconds/1e6 | |
#class App: | |
pwm.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment