예제 #1
0
def main():
    uartComm = UARTDevice(Port.S2, 9600, 100)
    uartComm.clear()
    xlimits = [-310, 310]

    while True:
        reflection = light.reflection()
        try:
            data_raw = uartComm.read(24).decode().replace('B', '')
            data = ujson.loads(data_raw)
        except Exception as e:
            uartComm.clear()
            print(e)
            print('Read Failed')
            data = {'x': 0, 'y': 0}  #need this or robot.drive throws an error

        try:
            signal = reading(reflection)
            uartComm.write(signal)
            print(signal)  #prints json signal
        except Exception as e:
            print(e)
            print("Write Failed")
        #print(data['x'], data['y'])
        robot.drive(data['y'] / 2, 0)
        print(horz.angle())
        horiz_dist = data['x'] * (360 / 90)
        constrain(horiz_dist, xlimits)
        horz.run_target(100, horiz_dist)
예제 #2
0
    x_ang= x_motor.angle()
    y_ang= y_motor.angle()
    #print("X Motor is ", x_ang," Y motor is ", y_ang)
    #Pad for digits to send the data for x and y position as strings

    x_ang= str(x_ang)
    y_ang= str(y_ang)
    anglestring = padder(x_ang, y_ang) 
    #print(len(anglestring))
    print(anglestring)
    return anglestring, x_ang,y_ang


sense = AnalogSensor(Port.S4, False)
sense.voltage()
uart = UARTDevice(Port.S4, 9600, timeout = 10000)
def UARTtest():
    uart.write("TEST")
    wait(100)
    data = uart.read_all()
    print(data)
    ev3.screen.print(data)

# Write your program here
def main():
    #UARTtest()

    x_motor = Motor(Port.C)
    y_motor = Motor(Port.D)
    speed = 0
    y_ang = 0
예제 #3
0
파일: main.py 프로젝트: drfricke/ME35Final
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile

import ubinascii, ujson, urequests, utime


#pycam set up
from pybricks.iodevices import AnalogSensor, UARTDevice
uart = UARTDevice(Port.S1, 9600, timeout=2000)

#On Board motors
rightMotor = Motor(Port.A)
leftMotor = Motor(Port.D)
clawMotor = Motor(Port.B)

#Sensor and Start up values
dist = UltrasonicSensor(Port.S4)
kp = 0.21
travel = 'off'
Motor_input = -150 # pos towards kitchen, neg towards living room


#API Setup
def SL_setup():
    Key = #####
예제 #4
0
        lightData = light_sensor.voltage() + lightData
        counter = counter + 1
    whiteLight = lightData / counter
    return whiteLight


'''
PROGRAM HERE
'''
ev3.speaker.beep()
'''
UART SET-UP
'''
sense1 = AnalogSensor(Port.S4, False)
sense1.voltage()
uart = UARTDevice(Port.S4, 9600, timeout=2000)
'''
MOTOR/SENSOR SET-UP
'''

# # Setup Motors
big_car = Motor(Port.D, Direction.COUNTERCLOCKWISE)
baby_car = Motor(Port.A)

# # Setup Sensors
light_sensor = AnalogSensor(Port.S1, False)
light_sensor.voltage()

#calibrate light sensor
whiteLight = lightCalibration()
ev3.speaker.set_volume(100)
예제 #5
0
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
from pybricks.iodevices import AnalogSensor, UARTDevice

import utime, serial, string, math 
#import IPython.display, imutils
#from matplotlib import pyplot as pyplot

from pybricks.iodevices import AnalogSensor, UARTDevice


# Write your program here
ev3 = EV3Brick()
uart = UARTDevice(Port.S4, 9600, timeout=200)
paddle = Motor(Port.C)
belt = Motor(Port.D)
pusher = Motor(Port.B)
ev3.speaker.beep()
wait(500)
paddle_closed = 0
message = ''
while True:
    belt.dc(23)
    pusher.dc(10)
    try:
       # uart.write('PLEASE WORK'.encode())
       # wait(50)
       if(uart.waiting() > 1):
            message = uart.read(1)
예제 #6
0
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.iodevices import UARTDevice

brick.sound.beep()

ymotor = Motor(Port.B, Direction.CLOCKWISE)
xmotor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
hapticmotor = Motor(Port.C, Direction.COUNTERCLOCKWISE)
direction = 1
print('????')
uart = UARTDevice(Port.S1, 9600, timeout=10000)

wait(500)

uart.write('a')
while uart.waiting() == 0:
    wait(10)
curr = ""
previous = 'q'
uart.write('q')
while True:
    xangle = xmotor.angle()
    yangle = ymotor.angle()
    holder = uart.read(1)
    #print(str(xangle) + " " + str(yangle))
    if yangle > 20 and xangle > 20:
예제 #7
0
파일: EV3code.py 프로젝트: drfricke/sorter
from pybricks.hubs import EV3Brick
from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile

# Write your program here

#start up stuff
from pybricks.parameters import Color, Port
from pybricks.iodevices import AnalogSensor, UARTDevice

uart = UARTDevice(Port.S1, 9600, timeout=2000)
#uart.write("HelloRpi".encode())

#ev3 waits for UART byte - once it sees, it reads it

placer = Motor(Port.A)
trash = Motor(Port.B)
redDudes = Motor(Port.C)

valIfRed = 1  #value pi sends if the brick is red (placeholder)
valIfNotRed = 0  #value pi sends if the brick is not red (placeholder)

placedTarget = 0  #angle value for placer to position brick under camera (placeholder)
placerwaiting = -120  #angle value for placer in the waiting for brick position (placeholder)

redAngleTarget = 300  #angle value for red mover to move red bricks to cup (placeholder)
예제 #8
0
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.iodevices import UARTDevice
from pybricks.parameters import Port
from pybricks.media.ev3dev import SoundFile

# Initialize the EV3
ev3 = EV3Brick()

# Initialize sensor port 2 as a uart device
ser = UARTDevice(Port.S2, baudrate=115200)

# Write some data
ser.write(b'\r\nHello, world!\r\n')

# Play a sound while we wait for some data
for i in range(3):
    ev3.speaker.play_file(SoundFile.HELLO)
    ev3.speaker.play_file(SoundFile.GOOD)
    ev3.speaker.play_file(SoundFile.MORNING)
    print("Bytes waiting to be read:", ser.waiting())

# Read all data received while the sound was playing
data = ser.read_all()
print(data)
예제 #9
0
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.parameters import Color, Port
from pybricks.ev3devices import (Motor, TouchSensor,
ColorSensor, UltrasonicSensor, GyroSensor)
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import AnalogSensor, UARTDevice
import time
import random

ev32 = EV3Brick()

# Initializing the uart device
uart2 = UARTDevice(Port.S1, 9600, timeout=2000)

# Initializing all signals
motorx = Motor(Port.A)
motory = Motor(Port.B)
sensor = ColorSensor(Port.S2)

while True: 
    text =uart2.read_all()
    if text == b'R':
        motorx.run(500)
    elif text == b'L':
        motorx.run(-500)
    elif text == b'N':
        motorx.run(0)
    elif text == b'F':
        motory.run(500)
    elif text == b'B':
예제 #10
0
from pybricks.robotics import DriveBase

#For Serial communication:
from pybricks.parameters import Color, Port
from pybricks.iodevices import AnalogSensor, UARTDevice, I2CDevice
from serial import Serial
import ubinascii, ujson, urequests, utime
import time
# Write your program here
brick.sound.beep()

motor = Motor(Port.A, Direction.CLOCKWISE)
left = Motor(Port.D, Direction.CLOCKWISE)
right = Motor(Port.C, Direction.CLOCKWISE)
robot = DriveBase(left, right, 56, 76.2)
uart = UARTDevice(Port.S1, 9600, timeout=2000)
print(motor.angle())

Key = 'bvd8X9LweQY9o2eP1NYL-p8mLL9wMAk6YYOnYSiIo0'


def SL_setup():
    urlBase = "https://api.systemlinkcloud.com/nitag/v2/tags/"
    headers = {"Accept": "application/json", "x-ni-api-key": Key}
    return urlBase, headers


def Put_SL(Tag, Type, Value):
    urlBase, headers = SL_setup()
    urlValue = urlBase + Tag + "/values/current"
    propValue = {"value": {"type": Type, "value": Value}}
예제 #11
0
#!/usr/bin/env pybricks-micropython
#brickrun -r -- pybricks-micropython

from pybricks.hubs import EV3Brick
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.parameters import Color, Port
from pybricks.ev3devices import Motor
from pybricks.iodevices import AnalogSensor, UARTDevice

# Initialize the EV3
ev3 = EV3Brick()
ev3.speaker.beep()

uart = UARTDevice(Port.S1, 9600, timeout=2000)
# short pins 5/6 (blue and yellow)
uart.write('Test')
wait(10)
data = uart.read_all(
)  #if you connect Pin 5 & 6 you should see Test on the screen
ev3.screen.print(data)

uart.write('Test')
uart.waiting()  # how many bytes on the port
uart.read(uart.waiting())

# Turn the light off
ev3.light.off()
예제 #12
0
#!/usr/bin/env pybricks-micropython
from pybricks.hubs import EV3Brick
from pybricks.parameters import Color, Port
from pybricks.ev3devices import (Motor, TouchSensor,
ColorSensor, UltrasonicSensor, GyroSensor)
from pybricks.tools import wait, StopWatch
from pybricks.iodevices import AnalogSensor, UARTDevice
import time
import random

ev3 = EV3Brick()

# Initializing the uart device
uart = UARTDevice(Port.S1, 9600, timeout=2000)

# Initializing the motors
motor1 = Motor(Port.A)
motor2 = Motor(Port.B)
motor3 = Motor(Port.C)

# Zeroing the initial angles
motor1.reset_angle(0)
motor2.reset_angle(0)

# Starting a timer
startTime = time.time()
timenow = time.time()

while True: 
    # Reads in the angles of motor 1 and 2 '
    yangle = -motor2.angle()
예제 #13
0
            side = 80 - side
        fobj.write(str(side) + ',' + str(up) + '\n')
    else:
        uart.write('a')


brick.sound.beep()
minimotor = Motor(Port.C)
leftmotor = Motor(Port.A, Direction.CLOCKWISE)
watch = StopWatch()
watchside = StopWatch()
rightmotor = Motor(Port.D, Direction.CLOCKWISE)
robot = DriveBase(leftmotor, rightmotor, 40, 200)
color = ColorSensor(Port.S1)

uart = UARTDevice(Port.S4, 9600, timeout=1000)
direction = 1

#initial waiting phase:
holder = b'a'
motorspeed = 0
minispeed = 0
filename = 'letters.csv'
fobj = open(filename, 'w')
for up in range(20):
    print(up)
    watch.reset()
    watch.resume()
    while watch.time() < 200:
        robot.drive(20, 0)
    robot.drive(0, 0)
예제 #14
0
from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.iodevices import UARTDevice

brick.sound.beep()

ymotor = Motor(Port.B, Direction.CLOCKWISE)
xmotor = Motor(Port.A, Direction.COUNTERCLOCKWISE)
direction = 1

uart = UARTDevice(Port.S3, 9600, timeout=10000)

wait(500)

uart.write('a')
print("Done")

curr = ""
previous = 'q'
uart.write('q')
while True:
    xangle = xmotor.angle()
    yangle = ymotor.angle()
    print(str(xangle) + " " + str(yangle))
    if yangle > 20 and xangle > 20:
        curr = 'x'
예제 #15
0
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.iodevices import AnalogSensor, UARTDevice

brick.sound.beep()

minimotor = Motor(Port.C)
leftmotor = Motor(Port.A, Direction.CLOCKWISE)
rightmotor = Motor(Port.D, Direction.CLOCKWISE)
robot = DriveBase(leftmotor, rightmotor, 40, 200)
button = TouchSensor(Port.S1)
color = ColorSensor(Port.S2)

#sense = AnalogSensor(Port.S3, False)
uart = UARTDevice(Port.S3, 9600, timeout=10000)
direction = 1

#initial waiting phase:

handshake = "f"
while uart.waiting() == 0:
    wait(10)

handshake = uart.read(1)
print(handshake)

while True:
    if uart.waiting() != 0:
        print(uart.read(1))
예제 #16
0
from pybricks.tools import print, wait, StopWatch, DataLog
from pybricks.robotics import DriveBase

import math
from pybricks.iodevices import AnalogSensor, UARTDevice

# Write your program here
brick.sound.beep()

joystick = Motor(Port.A)
indicator = Motor(Port.D)
xBut = TouchSensor(Port.S1)
yBut = TouchSensor(Port.S2)

sense = AnalogSensor(Port.S3, False)
uart = UARTDevice(Port.S3, 9600, timeout=2000)


def VibrateMotor():
    joystick.run_angle(1400, 180)


def CompletionVibrate():
    indicator.run_time(1400, 700)


uart.clear()

while True:
    while not (xBut.pressed() | yBut.pressed()):
        wait(100)
예제 #17
0
    motorA.track_target(-100)
    motorB.track_target(100)
    motorC.track_target(100)
    wait(1000)

    motorA.track_target(0)
    motorB.track_target(0)
    motorC.track_target(0)
    wait(200)
    motorD.track_target(0)
    wait(500)


# setup serial port
serial = UARTDevice(Port.S4, baudrate=9600, timeout=None)
serial.clear()
while (1):
    if SystemLink.Get_SL('Start27') == 'true':
        throw_ball()
        SystemLink.Put_SL('Start27', 'BOOLEAN', 'false')
    if touch1.pressed() == True:
        throw_ball()
        SystemLink.Put_SL('Start28', 'BOOLEAN', 'true')

    if len(ev3.buttons.pressed()) > 0:
        print("Catching Ball")
        wait(3000)
        motorD.track_target(40)

        # collect data from serial port and move armw
예제 #18
0
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase
from math import *

import utime, ujson
from pybricks.iodevices import UARTDevice

resetAngle = TouchSensor(Port.S1)
xMotor = Motor(Port.A)
yMotor = Motor(Port.D)
hapticMotor = Motor(Port.B)
uartComm = UARTDevice(Port.S2, 9600)
dZone = 15


def moveEncode(x, y):
    coords = {'x': x, 'y': y}
    moveCMD = ujson.dumps(coords)
    wait(100)
    return moveCMD + ''.join(['B' for i in range(24 - len(moveCMD))])


#Main Function
def main():
    reflection = 100
    #main loop
    while True:
예제 #19
0
파일: main.py 프로젝트: FStraceski/legosort
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.media.ev3dev import SoundFile, ImageFile
from pybricks.iodevices import UARTDevice

# Write your program here
ev3 = EV3Brick()
ev3.speaker.beep()

hopperMotor = Motor(Port.D)
conveyorMotor = Motor(Port.A)
bucketMotor = Motor(Port.B)
light = ColorSensor(Port.S1)

uart = UARTDevice(Port.S4, 115200, timeout=0)
time = StopWatch()
#Set up a queue for bricks on the conveyor belt
brickQueue = []

count = 0
reflectMean = 0
reflectMeanNum = 0
wasBrick = 0
meanSize = 10
numStep = 0
redPos = 0
trashPos = 180 
currPos = 0

bucketMotor.reset_angle(0)