def Move_Servo(): servo = Servo(26) servo.max() sleep(.5) servo.min() sleep(.25) servo.max()
def main(): myCorrectionMin=0.3 myCorrectionMax=0.275 maxPW=(2.0+myCorrectionMax)/1000 minPW=(1.0-myCorrectionMin)/1000 servo = Servo(PIN_A,min_pulse_width=minPW,max_pulse_width=maxPW) #servo = Servo(PIN_A) i = 0 while i in range(0,3): servo.mid() print("mid") sleep(0.5) servo.min() print("min") sleep(1) servo.mid() print("mid") sleep(0.5) servo.max() print("max") sleep(1) servo.mid() i+=1
def main(): stream = StreamListener.createStream() stream.filter("Google Yahoo", async=True) # build a recognizer and load it up with terms rec = aiy.cloudspeech.get_recognizer() rec.expect_phrase('min') rec.expect_phrase('max') rec.expect_phrase('mid') # start listening aiy.audio.get_recorder().start() # setup servo 0 servo = Servo(26) # setup the button but = aiy.voicehat.get_button() # the led for the button led = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(led, GPIO.OUT) # one time init message printed to console and said through speaker print("initializing system") say("initializing system") sleep(1) # wait for one second while True: say("press button and say min, max or mid to control servo") GPIO.output(led, GPIO.HIGH) print("press button to command servo") but.wait_for_press() print("listening") text = rec.recognize() if text is None: GPIO.output(led, GPIO.LOW) say("That is not a valid command!") else: text = text.lower() GPIO.output(led, GPIO.HIGH) if 'min' in text: say("min") print("min") servo.min() elif 'max' in text: say("max") print("max") servo.max() elif 'mid' in text: say("mid") print("mid") servo.mid() else: say("i'm sorry i heard, " + text + " which is not a valid command") print("i'm sorry i heard, " + text + " which is not a valid command") GPIO.output(led, GPIO.LOW)
def setServoState(flg): servo = Servo(21) if flg == 0: servo.min() else: servo.max() sleep(0.2)
def main(): recognizer = aiy.cloudspeech.get_recognizer() recognizer.expect_phrase('maximum') recognizer.expect_phrase('minimum') recognizer.expect_phrase('middle') button = aiy.voicehat.get_button() aiy.audio.get_recorder().start() servo = Servo(26) while True: print('Press the button and speak') button.wait_for_press() print('Listening...') text = recognizer.recognize() if text is None: print('Sorry, I did not hear you.') else: print('You said "', text, '"') if 'maximum' in text: print('Moving servo to maximum') servo.max() elif 'minimum' in text: print('Moving servo to minimum') servo.min() elif 'middle' in text: print('Moving servo to middle') servo.mid()
def FaceForward(self): s = Servo(self.pin, min_pulse_width=0.5 / 1000, max_pulse_width=10 / 1000, frame_width=20 / 1000) s.max() time.sleep(0.3) s.detach()
def blink(): myGPIO = 24 myServo = Servo(myGPIO) while True: myServo.max() sleep(1) myServo.min() sleep()
def FaceLeft(self): s = Servo(self.pin, min_pulse_width=1 / 1000, max_pulse_width=10.6 / 1000, frame_width=20 / 1000) s.max() time.sleep(0.3) s.detach()
def handle_brew(self, message): self.speak_dialog('brew') servo = Servo(17) servo.min() sleep(1) servo.max() sleep(1) servo.min() sleep(1)
def kick(d): print('kick') l1 = LED(15) l1.on() s = Servo(4) s.max() sleep(d) s.min() sleep(d * RATIO) l1.off()
class MotorControls: def __init__(self, pin1=18, pin2=19, correction=0.45): self.myGPIO1 = pin1 self.myGPIO2 = pin2 self.correction = correction self.maxPW = (2.0 + correction) / 1000 self.minPW = (1.0 - correction) / 1000 self.myServo1 = None self.myServo2 = None def __initServo(self): self.myServo1 = Servo(self.myGPIO1, min_pulse_width=self.minPW, max_pulse_width=self.maxPW) self.myServo2 = Servo(self.myGPIO2, min_pulse_width=self.minPW, max_pulse_width=self.maxPW) def forward(self): if self.myServo1 == None: self.__initServo() else: print("forward called") for i in range(-1, 2): self.myServo1.value = i self.myServo2.value = i sleep(1) def backward(self): if self.myServo1 == None: self.__initServo() else: print("backward called") self.myServo1.min() self.myServo2.min() sleep(0.5) def turn1(self): if self.myServo1 == None: self.__initServo() else: print("turn1 called") self.myServo1.max() self.myServo2.max() sleep(0.5) def turn2(self): if self.myServo1 == None: self.__initServo() else: print("turn2 called") self.myServo1.min() self.myServo2.min() sleep(0.5)
def feed(self, feed_size): if not is_gpio_capable: logging.getLogger('petfeedd').info( "This device is not GPIO capable. Simulating a feed.") return feed_size_time = float( self.config["gpio"]["servo_feed_time"]) * float(feed_size) servo = Servo(int(self.config["gpio"]["servo_pin"])) servo.max() time.sleep(feed_size_time) servo.detach()
def block(d): print('block') s = Servo(14) s.min() sleep(d) l2 = LED(18) l2.on() sleep(d) l2.off() s.max() sleep(d) s.value = None
def main(): rec = aiy.cloudspeech.get_recognizer() rec.expect_phrase('min') rec.expect_phrase('max') rec.expect_phrase('mid') aiy.audio.get_recorder().start() servo = Servo(26) but = aiy.voicehat.get_button() led = 26 GPIO.setmode(GPIO.BCM) GPIO.setup(led, GPIO.OUT) print("initializing system") say("initializing system") sleep(1) while True: say("press button and say min, max or mid to control servo") GPIO.output(led, GPIO.HIGH) print("press button to command servo") but.wait_for_press() print("listening") text = rec.recognize() if text is None: GPIO.output(led, GPIO.LOW) say("That is not a valid command!") else: text = text.lower() GPIO.output(led, GPIO.HIGH) if 'min' in text: say("min") print("min") servo.min() elif 'max' in text: say("max") print("max") servo.max() elif 'mid' in text: say("mid") print("mid") servo.mid() else: say("i'm sorry i heard, " + text + " which is not a valid command") print("i'm sorry i heard, " + text + " which is not a valid command") GPIO.output(led, GPIO.LOW)
class Arm: def __init__(self, pin): self.pin = pin self.arm = Servo(self.pin) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(self.pin, GPIO.OUT) def move(self): self.arm.max() time.sleep(0.8) self.arm.mid() time.sleep(0.8)
class Servo(object): def __init__(self): from gpiozero import Servo self.servo = Servo(pin=config.SERVO_PIN, min_pulse_width=config.SERVO_MIN_PULSE_WIDTH, max_pulse_width=config.SERVO_MAX_PULSE_WIDTH) def min(self): self.servo.min() def mid(self): self.servo.mid() def max(self): self.servo.max()
def main(): pygame.init() screen = pygame.display.set_mode((800, 600)) servo_left = Servo(17) servo_right = Servo(18) while True: for event in pygame.event.get(): servo_left.value = -0.13 servo_right.value = -0.15 if event.type == pygame.QUIT: raise SystemExit elif event.type == pygame.KEYDOWN: if event.key == pygame.K_w: servo_left.min() servo_right.min() print("Adelante") sleep(0.5) elif event.key == pygame.K_s: servo_left.max() servo_right.max() print("Atras") sleep(0.5) elif event.key == pygame.K_a: servo_left.value = -0.13 servo_right.min() print("Izquierda") sleep(0.5) elif event.key == pygame.K_d: servo_left.value = -0.13 servo_left.min() print("Derecha") sleep(0.5) elif event.key == pygame.K_SPACE: servo_left.value = -0.13 servo_right.value = -0.15 print("Detener")
class Motor(Servo): def __init__(self, servoPin): "Initializes the servo and has basic drive functions" self.servo = Servo(servoPin) def forward(self): "Function that drives the servos forward" self.servo.max() time.sleep(0.05) def backward(self): "Function that drives the servos backward" self.servo.min() time.sleep(0.05) def stop(self): "Stops motor movement" self.servo.detach()
class MedicationDispenser(IoTDevice): def __init__(self, thing_name, host, pub_topic, sub_topic, device_data, servo_pin): super().__init__(thing_name, host, pub_topic, sub_topic, device_data) self.servo = Servo(servo_pin) self.servo.min() def custom_callback(self, client, userdata, message): print(f"message received from: {message.topic}") self.dispense_meds(2) return def dispense_meds(self, dosage): for _ in range(dosage): self.servo.min() sleep(1) self.servo.max() sleep(1) self.servo.min() print("dispensed")
def main(): recognizer = aiy.cloudspeech.get_recognizer() recognizer.expect_phrase('turn off the light') recognizer.expect_phrase('turn on the light') recognizer.expect_phrase('blink') button = aiy.voicehat.get_button() led = aiy.voicehat.get_led() aiy.audio.get_recorder().start() servo = Servo(26) pwm = PWMOutputDevice(4) pwm2 = PWMOutputDevice(17) while True: print('Press the button and speak') button.wait_for_press() print('Listening...') text = recognizer.recognize() if text is None: print('Sorry, I did not hear you.') else: print('You said "', text, '"') if 'good boy' in text: pwm.on() pwm2.on() sleep(1) pwm.off() pwm2.off() sleep(1) servo.min() sleep(1) servo.mid() sleep(1) servo.max() sleep(1) elif 'turn off the light' in text: led.set_state(aiy.voicehat.LED.OFF) elif 'blink' in text: led.set_state(aiy.voicehat.LED.BLINK) elif 'goodbye' in text: break
def close_clamp(): from gpiozero import Servo from time import sleep myGPIO = 17 # Min and Max pulse widths converted into milliseconds # To increase range of movement: # increase maxPW from default of 2.0 # decrease minPW from default of 1.0 # Change myCorrection using increments of 0.05 and # check the value works with your servo. myCorrection = 0.45 maxPW = (2.0 + myCorrection) / 1000 minPW = (1.0 - myCorrection) / 1000 myServo = Servo(myGPIO, min_pulse_width=minPW, max_pulse_width=maxPW) myServo.max() print("Set to max position") sleep(1)
class ServoMotor(): "Simple wrapper for a servomotor" def __init__(self, pin: int, min: int = 0, max: int = 180): self.device = Servo(pin) @property def state(self) -> bool: if self.device.value == -1: return False return True def on(self) -> None: self.device.max() def off(self) -> None: self.device.min() def toggle(self) -> None: if self.state is True: self.off() else: self.on()
class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) # GPIO 17 --> pin 11 self.servo = Servo(17) self.setMinimumSize(QSize(500, 500)) self.setWindowTitle('LED Blink PyQt5 GUI') min_btn = QPushButton('MIN', self) min_btn.clicked.connect(self.min) min_btn.resize(100, 50) min_btn.move(50, 50) mid_btn = QPushButton('MID', self) mid_btn.clicked.connect(self.mid) mid_btn.resize(100, 50) mid_btn.move(200, 50) max_btn = QPushButton('MAX', self) max_btn.clicked.connect(self.max) max_btn.resize(100, 50) max_btn.move(350, 50) def min(self): print('MIN') self.servo.min() def mid(self): print('MID') self.servo.mid() def max(self): print('MAX') self.servo.max()
class Robot: def __init__(self): self._left = Servo(17) self._right = Servo(18) def left(self): self._left.max() self._right.min() def right(self): self._left.min() self._right.max() def forward(self): self._left.max() self._right.max() def backward(self): self._left.min() self._right.min() def stop(self): self._left.mid() self._right.mid()
# http://gpiozero.readthedocs.io/en/stable/api_output.html#servo from gpiozero import Servo from time import sleep servoVertical = 19 servoHorizontal = 17 servo = Servo(servoHorizontal) while True: servo.min() sleep(1) servo.mid() sleep(1) servo.max() sleep(1)
import RPi.GPIO as GPIO import time, sys from gpiozero import Servo from time import sleep servo1 = Servo(5) #servo1 = Servo(6) GPIO.setmode(GPIO.BCM) servo1.min() sleep(5) #change the value according to the experiment servo1.max() #sleep(2) #change the value according to the experiment
from gpiozero import Servo # importamos los módulos necesarios from time import sleep servo = Servo(18) # definimos el servo conectado al gpio 18 while True: # bucle infinito servo.min() # posición de un extremo sleep(2) # esperamos 2 segundos servo.mid() # posición central sleep(2) # esperamos 2 segundos servo.max() # posición del otro extremo sleep(2) # esperamos 2 segundos
from gpiozero import Servo from time import sleep s = Servo(18, initial_value=None, min_pulse_width=0.64 / 1000, max_pulse_width=1.2 / 1000, frame_width=100.0 / 1000) print "trying min()" s.min() sleep(5) print "trying mid()" s.mid() sleep(5) print "trying max()" s.max() sleep(5) #print "setting custom" #s.value = 0.6 #sleep(2)
from gpiozero import Servo from time import sleep t = True while t == True: Pin = 17 ServoMotore = Servo(Pin) ServoMotore.max() sleep(0.5) t = False
from gpiozero import Servo from time import sleep myGPIO = 17 # Min and Max pulse widths converted into milliseconds # To increase range of movement: # increase maxPW from default of 2.0 # decrease minPW from default of 1.0 # Change myCorrection using increments of 0.05 and # check the value works with your servo. myCorrection = 0.45 maxPW = (2.0 + myCorrection) / 1000 minPW = (1.0 - myCorrection) / 1000 myServo = Servo(myGPIO, min_pulse_width=minPW, max_pulse_width=maxPW) print("Using GPIO17") print("Max pulse width is set to 2.45 ms") print("Min pulse width is set to 0.55 ms") myServo.max() print("Set to minimum position") sleep(1)
from gpiozero import Servo from time import sleep servo = Servo(14) while True: servo.min() sleep(1) servo.max() sleep(1)
#!/usr/bin/env python3 """Demonstrates simultaneous control of two servos on the hat. One servo uses the simple default configuration, the other servo is tuned to ensure the full range is reachable. """ from time import sleep from gpiozero import Servo from aiy.pins import PIN_A from aiy.pins import PIN_B # Create a default servo that will not be able to use quite the full range. simple_servo = Servo(PIN_A) # Create a servo with the custom values to give the full dynamic range. tuned_servo = Servo(PIN_B, min_pulse_width=.0005, max_pulse_width=.0019) # Move the Servos back and forth until the user terminates the example. while True: simple_servo.min() tuned_servo.max() sleep(1) simple_servo.mid() tuned_servo.mid() sleep(1) simple_servo.max() tuned_servo.min() sleep(1)
from gpiozero import Button from gpiozero import Servo from time import sleep from signal import pause button_up = Button(21) button_down = Button(20) servo = Servo(14) servo.min() while True: button_up.when_pressed = servo.max() button_down.when_pressed = servo.mix() sleep(3)