Пример #1
0
def rd_snr():
    snr = direct_command.DirectCommand()
    snr.add_input_device_ready_raw3(1, 4, 29)
    with ev3.EV3() as brick:
        x = snr.send(brick)
        print x[0]
        return x[0]
Пример #2
0
def main():
    my_ev3 = ev3.EV3(protocol=const.USB)
    my_ev3.verbosity = 1

    print("*** change colors ***")
    for cmd in led_changer(8):
        my_ev3.send_direct_cmd(cmd)
        time.sleep(1)
Пример #3
0
def mv_rbt(direction, turn_ratio, step):
    mv = direct_command.DirectCommand()
    mv.add_output_ready(direct_command.OutputPort.PORT_C
                        | direct_command.OutputPort.PORT_B)
    mv.add_output_step_sync(
        direct_command.OutputPort.PORT_C | direct_command.OutputPort.PORT_B,
        direction, turn_ratio, step, 1)
    with ev3.EV3() as brick:
        mv.send(brick)
Пример #4
0
def rd_snr():
    snr = direct_command.DirectCommand()
    snr.add_input_device_ready_si(0, 0, 33)
    snr.add_input_device_ready_si(1, 2, 29)
    snr.add_input_device_get_bumps(3)
    with ev3.EV3() as brick:
        x = snr.send(brick)
        print x
        return x
def init()-> None:
	global myEV3, ev3host
	try:
		if len(os.environ["EV3"]) < 12:
	   		print ("ERROR EV3 var not set - please use>>> export EV3='Your EV3 Bluetooth MAC Address'")
	   		exit();
		else:
		    ev3host = str(os.environ["EV3"])
		    myEV3 = ev3.EV3(protocol=ev3.BLUETOOTH,host=ev3host)
	except:
	    print ("ERROR EV3 something is wrong EV3 is offline or so")
	    print("Unexpected error:", sys.exc_info()[0])
	    exit()
Пример #6
0
import ev3, struct, time

my_ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host='00:16:53:43:1b:92')


def change_color(color) -> bytes:
    return b''.join([ev3.opUI_Write, ev3.LED, color])


def play_sound(vol: int, freq: int, dur: int) -> bytes:
    return b''.join(
        [ev3.opSound, ev3.TONE,
         ev3.LCX(vol),
         ev3.LCX(freq),
         ev3.LCX(dur)])


def ready() -> None:
    print("Get ready to bump!")
    ops = change_color(ev3.LED_RED)
    my_ev3.send_direct_cmd(ops)
    time.sleep(1)


def steady() -> None:
    print("Steady")
    ops_color = change_color(ev3.LED_ORANGE)
    ops_sound = play_sound(1, 200, 60)
    my_ev3.send_direct_cmd(ops_color + ops_sound)
    time.sleep(0.25)
    for i in range(3):
Пример #7
0
#!/usr/bin/env python3

import ev3, struct, time

my_ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host='00:16:53:4A:47:26')


def change_color(color) -> bytes:
    return b''.join([ev3.opUI_Write, ev3.LED, color])


def play_sound(vol: int, freq: int, dur: int) -> bytes:
    return b''.join(
        [ev3.opSound, ev3.TONE,
         ev3.LCX(vol),
         ev3.LCX(freq),
         ev3.LCX(dur)])


def ready() -> None:
    ops = change_color(ev3.LED_RED)
    my_ev3.send_direct_cmd(ops)
    time.sleep(3)


def steady() -> None:
    ops_color = change_color(ev3.LED_ORANGE)
    ops_sound = play_sound(1, 200, 60)
    my_ev3.send_direct_cmd(ops_color + ops_sound)
    time.sleep(0.25)
    for i in range(3):
 def __init__(self, motors):
     self.host = '00:16:53:4A:BD:5F'
     # self.host = '00:16:53:4A:48:C3'
     self.ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host=self.host)
     self.base_pos = (10, 10)
     self.motors = motors
Пример #9
0
 def __init__(self, motors):
     self.host = '00:16:53:4A:47:26'
     self.ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host=self.host)
     self.base_pos = (10, 10)
     self.motors = motors
     self.base_pos = self.get_degrees_two_motors(self.motors)
Пример #10
0
def LEDs(pattern):
    LED = direct_command.DirectCommand()
    LED.add_set_leds(pattern)
    with ev3.EV3() as brick:
        LED.send(brick)
Пример #11
0
import math
import numpy
import time
import ev3

MBPORT = "/dev/tty.usbmodemFD122"
EVPORT = "/dev/tty.EV3-SerialPort"
BAUD = 115200

s = serial.Serial(MBPORT)
s.baudrate = BAUD
s.parity   = serial.PARITY_NONE
s.databits = serial.EIGHTBITS
s.stopbits = serial.STOPBITS_ONE

evie = ev3.EV3(protocol = ev3.BLUETOOTH, host = EVPORT)
wallee = ev3.TwoWheelVehicle(ev3_obj = evie)
wallee.port_left = ev3.port.B
wallee.port_right = ev3.port.C

st = time.time()
aspeed = .4
fwd = 0
rot = 0

def clamp(t,a,b):
    return max(a,min(t,b))

ops_clear = b''.join([
    ev3.op.Input.Device,
    ev3.cmds.clr.CHANGES,
Пример #12
0
#!/usr/bin/env python3

import ev3, time

my_ev3 = ev3.EV3(protocol=ev3.USB, host='00:16:53:49:CA:06')
my_ev3.verbosity = 1

ops = b''.join([
    ev3.opSound,
    ev3.PLAY,
    ev3.LCX(100),                  # VOLUME
    ev3.LCS('./ui/DownloadSucces') # NAME
])
my_ev3.send_direct_cmd(ops)

ops = b''.join([
    ev3.opSound,
    ev3.REPEAT,
    ev3.LCX(50),                  # VOLUME
    ev3.LCS('./ui/DownloadSucces') # NAME
])
my_ev3.send_direct_cmd(ops)
time.sleep(3)
ops = b''.join([
    ev3.opSound,
    ev3.BREAK
])
my_ev3.send_direct_cmd(ops)

ops = b''.join([
    ev3.opSound,
Пример #13
0
	def __init__(self, classifier: cls.SimpleClassifier, filter_settings: utils.FilterSettings,
				feature_extraction_info: utils.FeatureExtractionInfo,
				feature_types: [],
				trial_classes: [utils.TrialClass],
				parent=None,
				config: OnlineClassifierConfigurations = OnlineClassifierConfigurations()):
		super().__init__(parent)
		self.setWindowTitle("Online Classifier")
		self.setWindowModality(PyQt5.QtCore.Qt.ApplicationModal)

		# self.vibration_serial = serial.Serial(port=utils.vibration_port(), baudrate=115200, timeout=5000)
		# if not self.vibration_serial.isOpen():
		# 	print("Opening port")
		# 	self.vibration_serial.open()
		# else:
		# 	print("Port is already open")

		self.classifier = classifier
		self.filter_settings = filter_settings
		self.feature_extraction_info = feature_extraction_info
		self.feature_types = feature_types
		self.trial_classes = trial_classes
		self.config = config

		self.slice_generator = utils.SliceIndexGenerator(global_config.SAMPLING_RATE, trial_classes)
		self.sample_count = 0

		self.trial_count = 0
		self.correct_count = 0

		self.INTERNAL_BUFFER_EXTRA_SIZE = self.INTERNAL_BUFFER_EXTRA_DURATION * self.feature_extraction_info.sampling_rate

		self.data_buffer = np.array([])

		self.root_layout = QGridLayout()
		self.root_layout.setAlignment(PyQt5.QtCore.Qt.AlignTop)
		self.root_widget = QWidget()
		self.root_widget.setLayout(self.root_layout)
		self.setCentralWidget(self.root_widget)

		title = QLabel("<h1>Online Classifier</h1>")
		title.setAlignment(PyQt5.QtCore.Qt.AlignCenter)
		self.root_layout.addWidget(title, 0, 0, 1, 3)

		self.feature_window_edit = QLineEdit()
		self.feature_window_edit.setText(str(self.config.feature_window_size))

		self.repetition_interval_edit = QLineEdit()
		self.repetition_interval_edit.setText(str(self.config.repetition_interval))

		self.detection_threshold_edit = QLineEdit()
		self.detection_threshold_edit.setText(str(self.config.detection_threshold))

		self.online_training_checkbox = QCheckBox("Online Training")
		self.online_training = False

		self.robot_connect_btn = QPushButton("Connect to EV3")
		self.robot_connect_btn.clicked.connect(self.connect_clicked)

		self.manual_control_checkbox = QCheckBox("Manual Control")

		self.ev3 = ev3.EV3(self.EV3_MAC_ADDRESS)
		self.motor_control = ev3.MotorControl(1, 8, self.ev3)
		self.previous_direction = None

		self.previous_test_set_accuracy = 0.0
		self.previous_cross_validation_accuracy = 0.0

		self.root_layout.addWidget(utils.construct_horizontal_box([
			QLabel("Feature Window Size (sec): "), self.feature_window_edit,
			QLabel("Repetition Interval (sec): "), self.repetition_interval_edit,
			QLabel("Detection Threshold: "), self.detection_threshold_edit,
			self.online_training_checkbox,
			self.robot_connect_btn, self.manual_control_checkbox
		]), 1, 0, 1, 3)

		self.root_directory_label = QLabel()
		self.pick_root_directory_btn = QPushButton("Select/Change")
		self.pick_root_directory_btn.clicked.connect(self.pick_root_directory)

		self.root_layout.addWidget(utils.construct_horizontal_box([
			QLabel("Root directory:"), self.root_directory_label, self.pick_root_directory_btn
		]), 2, 0, 1, 3)

		self.start_btn = QPushButton("Start Streaming")
		self.start_btn.clicked.connect(self.start_clicked)
		self.stop_btn = QPushButton("Stop Streaming")
		self.stop_btn.clicked.connect(self.stop_clicked)

		self.root_layout.addWidget(utils.construct_horizontal_box([
			self.stop_btn, self.start_btn
		]), 3, 0, 1, 3)

		self.class_label = QLabel("Start stream to see result")
		self.class_label.setAlignment(PyQt5.QtCore.Qt.AlignCenter)

		self.root_layout.addWidget(self.class_label, 4, 0, 1, 3)

		self.root_layout.addWidget(utils.construct_horizontal_box([
			QLabel("<h2>Mental Tasks:</h2>")
		]), 5, 0, 1, 3)

		self.training_tasks_widget = QWidget()
		self.training_tasks_layout = QHBoxLayout()
		self.training_tasks_widget.setLayout(self.training_tasks_layout)

		self.class_tiles_list = []

		for trial_class in trial_classes:
			self.class_tiles_list.append(TrainingTaskTile(trial_class, self.CLASS_IMAGE_HEIGHT / 2))
			self.training_tasks_layout.addWidget(self.class_tiles_list[-1])

		self.root_layout.addWidget(self.training_tasks_widget, 6, 0, 1, 3)

		self.class_pixmap = QPixmap()

		self.log_textarea = QPlainTextEdit()

		self.root_layout.addWidget(self.log_textarea, 7, 0, 1, 3)

		self.board = self.initialize_board()
		self.board.prepare_session()

		self.reading_timer = None
		self.samples_push_count = 0
		self.online_training_samples_push_count = 0
		self.online_training_timer = None
		self.current_mental_task = None

		self.show()
Пример #14
0
#!/usr/bin/env python3

import curses
import ev3

myEV3 = ev3.EV3(protocol=ev3.WIFI, host='00:16:53:5E:89:BD')

# Program to calculate radious of the wheel 
ops = b''.join([
        ev3.opOutput_Step_Sync,
        ev3.LCX(0),                       # LAYER
        ev3.LCX(ev3.PORT_A + ev3.PORT_D), # NOS
        ev3.LCX(20),                      # SPEED
        ev3.LCX(0),                       # TURN
        ev3.LCX(3600),                    # STEP
        ev3.LCX(1),                       # BR
        ev3.opOutput_Start,
        ev3.LCX(0),                       # LAYER
        ev3.LCX(ev3.PORT_A + ev3.PORT_D)  # NOS
    ])

myEV3.send_direct_cmd(ops)

# It moved 99 - 99.5 cm 
# radius_wheel = distance / (20 * pi) = 0.015835

Пример #15
0
#! python3

# http://ev3directcommands.blogspot.co.uk/

import ev3
import time
import struct

my_ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host='/dev/tty.EV3-SerialPort')
my_ev3.sync_mode = ev3.SYNC
my_ev3.verbosity = 0
ev3_car = ev3.TwoWheelVehicle(ev3_obj=my_ev3)
ev3_car.verbosity = 1
ev3_car.port_left = ev3.port.B
ev3_car.port_right = ev3.port.C
#ev3_car.move(50,0)
ev3_car.stop()

ops = b''.join(
    [ev3.op.Com.Get, ev3.cmds.get.BRICKNAME,
     ev3.LCX(16),
     ev3.GVX(0)])

ops_clear = b''.join(
    [ev3.op.Input.Device, ev3.cmds.clr.CHANGES,
     ev3.LCX(0),
     ev3.LCX(0)])

ops_read = b''.join([
    ev3.op.Input.Device, ev3.cmds.Ready.SI,
    ev3.LCX(0),
Пример #16
0
import ev3, ev3_sound, ev3_vehicle
from task import STATE_STOPPED
import traceback, struct
from time import time

my_ev3 = ev3.EV3(protocol=ev3.BLUETOOTH, host='00:16:53:4f:28:a6')
my_vehicle = ev3_vehicle.TwoWheelVehicle(radius_wheel=0.056,tread=0.028,ev3_obj=my_ev3)
Пример #17
0
 def __init__(self):
     self.bricks = [
         ev3.EV3(protocol='Usb', host=host) for host in Robot.HOSTS
     ]
Пример #18
0
#
# print(binascii.hexlify(command))
# print(numerical.hex_str(command))
#
# socket.send(bytes(command))
#
# result = socket.recv(5)
#
# print(binascii.hexlify(result))
# print(numerical.hex_str(result))
#
# socket.close()
#
# print("Disconnected")

robot = ev3.EV3(MAC_ADDRESS)
robot.connect()

# builder = ev3.CommandBuilder()
# sound = ev3.OperationSound()
# sound.tone(50, 500, 5000)
# builder.append_command(sound)
#
# stop_cmd = builder.build(message_counter=42)
#
# print(binascii.hexlify(stop_cmd))
#
# robot.send_direct_command(stop_cmd)
#
# time.sleep(2)
#
Пример #19
0
#!/usr/bin/env python3

import time
import ev3

my_ev3 = ev3.EV3(protocol=ev3.WIFI, host='00:16:53:44:23:17')
my_ev3.verbosity = 1

from ev3mail import *

for i in range(5):

    s = ev3mailbox.encodeMessage(MessageType.Numeric, 'abc', i)

    print(i)
    my_ev3.send_system_cmd(s, False)
    time.sleep(1)

    s = ev3mailbox.encodeMessage(MessageType.Numeric, 'def', i + 100)
    my_ev3.send_system_cmd(s, False)
Пример #20
0
def stop_rbt():
    stop = direct_command.DirectCommand()
    stop.add_output_stop(
        direct_command.OutputPort.PORT_C | direct_command.OutputPort.PORT_B, 1)
    with ev3.EV3() as brick:
        stop.send(brick)
Пример #21
0
    cmd += cmd_rotate(ports1, deg1)
    cmd += cmd_waitdeg_wait(deg1, waitport, 0, 8)
    cmd += cmd_rotate(ports2, deg2)
    cmd += cmd_waitdeg_wait(deg1, waitport, 4, 8)
    brick.send_direct_cmd(cmd, global_mem=12)


# Check if a button is pressed
def is_pressed(brick, port):
    cmd = b''.join([
        ev3.opInput_Read,
        ev3.LCX(0),
        ev3.LCX(port),
        ev3.LCX(16),
        ev3.LCX(0),
        ev3.GVX(0)
    ])
    return struct.unpack('<b',
                         brick.send_direct_cmd(cmd, global_mem=1)[5:])[0] > 0


if __name__ == '__main__':
    brick = ev3.EV3(protocol='Usb', host='00:16:53:7F:36:D9')

    import time
    # time.sleep(5)
    tick = time.time()
    rotate(brick, ev3.PORT_A + ev3.PORT_B, 30, 15)
    # rotate(brick, ev3.PORT_C + ev3.PORT_D, 54, 53)
    print(time.time() - tick)
Пример #22
0
def rst_tch():
    chk2 = direct_command.DirectCommand()
    chk2.add_input_device_clr_all(3)
    with ev3.EV3() as brick:
        chk2.send(brick)
Пример #23
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
Пример #24
0
import time


def read_mac_address():
    # read MAC ADDRESS from file (in gitignore)
    f = open("MAC_ADDRESS", "r")
    mac = f.read().strip()
    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)