def car_control(conn): car = DRV8835() # if Pololulu Motoredriver is used car.stop() SPEED = 60 LEFT = 1.0 RIGHT = 1.0 car.forward(LEFT * SPEED * 1.0, RIGHT * SPEED * 1.0) while True: message = conn.recv() dx_mm, dy_mm, total_x, total_y, elapsed, dt = map( float, message.split()) if message == "END": break elif total_y >= 200: # Car is stopped when it moves 20 cm. car.stop() print("Vastaanotettu viesti {}, {}, {}, {}, {}, {}, {}, v_y={}".format( dx_mm, dy_mm, total_x, total_y, elapsed, dt, 1 / dt, dy_mm / dt))
KERNEL_SIZE = 9 #default value 15 LOW_THRESHOLD = 50 #default value 40 HIGH_THRESHOLD = 150 #default value 120 RHO = 10 #default 10 THRESHOLD = 10 #default 15 THETA = np.pi / 180 MIN_LINE_LENGTH = 80 #default 10 MAX_LINE_GAP = 1 camera = picamera.PiCamera() camera.vflip = True # Depending how picamera installed on the car camera.hflip = True camera.resolution = (640, 480) car = DRV8835() # if Pololulu Motoredriver is used car.stop() SPEED = 45 LEFT = 1.0 RIGHT = 1.0 while True: rawCapture = picamera.array.PiRGBArray(camera) time.sleep(0.1) camera.capture(rawCapture, format="bgr") frame = rawCapture.array #Convert to Grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #Blur image to reduce noise. The bigger the KERNEL_SIZE, more blurry the image
from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) from drv8835 import DRV8835 #import control_servos import input_handling from servos import SERVOS CAR = DRV8835() CAR.stop() SPEED = 60 TURNING_SPEED = 30 SERVOS = SERVOS() def drive_forward(): CAR.forward(SPEED, SPEED) def drive_backward(): CAR.backward(SPEED, SPEED) # TODO: miten kääntyy sujuvasti vasemmalle/oikealle def drive_left(): CAR.forward(SPEED, TURNING_SPEED)
import iot from time import sleep # from l293d_pwm import L293DPWM from drv8835 import DRV8835 # from testing_motor import TestingMotorDriver # car = L293DPWM(17, 27, 26, 23, 24, 6) # car = L293DPWM(24, 12, 26, 13, 5, 6) car = DRV8835() car.stop() @iot.subscribe("automessages") def new_message(message): if (message == "moveforward"): car.forward(100, 100) sleep(2) car.stop() elif (message == "movebackward"): car.backward(100, 100) sleep(2) car.stop() elif (message == "moveright"): car.backward(100, 25) sleep(2) car.stop() elif (message == "moveleft"): car.backward(25, 100) sleep(2) car.stop()
from threading import Thread # Maariteellaan Arduinon merkkilaitteen sijainti # testaa komennolla ls -l /deb/tty* microbitin usb-kytkennalla ja ilman! laite = "/dev/ttyACM0" # Luodaan Serial-olio ser = serial.Serial(laite, baudrate=115200, timeout=1) # Luodaan valmis Re-olio # dataRe = re.compile(r"^(\d{1,4}),(\d{1,4}),([01])$") dataRe = re.compile(r"^\s*(-?\d+[?:[.]\d+]?)\s+(-?\d+[?:[.]\d+]?)$") # car = L293DPWM(17, 27, 26, 23, 24, 6) # car = L293DPWM(24, 12, 26, 13, 5, 6) car = DRV8835() # if Polulu motor driver for raspberry is used def maxmin(arvo, maks, minn): return max(min(arvo, maks), minn) arvot = [] active = True def serial_read(): print("Serial_thread kaynnistetty") global arvot while active: # Luetaan sarjaliikennetta