예제 #1
0
def main():
    # Play a sound (1000Hz, 1000ms)
    brick.sound.file(SoundFile.SNORING, 1000)
    brick.sound.file(SoundFile.ERROR_ALARM, 1000)
    brick.display.image(ImageFile.UP)
    brick.sound.file(SoundFile.HELLO, 1000)

    # countodwn 
    brick.sound.file(SoundFile.THREE, 1000)
    brick.sound.file(SoundFile.TWO, 1000)
    brick.sound.file(SoundFile.ONE, 1000)

    brick.sound.file(SoundFile.MOTOR_START, 1000)

    brick.light(Color.RED)

    gameLoop(2)

    # END
    brick.sound.file(SoundFile.MOTOR_STOP, 1000)

    # brick.sound.file(SoundFile.SNEEZING, 1000)
    # brick.sound.file(SoundFile.SMACK, 1000)
    # brick.sound.file(SoundFile.OUCH, 1000)
    # brick.sound.file(SoundFile.CRYING, 1000)
    
    brick.sound.file(SoundFile.GAME_OVER, 1000)
예제 #2
0
def any_button_pressed(waiting_color=Color.RED):
    brick.light(waiting_color)

    while not any(brick.buttons()):
        wait(150)
    brick.light(Color.BLACK)
    return brick.buttons().copy()
 def run(self):
     while not self.stop:
         brick.light(self.color)
         wait(self.on_pause)
         if self.stop:
             return
         brick.light(None)
         wait(self.off_pause)
예제 #4
0
def wait_for_buttonpress():
    # waiting for next command
    brick.sound.file('OOT_PauseMenu_Select.wav')
    brick.light(Color.RED)
    while not any(brick.buttons()):
        wait(10)

    # running next command acknowledgement
    brick.light(Color.GREEN)
예제 #5
0
 def resetGyro(self):
     brick.light(Color.RED)
     speed = self.gyro.speed()
     angle = self.gyro.angle()
     while speed != 0:
         wait(100)
         speed = self.gyro.speed()
         angle = self.gyro.angle()
     self.gyro.reset_angle(0)
     brick.light(Color.GREEN)
예제 #6
0
def runDiagnose():
    brick.display.clear()
    success = True
    #---
    try:
        motor_r = Motor(Port.C)
    except OSError:
        brick.display.text("motor_r port C", (30, 20))
        success = False
    #---
    try:
        motor_l = Motor(Port.B)
    except OSError:
        brick.display.text("motor_l port B", (30, 30))
        success = False
    #---
    try:
        function_r = Motor(Port.D)
    except OSError:
        brick.display.text("function_r port D", (30, 40))
        success = False
    #---
    try:
        function_l = Motor(Port.A)
    except OSError:
        brick.display.text("function_l port A", (30, 50))
        success = False
    #---
    try:
        col_l = ColorSensor(Port.S2)
    except OSError:
        brick.display.text("col_l port 3", (30, 60))
        success = False
    #---
    try:
        col_r = ColorSensor(Port.S3)
    except OSError:
        brick.display.text("col_r port 4", (30, 70))
        success = False
    #---
    # brick.light(Color.PURPLE)
    # #battery
    # if brick.battery.voltage() < 7000:
    #     brick.display.text("battery",(30,80))
    if success == False:
        brick.light(Color.ORANGE)
        for i in range(2):
            brick.sound.beep(500, 50, 25)
            brick.sound.beep(500, 50, 0)
            brick.sound.beep(750, 50, 25)
            brick.sound.beep(500, 50, 0)
    else:
        brick.light(Color.GREEN)

    return success
예제 #7
0
파일: main.py 프로젝트: limingzhou23/Python
 def setSpeed(self, acc):
     if acc < 0:
         self.speed = max(-3, self.speed - 1)
     elif acc > 0:
         self.speed = min(3, self.speed + 1)
     else:
         self.speed = 0
     if self.speed != 0:
         self.motor.run(self.speed * 90)
     else:
         self.motor.stop()
     brick.light(self.colors[abs(self.speed)])
예제 #8
0
def setSpeed(acc):
    global speed
    if acc < 0:
        speed = max(0, speed - 1)
    elif acc > 0:
        speed = min(3, speed + 1)
    else:
        speed = 0
    if speed > 0:
        motor.run(speed * 90)
    else:
        motor.stop()
    brick.light(colors[speed])
예제 #9
0
def foundvictim():
    notes = [(523, 1000), (494, 1000), (440, 500), (330, 500),
             ("repeat", 5, 330), ("repeat", 3, 440), (440, 500), (392, 250),
             (440, 500), (349, 500)]
    #  brick.sound.beep(frequency=500, duration=100, volume=30)
    for note in notes:
        if note[0] == "repeat":
            for i in range(note[1]):
                brick.sound.beep(note[2], 125, 10)
                wait(125)
        else:
            brick.sound.beep(note[0], note[1], 10)

    brick.light(None)
예제 #10
0
def batterychk():
    while True:
        print("Battery level {}".format(brick.battery.voltage()))
        if brick.battery.voltage() < 5000:
            run = False
            robot.stop()
            print("Battery Low {}".format(brick.battery.voltage()))
            brick.display.text("Battery Low", (60, 50))
            while True:
                brick.light(Color.RED)
                brick.sound.beep()
                wait(500)
                brick.light(None)
                brick.sound.beep()
                # brick.sound.speak("Battery Low")
                wait(500)
        wait(2000)
예제 #11
0
 def startup(self):
     brick.light(Color.RED)  # Make the light red
     brick.display.clear()  # Clear the display
     if brick.battery.voltage() < 6000:  # Check the battery voltage
         # if brick.battery.voltage() < 7000: # Check the battery voltage
         brick.sound.beeps(
             10
         )  # Makes 10 simple beeps if the voltage is below 7V, and displays a warning about the battery
         brick.display.text(
             "Low Battery!", (30, 50)
         )  # Print "Low Battery" near the middle of the screen for 1000000 ms in case the battery voltage is less then 7 V
         wait(1000000)
     counting_back = [
         "Counting back: 5", "Counting back: 4", "Counting back: 3",
         "Counting back: 2", "Counting back: 1", "START"
     ]  # Counting back from 5 with 1 second increments and display "Start"
     for counter in counting_back:
         brick.display.text(counter, (30, 50))
         wait(1000)
     brick.display.clear()
예제 #12
0
def wartenAmAnfang():
    """
    Am Anfang eines Programmes warten bis ein Knopf gedrückt wird und danach noch eine halbe Sekunde
    """
    # einmal piepsen
    brick.sound.beep()
    # licht auf rot
    brick.light(Color.RED)
    # bild: ?
    brick.display.image(ImageFile.QUESTION_MARK)
    # "hello" abspielen
    brick.sound.file(SoundFile.HELLO)

    wartenBisKnopfGedruckt()

    # bild: /!\
    brick.display.image(ImageFile.WARNING)
    # licht auf gelb
    brick.light(Color.YELLOW)
    # "OK" abspielen
    brick.sound.file(SoundFile.OKAY)
    # 1/2 Sekunde warten
    wait(500)
    # dreinmal piepsen
    brick.sound.beeps(3)
    # Licht auf normal
    brick.light(None)
    # Bildschirm löschen
    brick.display.clear()
예제 #13
0
def inchWorm(lineCrossingModule, lineFollowingModule, direction):
    brick.light(Color.GREEN)
    lineFollowingModuleAmbience = lineFollowingModule.ambient()
    lineCrossingModuleColor = lineCrossingModule.color()
    lineCrossingModuleAmbience = lineCrossingModule.ambient()
    lineCrossingModuleSeesLine = False
    if lineFollowingModuleAmbience > lineFollowingModule.getEdgeOfLineAmbience(
    ):  # lighter
        lineFollowingModule.run(speedFactor=(1 / 2 * direction))
        lineCrossingModule.run(speedFactor=direction)
    elif lineFollowingModuleAmbience <= lineFollowingModule.getEdgeOfLineAmbience(
    ):  # darker
        if lineCrossingModuleColor == Color.BLACK:
            print("line cross sees line is black")
            lineCrossingModuleSeesLine = True
            brick.light(Color.RED)
            lineCrossingModule.run(speedFactor=(1 / 2 * direction))
            lineFollowingModule.run(speedFactor=(1 / 2 * direction))
        if lineCrossingModuleAmbience < lineCrossingModule.getEdgeOfLineAmbience(
        ):
            print("line cross sees darker than average")
            lineCrossingModuleSeesLine = True
            brick.light(Color.RED)
            lineCrossingModule.run(speedFactor=(1 / 2 * direction))
            lineFollowingModule.run(speedFactor=(1 / 2 * direction))
        else:
            lineCrossingModule.run(speedFactor=(1 / 2 * direction))
            lineFollowingModule.run(speedFactor=direction)
    return lineCrossingModuleSeesLine
예제 #14
0
def tick():
    global j
    global client_skt

    while True:
        j += 1
        print('tick ' + str(j))
        send_result = 0
        try:
            send_result = client_skt.send(bytes('*', 'utf-8'))
        except:
            print('send exception')
        finally:
            sleep(1)
            if (send_result == 0):
                connected = False
                brick.light(Color.RED)
                client_skt.close()
                connect()
            else:
                connection = True
                brick.light(Color.GREEN)
예제 #15
0
def routineRed():
    # Make the light red
    brick.light(Color.RED)
    wait(1000)
    # Turn the light off
    brick.light(None)
예제 #16
0
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.86.23',50001))

s.send(bytes('one\n', 'utf-8'))


turn_motor = Motor(Port.C, Direction.COUNTERCLOCKWISE, [12,36])
extend_motor = Motor(Port.B, Direction.CLOCKWISE, [8,48])
grip_motor = Motor(Port.A, Direction.CLOCKWISE, [12,8])
turn_sensor = TouchSensor(Port.S1)
extend_sensor = TouchSensor(Port.S2)


brick.sound.beep()
brick.light(Color.GREEN)
#turn_motor.run_time(255,5000,Stop.BRAKE,True)
turn_motor.run_until_stalled(255, Stop.COAST, 50)
brick.sound.file(SoundFile.TWO)
s.send(bytes('two\n', 'utf-8'))
turn_motor.reset_angle(-90)


turn_home_found = False
while not turn_home_found:

    turn_motor.run_until_stalled(-255,Stop.COAST,50)
    if turn_sensor.pressed() == True:
        turn_home_found = True
        brick.sound.file(SoundFile.THREE)
        s.send(bytes('three\n', 'utf-8'))
def light(color):
    global flashing_lock
    if isinstance(flashing_lock, (LightPulse, LightFlash)):
        flashing_lock.kill()
        flashing_lock = None
    brick.light(color)
예제 #18
0
brick.display.image('/home/robot/robomest/pics/logo2.bmp')
wait(300)
brick.display.image('/home/robot/robomest/pics/logo3.bmp')
wait(300)
# Joukkueiden logot
#brick.display.image('/home/robot/robomest/pics/bittipol.bmp')
#brick.sound.file(SoundFile.HORN_1)
#wait(2000)
#brick.display.image('/home/robot/robomest/pics/virtaluu.bmp')
#brick.sound.file(SoundFile.LASER)
#wait(2000)
# Show the current voltage on screen and with light colour
brick.display.clear()
brick.display.image('/home/robot/robomest/pics/logo1.bmp')
if brick.battery.voltage() < 6899:
    brick.light(Color.RED)
    brick.display.image('/home/robot/robomest/pics/Bar 0.bmp')
if brick.battery.voltage() < 7199 and brick.battery.voltage() > 6900:
    brick.light(Color.YELLOW)
    brick.display.image('/home/robot/robomest/pics/Bar 1.bmp')
if brick.battery.voltage() < 7499 and brick.battery.voltage() > 7200:
    brick.light(Color.ORANGE)
    brick.display.image('/home/robot/robomest/pics/Bar 2.bmp')
if brick.battery.voltage() < 7899 and brick.battery.voltage() > 7500:
    brick.light(Color.GREEN)
    brick.display.image('/home/robot/robomest/pics/Bar 3.bmp')
if brick.battery.voltage() > 7900:
    brick.light(Color.GREEN)
    brick.display.image('/home/robot/robomest/pics/Bar 4.bmp')
wait(2000)
# Show the current voltage
def test_light():
    brick.light(None)
    with pytest.raises(Exception):
        brick.light()
    # Have the robot spin in a circle 5 times after it has done it's rotation a certain number of times. 
    j = 10

    # Say that if someone touches the touch sensors, it will activate
    while not sensor2.pressed() and not sensor3.pressed():
        wait(10)
    
    # Have the robot beep
    brick.sound.beep()
    
    # Have the robot emit A high pitch(1500 Hz) for one second (1000 ms) at 50% volume 
    brick.sound.beep(1500, 1000, 25)

    # Make the light on the robot red
    brick.light(Color.RED)
    wait(1000)

    # Clear the display
    brick.display.clear()

    # Print ' 'Run.' ' near the middle of the screen 
    brick.display.text("Run.", (60, 50))

    # Print ' 'You Better Run' ' a little bit underneath it 
    brick.display.text("You Better Run", (60, 70))

    # Have the robot continue the loop for a certain number of times.
    while i > 0:
        # Spin Wings at full speed for 2 seconds
        motor3.run(400)
예제 #21
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

# Write your program here

motor = Motor(Port.B)
ultrasonic = UltrasonicSensor(Port.S4)

brick.sound.beep()
brick.light(None)

speed = 0
colors = [None, Color.GREEN, Color.YELLOW, Color.RED]


def setSpeed(acc):
    global speed
    if acc < 0:
        speed = max(0, speed - 1)
    elif acc > 0:
        speed = min(3, speed + 1)
    else:
        speed = 0
    if speed > 0:
        motor.run(speed * 90)
예제 #22
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

# Initialization

# brick.sound.beep()  # Play a beep sound
# brick.sound.beep(1000, 500)  # Play another beep sound, this time with a higher pitch (1000 Hz) and longer duration (500 ms)

brick.display.clear()
brick.light(Color.RED)  # Brick LED is red during initialization

motorL = Motor(Port.A)  # Left motor
motorR = Motor(Port.D)  # Right motor
ultrasonic = UltrasonicSensor(Port.S2)  # Ultrasonic sensor

motorSpeed = 200  # Motor speed
steeringSpeed = 200  # Steering speed (to be used when turning around)
minDistance = 200  # Minimum distance (in mm) before the brick starts decelerating or stops to turn around
maxSpeed = 400

started = False  # Flag to be used as manual start/stop switch; default is False (brick does not move)

###############################################################################################

while True:
예제 #23
0
파일: main.py 프로젝트: rasql/ev3-python
# button left=RED, right=GREEN
# while True:
#     b = brick.buttons()
#     if Button.LEFT in b:
#         brick.light(Color.RED)
#     elif Button.RIGHT in b:
#         brick.light(Color.GREEN)
#     else:
#         brick.light(None)

# up/down buttons to change frequency
freq = 500
while True:
    buttons = brick.buttons()
    if Button.UP in buttons:
        brick.light(Color.GREEN)
        freq += 10
    elif Button.DOWN in buttons:
        brick.light(Color.RED)
        freq -= 10
    else:
        brick.light(None)

    brick.sound.beep(freq, 100, 30)

for i in range(20):
    print('hello world')

brick.sound.beep()

# Initialize a motor at port B.
예제 #24
0
tilt_motor = Motor(Port.B)
radar_motor = Motor(Port.C)
antenna_motor = Motor(Port.D)
vscale = 1
radar = 0
antenna = 0
antenna_c = 0
rotate = 0
tilt = 0
rotate_motor.reset_angle(0)
tilt_motor.reset_angle(0)
#obstacle_sensor = UltrasonicSensor(Port.S4)
#color_sensor = ColorSensor(Port.1)

# fLASH SOME LIGHTS
brick.light(Color.BLACK)
wait(200)
brick.light(Color.GREEN)
wait(200)
brick.light(Color.ORANGE)
wait(200)
brick.light(Color.RED)
wait(200)
brick.light(Color.YELLOW)
wait(200)

# Read buttons and act accordingly. UP button ends
brick.display.text("USE PS4 CONTROLLER")
brick.light(None)

# PS4 control code
예제 #25
0
def routineYellow():
    # Make the light red
    brick.light(Color.YELLOW)
    wait(1000)
    # Turn the light off
    brick.light(None)
예제 #26
0
def routineBlue():
    # Make the light red
    brick.light(Color.BLACK)
    wait(1000)
    # Turn the light off
    brick.light(None)
예제 #27
0
def tracked_wall():
    brick.light(Color.GREEN)
    global wall_counter
    global last_distance
    kp = 1000

    # set distance to seconds
    distance = distanceSensor.distance() / 1000

    # print(str(distance))
    # set stall counter
    global stall_counter

    # print(stall_counter)
    # registered that the robot has passed the wall.
    # used because the bad sensor sometimes registered incorrect high values
    if wall_counter >= 85:
        return True

    # if stalled, move back slightly
    if stall_counter > 0:
        brick.light(Color.RED)
        right_motor.run(45)
        left_motor.run(45)
        stall_counter -= 1
        return False

    # if too far from wall, turn left SHARP
    if distance >= .7:
        wall_counter += 1
        left_motor.run(110)
        right_motor.run(70)
        # print("ERROR" + str(distance))
        last_distance = distance
        return False
    else:
        wall_counter = 0

    # stall and double check if the sudden change in distance is reading correctly
    if not last_distance == 0 and abs(distance - last_distance) > .05:
        # print("CHANGED")
        stop_robot()
        wait(100)
        last_distance = distance
        stall_counter = 15
        return False

    # set normal speed and error distance
    speed = 150
    error = .17 - distance

    # too far, turn left normal
    if error > .05:
        left_motor.run(speed)
        right_motor.run(speed / 2)
    # too close, turn right normal
    elif error < -.05:
        left_motor.run(speed / 2)
        right_motor.run(speed)
    # just right, turn right/left proportional to the error. (PID)
    else:
        right_motor.run(speed - kp * error)
        left_motor.run(speed + kp * error)

    # print(str(distance))
    # print(str(last_distance))

    last_distance = distance
    # turn = 25
    # speed = 200
    # if distance > .2:
    #     left_motor.run(speed - turn)
    #     right_motor.run(speed + turn)
    # elif distance < .15:
    #     left_motor.run(speed + turn)
    #     right_motor.run(speed - turn)

    # print(str(speed-kp*error) + " " + str(speed+kp*error))

    return False
예제 #28
0
def NewColor():
    colorshow.get_next_color()
    brick.light(colorshow.color_number)
예제 #29
0
import socket

client_skt = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connected = False
SERVER_IP = '192.168.86.35'
SERVER_PORT = 50001
_speed = 255

# define motors
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)

# defing sensors
ultrasonic_sensor = UltrasonicSensor(Port.S1)

brick.light(Color.BLACK)
print('running')
j = 0

def GoForwards():
    global _speed
    left_motor.run(_speed)
    right_motor.run(_speed)
    #brick.sound.file(SoundFile.FORWARDS)

def GoBackwards():
    global _speed
    left_motor.run(-1*_speed)
    right_motor.run(-1*_speed)
    #brick.sound.file(SoundFile.BACKWARDS)
예제 #30
0
def routineGreen():
    # Make the light red
    brick.light(Color.GREEN)
    wait(1000)
    # Turn the light off
    brick.light(None)