Example #1
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...")
Example #2
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)
Example #3
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(140) # To change the SPEED

    # Pushing our innovative architecture and the health units.
    robot.straight(350) 
    robot.straight(-97)
    robot.turn(-40)
    robot.straight(40)
  
    # Dropping the cube into hopscotch area and returning back to base. 
    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.turn(30)
    robot.straight(-300)
    # (In base) Wait block for attachment change.     
    wait(6000)
    
    # Bringing slide figures to base.
    robot.stop(Stop.BRAKE)
    robot.settings(240) # Speed change
    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)
    large_motor.run_angle(60,-100,then=Stop.HOLD, wait=True)
    robot.stop(Stop.BRAKE)
Example #4
0
def TestRuns():
    robot = DriveBase(left_motor,
                      right_motor,
                      wheel_diameter=46,
                      axle_track=102)

    ev3 = EV3Brick()
    robot.settings(800, 200, 100, 50)
    GoBackwards(bot=robot, distance=-70)
Example #5
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)
Example #6
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)
Example #7
0
def robot_setup():
    # Initialize the motors.
    left_motor = Motor(Port.A)
    right_motor = Motor(Port.B)

    # Initialize the drive base.
    print(left_motor)
    print(right_motor)
    robot = DriveBase(left_motor, right_motor, wheel_diameter=85.0, axle_track=123.3)

    # Go forward and backwards
    robot.settings(straight_speed=2000, straight_acceleration=791, turn_rate=30, turn_acceleration=735)

    return robot
def init_brick():
    # Create your objects here.
    ev3 = EV3Brick()

    # Initilize our motors
    left_motor = Motor(Port.A)
    right_motor = Motor(Port.D)
    front_motor_1 = Motor(Port.C)
    front_motor_2 = Motor(Port.B)

    left_motor.reset_angle(0)
    right_motor.reset_angle(0)
    front_motor_1.reset_angle(0)
    front_motor_2.reset_angle(0)

    # Initialize the color sensor.
    left_sensor = ColorSensor(Port.S4)
    right_sensor = ColorSensor(Port.S1)

    # Speeds
    right_sensor = ColorSensor(Port.S1)
    left_sensor = ColorSensor(Port.S4)
    ARM_MOTOR_SPEED = 400
    WHEEL_DIAMETER = 92
    AXLE_TRACK = 130
    DRIVE_SPEED_FAST = 350
    DRIVE_SPEED_NORMAL = 200
    DRIVE_SPEED_SLOW = 100
    DRIVE_EXTRA_SLOW = 30
    CIRCUMFERENCE = 3.14 * WHEEL_DIAMETER  # Diameter = 100mm, Circumference = 314.10mm = 1 rotation
    # Initialize the Gyro sensor
    gyro = GyroSensor(Port.S2)
    gyro.reset_angle(0)

    # All parameters are in millimeters
    robot = DriveBase(left_motor,
                      right_motor,
                      wheel_diameter=config.WHEEL_DIAMETER,
                      axle_track=config.AXLE_TRACK)

    # Set the straight speed and turn rate
    robot.settings(straight_speed=config.DRIVE_SPEED_NORMAL,
                   turn_rate=config.TURN_RATE)
Example #9
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)
Example #10
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)
from pybricks.parameters import Port, Direction
from pybricks.robotics import DriveBase
from pybricks.tools import wait

# Initialize the EVexit3 Brick.
ev3 = EV3Brick()

# Initialize the motors.
left_motor = Motor(Port.B, positive_direction=Direction.COUNTERCLOCKWISE)
right_motor = Motor(Port.C, positive_direction=Direction.COUNTERCLOCKWISE)
lift_motor = Motor(Port.A)
forklift_motor = Motor(Port.D, positive_direction=Direction.COUNTERCLOCKWISE)

robot = DriveBase(left_motor, right_motor, wheel_diameter=94.2, axle_track=94)
robot.settings(straight_speed=200,
               straight_acceleration=50,
               turn_rate=150,
               turn_acceleration=200)
ev3.screen.draw_text(50, 60, "Alright, let's do this.")
ev3.speaker.beep()

gyro_sensor = GyroSensor(Port.S2, Direction.COUNTERCLOCKWISE)


def gyro_turn(angle, speed=150):
    gyro_sensor.reset_angle(0)
    if angle < 0:
        while gyro_sensor.angle() > angle:
            left_motor.run(speed=(-1 * speed))
            right_motor.run(speed=speed)
            wait(10)
    elif angle > 0:
Example #12
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)
Example #13
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)
Example #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)
    '''
DRIVE_SPEED_NORMAL = 200
DRIVE_SPEED_SLOW = 100
DRIVE_EXTRA_SLOW = 30
CIRCUMFERENCE = 3.14 * WHEEL_DIAMETER  # Diameter = 100mm, Circumference = 314.10mm = 1 rotation
# Initialize the Gyro sensor
gyro = GyroSensor(Port.S2)
gyro.reset_angle(0)

# All parameters are in millimeters
robot = DriveBase(left_motor,
                  right_motor,
                  wheel_diameter=config.WHEEL_DIAMETER,
                  axle_track=config.AXLE_TRACK)

# Set the straight speed and turn rate
robot.settings(straight_speed=config.DRIVE_SPEED_NORMAL,
               turn_rate=config.TURN_RATE)

# TRIP 1 CODE ####################

# This program requires LEGO EV3 MicroPython v2.0 or higher.

# Start a stopwatch to measure elapsed time
watch = StopWatch()

# Create your brick object and initialize
ev3 = EV3Brick()
# init_brick()

# Select or skip this trip
ev3.speaker.beep()
ev3.screen.print("TRIP 1")
class Gripp3r(EV3Brick):
    WHEEL_DIAMETER = 26
    AXLE_TRACK = 115

    def __init__(self,
                 left_motor_port: Port = Port.B,
                 right_motor_port: Port = Port.C,
                 grip_motor_port: Port = Port.A,
                 touch_sensor_port: Port = Port.S1,
                 ir_sensor_port: Port = Port.S4,
                 ir_beacon_channel: int = 1):
        self.drive_base = DriveBase(
            left_motor=Motor(port=left_motor_port,
                             positive_direction=Direction.CLOCKWISE),
            right_motor=Motor(port=right_motor_port,
                              positive_direction=Direction.CLOCKWISE),
            wheel_diameter=self.WHEEL_DIAMETER,
            axle_track=self.AXLE_TRACK)

        self.drive_base.settings(
            straight_speed=750,  # milimeters per second
            straight_acceleration=750,
            turn_rate=90,  # degrees per second
            turn_acceleration=90)

        self.grip_motor = Motor(port=grip_motor_port,
                                positive_direction=Direction.CLOCKWISE)

        self.touch_sensor = TouchSensor(port=touch_sensor_port)

        self.ir_sensor = InfraredSensor(port=ir_sensor_port)
        self.ir_beacon_channel = ir_beacon_channel

    def keep_driving_by_ir_beacon(
            self,
            channel: int = 1,
            speed: float = 1000  # milimeters per second
    ):
        while True:
            ir_beacon_buttons_pressed = set(
                self.ir_sensor.buttons(channel=channel))

            # forward
            if ir_beacon_buttons_pressed == {Button.LEFT_UP, Button.RIGHT_UP}:
                self.drive_base.drive(
                    speed=speed,
                    turn_rate=0  # degrees per second
                )

            # backward
            elif ir_beacon_buttons_pressed == {
                    Button.LEFT_DOWN, Button.RIGHT_DOWN
            }:
                self.drive_base.drive(
                    speed=-speed,
                    turn_rate=0  # degrees per second
                )

            # turn left on the spot
            elif ir_beacon_buttons_pressed == {
                    Button.LEFT_UP, Button.RIGHT_DOWN
            }:
                self.drive_base.drive(
                    speed=0,
                    turn_rate=-90  # degrees per second
                )

            # turn right on the spot
            elif ir_beacon_buttons_pressed == {
                    Button.LEFT_DOWN, Button.RIGHT_UP
            }:
                self.drive_base.drive(
                    speed=0,
                    turn_rate=90  # degrees per second
                )

            # turn left forward
            elif ir_beacon_buttons_pressed == {Button.LEFT_UP}:
                self.drive_base.drive(
                    speed=speed,
                    turn_rate=-90  # degrees per second
                )

            # turn right forward
            elif ir_beacon_buttons_pressed == {Button.RIGHT_UP}:
                self.drive_base.drive(
                    speed=speed,
                    turn_rate=90  # degrees per second
                )

            # turn left backward
            elif ir_beacon_buttons_pressed == {Button.LEFT_DOWN}:
                self.drive_base.drive(
                    speed=-speed,
                    turn_rate=90  # degrees per second
                )

            # turn right backward
            elif ir_beacon_buttons_pressed == {Button.RIGHT_DOWN}:
                self.drive_base.drive(
                    speed=-speed,
                    turn_rate=-90  # degrees per second
                )

            # otherwise stop
            else:
                self.drive_base.stop()

    def grip_or_release_by_ir_beacon(self, speed: float = 500):
        while True:
            if Button.BEACON in self.ir_sensor.buttons(
                    channel=self.ir_beacon_channel):
                if self.touch_sensor.pressed():
                    self.speaker.play_file(file=SoundFile.AIR_RELEASE)

                    self.grip_motor.run_time(speed=speed,
                                             time=1000,
                                             then=Stop.BRAKE,
                                             wait=True)

                else:
                    self.speaker.play_file(file=SoundFile.AIRBRAKE)

                    self.grip_motor.run(speed=-speed)

                    while not self.touch_sensor.pressed():
                        pass

                    self.grip_motor.stop()

                while Button.BEACON in self.ir_sensor.buttons(
                        channel=self.ir_beacon_channel):
                    pass

    def main(self, speed: float = 1000):
        self.grip_motor.run_time(speed=-500,
                                 time=1000,
                                 then=Stop.BRAKE,
                                 wait=True)

        Thread(target=self.grip_or_release_by_ir_beacon).start()

        self.keep_driving_by_ir_beacon(speed=speed)
Example #17
0
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()
ev3.speaker.set_speech_options('en', 'm1', 160, None)

# Initialize the robots
left_motor = Motor(Port.A)
right_motor = Motor(Port.B)
robot = DriveBase(left_motor, right_motor, 80, 80)
robot.settings(200, 400, 90, 180)


def main():
    # Start the mission
    ev3.light.on(Color.YELLOW)
    ev3.speaker.say('Marshmallow Panda, getting started!')

    # Move the robots
    robot.straight(100)
    robot.turn(90)
    robot.drive(300, 0)
    wait(300)
    robot.stop()

    # Complete the mission
Example #18
0
PROPORTIONAL_GAIN_NORMAL = 1.2
PROPORTIONAL_GAIN_BIG_LEFT_TURN = 3.0

# The DriveBase is composed of two motors, with a wheel on each motor.
# The wheel_diameter and axle_track values are used to make the motors
# move at the correct speed when you give a motor command.
# The axle track is the distance between the points where the wheels
# touch the ground.
robot = DriveBase(common.left_motor,
                  common.right_motor,
                  wheel_diameter=55.5,
                  axle_track=165)

# This is fast, so we might lower the max later.

robot.settings(straight_speed=ROBOT_STRAIGHT_SPEED)

# We tried a few acceleration values.  2 is crazy slow...
#   400 seems to work.  the original made the robot jump when starting
robot.distance_control.limits(acceleration=500)


# Adjust the line follow and keep going
#   smooth turn is normal
#   for big left turn use PROPORTIONAL_GAIN_BIG_LEFT_TURN
def check_n_turn(turn_multiply=PROPORTIONAL_GAIN_NORMAL,
                 drive_speed=LINE_DRIVE_SPEED):
    # Calculate the deviation from the threshold.
    deviation = common.line_sensor.reflection() - line_threshold

    # Calculate the turn rate.
Example #19
0
# Click "Open user guide" on the EV3 extension tab for more information.
# Variables and cons
#Version notes: 3
#removed turntoangle

import multiprocessing

ev3 = EV3Brick()
leftmotor = Motor(Port.C, Direction.CLOCKWISE)
rightmotor = Motor(Port.B, Direction.CLOCKWISE)
#left medium motor
mediummotor = Motor(Port.D, Direction.COUNTERCLOCKWISE)
#right medium motor
mediummotor2 = Motor(Port.A, Direction.COUNTERCLOCKWISE)
robot = DriveBase(leftmotor, rightmotor, 55.85, 150)
print(robot.settings())
robot.settings(200, 520, 200, 100)
rightcolor = ColorSensor(Port.S1)
leftcolor = ColorSensor(Port.S2)
gyroSensor = GyroSensor(Port.S3)
accangle = 0  # accumulated angle, angle you're supposed to be at.
log = False

black = 3
white = 41
threshold = int((black + white) / 2)  #19

import time


def oldstraight(desmond, sped):
Example #20
0
# Initialize the motors.
left_motor = Motor(Port.C)
right_motor = Motor(Port.D)
arm_motor = Motor(Port.A)
arm_motor.reset_angle(0)
line_sensor = LightSensor(Port.S1)

sensor_center = UltrasonicSensor(Port.S2)
sensor_left = InfraredSensor(Port.S3)
sensor_right = InfraredSensor(Port.S4)

# Initialize the drive base.
arm_motor.run_angle(200, 120)
robot = DriveBase(left_motor, right_motor, wheel_diameter=40, axle_track=125)
robot.settings(500, 500, 500, 500)


def outOfBounds():
    if line_sensor.reflection() > 40:
        robot.straight(80)
        # arm_motor.run_angle(500,30)
        robot.reset()
        robot.turn(-280)
        # arm_motor.run_angle(500,-30)


def scanSensor():  # 1-left, 2-center, 3-right
    degree = 0.0
    offset = 60
    distance_center = sensor_center.distance()  #in mm
Example #21
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) 
Example #22
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)
Example #23
0
    robot.drive(100, 0)
    while (csRight.reflection() > 40):
        robot.drive(100, 0)

    robot.stop()


def StopAtBlackLineRight():
    robot.drive(100, 0)
    while (csRight.reflection() < 15):
        robot.drive(100, 0)

    robot.stop()


robot.settings(500, 600, 100, 600)

#Small Tire Flip
robot.straight(1000)
robot.stop()
robot.settings(250, 300, 100, 600)
StopAtWhiteLine()
robot.straight(175)
#robot turns toward the wall and reveres:

robot.turn(-120)
robot.straight(-180)
#goes off the wall and turns to the wheel
robot.straight(200)
robot.turn(-65)
robot.stop()
Example #24
0
# Create your objects here.
ev3 = EV3Brick()

# Initilize our motors
left_motor = Motor(Port.A)
right_motor = Motor(Port.D)
front_motor_1 = Motor(Port.C)
front_motor_2 = Motor(Port.B)

left_motor.reset_angle(0)
right_motor.reset_angle(0)
front_motor_1.reset_angle(0)
front_motor_2.reset_angle(0)

# Initialize the color sensor.
left_sensor = ColorSensor(Port.S4)
right_sensor = ColorSensor(Port.S1)

# Initialize the Gyro sensor
gyro = GyroSensor(Port.S2)
gyro.reset_angle(0)

# All parameters are in millimeters
robot = DriveBase(left_motor,
                  right_motor,
                  wheel_diameter=config.WHEEL_DIAMETER,
                  axle_track=config.AXLE_TRACK)

# Set the straight speed and turn rate
robot.settings(straight_speed=config.DRIVE_SPEED_NORMAL,
               turn_rate=config.TURN_RATE)
Example #25
0
from pybricks.media.ev3dev import SoundFile, ImageFile
import time

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

# Variables and constants
ev3 = EV3Brick()
leftmotor = Motor(Port.C, Direction.CLOCKWISE)
rightmotor = Motor(Port.B, Direction.CLOCKWISE)
#left medium motor
mediummotor = Motor(Port.D, Direction.COUNTERCLOCKWISE)
#right medium motor
mediummotor2 = Motor(Port.A, Direction.COUNTERCLOCKWISE)
robot = DriveBase(leftmotor, rightmotor, 55.85, 108)
robot.settings(300, 100, 200, 100)
rightcolor = ColorSensor(Port.S1)
leftcolor = ColorSensor(Port.S2)
gyroSensor = GyroSensor(Port.S3)
black = 3
white = 35
threshold = int((black + white) / 2)  #19
print(threshold)


#seeing white first and then line squaring
def linesquare():
    lightrange = range(threshold - 2,
                       threshold + 2)  #light range for final result
    #lightrange = range(threshold - 4, threshold + 4) #light rnage for adjustment
Example #26
0
BRICK = EV3Brick()

MEDIUM_MOTOR = Motor(port=Port.A, positive_direction=Direction.CLOCKWISE)

LEFT_MOTOR = Motor(port=Port.B, positive_direction=Direction.CLOCKWISE)
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)

TOUCH_SENSOR = TouchSensor(port=Port.S1)
COLOR_SENSOR = ColorSensor(port=Port.S3)


def run_away_whenever_dark():
    while True:
        if COLOR_SENSOR.ambient() < 5:  # 15 not dark enough
            BRICK.screen.load_image(ImageFile.MIDDLE_LEFT)

            DRIVE_BASE.straight(distance=-100  # milimeters
                                )
Example #27
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)
Example #28
0
class Ev3rstorm(EV3Brick):
    WHEEL_DIAMETER = 26
    AXLE_TRACK = 102

    def __init__(self,
                 left_foot_motor_port: Port = Port.B,
                 right_foot_motor_port: Port = Port.C,
                 bazooka_blast_motor_port: Port = Port.A,
                 touch_sensor_port: Port = Port.S1,
                 color_sensor_port: Port = Port.S3,
                 ir_sensor_port: Port = Port.S4,
                 ir_beacon_channel: int = 1):
        self.drive_base = DriveBase(
            left_motor=Motor(port=left_foot_motor_port,
                             positive_direction=Direction.CLOCKWISE),
            right_motor=Motor(port=right_foot_motor_port,
                              positive_direction=Direction.CLOCKWISE),
            wheel_diameter=self.WHEEL_DIAMETER,
            axle_track=self.AXLE_TRACK)
        self.drive_base.settings(
            straight_speed=300,  # milimeters per second
            straight_acceleration=300,
            turn_rate=90,  # degrees per second
            turn_acceleration=90)

        self.bazooka_blast_motor = Motor(
            port=bazooka_blast_motor_port,
            positive_direction=Direction.CLOCKWISE)

        self.touch_sensor = TouchSensor(port=touch_sensor_port)
        self.color_sensor = ColorSensor(port=color_sensor_port)

        self.ir_sensor = InfraredSensor(port=ir_sensor_port)
        self.ir_beacon_channel = ir_beacon_channel

    def drive_once_by_ir_beacon(
            self,
            speed: float = 1000  # milimeters per second
    ):
        ir_beacon_buttons_pressed = set(
            self.ir_sensor.buttons(channel=self.ir_beacon_channel))

        # forward
        if ir_beacon_buttons_pressed == {Button.LEFT_UP, Button.RIGHT_UP}:
            self.drive_base.drive(
                speed=speed,
                turn_rate=0  # degrees per second
            )

        # backward
        elif ir_beacon_buttons_pressed == {
                Button.LEFT_DOWN, Button.RIGHT_DOWN
        }:
            self.drive_base.drive(
                speed=-speed,
                turn_rate=0  # degrees per second
            )

        # turn left on the spot
        elif ir_beacon_buttons_pressed == {Button.LEFT_UP, Button.RIGHT_DOWN}:
            self.drive_base.drive(
                speed=0,
                turn_rate=-90  # degrees per second
            )

        # turn right on the spot
        elif ir_beacon_buttons_pressed == {Button.LEFT_DOWN, Button.RIGHT_UP}:
            self.drive_base.drive(
                speed=0,
                turn_rate=90  # degrees per second
            )

        # turn left forward
        elif ir_beacon_buttons_pressed == {Button.LEFT_UP}:
            self.drive_base.drive(
                speed=speed,
                turn_rate=-90  # degrees per second
            )

        # turn right forward
        elif ir_beacon_buttons_pressed == {Button.RIGHT_UP}:
            self.drive_base.drive(
                speed=speed,
                turn_rate=90  # degrees per second
            )

        # turn left backward
        elif ir_beacon_buttons_pressed == {Button.LEFT_DOWN}:
            self.drive_base.drive(
                speed=-speed,
                turn_rate=90  # degrees per second
            )

        # turn right backward
        elif ir_beacon_buttons_pressed == {Button.RIGHT_DOWN}:
            self.drive_base.drive(
                speed=-speed,
                turn_rate=-90  # degrees per second
            )

        # otherwise stop
        else:
            self.drive_base.stop()

    def keep_driving_by_ir_beacon(self, speed: int = 100):
        while True:
            self.drive_once_by_ir_beacon(speed=speed)

    def blast_bazooka_whenever_touched(self):
        while True:
            if self.touch_sensor.pressed():
                if self.color_sensor.ambient() < 5:  # 15 not dark enough
                    self.speaker.play_file(file=SoundFile.UP)

                    self.bazooka_blast_motor.run_angle(
                        speed=1000,  # degrees per second
                        rotation_angle=-3 * 360,  # degrees
                        then=Stop.HOLD,
                        wait=True)

                else:
                    self.speaker.play_file(file=SoundFile.DOWN)

                    self.bazooka_blast_motor.run_angle(
                        speed=1000,  # degrees per second
                        rotation_angle=3 * 360,  # degrees
                        then=Stop.HOLD,
                        wait=True)

    def main(
            self,
            driving_speed: float = 1000  # mm/s
    ):
        self.screen.load_image(ImageFile.TARGET)

        run_parallel(self.keep_driving_by_ir_beacon,
                     self.blast_bazooka_whenever_touched)
Example #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!")
Example #30
0
    UltrasonicSensor,
)
from pybricks.hubs import EV3Brick
from pybricks.media.ev3dev import ImageFile, SoundFile
from pybricks.parameters import Button, Color, Direction, Port, Stop
from pybricks.robotics import DriveBase
from pybricks.tools import DataLog, StopWatch, wait

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

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

# For robot.settings, the four numbers mean straight speed, straight acelleration, turn rate, turn acceleration.
robot.settings(800, 200, 100, 50)

ev3 = EV3Brick()


def go_straight_then_stop(distance, speed):
    (
        straight_speed,
        straight_acceleration,
        turn_rate,
        turn_acceleration,
    ) = robot.settings()
    robot.stop()
    robot.settings(speed, straight_acceleration, turn_rate, turn_acceleration)
    robot.straight(distance)
    robot.stop()