Esempio n. 1
0
def main():
    pygame.init()
    pygame.font.init()

    pygame.display.set_caption("key capture test")

    screen = pygame.display.set_mode((240, 180))

    myfont = pygame.font.Font(pygame.font.get_default_font(), 30)
    textsurface = myfont.render('Some Text', True, (255, 0, 0))
    screen.blit(textsurface, (0, 0))
    pygame.display.update()

    vehicle = ev3_vehicle.TwoWheelVehicle(
        0.02128,  # radius_wheel
        0.1175,  # tread
        protocol=ev3.constants.USB,
    )

    is_driving = None
    running = True
    while running:
        # event handling, gets all event from the event queue
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False

            if event.type == pygame.KEYDOWN:
                mods = pygame.key.get_mods()
                # print("MOD: %s, KEY: %s" % (mods, pygame.key.name(event.key)))

                if event.key == pygame.K_ESCAPE:
                    running = False
                elif event.key == pygame.K_q:  # and mods & pygame.KMOD_META:
                    running = False
                elif event.key == pygame.K_w and mods & pygame.KMOD_META:
                    running = False
                elif event.key == pygame.K_BACKSPACE:
                    running = False
                elif not is_driving:
                    if event.key == pygame.K_UP:
                        is_driving = event.key
                        print("START DRIVING FORWARD")
                        vehicle._drive_straight(25, 0.1)
                    elif event.key == pygame.K_DOWN:
                        is_driving = event.key
                        print("START DRIVING BACKWARD")

            elif event.type == pygame.KEYUP:
                # print("KEY RELEASED: %s" % pygame.key.name(event.key))
                if event.key == is_driving:
                    is_driving = None
                    print("BRAKE")
                    vehicle.stop()

    pygame.quit()
Esempio n. 2
0
def main(screen):

    vehicle = ev3_vehicle.TwoWheelVehicle(
        0.02128,  # radius_wheel
        0.1175,  # tread
        protocol=ev3.constants.USB,
    )

    # turn off input echoing
    curses.noecho()

    # respond to keys immediately (don't wait for enter)
    curses.cbreak()

    # map arrow keys to special values
    screen.keypad(True)

    screen.addstr(0, 0, "Press 'q' to quit")

    i = 0
    while True:
        i += 1

        char = screen.getch()

        if char in (curses.KEY_UP, curses.KEY_DOWN, curses.KEY_RIGHT,
                    curses.KEY_LEFT):
            speed = 25
            if char in (curses.KEY_UP, curses.KEY_RIGHT):
                speed *= -1

            screen.addstr(1, 0,
                          f'Driving {curses.keyname(char).decode():<20} {i}')
            if char in (curses.KEY_UP, curses.KEY_DOWN):
                vehicle._drive_straight(speed, 0.1)
            else:
                vehicle._drive_turn(speed, 0.25, 60, speed < 0)
        else:
            vehicle.stop()
            if char == ord('q'):
                break
Esempio n. 3
0
import ev3, ev3_sound, ev3_vehicle
from task import STATE_STOPPED
import traceback, struct
from time import time
from flask import Flask
wwwapp = Flask(__name__)

my_ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host='00:16:53:55:03:38')
my_music = ev3_sound.Jukebox(ev3_obj=my_ev3)
my_vehicle = ev3_vehicle.TwoWheelVehicle(radius_wheel=0.056,
                                         tread=0.028,
                                         ev3_obj=my_ev3)

curLED = "N/A"
lastUltra = 0
curUltra = -1
curDirection = {"port_ad": "N/A", "port_bc": "N/A"}
curSpeed = {"port_ad": 0, "port_bc": 0}
curSong = None


def ultra(port):
    global lastUltra
    global curUltra
    if time() - lastUltra < 0.5:
        return curUltra
    ops = b''.join([
        ev3.opInput_Device,
        ev3.READY_SI,
        ev3.LCX(0),  # LAYER
        ev3.LCX(port),  # NO
Esempio n. 4
0
#!/usr/bin/env python3

# 2 Azul
# 3 Verde
# 4 Amarillo
# 5 Rojo

import ev3, ev3_vehicle

my_vehicle = ev3_vehicle.TwoWheelVehicle(radius_wheel=0.015835,
                                         tread=0.1689,
                                         protocol=ev3.WIFI,
                                         host='00:16:53:5E:89:BD')
my_vehicle.verbosity = 1
my_vehicle._pos_x = pos_x_init = 0.14
my_vehicle._pos_y = pos_y_init = 0.11
my_vehicle._sync_mode = ev3.SYNC

speed = 40
speed_claw = 20

pieces = [[0.40, 0.30], [0.70, 0.50], [1.10, 0.20]]

stores = {2: [0.1, 0.15], 3: [0.1, 0.30], 4: [0.1, 0.45], 5: [0.1, 0.60]}

# Pick up ALL
for piece in pieces:
    my_vehicle.define_front(claw=False)
    my_vehicle.drive_to(speed, piece[0], piece[1], stop_at=0.23)
    optimal_o = my_vehicle.poll_area(speed, 90)
    my_vehicle.rotate_to(int(speed / 2), optimal_o[0])
Esempio n. 5
0
#!/usr/bin/env python3

import task
import time
import ev3
import ev3_vehicle

vehicle = ev3_vehicle.TwoWheelVehicle(
    0.02128,                 # radius_wheel
    0.1175,                  # tread
    protocol=ev3.constants.USB,
)

speed = 25

vehicle._drive_turn(speed, 0.25, 60, True)
time.sleep(2)
vehicle._drive_straight(speed=speed, distance=None)
time.sleep(1)
vehicle.stop()
Esempio n. 6
0
    f.close()
    if len(mac) != 2 * 6 + 5:
        raise Exception("file MAC_ADDRESS has wrong format")


mac_address = read_mac_address()

e = ev3.EV3(protocol=ev3.BLUETOOTH, host=mac_address)

e.verbosity = 1

ops = b''.join([
    ev3.opSound,
    ev3.TONE,
    ev3.LCX(1),
    ev3.LCX(440),
    ev3.LCX(1000),
])

e.send_direct_cmd(ops)

# v=ev3_vehicle.TwoWheelVehicle(e)

v = ev3_vehicle.TwoWheelVehicle(0.02, 0.02, ev3_obj=e)

v.move(10, 0)

time.sleep(2)

v.stop()