Example #1
0
async def motor():
	global motorON
	global motor
	global previousMotorON
	# Adjust the pulse values to set rotation range
	min_pulse = 0.000544    # Library default = 1/1000
	max_pulse = 0.0024              # Library default = 2/1000
	# Initial servo position
	pos =  1
	test = 0
	servo = Servo(17, pos, min_pulse, max_pulse, 20/1000, None)
	

	while True:
		await asyncio.sleep(0.2)
		if motorON == True:
			pos=pos*(-1)
			servo.value=pos
			await asyncio.sleep(2)
		else :
                        #put back in original position
                        servo.value=0
                        #detach the motor to avoid glitches and save energy
                        servo.detach()
                        previousMotorON = False
Example #2
0
def moveServo():
    led = LED(23)
    led.on()
    servo = Servo(14)
    servo.value = -1
    sleep(2)
    servo.value = 0
    sleep(2)
    servo.value = 1
    sleep(2)
    led.off()
Example #3
0
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
Example #4
0
    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.value = 0
        time.sleep(0.02)
        servo.detach()
Example #5
0
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")
Example #6
0
#5v -> red
#GND -> black
#23 -> white
from gpiozero import Servo
from time import sleep

servo = Servo(23)

servo.value = 0.5
'''
while True:
    servo.min()
    sleep(3)
    servo.mid()
    sleep(3)
    servo.max()
    sleep(3)
'''
Example #7
0
import argparse
import torch.optim as optim
from gpiozero import Servo, Button, LED

servo = Servo(17)
safeGreenStatus = LED(21)
safeOrangeStatus = LED(20)
safeRedStatus = LED(16, initial_value=True)
voiceGreenStatus = LED(5)
voiceOrangeStatus = LED(6)
voiceRedStatus = LED(12, initial_value=True)
faceGreenStatus = LED(13)
faceOrangeStatus = LED(19)
faceRedStatus = LED(26, initial_value=True)
lockButton = Button(18)
servo.value = -1
sleep(2)
servo.value = None
sleep(2)


def setSafeStatus(status):
    if status == "red":
        safeOrangeStatus.off()
        safeGreenStatus.off()
        safeRedStatus.on()
    elif status == "green":
        safeRedStatus.off()
        safeOrangeStatus.off()
        safeGreenStatus.on()
    elif status == "orange":
Example #8
0
def last_row(sheet, cols_to_sample=2):
    # looks for empty row based on values appearing in 1st N columns
    cols = sheet.range(1, 1, sheet.row_count, cols_to_sample)
    return max([cell.row for cell in cols if cell.value])  #+ 1


prevID = 0

while True:
    ID = last_row(sheet)
    if ID != prevID:  # Only read out the cell value if it hasn't been read out already
        print("Different")
        print(ID)
        cell = sheet.cell(ID, 3).value  # Which cell to read out, 3 is column C
        print(cell)
        myServo.value = 0
        GPIO.output(14, True)  # Lasers & Pump ON
        ding.play()  # Laser sound
        sleep(1.2)
        myServo.value = -0.2  # Move eyes
        ding.play()
        sleep(1.2)
        myServo.value = 0.2
        ding.play()
        sleep(1.2)
        myServo.value = -0.3
        ding.play()
        sleep(1.2)
        myServo.value = 0.3
        ding.play()
        sleep(1.2)
Example #9
0
from gpiozero import Servo
from time import sleep
import math

correction = 0.5
maxPW = (2.0 + correction) / 1000
minPW = (1.0 - correction) / 1000

servo = Servo(23, min_pulse_width=minPW, max_pulse_width=maxPW)

angleNum = 0
servoPos = 0

while True:

    angle = input('Angle Num:')
    angleNum = (float(angle))

    if (angleNum > 90):
        print("Please input a number below 90 degrees.")
    if (angleNum < -90):
        print("Please input a number above -90 degrees.")
    if (angleNum >= -90 and angleNum <= 90):
        servoPos = angleNum / 90
        print("Setting servo to ", angleNum, " degrees...")
        servo.value = servoPos
from gpiozero import Servo
from time import sleep

Pin = 21  # Posicion GPIO
Crt = 0.5  # Correcion

maxPW = (2.0 + Crt) / 1000
minPW = (1.0 - Crt) / 1000

servo = Servo(Pin, min_pulse_width=minPW, max_pulse_width=maxPW)

while True:
    servo.value = 0
    print("Centro")
    sleep(1)
    servo.value = None
    sleep(1)
    servo.value = -1
    print("Cerrado")
    sleep(1)
    servo.value = None
    sleep(1)
    servo.value = 0
    print("Centro")
    sleep(1)
    servo.value = None
    sleep(1)
    servo.value = 1
    print("Abierto")
    sleep(1)
    servo.value = None
Example #11
0
from gpiozero import Servo
from time import sleep

from gpiozero.pins.pigpio import PiGPIOFactory

factory = PiGPIOFactory()

servo = Servo(12,
              min_pulse_width=0.5 / 1000,
              max_pulse_width=2.5 / 1000,
              pin_factory=factory)

print("Start in the middle")
servo.mid()
sleep(5)
print("Go to min")
servo.min()
sleep(5)
print("Go to max")
servo.max()
sleep(5)
print("And back to middle")
servo.mid()
sleep(5)
servo.value = None
        # The section below works out the left / right position of the servo for steering
        if event.code == 00:
            print("00")
            print(event)
            if event.value < 65535:
                lrcalc = event.value / 65535.0
                lrcalcc = round(lrcalc, 1)
                print("lrcalcc = ", lrcalcc)
                lrcalcx2 = lrcalcc * 2
                print("lrcalcx2 = ", lrcalcx2)
                lrcalc2xm1 = lrcalcx2 - 1
                print("lrcalcx2m1 = ", lrcalc2xm1)
                print("Full Left")
                mannacalc = lrcalcc - (1 - lrcalcc)
                print("Mannacalc =", mannacalc)
                servo.value = lrcalc2xm1
        if event.code == 01:
            print("01")
            print(event)
        if event.code == 02:
            print("02")
            print(event)

        if event.code == 9:
            # this is for controlling the forward movement
            print("09 - right trigger")
            print(event.value)
            if event.value > 1:
                print("ON")
                speedcalc = event.value / 1023.0
                speedclean = round(speedcalc, 4)
Example #13
0
from gpiozero import Servo, MCP3008
from time import sleep

pot = MCP3008(channel=0)
servo = Servo(21)

def map_values(x, a, b, c, d):
    """Maps value range from input to output.
    
    For value x in input range a to b, calculate corresponding
    value in output range c to d."""
    y = (x-a)/(b-a) * (d-c)+c
    return y

while True:
    potReading = pot.value
    servoSetting = map_values(potReading, 0.0, 1.0, -1.0, 1.0)
    # Spew diagnostics to the terminal, but formatted neatly
    print("{0:1.3f}, {1:1.3f}".format(potReading, servoSetting))
    # Move the servo
    servo.value = servoSetting
    sleep(0.05)
Example #14
0
    new[6][termios.VMIN] = 1
    new[6][termios.VTIME] = 0
    termios.tcsetattr(fd, termios.TCSANOW, new)
    key = None
    try:
        key = os.read(fd, 3)
    finally:
        termios.tcsetattr(fd, termios.TCSAFLUSH, old)
    return key


servo1 = Servo(2)
servo2 = Servo(3)
x = 0
y = 0
servo1.value = x
servo2.value = y
sleep(1)

try:
    while True:
        key = getKey()
        if key == 'w':
            y = y - 0.2
        elif key == 's':
            y = y + 0.2
        elif key == 'd':
            x = x + 0.2
        elif key == 'a':
            x = x - 0.2
        else:
Example #15
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()
servo_left_correction = 0.45
servo_left_maxPW = (2.0 + servo_left_correction) / 1000
servo_left_minPW = (1.0 - servo_left_correction) / 1000

servo_left = Servo(servo_left_pin,
                   min_pulse_width=servo_left_minPW,
                   max_pulse_width=servo_left_maxPW)
servo_right = Servo(servo_right_pin,
                    min_pulse_width=servo_right_minPW,
                    max_pulse_width=servo_right_maxPW)
fan_servo = Servo(fan_servo_pin,
                  min_pulse_width=fan_servo_minPW,
                  max_pulse_width=fan_servo_maxPW)

servo_left.value = 1
servo_right.value = -1

sleep(1)
servo_left.value = None
servo_right.value = None
fan_servo.value = None

shutters_opened = False
fan_on = False
fan_on_doublespeed = False

letter_m_is_on = False
letter_y_is_on = False

datapoints_iterator = 0  # iterator within datapoints
Example #17
0
from gpiozero import Servo
from time import sleep

servo = Servo(21)

while True:
    servo.value = -1.0
    sleep(1)
    servo.value = 0.0
    sleep(1)
    servo.value = 1.0
    sleep(1)

Example #18
0
#Pino US Trig GPIO 13 (33)

pinServo = 19
pinEcho = 16
pinTrig = 13

myCorrection = 0.45
maxPW = (2.0 + myCorrection + 0.01) / 1000
minPW = (1.0 - myCorrection) / 1000

servo = Servo(pinServo, min_pulse_width=minPW, max_pulse_width=maxPW)
sensor = DistanceSensor(echo=pinEcho, trigger=pinTrig)

#Starts servo at min position
servo_position = 1.0
servo.value = servo_position

###############################################################################
#Teste Servo

# while True:
#     servo.value = 0
#     print("mid")
#     sleep(0.5)
#     servo.value = -1
#     print("min")
#     sleep(1)
#     servo.value = 0
#     print("mid")
#     sleep(0.5)
#     servo.value = 1
Example #19
0
                    if number == 0:
                        stop_pwm()
                    elif number > 0:
                        forward(speed=number * 100)
                    elif number < 0:
                        backward(speed=abs(number) * 100)

            except ValueError as err:
                print('found shit', err)

        rudder_stuff = find_string(string, 'R: ')
        if rudder_stuff:
            try:
                number = float(rudder_stuff)
                if number >= -1 and number <= 1:
                    servo.value = number

            except ValueError:
                print('found shit')

    time.sleep(0.01)

# === experimental for service


def listen():
    line = ser.readline()
    if line:
        string = line.decode('utf-8')
        motor_stuff = find_string(string, 'M: ')
        if motor_stuff:
Example #20
0
from aiy.pins import PIN_B

leds = Leds()
leds.update(Leds.rgb_off())

RED = (0xFF, 0x00, 0x00)
GREEN = (0x00, 0xFF, 0x00)
BLUE = (0x00, 0x00, 0xFF)
PURPLE = (0xFF, 0x00, 0xFF)

tuned_servoA = Servo(PIN_A)
tuned_servoB = Servo(PIN_B)

ddef send_signal_to_servos(result0):
    if 'stop' in result0:
        tuned_servoA.value = 0
        tuned_servoB.value = 0
        leds.update(Leds.rgb_on(RED))
    elif 'left' in result0:
        tuned_servoA.value = -0.8
        tuned_servoB.value = -0.8
        leds.update(Leds.rgb_on(BLUE))
    elif 'right' in result0:
        tuned_servoA.value = 0.8
        tuned_servoB.value = 0.8
        leds.update(Leds.rgb_on(PURPLE))
    elif 'slow' in result0:
        tuned_servoA.value = 0.2 
        tuned_servoB.value = -0.2
        leds.update(Leds.rgb_on(GREEN))
    else:
Example #21
0
from gpiozero import Servo
from time import sleep

myGPIO = 17

myCorrection = 0
maxPW = (2.0 + myCorrection) / 1000
minPW = (1.0 - myCorrection) / 1000

servo = Servo(myGPIO, min_pulse_width=minPW, max_pulse_width=maxPW)

while True:

    print("Set value range -1.0 to +1.0")
    for value in range(0, 21):
        value2 = (float(value) - 10) / 10
        servo.value = value2
        print(value2)
        sleep(0.5)

    print("Set value range +1.0 to -1.0")
    for value in range(20, -1, -1):
        value2 = (float(value) - 10) / 10
        servo.value = value2
        print(value2)
        sleep(0.5)
from gpiozero import Servo
from time import sleep

servo = Servo(26)
while True:
    servo.value = -1
    sleep(3)
    servo.value = 0
    sleep(3)
    servo.value = 1
    sleep(3)
Example #23
0
from gpiozero import Servo
import math
from time import sleep

from gpiozero.pins.pigpio import PiGPIOFactory

factory = PiGPIOFactory()

servo = Servo(12,
              min_pulse_width=0.5 / 1000,
              max_pulse_width=2.5 / 1000,
              pin_factory=factory)

while True:
    for i in range(0, 360):
        servo.value = math.sin(math.radians(i))
        sleep(0.01)
from gpiozero import LED
from gpiozero import Buzzer
from signal import pause

lamp = gpiozero.OutputDevice(4, active_high=False, initial_value=False)
fan = gpiozero.OutputDevice(3, active_high=False, initial_value=False)

# GPIO PINS
button = Button(26)
button_led = LED(25)
red_led = LED(16)
white_led = LED(21)
buzzer = Buzzer(5)
servo = Servo(17)

servo.value = None  # if you don't have this, servo will start moving immediately when program starts

door_sensor = digitalio.DigitalInOut(board.D23)  # Door sensor on gpio pin 23
door_sensor.direction = digitalio.Direction.INPUT


def kill_switch():
    print('kill switch active')
    while True:
        if door_sensor.value:
            print('DOOR OPEN!')
            lamp.off()
            buzzer.on()
            time.sleep(1.5)
            buzzer.off()
        time.sleep(0.25)
Example #25
0
    print('System error: {0}'.format(error))
    print('See datasheet section 4.3.59 for the meaning.')

# Print BNO055 software revision and other diagnostic data.
sw, bl, accel, mag, gyro = bno.get_revision()
print('Software version:   {0}'.format(sw))
print('Bootloader version: {0}'.format(bl))
print('Accelerometer ID:   0x{0:02X}'.format(accel))
print('Magnetometer ID:    0x{0:02X}'.format(mag))
print('Gyroscope ID:       0x{0:02X}\n'.format(gyro))

servo = Servo(servoPIN, min_pulse_width=minPW,
              max_pulse_width=maxPW)  # initalize a servo

# initalize and get the servo's range of motion
servo.value = 1  # move servo all the way in one direction
time.sleep(
    moveDelay * moveDelayMultiplier
)  # let the servo move, but wait longer because it's a full sweep of the arm
heading, roll, pitch = bno.read_euler()  # we're only using heading
servoMaxHeading = heading  # this is as far as the servo can go
servo.value = -1  # move servo all teh way in the other direction
time.sleep(
    moveDelay * moveDelayMultiplier
)  # let the servo move, but wait longer because it's a full sweep of the arm
heading, roll, pitch = bno.read_euler()  # we're only using heading
servoMinHeading = heading  # this is as far as the servo can go in the other direction
print("servoMaxHeading: {}, servoMinHeading: {}".format(
    servoMaxHeading, servoMinHeading))

servo.value = 0  # move the servo to 0 heading
Example #26
0
from time import sleep
 
# Adjust the pulse values to set rotation range
min_pulse = 0.000544    # Library default = 1/1000
max_pulse = 0.0024      # Library default = 2/1000
# Initial servo position
pos = 0
test = 0
 
servo = Servo(17, pos, min_pulse, max_pulse, 20/1000, None)
 
while True:
    # For statement example
    for pos in range(0, 20):
        pos = pos * 0.1 - 1
        servo.value = pos
        print(pos)
        sleep(0.05)
 
    for pos in range(20, -1, -1):
        pos = pos * 0.1 - 1
        servo.value = pos
        print(pos)
        sleep(0.05)
 
    # While statement example
    """
    while test < 20:
        pos = test * 0.1 - 1
        servo.value = pos
        print(pos)
# Code to execute from remote computer. Make sure to have the Raspberry Pi configured for Remote GPIO
# see here https://gpiozero.readthedocs.io/en/stable/remote_gpio.html for more
from gpiozero import Servo
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep

factory = PiGPIOFactory(host='192.168.0.130')  #Set host to IP of your RaspPi

myGPIO = 17  #pin 17 for PWM control
servo = Servo(myGPIO, pin_factory=factory)

servo.value = -1


def toggleComputer():
    servo.value = -0.25
    sleep(0.2)
    servo.value = -1


toggleComputer()  #Turn off computer
sleep(20)
toggleComputer()  #Turn on computer
Example #28
0
right = Servo(13)
#create a udp datagram socket to listen on 192.168.0.1:60065
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(("192.168.0.1", 60065))

#loop through two smaller loops forever
while True:
    #in this first loop, wait for a signal. break and proceed if it's from our app; wait for the next if it's not.
    while True:
        question, address = sock.recvfrom(19)
        if question.decode("utf-8") == "Are you our RC car?":
            sock.sendto('y'.encode("utf-8"), address)
            appAddress = address
            break

    #now that we have an app connected, receive and execute instructions from it.
    while True:
        controlIn, address = sock.recvfrom(2)

        #only obey the command if they come from the app's IP; otherwise, discard.
        if address == appAddress:
            leftSpeed = int.from_bytes(controlIn[:1],
                                       byteorder='big',
                                       signed=True)
            rightSpeed = int.from_bytes(controlIn[1:],
                                        byteorder='big',
                                        signed=True)

            #divide each speed by 127 to assign the esc a value between -1 and 1
            left.value(leftSpeed / 127)
            right.value(rightSpeed / 127)
Example #29
0
from gpiozero import Servo, LED
from time import sleep
from slow import sweep

#pins 23 and 24 connect to servos w signal wire
tilt = Servo(24)
pan = Servo(23)
l_led = LED(22)
r_led = LED(17)

#initial tilt to minimum pos (horizontal)
#inital pan to middle pos (straight)
tilt.value = -1
pan.value = 0
#after any position adjustment allow small wait for servo to respond before detachment
sleep(0.3)
tilt.detach()
pan.detach()
sleep(1)
print('Left LED On')
l_led.on()
sleep(2)
print('Left LED Off')
l_led.off()
sleep(1)
print('Right LED On')
r_led.on()
sleep(2)
print('Right LED Off')
r_led.off()
sleep(1)
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")

#while True:
start = time.time()
cont = 0
cont2 = 0
#value = 3.0
#value2 = (float(value)-10)/10.0
#time.sleep(3)
for value in numpy.arange(3, 17, 0.3):
    cont2 = cont2 + 1
    value2 = (float(value) - 10) / 10
    distance = tof.get_distance()
    if distance > 0:
        print(distance / 10)
        cont = cont + 1
    myServo.value = value2
    #print("Servo value set to "+str(value2))
    time.sleep(timing / 1000000.00)
print("Numero de leituras")
print(cont)
print("Execucoes:")
print(cont2)
#print(time.time() - start)
tof.stop_ranging()
tof.close()