コード例 #1
0
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()
コード例 #2
0
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)
コード例 #3
0
def min():
    myGPIO = 24
    myServo = Servo(myGPIO)
    while True:
        myServo.mid()
        sleep(1)
        myServo.max()
        sleep(1)
コード例 #4
0
 def doIt3():
     try:
         for pin in PINS:
             servo = Servo(pin)
             servo.mid()
             time.sleep(1)
     except Exception as e:
         with open('failedToFeed.txt', 'w') as info:
             info.write('something went wrong with the servo')
             info.write(str(e))
コード例 #5
0
def execute():
    gpio = 17
    servo = Servo(gpio)
    print("Airdrop initiated!")
    i = 1
    while i in range(1, 4):
        servo.mid()
        sleep(1)
        i = i + 1
    print("Done.. Enjoy!")
    return
コード例 #6
0
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)
コード例 #7
0
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)
コード例 #8
0
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()
コード例 #9
0
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
コード例 #10
0
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
コード例 #11
0
def open_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.mid()
    print("Set to middle position")
    sleep(0.5)
コード例 #12
0
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()
コード例 #13
0
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()
コード例 #14
0
class ServoDevice:
    servo_pin = 17

    def __init__(self, servo_position=-1):
        self.servo = Servo(self.servo_pin)

    # self.move_servo(servo_position)

    def validator(self, pPos):
        #print("run validator")
        if (pPos < -1):
            print("Value is below minimum range for servo!")
            print(pPos)
            pPos = -1


#            return pPos
        elif (pPos > 1):
            print("Value is above maximum range for servo!")
            print(pPos)
            pPos = 1

        return pPos

    def move_servo(self, servo_position):
        #self.servo.value=self.convert_percentage_to_integer(servo_position)
        servo_position = self.validator(servo_position)
        self.servo.value = servo_position

    def convert_percentage_to_integer(self, percentage_amount):
        return (percentage_amount * 0.02) - 1

    def calculatePosFromTemp(self, data):
        maxPos = -1  #value is in degrees
        minPos = 1
        totalRange = abs(maxPos) + abs(minPos)
        maxTemp = 50  # value is in Celcius
        conversionVal = totalRange / maxTemp
        currentTemp = data
        nextPos = 0
        if (float(currentTemp) > 25):
            nextPos = minPos
        elif (float(currentTemp) < 18.5):
            nextPos = maxPos
        else:
            nextPos = float(currentTemp) * conversionVal

        print(nextPos)
        self.move_servo(nextPos)
        time.sleep(1)
        self.servo.detach()
        return nextPos

    def sweep_motor(self):
        pos = 0
        speedRateLimiter = .02
        #(pos = 0 pos <= 171 pos += 1)
        for x in arange(-1, 1, 0.05):
            pos = x
            self.move_servo(pos)
            time.sleep(speedRateLimiter)
        #(pos = 172 pos >= 0 pos -= 1)
        for x in arange(1, -1, -0.05):
            pos = x
            self.move_servo(pos)
            time.sleep(speedRateLimiter)

    def test_range_of_motion(self):
        self.sweep_motor()
        self.servo.max()
        time.sleep(1)
        self.servo.mid()
        time.sleep(1)
        self.servo.min()
        time.sleep(1)
        self.servo.detach()

    def test_calculation(self, data):
        newPos = servo_device.calculatePosFromTemp(data)
        self.move_servo(newPos)
        time.sleep(1)
        self.servo.detach()
コード例 #15
0
ファイル: pantilt.py プロジェクト: duckida/legosort
from gpiozero import Servo
import time

btm = Servo(17)
top = Servo(26)

#The Drop mechanism
print("Demo of Dropping Bricks")
top.mid()
print("Dropping into Box")
time.sleep(1)
top.min()
print("going back")
time.sleep(1)

#The Turn-To-Box mechanism
print("Demo of Multiple Boxes")
btm.min()
print("Box 1")
time.sleep(1)
btm.mid()
print("Box 2")
time.sleep(1)
btm.max()
print("Box 3")
time.sleep(1)

#The Full demo
print("Full Demo")
btm.min()
print(btm.min())
コード例 #16
0
from gpiozero import Servo
from time import sleep

t = True

while t == True:
    Pin = 17
    ServoMotore = Servo(Pin)
    ServoMotore.mid()
    sleep(0.5)
    t = False
コード例 #17
0
from gpiozero import Servo
from time import sleep
from gpiozero.pins.pigpio import PiGPIOFactory
 
myGPIO1=23 #back
myGPIO2=18 #front sonar
myGPIO3=15 #front camera
 
myCorrection=0.5
maxPW=(2.0+myCorrection)/1000
minPW=(1.0-myCorrection)/1000
 
servo1 = Servo(myGPIO1,min_pulse_width=minPW,max_pulse_width=maxPW,pin_factory = PiGPIOFactory())
servo2 = Servo(myGPIO2,min_pulse_width=minPW,max_pulse_width=maxPW,pin_factory = PiGPIOFactory())
servo3 = Servo(myGPIO3,min_pulse_width=minPW,max_pulse_width=maxPW,pin_factory = PiGPIOFactory())

servo1.mid()
servo2.mid()
servo3.mid()
コード例 #18
0
#!/usr/bin/env python3

from gpiozero import Servo
from time import sleep

pan = Servo(17)
tilt = Servo(18)

while True:
    print("pan.min")
    pan.min()
    sleep(2)
    print("pan.mid")
    pan.mid()
    sleep(2)
    print("pan.max")
    pan.max()
    sleep(2)

    print("tilt.min")
    tilt.min()
    sleep(2)
    print("tilt.mid")
    tilt.mid()
    sleep(2)
    print("tilt.max")
    tilt.max()
    sleep(2)
コード例 #19
0
''' ### Turning a piezo on and off with a capacitive touch button, and led intialization ###
led = LED(21)
piezo = LED(12)

button.when_pressed = piezo.off
button.when_released = piezo.on
'''

while True:  # Run the indented code forever
    if button.is_pressed == False:  # If capactive touch button is touched (False meaning the signal is low run the indented code below, otherwise skip to the indented code below else
        servo.max()  # Turn the servo to its maximum position
        sleep(.5)  # Waits 0.5 seconds before next line of code
        servo.min()  # Turn the servo to its minimum position
        sleep(.5)  # Waits 0.5 seconds before next line of code
    else:  # If if statement is not satisfied, run the indented code below
        servo.mid()  # Turn the servo to its midpoint
''' ### Turning an led on and off with an if-else statement ###
while True:
    if button.is_pressed:
        led.off()
    else:
        led.on()
'''
''' ### Distance sensor code ###
distanceMeters = DistanceSensor(trigger = 18, echo = 14, threshold_distance = 0.15)

while True:
    distanceInches = distanceMeters.distance * 39.37
    distanceInches = round(distanceInches, 1)
    
    print('Distance: ', distanceInches, 'in')
コード例 #20
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--num_frames',
        '-n',
        type=int,
        dest='num_frames',
        default=-1,
        help='Sets the number of frames to run for, otherwise runs forever.')
    args = parser.parse_args()

    with PiCamera() as camera:
        camera.sensor_mode = 4
        camera.resolution = (1640, 1232)
        camera.framerate = 30
        camera.start_preview()
        servo = Servo(PIN_A, min_pulse_width=.0005, max_pulse_width=.0019)
        servo.mid()
        position = 0
        zero_counter = 0

        annotator = Annotator(camera, dimensions=(320, 240))
        scale_x = 320 / 1640
        scale_y = 240 / 1232

        def transform(bounding_box):
            x, y, width, height = bounding_box
            return (scale_x * x, scale_y * y, scale_x * (x + width),
                    scale_y * (y + height))

        with CameraInference(face_detection.model()) as inference:
            for i, result in enumerate(inference.run()):
                if i == args.num_frames:
                    break
                faces = face_detection.get_faces(result)
                annotator.clear()
                for face in faces:
                    annotator.bounding_box(transform(face.bounding_box), fill=0)
                annotator.update()
                print('Iteration #%d: num_faces=%d' % (i, len(faces)))

                if faces:
                    face = faces[0]
                    x, y, width, height = face.bounding_box
                    print('             : Face is at %d' % x)
                    if x < 300:
                       print('             : Face left of center')
                       position = position - 0.1
                       if position < -1:
                           position = -0.99
                    elif x > 500:
                       print('             : Face right of center')
                       position = position + 0.1
                       if position > 1:
                           position = 0.99
                    else:
                       print('             : Face in CENTER of image')
                       positon = position

                    servo.value = position

                else:
                    zero_counter = zero_counter + 1
                    if zero_counter == 100:
                       servo.mid()
                       position = 0
                       print('             :Ignoring you')
                       zero_counter = 0

        camera.stop_preview()
コード例 #21
0
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
コード例 #22
0
#
# Author : Matt Hawkins
# Date   : 01/01/2018
#
# https://www.raspberrypi-spy.co.uk/tag/servo/
#
#--------------------------------------
from gpiozero import Servo
from time import sleep

myGPIO = 17

myServo = Servo(myGPIO)

print("Using GPIO17")
print("Using Gpiozero defaults for the servo class")

while True:
    myServo.mid()
    print("Set to middle position")
    sleep(5)
    myServo.min()
    print("Set to minimum position")
    sleep(5)
    myServo.mid()
    print("Set to middle position")
    sleep(5)
    myServo.max()
    print("Set to maximum position")
    sleep(5)
コード例 #23
0
ファイル: servo_example.py プロジェクト: eosurman/physicsc
#!/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)
コード例 #24
0
ファイル: servo.py プロジェクト: chitranshu651/Felix-Hack36
import numpy as np
import cv2
import RPi.GPIO as GPIO
from picamera import PiCamera
import time

import math
from gpiozero import Servo
from time import sleep
#from video import create_capture
#from common import clock, draw_str

p1 = Servo(2)  #left
q1 = Servo(3)  #right
p1.mid()
q1.mid()

cap = cv2.VideoCapture(0)
#print(type(cap))
cap.set(3, 320)
cap.set(4, 240)
cap.set(5, 15)
ret, frame = cap.read()
cv2.namedWindow('frame', cv2.WINDOW_NORMAL)
theta = 0
minLineLength = 5
maxLineGap = 10
while (cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()
    # x=cv2.GetMat(frame)
コード例 #25
0
ファイル: servo_example.py プロジェクト: fobibot/FOBI-Robot
"""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.vision.pins import PIN_A
from aiy.vision.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)
コード例 #26
0
ファイル: servo_reset.py プロジェクト: ryanallen82/AIY_Vision
def main():

    while True:
        servo = Servo(PIN_A)
        servo.mid()
コード例 #27
0
ファイル: servo_control.py プロジェクト: Maloy-Baroi/robot
from gpiozero import Servo
from time import sleep

servoH, servoRHU, servoRHD, servoLHU, servoLHD = Servo(14), Servo(15), Servo(
    18), Servo(23), Servo(24)

while True:
    servoH.mid()
    sleep(2)
    servoH.max()
    sleep(1)
    servoH.mid()
    sleep(2)
    servoH.min(1)
コード例 #28
0
ファイル: sg90.py プロジェクト: miklospocsaji/pombru
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)
コード例 #29
0
ファイル: motor.py プロジェクト: BenjaminAtbi/Ecobot
class MotorController:
    def __init__(self):

        self.leftWheel = Servo(leftWheelGPIO)
        self.leftBackGate = Servo(leftBackGateGPIO)
        self.rightArm = Servo(rightArmGPIO)
        self.rightWheel = Servo(rightWheelGPIO)
        self.rightBackGate = Servo(rightBackGateGPIO)
        self.sorter = Servo(sorterGPIO)
        self.frontGate = Servo(frontGateGPIO)

        # requires input of angles
        # *********************************

    # RIGHT BACK GATE
# closed ->  max()
# open -> mid()

# LEFT BACK GATE
# closed -> min()
# open -> mid()

# SORTER
# left -> min()
# middle -> .value = -0.5
# right -> .value = 0

# RIGHT ARM
# up -> .value = 0.2
#        sleep .5
#       .value = -0.2
# down -> .value = -0.5
#       sleep .7
#       .value = -0.2

# LEFT MOTOR
# forward -> .value = 0.2
# bakcward -> .value = -0.6
# stop -> .value = -0.2

# RIGHT MOTOR
# forward -> .value = -0.6
# backward -> .value = 0.2
# stop -> .value = -0.2

    def rightGateClose(self):
        self.rightBackGate.max()

    def rightGateOpen(self):
        self.rightBackGate.mid()

    def leftGateClose(self):
        self.leftBackGate.min()

    def leftGateOpen(self):
        self.leftBackGate.mid()

    def sorterLeft(self):
        self.sorter.min()

    def sorterRight(self):
        self.sorter.value = 0

    def sorterMid(self):
        self.sorter.value = -0.5

    def armUp(self):
        self.rightArm.value = 0.2
        sleep(.5)
        self.value = -0.2

    def armDown(self):
        self.rightArm.value = -0.5
        sleep(.7)
        self.value = -0.2

    def pause(self):
        self.leftWheel.value = -0.2
        self.rightWheel.value = -0.2
        sleep(1)

    def forward(self, length):
        self.leftWheel.value = 0.2
        self.rightWheel.value = -0.6
        sleep(length)
        self.pause()

    def backward(self, length):
        self.leftWheel.value = -0.6
        self.rightWheel.value = 0.2
        sleep(length)
        self.pause()

    def left(self, length):
        self.leftWheel.value = -0.6
        self.rightWheel.value = -0.6
        sleep(length)
        self.pause()

    def right(self, length):
        self.rightWheel.value = 0.2
        self.leftWheel.value = 0.2
        sleep(length)
        self.pause()

    def AngleLeft(self, length):
        self.left(length / 90 * 2.5)

    def AngleRight(self, length):
        self.right(length / 90 * 2.5)

    def forwardDist(self, length):
        self.forward(length)

    def backDist(self, length):
        self.backward(length)

    def gateOpen(self):
        self.frontGate.max()

    def gateClose(self):
        self.frontGate.min()

    def initialize(self):
        self.pause()
        self.armDown()
        self.gateOpen()
        self.leftGateClose()
        self.rightGateClose()
        self.sorterMid()

    def load(self, robot):
        self.gateClose()
        sleep(.3)
        self.armUp()
        left = bool(False)
        for i in range(10):
            left = not left
            if left:
                robot.motor.sorterLeft()
            else:
                robot.motor.sorterRight()
            sleep(.2)
        robot.motor.sorterMid()
コード例 #30
0
# 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)
コード例 #31
0
ファイル: controller.py プロジェクト: Astrol99/FaceNerf
from gpiozero import Servo
from time import sleep

horizontal_servo = Servo(2)
servo_speed = 0.05

horizontal_servo.mid()  # Set servo at middle by default


def right():
    if horizontal_servo.value > -0.9:
        print("RIGHT")
        horizontal_servo.value -= servo_speed


def left():
    if horizontal_servo.value < 0.9:
        print("LEFT")
        horizontal_servo.value += servo_speed


def fire():
    print("FIRE")