def add_brick(self, address): if not self.is_brick_connected(address): try: brick = ev3.connect_to_brick(address) self._connected_brick[address] = brick return True except ev3.BrickNotFoundException: pass # care return False
def add_brick(self, address): if not self.is_brick_connected(address): try: brick = ev3.connect_to_brick(address) self._connected_brick[address] = brick return True except ev3.BrickNotFoundException: pass # care return False
def __init__(self, ip): self.brick = ev3.connect_to_brick(ip) self.belt_motor = ev3.Motor(self.brick, MOTOR_PORTS.PORT_D) self.throw_out_motor = ev3.Motor(self.brick, MOTOR_PORTS.PORT_A) self.throw_out_motor.set_speed(640) ev3_color_sensor = ev3.EV3ColorSensor(self.brick, SENSOR_PORTS.PORT_3) ev3_touch_sensor = ev3.EV3TouchSensor(self.brick, SENSOR_PORTS.PORT_1) self.color = ev3_color_sensor.get_color_id_mode() self.touch = ev3_touch_sensor.get_touch_mode() self.color_movement = { 'blue': self.move_to_blue_position, 'green': self.move_to_green_position, 'yellow': self.move_to_yellow_position, 'red': self.move_to_red_position }
def __init__(self, ip): self.brick = ev3.connect_to_brick(ip) self.belt_motor = ev3.Motor(self.brick, MOTOR_PORTS.PORT_D) self.throw_out_motor = ev3.Motor(self.brick, MOTOR_PORTS.PORT_A) self.throw_out_motor.set_speed(640) ev3_color_sensor = ev3.EV3ColorSensor(self.brick, SENSOR_PORTS.PORT_3) ev3_touch_sensor = ev3.EV3TouchSensor(self.brick, SENSOR_PORTS.PORT_1) self.color = ev3_color_sensor.get_color_id_mode() self.touch = ev3_touch_sensor.get_touch_mode() self.color_movement = { 'blue': self.move_to_blue_position, 'green': self.move_to_green_position, 'yellow': self.move_to_yellow_position, 'red': self.move_to_red_position }
def __init__(self, ip): self._brick = ev3.connect_to_brick(ip) self._belt_motor = ev3.Motor(self._brick, MOTOR_PORTS.PORT_D) self._throw_out_motor = ev3.Motor(self._brick, MOTOR_PORTS.PORT_A) self._throw_out_motor.set_speed(640) self._throw_out_motor.rotate(180, True) ev3_color_sensor = ev3.EV3ColorSensor(self._brick, SENSOR_PORTS.PORT_3) ev3_touch_sensor = ev3.EV3TouchSensor(self._brick, SENSOR_PORTS.PORT_1) self._color = ev3_color_sensor.get_color_id_mode() self._touch = ev3_touch_sensor.get_touch_mode() self._movement = { 'blue': 0, 'green': 200, 'yellow': 350, 'red': 550, } self._position = 0
def __init__(self, ip): self._brick = ev3.connect_to_brick(ip) self._belt_motor = ev3.Motor(self._brick, MOTOR_PORTS.PORT_D) self._throw_out_motor = ev3.Motor(self._brick, MOTOR_PORTS.PORT_A) self._throw_out_motor.set_speed(640) self._throw_out_motor.rotate(180, True) ev3_color_sensor = ev3.EV3ColorSensor(self._brick, SENSOR_PORTS.PORT_3) ev3_touch_sensor = ev3.EV3TouchSensor(self._brick, SENSOR_PORTS.PORT_1) self._color = ev3_color_sensor.get_color_id_mode() self._touch = ev3_touch_sensor.get_touch_mode() self._movement = { 'blue': 0, 'green': 200, 'yellow': 350, 'red': 550, } self._position = 0
# -*- coding: utf-8 -*- import time import ev3 import threading print "starting" time.sleep(1000) # brick = ev3.connect_to_brick(address='10.0.1.1') brick = ev3.connect_to_brick('00:16:53:3D:E4:77') ultrasonic = ev3.EV3UltrasonicSensor(brick, 1) distance = ultrasonic.get_selected_mode() print "opened ultrasonic" def time_that(iterations): time_taken = 0.0 for _ in range(iterations + 1): start = time.time() sample = distance.fetch_sample() end = time.time() time_taken += end - start print(end - start, sample) print "time taken", time_taken print "avg time", time_taken / iterations print "Starting timer" time_that(100000)
# -*- coding: utf-8 -*- import ev3 import time brick = ev3.connect_to_brick(address='10.0.1.1') compass_sensor = ev3.HiTechnicCompass(brick, 1) heading = compass_sensor.get_compass_mode() for _ in range(0, 4): time.sleep(2) print heading.fetch_sample()
self.right_motor = ev3.Motor(connected_brick, ev3.MOTOR_PORTS.PORT_A) self.ultrasonic = ev3.EV3UltrasonicSensor(connected_brick, ev3.SENSOR_PORTS.PORT_1).get_distance_mode() def check(self): distance = self.ultrasonic.fetch_sample()[0] print "DISTANCE:", distance if distance < 0.25 and distance != -1: # returns meter return True return False def action(self): self.left_motor.rotate(600, immediate_return=True) self.right_motor.rotate(-600) def suppress(self): pass if __name__ == "__main__": brick = ev3.connect_to_brick('10.0.1.1') brick.buzz() conjecture = behaviors.subsumption.Controller(True) avoid = AvoidColliding(brick) drive = DriveAround(brick) conjecture.add(avoid) conjecture.add(drive) conjecture.start() brick.beep() # we are complete
# -*- coding: utf-8 -*- import ev3 import pygame pygame.init() brick = ev3.connect_to_brick('00:16:53:3D:E4:77') screen = pygame.display.set_mode((200, 200)) brick.buzz() left_motor = ev3.Motor(brick, ev3.MOTOR_PORTS.PORT_D) right_motor = ev3.Motor(brick, ev3.MOTOR_PORTS.PORT_A) left_motor.set_speed(700) right_motor.set_speed(700) def event_loop(): events = pygame.event.get() for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: left_motor.forward() right_motor.forward() elif event.key == pygame.K_RIGHT: left_motor.forward() right_motor.backward() elif event.key == pygame.K_LEFT: left_motor.backward() right_motor.forward() elif event.key == pygame.K_DOWN: left_motor.backward()