Created
April 4, 2018 20:03
-
-
Save mirwox/a8b63c7bb55005f8be76e5c00c3c5bde to your computer and use it in GitHub Desktop.
Teste para o servo nos Turtlebot3 do Insper
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
#Controle de servo no Raspberry Pi | |
#Autor: Simon Monk | |
import RPi.GPIO as GPIO | |
import time | |
servo_pin = 18 | |
angulo = 45 | |
#Ajuste estes valores para obter o intervalo completo do movimento do servo | |
deg_0_pulse = 0.5 | |
deg_180_pulse = 2.5 | |
f = 50.0 | |
# Faca alguns calculos dos parametros da largura do pulso | |
period = 1000/f | |
k = 100/period | |
deg_0_duty = deg_0_pulse*k | |
pulse_range = deg_180_pulse - deg_0_pulse | |
duty_range = pulse_range * k | |
#Iniciar o pino gpio | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(servo_pin,GPIO.OUT) | |
pwm = GPIO.PWM(servo_pin,f) | |
pwm.start(0) | |
def set_angle(angle): | |
duty = deg_0_duty + (angle/180.0)* duty_range | |
pwm.ChangeDutyCycle(duty) | |
try: | |
print("definindo angulo para 45") | |
set_angle(angulo) | |
time.sleep(3) | |
finally: | |
print("cleaning up") | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment