Пример #1
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)

        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
        }
Пример #2
0
    def __init__(self, connected_brick):
        self.brick = connected_brick
        self.motor = ev3.Motor(connected_brick, ev3.MOTOR_PORTS.PORT_A)
        self.touch = ev3.EV3TouchSensor(
            connected_brick, ev3.SENSOR_PORTS.PORT_1).get_touch_mode()
        self.motor.set_speed(1200)

        self.initialize_position()
        self.pos = 0
        self.max_pos = -31000
Пример #3
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
Пример #4
0
    def setup(self):
        right = ev3.Motor(BRICK, "A")
        left = ev3.Motor(BRICK, "D")
        right.set_speed(350)
        right.forward()

        left.set_speed(350)
        left.forward()

        right_motor = BigMotor(right)
        self.add_active_actuators(right_motor)

        rotate = Rotate(right_motor)
        translate = Translate(right_motor)

        self.add_controller(rotate)
        self.add_controller(translate)

        self.add_behavior(Forward({'rotate': rotate, 'translate': translate}))
        self.add_behavior(
            AvoidColliding({
                'rotate': rotate,
                'translate': translate
            }))
Пример #5
0
import ev3
from ev3dev.ev3 import Button
from time import sleep
from math import pi

leftMotor = ev3.Motor("outD")
rightMotor = ev3.Motor("outA")
clawMotor = ev3.Motor("outB")

leftSensor = ev3.ColourSensor("in1")
rightSensor = ev3.ColourSensor("in4")

SILVER = 0

ultrasonicSensor = ev3.UltrasonicSensor("in2")

Buttons = Button()

BASE_POWER = 60
CALIBRATED_RANGE = 10  # The margin of error that is used when checking for colour
WHEEL_CIRCUMFERENCE = 13.573
TURNING_DIAMETRE = 10.5
WATER_TOWER_DETECT_DISTANCE = 8
WATER_TOWER_DETECT_ANGLE = 40
WATER_TOWER_DETECT_ANGLED_DISTANCE = 10.44  # 8 / cos(40)


def withinrange(x, y, range):
    return (x - range / 2 <= y) and (x + range / 2 >= y)

Пример #6
0
 def __init__(self, connected_brick):
     self.left_motor = ev3.Motor(connected_brick, ev3.MOTOR_PORTS.PORT_D)
     self.right_motor = ev3.Motor(connected_brick, ev3.MOTOR_PORTS.PORT_A)
     self._running = True
Пример #7
0
 def __init__(self, connected_brick):
     self._brick = connected_brick
     self.left_motor = ev3.Motor(connected_brick, ev3.MOTOR_PORTS.PORT_D)
     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()
Пример #8
0
# -*- 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()
Пример #9
0
import ev3
ev3.Motor("outA").off("brake")
ev3.Motor("outB").off("brake")
ev3.Motor("outD").off("brake")