示例#1
0
文件: robot.py 项目: zhenyat/Rob
    def __init__(self, motors, factory):

        for motor in motors:
            if motor['side'] == 'left':
                left_forward = motor['forward_gpio']
                left_backward = motor['backward_gpio']
            else:
                right_forward = motor['forward_gpio']
                right_backward = motor['backward_gpio']

        self.robot_gpio = GPIO.Robot(left=(left_forward, left_backward),
                                     right=(right_forward, right_backward),
                                     pin_factory=factory)
        self.motors_speed = motors[0]['speed']
示例#2
0
import gpiozero

SPEED = 0.25

robot = gpiozero.Robot(left=(17, 18), right=(27, 22))

left = gpiozero.DigitalInputDevice(9)
right = gpiozero.DigitalInputDevice(11)

while True:
    if (left.is_active == True) and (right.is_active == True):
        robot.forward(SPEED)
    elif (left.is_active == False) and (right.is_active == True):
        robot.right(SPEED)
    elif (left.is_active == True) and (right.is_active == False):
        robot.left(SPEED)
    else:
        robot.stop()
import gpiozero
import time

robot = gpiozero.Robot(left=(27, 17), right=(24, 23))

try:
    # Robot actions here
    for n in range(6):
        robot.forward()
        time.sleep(0.5)
        robot.left()
        time.sleep(0.3)
    robot.right()
    time.sleep(1)
finally:
    robot.stop()
示例#4
0
import gpiozero

import sys

robot = gpiozero.Robot(left=(26, 16), right=(5, 6))

lefts = gpiozero.DigitalInputDevice(17)
rights = gpiozero.DigitalInputDevice(27)
leftend = gpiozero.DigitalInputDevice(22)
rightend = gpiozero.DigitalInputDevice(23)

robot.right()

while True:
    if (lefts.is_active == True) and (rights.is_active == True):
        robot.stop()
        break
    else:
        continue

sys.exit()
# imports
import argparse
import time
import cv2
import imutils
import numpy as np
import picamera
import gpiozero

# globals
from imutils.video import VideoStream

wheels = gpiozero.Robot(left=(7, 8), right=(9, 10))
camera = picamera.PiCamera()
us_sensor = gpiozero.input_devices.DistanceSensor(24, 18)


def image_detection_setup():
    ap = argparse.ArgumentParser()
    ap.add_argument("-p",
                    "--prototxt",
                    required=True,
                    help="path to Caffe 'deploy' prototxt file")
    ap.add_argument("-m",
                    "--model",
                    required=True,
                    help="path to Caffe pre-trained model")
    ap.add_argument("-c",
                    "--confidence",
                    type=float,
                    default=0.2,
示例#6
0
 def __init__(self, l_ports, r_ports):
     self.robot = gpi.Robot(left=l_ports, right=r_ports)
     self.ldir = -1
     self.rdir = -1
示例#7
0
#!/usr/bin/env python3

#   Curses Test with Robot

import curses
import gpiozero as GPIO
from gpiozero.pins.pigpio import PiGPIOFactory
from time import sleep

addr = '192.168.2.44'
factory = PiGPIOFactory(host=addr)
GPIO.Device.pin_factory = factory  # Workaround: MUST BE!!!

robot = GPIO.Robot(left=(19, 16), right=(22, 23), pin_factory=factory)
speed = 1

# Init curses and set it up
screen = curses.initscr()
curses.noecho()  # no echoing of keys to the screen
curses.cbreak()  # to react on a key instantly without Enter (buffering)
screen.keypad(True)  # enable keypad mode (can return curses.KEY_UP, etc.)

try:
    while True:
        char = screen.getch()

        if char == ord('q'):
            print('\r\rQuit')
            sleep(2)
            break
        elif char == curses.KEY_UP:
import tornado.ioloop
import tornado.web
import RPi.GPIO as GPIO
import datetime
import gpiozero
import time
import serial
import subprocess
import os

robot = gpiozero.Robot(left=(11, 25), right=(9, 10))

leftend = gpiozero.DigitalInputDevice(17)
center = gpiozero.DigitalInputDevice(27)
rightend = gpiozero.DigitalInputDevice(22)
leftback = gpiozero.DigitalInputDevice(23)
rightback = gpiozero.DigitalInputDevice(19)

thermal = gpiozero.LED(20)
pressures = gpiozero.LED(21)

rfid_dict = {
    'E235FC8B\r\n': 'A1',
    'C0B4FD79\r\n': 'A4',
    '340B53B9\r\n': 'A3',
    '7DC476A9\r\n': 'A2',
    '8CBC01E4\r\n': 'AN'
}
active_beds = ('A1', 'A2', 'A3', 'A4')  #fetch from main server
left_beds = ('A1', 'A3')
示例#9
0
 def __init__(self):
     self.robot = gpiozero.Robot(left=(17, 18), right=(22, 27))
示例#10
0
        clientsock.close()
    
 
camera = PiCamera()
image_width = 640
image_height = 480
camera.resolution = (image_width, image_height)
camera.framerate = 32
camera.rotation=180
rawCapture = PiRGBArray(camera, size=(image_width, image_height))
center_image_x = image_width / 2
center_image_y = image_height / 2
minimum_area = 250
maximum_area = 100000
 
robot = gpiozero.Robot(left=(22,27), right=(17,18))
forward_speed = 0.8
turn_speed = 0.6
 
HUE_VAL = int(get_HUE())
print(HUE_VAL,"dahab")
 
lower_color = np.array([HUE_VAL-10,100,100])
upper_color = np.array([HUE_VAL+10, 255, 255])
 
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    image = frame.array
 
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
 
    color_mask = cv2.inRange(hsv, lower_color, upper_color)
示例#11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

#  Mit diesem Programm testen wir erneut ob die Motoren korrekt funktionieren
#  und verwenden dafür die "gpiozero" library.
#
#  Dieses Programm ist Bestandteil des Erfindergarden Roboter-Workshops.
#  http://www.erfindergarden.de

import gpiozero				# Eine Abstraktion der GPIO, die Funktionen
							# zur Steuerung der Motoren enthält

import time					# Hiermit können wir den Ablauf unseres Programms pausieren.
							# Das wird später benötigt um zu bestimmen, wie
							# lange die Motoren laufen sollen.

robot = gpiozero.Robot(left = (9, 10), right = (7, 8))	# Hier sagen wir gpiozero an welche Pins
														# unsere Motoren angeschlossen sind

robot.forward()				# gpiozero stellt nun im Hintergrund die Pins 8 und 10 auf 1
							# und die Pins 7 und 9 auf 0, genau wie im vorigen Motor-Test.
							# Nur ist dieser Code hier wesentlich besser "lesbar".

time.sleep(1)				# Warte eine Sekunde
robot.stop()				# gpiozero stellt alle vier Pins der Motoren auf 0
import cv2
import numpy as np
import imutils
import gpiozero

input_led = gpiozero.LED(17)  # RPi initialisations
input_led.off()
robot = gpiozero.Robot(left=(4, 14), right=(17, 18))
# speed = 1   # later dynamically define speed depending on distance


def nothing(n):
    pass


def select_obj():
    cv2.namedWindow("Choose the object")
    cv2.createTrackbar("Hue Start", "Choose the object", 0, 179, nothing)
    cv2.createTrackbar("Hue End", "Choose the object", 179, 179, nothing)
    cv2.createTrackbar("Saturation Start", "Choose the object", 0, 255,
                       nothing)
    cv2.createTrackbar("Saturation End", "Choose the object", 255, 255,
                       nothing)
    cv2.createTrackbar("Value Start", "Choose the object", 0, 255, nothing)
    cv2.createTrackbar("Value End", "Choose the object", 255, 255, nothing)
    cv2.createTrackbar("2 = Selection Made\n1 = Previous Selection\n0 = Quit",
                       "Choose the object", 0, 2, nothing)
    lower_range = None
    upper_range = None
    key = 0
示例#13
0
    time.sleep(button_delay)
 
  if (buttons & cwiid.BTN_B):
    print 'Button B pressed'
    time.sleep(button_delay)
 
  if (buttons & cwiid.BTN_HOME):

"""


import cwiid
import time
import gpiozero

boomer = gpiozero.Robot(left=(X,y), right=(x,y))

#controller initialization
print("Press and hold the 1 + 2 buttons on the WII remote at the same time:")
time.sleep(2)
wii = cwiid.Wiimote()
print("Connection with remote established")
wii.rpt_mode= cwiid.RPT_BTN



#main command loop
while True:
    
    button_status = wii.state["buttons"]