Ejemplo n.º 1
0
def GreenMission(): # Green Run (Boccia Frame, Boccia Share, and Dance Mission)

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.


    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    front_largeMotor = Motor(Port.D)

    wheel_diameter = 56
    axle_track = 114.3 

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    ## Write your code here: 
    
    robot.settings(300) # Speed Change
    
    ## The robot goes straight until the Boccia Mission's target. 
    robot.straight(1050)

    ## The robot moves the large motor down to drop the cubes into the target. 
    front_largeMotor.run_angle(80, 110, then=Stop.HOLD, wait=True)

    ## BOCCIA SHARE !!!
    robot.straight(-220)
    robot.turn(-100)
    robot.straight(135)
    front_largeMotor.run_angle(-80, 105, then=Stop.HOLD, wait=True)
    robot.straight(-60)
    robot.turn(-100)
    robot.straight(-80)

    # This is the DANCE Mission!
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)

    robot.stop(Stop.BRAKE)
Ejemplo n.º 2
0
def BlackMission():
    
    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    #define your variables
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    large_motor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115  
    line_sensor = ColorSensor(Port.S2)
    line_sensor1 = ColorSensor(Port.S3)
    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
    
    robot.settings(140)

    robot.straight(350) 
    robot.straight(-97)
    robot.turn(-40)
  
    large_motor.run_angle(30,50,then=Stop.HOLD, wait=True)
    
    ev3.speaker.beep(15)
    large_motor.run_angle(60,-180,then=Stop.HOLD, wait=False)
    robot.straight(-300)
   
    
    wait(10000)
    robot.stop(Stop.BRAKE)
    robot.settings(240)
    ev3.speaker.beep(20)
    robot.straight(390)
    ev3.speaker.beep(300)
    large_motor.run_angle(60,130)
    
    robot.straight(-90)
    large_motor.run_angle(60,40,then=Stop.HOLD, wait=True)
    robot.straight(-500)
    # test straight after beep and see if it works...
    robot.stop(Stop.BRAKE)
Ejemplo n.º 3
0
def RedMission(): # Red Run (Bench Mission (including backrest removal))
    
    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.


    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    wheel_diameter = 56
    axle_track = 115

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    Medium_Motor = Motor(Port.A)
    Large_Motor = Motor(Port.D)

    leftcolorsensor = ColorSensor(Port.S3)
    rightcolorsensor = ColorSensor(Port.S2)


    robot.settings(300) # Speed change

    # Starts off from base and approaches the bench model.
    robot.straight(200)
    robot.turn(-115)

    # Removes backrest and flattens the bench.
    Medium_Motor.run_angle(300, 135, then=Stop.HOLD, wait=True)
    robot.stop(Stop.BRAKE)
    robot.settings(500)
    robot.turn(-60)

    # Returns to base.
    robot.straight(400)

    Large_Motor.run_angle(80, 95, then=Stop.HOLD, wait=True)

    robot.stop(Stop.BRAKE)
Ejemplo n.º 4
0
def slide(robot):
    robot.stop()
    motor_b, motor_c = Motor(Port.B,
                             positive_direction=Direction.CLOCKWISE), Motor(
                                 Port.C,
                                 positive_direction=Direction.CLOCKWISE)
    robot = DriveBase(motor_b, motor_c, wheel_diameter=94.2, axle_track=95)
    robot.straight(220)
    wait(500)
    # robot.stop()
    while gyro.angle() < 265:
        robot.drive(-100, 80)
    dead_stop()
    motor_a.run_angle(1500, -1000, then=Stop.HOLD, wait=False)
    robot.straight(515)
    dead_stop()
    robot.turn(125)  # 105
    robot.stop()
    motor_b, motor_c = Motor(
        Port.B, positive_direction=Direction.COUNTERCLOCKWISE), Motor(
            Port.C, positive_direction=Direction.COUNTERCLOCKWISE)
    robot = DriveBase(motor_b, motor_c, wheel_diameter=94.2, axle_track=95)
    robot.straight(200)
    robot.turn(70)
    robot.turn(-60)
    LineFollow(100, 1.05, robot, 50)
    robot.straight(250)
Ejemplo n.º 5
0
def Treadmill(robot):
    moveTank(-300, 95, -130)
    robot.turn(105)
    robot.stop()
    motor_b, motor_c = Motor(
        Port.B, positive_direction=Direction.COUNTERCLOCKWISE), Motor(
            Port.C, positive_direction=Direction.COUNTERCLOCKWISE)
    robot = DriveBase(motor_b, motor_c, wheel_diameter=94.2, axle_track=95)
    LineFollow(70, 1.05, robot, 200)
    robot.turn(28)
    robot.straight(180)
    robot.turn(-28)
    motor_d.run_time(-500, 1000, then=Stop.COAST, wait=False)
    robot.straight(70)
    wait(1000)
    motor_d.run_time(-200, 10000, then=Stop.COAST, wait=True)
    robot.stop()
Ejemplo n.º 6
0
def GreenMission(): # Green Run (Boccia Frame, Boccia Share, and Dance Mission)
    # RIGHT BUTTON
    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.


    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    front_largeMotor = Motor(Port.D)

    wheel_diameter = 56
    axle_track = 114.3 

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
    robot.settings(300) 
    robot.straight(1050) 
    front_largeMotor.run_angle(80, 110, then=Stop.HOLD, wait=True)
    front_largeMotor.run_angle(80, -110, then=Stop.HOLD, wait=False)
    robot.straight(-1100)
    wait(7000)
    robot.straight(380)
    front_largeMotor.run_angle(60,90)
    robot.straight(-150)
    front_largeMotor.run_angle(60,40,then=Stop.HOLD, wait=True)
    robot.straight(-500)
    front_largeMotor.run_angle(60,-130,then=Stop.HOLD, wait=True)
    ev3.speaker.beep(7000)
    robot.stop(Stop.BRAKE)
Ejemplo n.º 7
0
def BlackMission(
):  # Black Run (Innovatice Architecture, Health Units, Hopscotch, Bringing Slide Figures back HOME)

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                     InfraredSensor, UltrasonicSensor,
                                     GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile

    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    # define your variables
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    large_motor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115
    line_sensor = ColorSensor(Port.S2)
    line_sensor1 = ColorSensor(Port.S3)
    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    robot.settings(500)  # To change the SPEED

    # Pushing our innovative architecture and the health units.
    robot.straight(-350)
    robot.straight(50)
    robot.turn(-15)
    robot.straight(-70)
    robot.turn(-206)
    robot.straight(15)
    large_motor.run_angle(60, 80, then=Stop.HOLD, wait=True)
    robot.stop(Stop.BRAKE)
    robot.straight(-340)
    robot.stop(Stop.BRAKE)
Ejemplo n.º 8
0
def Bench_M04():
    # Initialize the motors.

    robot = DriveBase(left_motor,
                      right_motor,
                      wheel_diameter=95,
                      axle_track=94)

    robot.settings(800, 200, 100, 50)
    ev3 = EV3Brick()
    # ev3.speaker.say("LICKo is the best and will definitely win!")

    # go forward
    robot.straight(distance=720)
    # robot.turn(angle=-10)
    robot.turn(angle=30)
    # robot.straight(distance=-100)
    medium_motor.run_time(speed=750, time=125, then=Stop.HOLD, wait=True)
    medium_motor.run_until_stalled(1000)
    robot.straight(distance=-250)
    # medium_motor.run_time(speed=2500, time=500, then=Stop.HOLD, wait=True)
    # medium_motor.run_time(speed=-100, time=75, then=Stop.HOLD, wait=True)
    robot.straight(distance=425)
    medium_motor.run_time(speed=-1000, time=925, then=Stop.HOLD, wait=True)
    medium_motor.run_until_stalled(1000)
    ev3.speaker.say("YAY!")
    ev3.speaker.say("Sigh...")
Ejemplo n.º 9
0
def Basket_05():
    # robot.settings(800,200,100,50)
    ev3.speaker.say("LICKo is the best")
    robot.straight(distance=600)
    robot.turn(-200)
    robot.straight(distance=1111)
    robot.turn(-100)
    robot.straight(distance=128)
    # ev3.speaker.say("Robot drops green thing into basket")
    medium_motor.run_time(speed=550, time=400, then=Stop.HOLD, wait=True)
    medium_motor.run_time(speed=-250, time=400, then=Stop.HOLD, wait=True)
    medium_motor.run_time(speed=550, time=400, then=Stop.HOLD, wait=True)
    # arm goes up
    # ev3.speaker.say("arm goes up")
    medium_motor.run_until_stalled(-500)
    # robot goes back
    # ev3.speaker.say("robot goes back")
    robot = DriveBase(left_motor,
                      right_motor,
                      wheel_diameter=95,
                      axle_track=94)
    robot.straight(distance=-200)
    # arm goes to the ground until it can't go farther
    # ev3.speaker.say("arm goes to the ground until it can't")
    medium_motor.run_time(speed=1000, time=125, then=Stop.HOLD, wait=True)
    medium_motor.run_until_stalled(1000)
    # arm goes up
    # ev3.speaker.say("arm goes up")
    medium_motor.run_angle(speed=50,
                           rotation_angle=-55,
                           then=Stop.HOLD,
                           wait=False)
    # ev3.speaker.say("Gooooooo!")
    robot.straight(distance=325)
    # medium_motor.run_time(speed=-1700, time=400, then=Stop.HOLD, wait=True)
    medium_motor.run_angle(speed=5000,
                           rotation_angle=-250,
                           then=Stop.HOLD,
                           wait=True)
    wait(10000)
Ejemplo n.º 10
0
def erstes():

    ev3.speaker.beep()

    m_r = Motor(Port.C, Direction.COUNTERCLOCKWISE)
    m_l = Motor(Port.B, Direction.COUNTERCLOCKWISE)

    db = DriveBase(m_l, m_r, wheel_diameter=30, axle_track=140)

    db.straight(distance=50)
    db.turn(90)
    db.straight(distance=-50)

    # play some sound and get angry
    #im = Image('./Angry.bmp')
    im = ImageFile.ANGRY
    ev3.screen.load_image(im)
    ev3.speaker.play_file(SoundFile.CAT_PURR)

    # drive up to a distance of 100 mm
    db.drive(speed=10, turn_rate=0)  # start driving
    while abs(db.distance()) < 100:
        time.sleep(0.1)  # wait 100 msec before querying distance again
    db.stop()
Ejemplo n.º 11
0
def RedMission1():

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                     InfraredSensor, UltrasonicSensor,
                                     GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile

    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    wheel_diameter = 56
    axle_track = 115

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    Medium_Motor = Motor(Port.A)
    Large_Motor = Motor(Port.D)

    leftcolorsensor = ColorSensor(Port.S3)
    rightcolorsensor = ColorSensor(Port.S2)

    #####

    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2

    ######

    robot.straight(320)
    robot.turn(110)

    while True:
        robot.drive(90, 0)
        if leftcolorsensor.reflection() <= 9:
            robot.stop(Stop.BRAKE)
            break

    robot.turn(-110)

    robot.straight(200)

    # Calculate the light threshold. Choose values based on your measurements.
    BLACK = 6
    WHITE = 85
    threshold = (BLACK + WHITE) / 2

    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 110

    # Set the gain of the proportional line controller. This means that for every
    # percentage point of light deviating from the threshold, we set the turn
    # rate of the drivebase to 1.2 degrees per second.

    # For example, if the light value deviates from the threshold by 10, the robot
    # steers at 10*1.2 = 12 degrees per second.
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    # Start following the line endlessly.
    while runWhile:
        # Calculate the deviation from the threshold.
        deviation = rightcolorsensor.reflection() - threshold

        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation

        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)

        if robot.distance() == 1000:
            runWhile = False

    # robot stops after finishing up line following code

    robot.stop(Stop.BRAKE)

    robot.straight(-40)

    robot.turn(-50)
    robot.straight(145)
    Large_Motor.run_angle(50, 90, then=Stop.HOLD, wait=True)

    #robot continues run, to do Boccia mission

    while True:
        robot.drive(-80, 0)
        if leftcolorsensor.reflection() <= 10:
            robot.stop(Stop.BRAKE)
            break

    robot.straight(80)
    robot.turn(60)
    robot.straight(100)

    Large_Motor.run_angle(-50, 150, then=Stop.HOLD, wait=True)
    robot.straight(-40)
    Large_Motor.run_angle(50, 150, then=Stop.HOLD, wait=True)

    robot.straight(-40)

    while True:
        robot.drive(-80, 0)
        if leftcolorsensor.reflection() <= 9:
            robot.stop(Stop.BRAKE)
            break

    robot.straight(40)
    robot.turn(-85)

    robot.straight(340)
    robot.turn(165)

    robot.straight(55)
    Large_Motor.run_angle(-50, 150, then=Stop.HOLD, wait=True)

    robot.straight(20)

    Medium_Motor.run_angle(150, 250, then=Stop.HOLD, wait=True)
    robot.turn(70)
    Medium_Motor.run_angle(-150, 250, then=Stop.HOLD, wait=True)
    robot.turn(-20)
    robot.straight(-35)
    Medium_Motor.run_angle(150, 250, then=Stop.HOLD, wait=True)

    robot.turn(30)
    robot.straight(-130)
Ejemplo n.º 12
0
def YellowMission():

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                     InfraredSensor, UltrasonicSensor,
                                     GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile

    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    # Create your objects here.
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    front_largeMotor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
    # Initialize the color sensor.
    line_sensor = ColorSensor(Port.S2)
    line_sensor2 = ColorSensor(Port.S3)

    robot.straight(110)

    # Calculate the light threshold. Choose values based on your measurements.
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2

    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100

    # Set the gain of the proportional line controller. This means that for every
    # percentage point of light deviating from the threshold, we set the turn
    # rate of the drivebase to 1.2 degrees per second.

    # For example, if the light value deviates from the threshold by 10, the robot
    # steers at 10*1.2 = 12 degrees per second.
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    # Start following the line endlessly.
    while runWhile:
        # Calculate the deviation from the threshold.
        deviation = line_sensor.reflection() - threshold

        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation

        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)

        if robot.distance() == 800:
            runWhile = False

    robot.stop(Stop.BRAKE)

    robot.drive(100, 0)
    if line_sensor2 and cl.Color() == Color.BLACK:
        robot.stop(Stop.BRAKE)

    # robot stops after finishing up line following code
    robot.stop(Stop.BRAKE)

    # robot turns after finishing up line following code
    robot.turn(-103.5)
    # robot goes straight as it heads towards the mission
    robot.straight(138)
    # robot turns right for 90 degrees
    robot.turn(80)
    # robot goes straight towards the mission to line the attachment to the wheel
    robot.straight(97)
    # large motor attachment goes down to trap the wheel in
    front_largeMotor.run_angle(60, 162)
    # robot moves backwards to bring wheel outside of the large circle
    robot.straight(-115)
    # large motor releases the trapped tire
    front_largeMotor.run_angle(60, -148)
    # robot moves straight to get closer the wheel
    robot.straight(38)
    # robot turns so the wheel can get into the smaller target
    robot.turn(-40)
    robot.stop(Stop.BRAKE)
    # robot goes backwards to leave the target and the wheel inside of it
    robot.straight(-110)
    # robot turns towards the weight machine
    robot.turn(-30)
    # going straight from row machine to weight machine
    robot.straight(505)
    # stopping for accuracy.
    robot.stop(Stop.BRAKE)
    # turning towards the weight machine.
    robot.turn(30)
    # robot goes straight to get closer to the weight machine
    robot.straight(145)
    # large motor going down to complete mission (weight machine).
    front_largeMotor.run_angle(120, 130)
    # going backwards away from the weight machine
    robot.straight(-120)
    # large motor goes back up
    # front_largeMotor.run_angle(50, -100)
    ## The robot is turning away from the Weight Machine and towards the Boccia.
    robot.turn(-127)
    ## The robot is moving straight towards the Boccia Mission.
    robot.straight(290)
    # the robot turns right to turn the aim boccia with the yellow axle on the bottom of the bot.
    robot.turn(60)
    # robot.straight(-10)
    # robot.turn(15)
    # front_largeMotor.run_angle(50, 60)
    # robot.straight(55)
    # the large motor goes up to push the yellow cube down into the target area.
    front_largeMotor.run_angle(50, -50)
    robot.straight(-100)
    robot.turn(-45)
    robot.straight(900)
    robot.turn(25)
    robot.straight(700)
Ejemplo n.º 13
0
def BlackandGreen():

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                     InfraredSensor, UltrasonicSensor,
                                     GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile

    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    #define your variables
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    large_motor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115
    line_sensor = ColorSensor(Port.S2)
    line_sensor1 = ColorSensor(Port.S3)
    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
    #follows the line underneath the pull up bar until the leftsensor detects black
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    #goes straight to get ready for line following then resets the distance
    robot.straight(250)
    robot.reset()
    #starts to follow the line towards the replay logo
    while True:
        # Calculate the deviation from the threshold.
        deviation = line_sensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(robot.distance())
        if (robot.distance() >= 450):
            robot.stop(Stop.BRAKE)
            break
    #the robot pushes the phone into the replay logo and moves back to get ready to drop the health units into the replay logo
    robot.straight(-75)
    robot.stop(Stop.BRAKE)
    #the robot then turns so it is going to be perfectly into the replay logo
    robot.turn(-35)
    #the robot drops the health units
    large_motor.run_angle(100, 150)
    #then turns to an angle to go back to base
    robot.turn(50)
    robot.straight(-1000)

    wait(50)

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                     InfraredSensor, UltrasonicSensor,
                                     GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile

    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    front_largeMotor = Motor(Port.D)

    wheel_diameter = 56
    axle_track = 114.3

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    ## Write your code here:

    ## The robot goes straight until the Boccia Mission's target.
    robot.straight(1060)

    ## The robot moves the large motor down to drop the cubes in the target.
    front_largeMotor.run_angle(80, 70, then=Stop.HOLD, wait=True)
    front_largeMotor.run_angle(-80, 70, then=Stop.HOLD, wait=True)

    ## Dance Mission

    ## The robot moves backwards to reach the Dance Floor so it can Dance as the last mission.
    robot.straight(-185)
    robot.turn(-70)
    robot.straight(138)

    ## The following code is all the dance moves we do for the Dance Mission.

    robot.turn(160)
    robot.turn(-160)
    robot.straight(60)
    front_largeMotor.run_target(500, 60)
    front_largeMotor.run_target(500, -40)
    robot.straight(-60)
    robot.turn(260)
    robot.turn(-260)
    robot.turn(100)
    robot.straight(40)
    robot.turn(100)
    front_largeMotor.run_angle(500, 30)
Ejemplo n.º 14
0
def BlueMission():

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                     InfraredSensor, UltrasonicSensor,
                                     GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile

    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    #define your variables
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    large_motor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115
    line_sensor = ColorSensor(Port.S2)
    line_sensor1 = ColorSensor(Port.S3)
    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    #go front towards the step counter
    robot.straight(650)
    robot.stop(Stop.BRAKE)
    wait(20)

    #makes the robot go slower
    robot.settings(40)

    #slowly pushes the step counter by going back and front 2 times
    robot.straight(140)
    robot.stop(Stop.BRAKE)
    robot.straight(-45)
    robot.stop(Stop.BRAKE)
    robot.straight(120)
    robot.stop(Stop.BRAKE)
    robot.settings(100)
    robot.straight(-30)
    robot.stop(Stop.BRAKE)
    #the robot then turns and goes backwards
    robot.turn(45)
    robot.straight(-100)
    # the robot then goes back until the right color sensor detects back
    while True:
        robot.drive(-30, 0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    #the large motor attatchment comes down at the same time the robot takes a turn towards the black line underneath the pull up bar
    large_motor.run_angle(50, 170, then=Stop.HOLD, wait=False)
    left_motor.run_angle(50, -300, then=Stop.HOLD, wait=True)
    #the robot then goes straight towards that line
    robot.straight(120)
    robot.stop(Stop.BRAKE)
    #robot continues to go forwards until the left color sensor detects black
    while True:
        robot.drive(30, 0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    right_motor.run_angle(50, 150, then=Stop.HOLD, wait=True)
    #the robot then turns with the right motor until it detects black
    while True:
        right_motor.run(85)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    #follows the line underneath the pull up bar until the leftsensor detects black
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    while True:
        # Calculate the deviation from the threshold.
        deviation = line_sensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(line_sensor.color())
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    #the robot then turns towards the boccia aim and moves straight to push it towards the target and finishes the misison
    robot.straight(100)  #after line following, it goes straight for 100 mm
    robot.turn(50)
    robot.straight(100)
    robot.straight(-30)
    large_motor.run_angle(100, -65)
    robot.straight(-60)
    #the robot then takes a turn (at the same time bringing the attatchment down) towards the slide mission and completes the mission
    large_motor.run_angle(50, 80, then=Stop.HOLD, wait=False)
    robot.turn(-195)
    robot.straight(165)
    large_motor.run_angle(300, -120, then=Stop.HOLD, wait=True)
    robot.straight(-30)
    large_motor.run_angle(200, 120, then=Stop.HOLD, wait=True)
    ## The robot moves straight towards the mission, getting ready to attempt to push the slide figures off once more. (In case it didn't work before.)
    robot.straight(30)
    large_motor.run_angle(300, -120, then=Stop.HOLD, wait=True)
    robot.straight(-50)
    '''
Ejemplo n.º 15
0
# This program requires LEGO EV3 MicroPython v2.0 or higher.
# Click "Open user guide" on the EV3 extension tab for more information.
# Create your objects here.
ev3 = EV3Brick()
# Write your program here.
ev3.speaker.beep()
# Initialize the motors.
left_motor = Motor(Port.A)
right_motor = Motor(Port.B)
# Initialize the drive base.
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)
ir_sensor = InfraredSensor(Port.S4)
ir_sensor.beacon(1)
while True:
    buttons = ir_sensor.keypad()
    if len(buttons) == 1:
        print(buttons[0])
        if (buttons[0] == Button.LEFT_UP):
            print("###")
            robot.straight(-30)
        elif (buttons[0] == Button.RIGHT_UP):
            pass
        elif (buttons[0] == Button.LEFT_DOWN):
            pass
        elif (buttons[0] == Button.RIGHT_DOWN):
            pass
    elif len(buttons) == 2:
        print(str(buttons[0]) + " and " + str(buttons[1]))
    else:
        continue
    sleep(0.1)
Ejemplo n.º 16
0
wheel_diameter = 56
axle_track = 115
line_sensor = ColorSensor(Port.S2)
line_sensor1 = ColorSensor(Port.S3)
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
#follows the line underneath the pull up bar until the leftsensor detects black
BLACK = 9
WHITE = 85
threshold = (BLACK + WHITE) / 2
# Set the drive speed at 100 millimeters per second.
DRIVE_SPEED = 100
# Set the gain of the proportional line controller. This means that for every
PROPORTIONAL_GAIN = 1.2
runWhile = True
#goes straight to get ready for line following then resets the distance
robot.straight(250)
robot.reset()
#starts to follow the line towards the replay logo
while True:
    # Calculate the deviation from the threshold.
    deviation = line_sensor.reflection() - threshold
    # Calculate the turn rate.
    turn_rate = PROPORTIONAL_GAIN * deviation
    # Set the drive base speed and turn rate.
    robot.drive(DRIVE_SPEED, turn_rate)
    wait(10)
    print(robot.distance())
    if (robot.distance() >= 450):
        robot.stop(Stop.BRAKE)
        break
#the robot pushes the phone into the replay logo and moves back to get ready to drop the health units into the replay logo
Ejemplo n.º 17
0
Medium_Motor = Motor(Port.A)
Large_Motor = Motor(Port.D)

line_sensor = ColorSensor(Port.S3)
#line_sensor2 = Color Sensor(Port.S2)

#####

BLACK = 9
WHITE = 85
threshold = (BLACK + WHITE) / 2

######

robot.straight(320)
robot.turn(110)

while True:
    robot.drive(90, 0)
    if line_sensor.reflection() <= 10:
        robot.stop(Stop.BRAKE)
        break

robot.turn(-100)

robot.straight(200)

# Calculate the light threshold. Choose values based on your measurements.
BLACK = 9
WHITE = 85
Ejemplo n.º 18
0
# Create a DriveBase object. The wheel_diameter and axle_track values are needed to move robot correct speed/distance when you give drive commands.
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

# This drives at 100 mm/sec straight

import random
a = random.randint(-90, 90)

while True:
    robot.drive(200, 0)

    while irSensor.distance() < 50:
        a = random.randint(0, 100)
        b = random.randint(45, 180)
        c = random.randint(-180, -45)
        robot.straight(-50)
        if a <= 50:
            robot.turn(b)
        else:
            robot.turn(c)

    while touchsensor.pressed():
        robot.straight(-50)
        a = random.randint(0, 100)
        b = random.randint(45, 180)
        c = random.randint(-180, -45)
        if a <= 50:
            robot.turn(b)
            sound.beep()
        else:
            robot.turn(c)
Ejemplo n.º 19
0
This program requires LEGO® EV3 MicroPython v2.0.
Download: https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3

Building instructions can be found at:
https://education.lego.com/en-us/support/mindstorms-ev3/building-instructions#robot
"""

from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
from pybricks.robotics import DriveBase

# Initialize the EV3 Brick.
ev3 = EV3Brick()

# Initialize the motors.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
lift_motor = Motor(Port.A)

# Initialize the drive base.
robot = DriveBase(left_motor, right_motor, wheel_diameter=94.2, axle_track=110)

robot.settings(300, 620, 620, 300)
ev3.screen.draw_text(50, 60, "Pigeons!")
ev3.speaker.beep()

robot.straight(1050)
lift_motor.run_angle(100, 180)
robot.straight(-1200)
Ejemplo n.º 20
0
def BlueMission(): # Blue Run (Step Counter, Pull-Up Bar, Boccia Aim, Slide, Health Unit - 1)
    # DOWN BUTTON
    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    #define your variables
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    large_motor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115  
    line_sensor = ColorSensor(Port.S2)
    line_sensor1 = ColorSensor(Port.S3)
    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
  
    # Go towards the step counter mission from base
    robot.settings(800) # Speed Change
    robot.straight(650)
    robot.stop(Stop.BRAKE)
    wait(20)

    # Slow the robot down to succesfully push the step counter. 
    robot.settings(200)

    # Slowly pushes the step counter by going backward and forward a couple times to increase reliability. 
    robot.straight(230)
    robot.straight(-20)
    robot.straight(50)
    robot.stop(Stop.BRAKE)
    
    #robot.straight(-45)
    #robot.stop(Stop.BRAKE)
    #robot.straight(120) 
    #robot.stop(Stop.BRAKE)
    
    robot.straight(-60)
    robot.stop(Stop.BRAKE)
    
    # The robot then turns and goes backwards until the right color sensor detects black. 
    #robot.settings(250,300,250,300)
    robot.turn(45)
    robot.straight(-100)

    while True:
        robot.drive(-100,0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break 

    #The large motor attatchment comes down at the same time the robot takes a turn towards 
    #the black line underneath the pull up bar
    left_motor.run_angle(50,-300,then=Stop.HOLD, wait=True)
    
    # The robot then goes straight towards the line under the pull-up bar. 
    robot.straight(120)
    robot.stop(Stop.BRAKE)
    
    # Robot continues to go forwards until the left color sensor detects black.
    while True:
        robot.drive(115,0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break 
    right_motor.run_angle(100,150,then=Stop.HOLD, wait=True)
    
    # The robot turns using the right motor until it detects black.
    while True:
        right_motor.run(100)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    robot.straight(-90)
    large_motor.run_angle(100,150,then=Stop.HOLD, wait=True)

    robot.stop(Stop.BRAKE)
    
    robot.stop(Stop.BRAKE)

    while True:
        right_motor.run(40)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break

    robot.stop(Stop.BRAKE)

    ev3.speaker.beep()
    
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    ev3.speaker.beep()
    while True:
        # Calculate the deviation from the threshold.
        deviation = line_sensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(line_sensor1.color())
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    robot.stop(Stop.BRAKE)

    
    robot.stop(Stop.BRAKE)
    large_motor.run_angle(-150, 150, then=Stop.HOLD, wait=False)
    robot.turn(20)
    robot.stop(Stop.BRAKE)
    robot.settings(800)
    robot.straight(280)
    ev3.speaker.beep(3)
    while True:
        robot.drive(-115,0)
        if line_sensor.color() == Color.BLACK:
            ev3.speaker.beep(10)
            robot.stop(Stop.BRAKE)
            break 
    robot.stop(Stop.BRAKE)
    # robot.straight(-10)
    robot.stop(Stop.BRAKE)
    robot.turn(50)
    
    # left_motor.run_angle(100, 150)
    '''
    large_motor.run_angle(30,-20,then=Stop.HOLD, wait=False)
    robot.turn(10)
    robot.stop(Stop.BRAKE)
    
    large_motor.run_angle(100, -50, then=Stop.HOLD, wait=False)
    robot.turn(90)
    robot.stop(Stop.BRAKE)
    
    '''
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    ev3.speaker.beep()
    while True:
        # Calculate the deviation from the threshold.
        deviation = line_sensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(line_sensor.color())
        if robot.distance() >= 500:
            robot.stop(Stop.BRAKE)
            break
    ev3.speaker.beep(3)

    while True:
        robot.drive(40,0)
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break

    robot.stop(Stop.BRAKE)
    ev3.speaker.beep()
    robot.straight(30)
    robot.turn(-100)
    robot.straight(70)
    large_motor.run_angle(600,150,then=Stop.HOLD, wait=True)

    while True:
        robot.drive(-50, 0)
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    robot.stop(Stop.BRAKE)

    right_motor.run_angle(600,500,then=Stop.HOLD,wait=True)

    
    robot.straight(20)
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    ev3.speaker.beep()
    while True:
        # Calculate the deviation from the threshold.
        deviation = line_sensor1.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(line_sensor1.color())
        if robot.distance() >= 580:
            robot.stop(Stop.BRAKE)
            break
    robot.stop(Stop.BRAKE)
    
    while True:
        robot.drive(50, 0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    robot.stop(Stop.BRAKE)
    ev3.speaker.beep(3)

    robot.turn(-45)
    robot.stop(Stop.BRAKE)
    
    robot.straight(30)
    
    large_motor.run_angle(1000,-150,then=Stop.HOLD, wait=True)
    robot.straight(-40)
    large_motor.run_angle(1000,150,then=Stop.HOLD, wait=True)
    robot.straight(40)
    large_motor.run_angle(1000,-150,then=Stop.HOLD, wait=True)

    robot.straight(-115)
    robot.turn(95)
    robot.straight(420)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
Ejemplo n.º 21
0
def GreenMission():

    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.


    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    front_largeMotor = Motor(Port.D)

    wheel_diameter = 56
    axle_track = 114.3 

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    ## Write your code here: 
    robot.settings(300)
    ## The robot goes straight until the Boccia Mission's target. 
    robot.straight(1050)

    ## The robot moves the large motor down to drop the cubes in the target. 
    front_largeMotor.run_angle(80, 110, then=Stop.HOLD, wait=True)

    ## BOCCIA SHARE !!!
    robot.straight(-200)
    robot.turn(-100)
    robot.straight(130)
    front_largeMotor.run_angle(-80, 105, then=Stop.HOLD, wait=True)
    robot.straight(-30)
    robot.turn(-100)
    robot.straight(-80)

    
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)
    robot.turn(-100)
    robot.turn(100)


    ## Dance Mission
    '''
    #The robot moves backwards to reach the Dance Floor so it can Dance as the last mission. 
    robot.straight(-185)
    robot.turn(-80)
    robot.straight(110) 


    ## The following code is all the dance moves we do for the Dance Mission. 

    robot.turn(-75)

    robot.straight(50)

    front_largeMotor.run_angle(60, 50)

    robot.straight(40)

    front_largeMotor.run_angle(60, -50)
    
    robot.straight(-40)

    front_largeMotor.run_angle(60, 50)

    robot.straight(+30)

    front_largeMotor.run_angle(60, -50)
    
    robot.straight(-45)

    robot.turn(-500)

    robot.turn(500)

    
    front_largeMotor.run_angle(60, 50)
    robot.straight(92)
    front_largeMotor.run_angle(60, -50)
    robot.straight(-20)
    robot.straight(35)
    front_largeMotor.run_angle(60, -50)
    robot.straight(-60)
    robot.turn(100)
    robot.turn(-80)
    robot.turn(120)
    robot.turn(-400)
    
    large_motor.run_angle(20, -10)
    robot.straight(-30)

    
    robot.turn(-160)
    robot.straight(60)
    robot.straight(-60)
    robot.turn(260)
    robot.turn(-260)
    robot.turn(100)
    robot.straight(40)
    robot.turn(100)
    robot.straight(-25)
    '''
    robot.stop(Stop.BRAKE)
Ejemplo n.º 22
0
ev3.light.on(Color.YELLOW)

flag = 0
while True:
    robot.drive(500, 0)

    if (touch_sensor.pressed()):
        robot.stop()
        flag = 1
        ev3.light.on(Color.RED)
        break

    if (color_sensor_front.color() == Color.BLACK
            and color_sensor_back.color() != Color.BLACK):
        robot.stop()
        ev3.speaker.beep(1)
        robot.turn(180)

    elif (color_sensor_back.color() == Color.BLACK
          and color_sensor_front.color() == Color.BLACK):
        robot.stop()
        ev3.screen.load_image(ImageFile.KNOCKED_OUT)
        ev3.light.on(Color.RED)
        ev3.speaker.say('Ono lost')
        break

if (flag == 1):
    robot.straight(1000)
    robot.drive(2000, 0)

robot.stop()
Ejemplo n.º 23
0
right_motor = Motor(Port.C)
lift_motor = Motor(Port.A)

# Initialize the drive base.
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)











ev3.screen.draw_text(50, 60, "Pigeons!")
ev3.speaker.beep()

robot.straight(1200)
robot.turn(90)
robot.straight(480)
robot.turn(80) 
robot.straight(900)
ev3.speaker.beep()
robot.turn(-90)
robot.straight(500)
robot.turn(-90)
robot.straight(1800)
ev3.scren.draw_text(50, 60,  "Pigeons!")
RIGHT_MOTOR = Motor(port=Port.C, positive_direction=Direction.CLOCKWISE)
WHEEL_DIAMETER = 26
AXLE_TRACK = 102
DRIVE_BASE = DriveBase(left_motor=LEFT_MOTOR,
                       right_motor=RIGHT_MOTOR,
                       wheel_diameter=WHEEL_DIAMETER,
                       axle_track=AXLE_TRACK)
DRIVE_BASE.settings(
    straight_speed=300,  # milimeters per second
    straight_acceleration=300,
    turn_rate=90,  # degrees per second
    turn_acceleration=90)

BRICK.screen.load_image(ImageFile.NEUTRAL)

DRIVE_BASE.straight(distance=300  # milimeters
                    )

BRICK.screen.load_image(ImageFile.MIDDLE_LEFT)

DRIVE_BASE.turn(angle=90  # degrees
                )

BRICK.screen.load_image(ImageFile.NEUTRAL)

DRIVE_BASE.straight(distance=300  # milimeters
                    )

BRICK.screen.load_image(ImageFile.MIDDLE_RIGHT)

DRIVE_BASE.turn(angle=-90  # degrees
                )
Ejemplo n.º 25
0
def RedMission(): # Red Run (Bench Mission (including backrest removal))
    # UP BUTTON
    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.


    # Create your objects here.
    ev3 = EV3Brick()

    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    wheel_diameter = 56
    axle_track = 115

    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    Medium_Motor = Motor(Port.A)
    Large_Motor = Motor(Port.D)

    leftcolorsensor = ColorSensor(Port.S3)
    rightcolorsensor = ColorSensor(Port.S2)

    robot.settings(500)
    robot.straight(290)
    robot.stop(Stop.BRAKE)
    robot.settings(700,400,700,400)
    robot.turn(110)
    robot.stop(Stop.BRAKE)
    while True:
        robot.drive(200,0)
        if leftcolorsensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break 
    robot.stop(Stop.BRAKE)
    ev3.speaker.beep(3)
    robot.turn(-110)
    robot.straight(80)
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    ev3.speaker.beep()
    
    while True:
        # Calculate the deviation from the threshold.
        deviation = rightcolorsensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(rightcolorsensor.color())
        
        if robot.distance() >= 100:
            robot.stop(Stop.BRAKE)
            break
    robot.stop(Stop.BRAKE)
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    
    while True:
        # Calculate the deviation from the threshold.
        deviation = rightcolorsensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(rightcolorsensor.color())
        
        if leftcolorsensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break

    robot.turn(-25)
    robot.straight(230)
    Large_Motor.run_angle(50,100,then = Stop.HOLD, wait = True)
    
    robot.straight(-60)
    robot.turn(35)
    robot.straight(-10)
    Large_Motor.run_angle(50,-50,then = Stop.HOLD, wait = True)
    robot.straight(-85)
    robot.turn(-85)
    robot.straight(500)
    robot.turn(-20)
    robot.straight(250)
    Large_Motor.run_angle(50,-70,then = Stop.HOLD, wait = False)
    robot.turn(110)
    robot.stop(Stop.BRAKE)
Ejemplo n.º 26
0

# Create your objects here.
ev3 = EV3Brick()
left_motor = Motor(Port.C)
right_motor = Motor(Port.B)
medium_motor = Motor(Port.A)
front_largeMotor = Motor(Port.D)
wheel_diameter = 56
axle_track = 115

robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
# Initialize the color sensor.
line_sensor = ColorSensor(Port.S2)

robot.straight(110)

# Calculate the light threshold. Choose values based on your measurements.
BLACK = 9
WHITE = 85
threshold = (BLACK + WHITE) / 2

# Set the drive speed at 100 millimeters per second.
DRIVE_SPEED = 100

# Set the gain of the proportional line controller. This means that for every
# percentage point of light deviating from the threshold, we set the turn
# rate of the drivebase to 1.2 degrees per second.

# For example, if the light value deviates from the threshold by 10, the robot
# steers at 10*1.2 = 12 degrees per second.
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
from pybricks.robotics import DriveBase
from pybricks.tools import wait

# Initialize the EV3 Brick.
ev3 = EV3Brick()

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

# Initialize the drive base.
robot = DriveBase(left_motor,
                  right_motor,
                  wheel_diameter=54.6,
                  axle_track=104.1)

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

ev3.screen.draw_text(50, 60, "Pigeons!")
ev3.speaker.beep()

#robot.settings(1000 ,250 ,150 ,100)

robot.straight(700)
while robot.distance() < 800:
    robot.drive(250, 180)

robot.straight(700)
Ejemplo n.º 28
0
def BlueMission():
    #!/usr/bin/env pybricks-micropython
    from pybricks.hubs import EV3Brick
    from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                    InfraredSensor, UltrasonicSensor, GyroSensor)
    from pybricks.parameters import Port, Stop, Direction, Button, Color
    from pybricks.tools import wait, StopWatch, DataLog
    from pybricks.robotics import DriveBase
    from pybricks.media.ev3dev import SoundFile, ImageFile


    # This program requires LEGO EV3 MicroPython v2.0 or higher.
    # Click "Open user guide" on the EV3 extension tab for more information.

    #define your variables
    ev3 = EV3Brick()
    left_motor = Motor(Port.C)
    right_motor = Motor(Port.B)
    medium_motor = Motor(Port.A)
    large_motor = Motor(Port.D)
    wheel_diameter = 56
    axle_track = 115  
    line_sensor = ColorSensor(Port.S2)
    line_sensor1 = ColorSensor(Port.S3)
    robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

    #go front towards the step counter
    robot.settings(250)
    robot.straight(650)
    robot.stop(Stop.BRAKE)
    wait(20)

    #makes the robot go slower 
    robot.settings(40)

    #slowly pushes the step counter by going back and front 2 times
    robot.straight(140)
    robot.stop(Stop.BRAKE)
    robot.straight(-45)
    robot.stop(Stop.BRAKE)
    robot.straight(120) 
    robot.stop(Stop.BRAKE)
    robot.straight(-30)
    robot.stop(Stop.BRAKE)
    #the robot then turns and goes backwards
    robot.settings(250,500,250,500)
    robot.turn(45)
    robot.straight(-100)
    # the robot then goes back until the right color sensor detects back
    while True:
        robot.drive(-115,0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break 
    #the large motor attatchment comes down at the same time the robot takes a turn towards the black line underneath the pull up bar
    large_motor.run_angle(50,200,then=Stop.HOLD, wait=False)
    left_motor.run_angle(50,-300,then=Stop.HOLD, wait=True)
    #the robot then goes straight towards that line
    robot.straight(120)
    robot.stop(Stop.BRAKE)
    #robot continues to go forwards until the left color sensor detects black
    while True:
        robot.drive(115,0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break 
    right_motor.run_angle(50,150,then=Stop.HOLD, wait=True)
    #the robot then turns with the right motor until it detects black
    while True:
        right_motor.run(85)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    #follows the line underneath the pull up bar until the leftsensor detects black
        #follows the line underneath the pull up bar until the leftsensor detects black
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2
    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100
    # Set the gain of the proportional line controller. This means that for every
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    robot.reset()
    while True:
        # Calculate the deviation from the threshold.
        deviation = line_sensor.reflection() - threshold
        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation
        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)
        wait(10)
        print(line_sensor1.color())
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break
    #the robot then turns towards the boccia aim and moves straight to push it towards the target and finishes the misison 
    robot.turn(25)
    robot.straight(250)
    robot.straight(-50)
    # this is importate kekekekee
    large_motor.run_angle(75,-65)
    robot.straight(-60)
    while True:
        robot.drive(-70,0)
        if line_sensor.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            ev3.speaker.beep()
            break 
    while True:
        left_motor.run(-50)
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            ev3.speaker.beep()
            break
    left_motor.run_angle(50, -20)
    right_motor.run_angle(50, 20)
    robot.settings(200)
    robot.straight(60)
    robot.turn(-137)
    #this is also importante jekeke
    large_motor.run_angle(50,80)
    robot.straight(143)
    large_motor.run_angle(550, -120)
    robot.straight(-40)
    large_motor.run_angle(550, 120)
    robot.straight(40)
    large_motor.run_angle(550, -120)
    large_motor.run_angle(300, 30, then=Stop.HOLD, wait=True)
    #robot.straight(40)
    large_motor.run_angle(300, -100, then=Stop.HOLD, wait=True)
    #goes to collect the health unit near the basketball (goes back to base)
    robot.straight(-200)
    robot.turn(40)
    robot.straight(556)
    robot.straight(50)
    robot.stop(Stop.BRAKE)
    while True:
        left_motor.run(50)
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            ev3.speaker.beep()
            break
    robot.stop(Stop.BRAKE)
    
    robot.reset()
    # Calculate the light threshold. Choose values based on your measurements.
    BLACK = 9
    WHITE = 85
    threshold = (BLACK + WHITE) / 2

    # Set the drive speed at 100 millimeters per second.
    DRIVE_SPEED = 100

    # Set the gain of the proportional line controller. This means that for every
    # percentage point of light deviating from the threshold, we set the turn
    # rate of the drivebase to 1.2 degrees per second.

    # For example, if the light value deviates from the threshold by 10, the robot
    # steers at 10*1.2 = 12 degrees per second.
    PROPORTIONAL_GAIN = 1.2
    runWhile = True
    # Start following the line endlessly.
    while runWhile:
        # Calculate the deviation from the threshold.
        deviation = line_sensor1.reflection() - threshold

        # Calculate the turn rate.
        turn_rate = PROPORTIONAL_GAIN * deviation

        # Set the drive base speed and turn rate.
        robot.drive(DRIVE_SPEED, turn_rate)

        if robot.distance() >= 210:
            runWhile = False
            break
    robot.stop(Stop.BRAKE)
    robot.turn(5.244312)
    robot.straight(700)
    #the robot then goes back until the right color sensor detects back
    '''
    while True:
        if line_sensor1.color() == Color.BLACK:
            robot.stop(Stop.BRAKE)
            break 
    
    #robot.straight(980)
    '''
    robot.stop(Stop.BRAKE) 
Ejemplo n.º 29
0
# Initialize the drive base.
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)











ev3.screen.draw_text(50, 60, "Pigeons!")
ev3.speaker.beep()

robot.settings(1000 ,250 ,150 ,100)
robot.straight(950)
robot.turn(87)
robot.straight(400)
robot.turn(90) 
robot.straight(780)
ev3.speaker.beep()
robot.turn(-93)
robot.straight(350)
robot.turn(-90)
robot.straight(1500)
robot.stop()
robot.settings(1000 ,1000 ,1000000 ,100000)
ev3.scren.draw_text(50, 60,  "Pigeons!")
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port
from pybricks.robotics import DriveBase
from pybricks.tools import wait

# Initialize the EV3 Brick.
ev3 = EV3Brick()

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

# Initialize the drive base.
robot = DriveBase(left_motor,
                  right_motor,
                  wheel_diameter=54.6,
                  axle_track=104.1)

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

ev3.screen.draw_text(50, 60, "Pigeons!")

robot.settings(300, 250, 150, 100)

x = 0
while x < 4:
    robot.straight(340)
    robot.turn(88)
    x = x + 1