Esempio n. 1
0
    def __init__(self, controller_component, driver_component, id, init_map_location=0,angle_treshold=5):
        """
        Initializes the robot with the given controller and components.
        :param controller_component: the controller component that controls wheel motors
        :param driver_component: the driver component to decide how to drive
        :param init_map_location: int to indicate where the robot starts on the map
        """
        self._controller = controller_component
        self._driver = driver_component
        self._id = id

        #variables pour localiser le robot
        #self._map = [['A',0],['B',1],['C',0],['D',2],['E',0],['F',2],['G',0],['H',1]]
        #self._map = [['A',90],['B',45],['C',45],['D',90],['E',45],['F',90],['G',45],['H',90]]
        self._map = [['A',0],['B',45],['C',130],['D',85],['E',0],['F',-45],['G',-130],['H',-85]]
        self.map_location = init_map_location
        self.action = self._map[self.map_location][1]
        self._controller.action = self.action
        self._recorded_angle = 0
        self._angle_treshold = angle_treshold

        #variables pour la gestion des messages MQTT
        self.allowed = True

        #variable pour l'ordonnancement
        self.waiting_list = []
        self.intersection = 0

        #gestion couleur
        self.ev3 = EV3Brick()
        self.ev3.light.on(Color.YELLOW)
Esempio n. 2
0
def main():
    ev3 = EV3Brick()
    ev3.speaker.beep()
    ev3.screen.clear()
    ev3.light.on( Color.YELLOW )

    gps = dGPS( Port.S3 )

    print( 'Firmware Version', gps.firmwareVersion() )

    while ( not ev3.buttons.pressed() ):

        # wait for link
        if ( not gps.link() ):
            print( "No link..." )

        else:
            ev3.light.on( Color.GREEN )

            print( 'Link', True )
            print( 'UTC', gps.utc() )
            
            (lat, lon) = gps.location()
            print( 'Latitude %.6f' % lat )
            print( 'Longitude %.6f' % lon )
            
            print( 'Heading', gps.heading() )
            print( 'Velocity', gps.velocity() )
            print( 'Altitude', gps.altitude() )
            print( 'HDOP', gps.hdop() )
            print( 'Satellites in view', gps.satellitesInView() )
 
        wait( 2500 )
Esempio n. 3
0
    def __init__(self):
        left_motor = Motor(Port.B)
        right_motor = Motor(Port.C)
        self.brobot = DriveBase(left_motor,
                                right_motor,
                                wheel_diameter=55,
                                axle_track=127)
        self.left_color_sensor = ColorSensor(Port.S4)
        self.right_color_sensor = ColorSensor(Port.S2)

        self.ev3 = EV3Brick()

        self.RED_ON_WHITE = 57
        self.RED_ON_BLACK = 5

        self.GREEN_ON_WHITE = 55
        self.GREEN_ON_BLACK = 4

        self.BLUE_ON_WHITE = 100
        self.BLUE_ON_BLACK = 10

        self.RED = (self.RED_ON_WHITE + self.RED_ON_BLACK) // 2
        self.GREEN = (self.GREEN_ON_WHITE + self.GREEN_ON_BLACK) // 2
        self.BLUE = (self.BLUE_ON_WHITE + self.BLUE_ON_BLACK) // 2

        self.self.start_time = time.time()
        self.execute_program = True
        self.no_line = False
Esempio n. 4
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...")
Esempio n. 5
0
    def __init__(self,
                 left_motor_port: str = Port.B,
                 right_motor_port: str = Port.C,
                 lift_motor_port: str = Port.A,
                 ir_sensor_port: str = Port.S4,
                 ir_beacon_channel: int = 1):
        self.ev3_brick = EV3Brick()

        self.drive_base = \
            DriveBase(
                left_motor=
                    Motor(port=left_motor_port,
                          positive_direction=Direction.COUNTERCLOCKWISE),
                right_motor=
                    Motor(port=right_motor_port,
                          positive_direction=Direction.COUNTERCLOCKWISE),
                wheel_diameter=self.WHEEL_DIAMETER,
                axle_track=self.AXLE_TRACK)

        self.lift_motor = Motor(port=lift_motor_port,
                                positive_direction=Direction.CLOCKWISE)

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

        self.reversing = False
Esempio n. 6
0
    def __init__(self):
        # Initialize the EV3 Brick.
        self.ev3 = EV3Brick()
        self.ev3.speaker.set_speech_options(voice='f3')

        # large motors
        self.left_motor = Motor(Port.A,
                                positive_direction=Direction.COUNTERCLOCKWISE,
                                gears=None)
        self.right_motor = Motor(Port.B,
                                 positive_direction=Direction.COUNTERCLOCKWISE,
                                 gears=None)

        # small (medium) motors
        self.small_motor_left = Motor(Port.C,
                                      positive_direction=Direction.CLOCKWISE,
                                      gears=None)
        self.small_motor_right = Motor(Port.D,
                                       positive_direction=Direction.CLOCKWISE,
                                       gears=None)

        # gyro sensor
        self.gyro_sensor = GyroSensor(Port.S3, Direction.CLOCKWISE)

        # Initialize the drive base.
        self.drive_base = DriveBase(self.left_motor,
                                    self.right_motor,
                                    wheel_diameter=93.5,
                                    axle_track=120)
        return
Esempio n. 7
0
    def __init__(self,
                 left_motor_port: Port = Port.C,
                 right_motor_port: Port = Port.B,
                 wiggle_motor_port: Port = Port.A,
                 polarity: str = 'inversed',
                 touch_sensor_port: Port = Port.S1,
                 color_sensor_port: Port = Port.S3,
                 ir_sensor_port: Port = Port.S4,
                 ir_beacon_channel: int = 1):
        super().__init__(wheel_diameter=self.WHEEL_DIAMETER,
                         axle_track=self.AXLE_TRACK,
                         left_motor_port=left_motor_port,
                         right_motor_port=right_motor_port,
                         polarity=polarity,
                         ir_sensor_port=ir_sensor_port,
                         ir_beacon_channel=ir_beacon_channel)

        self.ev3_brick = EV3Brick()

        self.wiggle_motor = Motor(port=wiggle_motor_port,
                                  positive_direction=Direction.CLOCKWISE)

        self.touch_sensor = TouchSensor(port=touch_sensor_port)

        self.color_sensor = ColorSensor(port=color_sensor_port)
Esempio n. 8
0
    def __init__(
            self,
            crushing_claw_motor_port: Port = Port.A,
            moving_motor_port: Port = Port.B,
            lightning_tail_motor_port: Port = Port.D,
            touch_sensor_port: Port = Port.S1,
            color_sensor_port: Port = Port.S3,
            ir_sensor_port: Port = Port.S4,
            ir_beacon_channel: int = 1):
        self.ev3_brick = EV3Brick()

        self.crushing_claw_motor = \
            Motor(port=crushing_claw_motor_port,
                  positive_direction=Direction.CLOCKWISE)
        self.moving_motor = \
            Motor(port=moving_motor_port,
                  positive_direction=Direction.CLOCKWISE)
        self.lightning_tail_motor = \
            Motor(port=lightning_tail_motor_port,
                  positive_direction=Direction.CLOCKWISE)

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

        self.touch_sensor = TouchSensor(port=touch_sensor_port)
        self.color_sensor = ColorSensor(port=color_sensor_port)
Esempio n. 9
0
def main():
    # Objects for ev3-brick and Pixy2 camera
    ev3 = EV3Brick()
    pixy2 = Pixy2(port=1, i2c_address=0x54)

    # Detect all signatures (set sig to 255)
    sig = 255
    max_blocks = 10

    while not ev3.buttons.pressed():
        # Read data from Pixy2
        try:
            nr_blocks, blocks = pixy2.get_blocks(sig, max_blocks)
            print('{} blocks detected:'.format(nr_blocks))
            # Parse data
            if nr_blocks > 0:
                # Print information about detected blocks
                for block in blocks:
                    print(block, '\n')
        except Pixy2ConnectionError:
            # No data, stop program and check the connection of Pixy2
            print('Check connection Pixy2!')
            break
        except Pixy2DataError:
            # Data error, try reading again
            pass
Esempio n. 10
0
    def __init__(
            self,
            left_track_motor_port: Port = Port.B,
            right_track_motor_port: Port = Port.C,
            gripping_motor_port: Port = Port.A,
            touch_sensor_port: Port = Port.S1,
            ir_sensor_port: Port = Port.S4,
            ir_beacon_channel: int = 1):
        super().__init__(
            wheel_diameter=self.WHEEL_DIAMETER,
            axle_track=self.AXLE_TRACK,
            left_motor_port=left_track_motor_port,
            right_motor_port=right_track_motor_port,
            ir_sensor_port=ir_sensor_port,
            ir_beacon_channel=ir_beacon_channel)

        self.ev3_brick = EV3Brick()

        self.gripping_motor = Motor(port=gripping_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
Esempio n. 11
0
	def __init__(self):
		# micro controller
		ev3 = EV3Brick()
		ev3.speaker.beep()
		# sensors
		# low value = registers black tape
		# high value = aluminum
		self.sensorYellow = ColorSensor(Port.S1)
		self.sensorRed = ColorSensor(Port.S3)
		self.sensorBlue = ColorSensor(Port.S2)
		# motor
		left_motor = Motor(Port.A, gears=[40, 24])
		right_motor = Motor(Port.B, gears=[40, 24])
		axle_track = 205
		wheel_diameter = 35
		self.motors = DriveBase(left_motor, right_motor,
														wheel_diameter, axle_track)
		# constants

		# intersection detection of side sensors
		self.thresholdBlueSensor = 30

		# value for making turns
		self.thresholdSideSensors = 15

		# timer

		self.watch = StopWatch()
		self.timer = 0
Esempio n. 12
0
def button_press():
    brick = EV3Brick()
    while len(brick.buttons.pressed()) == 0:
        wait(10)

    while len(brick.buttons.pressed()) > 0:
        wait(10)
Esempio n. 13
0
    def __init__(self):
        self.brick = EV3Brick()
        self.frontMotor = Motor(Port.D)
        self.rearMotor = Motor(Port.A)
        self.leftMotor = Motor(Port.C)
        self.rightMotor = Motor(Port.B)

        if path.exists('sensorpoints.py'):
            import sensorpoints
            self.leftSensor = LightSensor(Port.S3, sensorpoints.leftLow,
                                          sensorpoints.leftHigh)
            self.rightSensor = LightSensor(Port.S2, sensorpoints.rightLow,
                                           sensorpoints.rightHigh)

        else:
            self.leftSensor = LightSensor(Port.S3, 10, 105)
            self.rightSensor = LightSensor(Port.S2, 20, 160)

        self.gyroSensor = GyroSensor(Port.S1)
        wait(100)
        self.gyroSensor.speed()
        self.gyroSensor.angle()
        wait(500)
        self.gyroSensor.reset_angle(0.0)
        wait(200)
Esempio n. 14
0
    def __init__(self):
        # Initialize the EV3 brick.
        self.ev3 = EV3Brick()

        # Initialize the motors connected to the back legs.
        self.left_leg_motor = Motor(Port.D, Direction.COUNTERCLOCKWISE)
        self.right_leg_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)

        # Initialize the motor connected to the head.
        # Worm gear moves 1 tooth per rotation. It is interfaced to a 24-tooth
        # gear. The 24-tooth gear is connected to parallel 12-tooth gears via
        # an axle. The 12-tooth gears interface with 36-tooth gears.
        self.head_motor = Motor(Port.C,
                                Direction.COUNTERCLOCKWISE,
                                gears=[[1, 24], [12, 36]])

        # Initialize the Color Sensor.
        self.color_sensor = ColorSensor(Port.S4)

        # Initialize the touch sensor.
        self.touch_sensor = TouchSensor(Port.S1)

        # This attribute is used by properties.
        self._eyes = None

        # These attributes are used by the playful behavior.
        self.playful_timer = StopWatch()
        self.playful_bark_interval = None
Esempio n. 15
0
def run(robot: Robot):

    straight_line_follow_pid = Pid(1.5, 0, 10)
    sharp_line_follow_pid = Pid(5, 0, 0)
    turn_pid = Pid(10, 0, 5)
    slow_turn_pid = Pid(3, 0, 0)
    drive_pid = Pid(2, 0, 0)
    sharp_drive_pid = Pid(4, 0, 0)
    robot.reset_sensors()
    brick = EV3Brick()

    robot.drive(sharp_drive_pid, 200, 0, 1600)
    robot.turn(turn_pid, -35)
    robot.drive(drive_pid, 200, -35, 2500)


    robot.drive(drive_pid, -200, -35, 900)
    wait(500)
    robot.stop_motors()

    robot.drive(drive_pid, -400, -35, 550)
    robot.drive(sharp_drive_pid, -400, 0, 1500)

    while len(brick.buttons.pressed()) == 0:
        wait(10)

    while len(brick.buttons.pressed()) > 0:
        wait(10)

    robot.linear_attachment_motor.run_until_stalled(200, Stop.BRAKE, 20)
Esempio n. 16
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)
Esempio n. 17
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)
Esempio n. 18
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)
Esempio n. 19
0
class Robot():

    #robot hardware
    brick = EV3Brick()

    wheel_left = Motor(Port.A)
    wheel_right = Motor(Port.B)

    arm_left = Motor(Port.D)
    arm_right = Motor(Port.C)

    gyro = GyroSensor(Port.S1, Direction.COUNTERCLOCKWISE)
    color_left = ColorSensor(Port.S2)
    color_right = ColorSensor(Port.S3)

    chassis = DriveBase(wheel_left,
                        wheel_right,
                        wheel_diameter=49.5,
                        axle_track=150)

    @classmethod
    def reset_settings(cls):
        cls.chassis.stop()
        cls.chassis.settings(115, 460, 88, 352)

    @classmethod
    def settings(cls,
                 straight_speed=None,
                 straight_acceleration=None,
                 turn_rate=None,
                 turn_acceleration=None):
        cls.chassis.stop()  #Settings can only be changed while stopped
        current_settings = cls.chassis.settings()
        cls.chassis.settings(
            straight_speed if straight_speed is not None else
            current_settings[0], straight_acceleration
            if straight_acceleration is not None else current_settings[1],
            turn_rate if turn_rate is not None else current_settings[2],
            turn_acceleration
            if turn_acceleration is not None else current_settings[3])

    @classmethod
    def brake(cls):
        cls.chassis.stop()
        cls.wheel_left.brake()
        cls.wheel_right.brake()

    @classmethod
    def reset_gyro(cls):
        cls.gyro.reset_angle(0)

        cls.gyro.angle()
        cls.gyro.speed()
        cls.gyro.angle()

        wait(10)
Esempio n. 20
0
    def __init__(
            self,
            gear_motor_port: Port = Port.A,
            color_sensor_port: Port = Port.S3):
        self.ev3_brick = EV3Brick()

        self.gear_motor = Motor(port=gear_motor_port,
                                positive_direction=Direction.CLOCKWISE)

        self.color_sensor = ColorSensor(port=color_sensor_port)
Esempio n. 21
0
 def __init__(self):
     self.ev3 = EV3Brick()
     #self.motorleft = Motor(Port.D)
     self.motorright = Motor(Port.A)
     self.right = ColorSensor(Port.S3)
     self.left = ColorSensor(Port.S2)
     #self.gyro = GyroSensor(Port.S4)
     self.leftambient = 0
     self.rightambient = 0
     self.delta = 0
Esempio n. 22
0
 def __init__(self):
     self.ev3 = EV3Brick()
     self.motorleft = Motor(Port.D)
     self.motorright = Motor(Port.A)
     self.right = ColorSensor(Port.S2)
     self.left = ColorSensor(Port.S3)
     self.leftambient = 0
     self.rightambient = 0
     self.currentambient = self.right.ambient()
     self.currentdelta = 0
     self.currentdelta2 = 0
Esempio n. 23
0
def run(robot: Robot):
    brick = EV3Brick()

    music = [
        ["E4/16", "E4/8", "E4/8", "C4/16", "E4/8", "G4/4", "G3/4"],
        ["C4/8.", "G3/8.", "E3/8", "R/16", "A3/8", "B3/8", "Bb3/16", "A3/8"],
        [
            "G3/16.", "E4/16.", "G4/16.", "A4/5", "F4/16", "G4/8", "E4/8",
            "C4/16", "D4/16", "B3/16"
        ],
        [
            "R/4", "G4/16", "Gb4/16", "F4/16", "D#4/8", "E4/16", "R/16",
            "G3/16", "A3/16", "C4/16", "R/16", "A3/16", "C4/16", "D4/16", "R/8"
        ],
        [
            "G4/16", "Gb4/16", "F4/16", "D#4/8", "E4/16", "R/16", "C5/16",
            "R/16", "C5/16", "C5/4"
        ],
        [
            "R/4", "G4/16", "Gb4/16", "F4/16", "D#4/8", "E4/16", "R/16",
            "G3/16", "A3/16", "C4/16", "R/16", "A3/16", "C4/16", "D4/16"
        ],
        ["R/8", "Eb4/8", "R/16", "D4/8.", "C4/4", "R/4"],
        [
            "C4/16", "C4/8", "C4/8", "C4/16", "D4/8", "E4/16", "C4/8", "A3/16",
            "G3/4"
        ],
        ["C4/16", "C4/8", "C4/8", "C4/16", "D4/16", "E4/16", "R/2"],
        [
            "C4/16", "C4/8", "C4/8", "C4/16", "D4/8", "E4/16", "C4/8", "A3/16",
            "G3/4"
        ],
        ["E4/16", "E4/8", "E4/8", "C4/16", "E4/8", "G4/4", "G3/4"],
        ["E4/16", "C4/8", "G3/8", "G#3/8", "A3/16", "F4/8", "F4/16", "A3/4"],
        [
            "B3/16.", "A4/16.", "A4/16.", "A4/16.", "G4/16.", "F4/16.",
            "E4/16", "C4/8", "A3/16", "G3/4"
        ],
        ["E4/16", "C4/8", "G3/8", "G#3/8", "A3/16", "F4/8", "F4/16", "A3/4"],
        [
            "B3/16", "F4/8", "F4/16", "F4/16.", "E4/16.", "D4/16.", "C4/4",
            "R/8"
        ],
    ]
    duration = [
        0, 2400, 2700, 2420, 2470, 2420, 2740, 2260, 2160, 2250, 2540, 2800,
        1920, 2560, 2170, 2250
    ]
    speed = -200
    counter = 0
    while True:
        if robot.dance(speed, duration[counter % len(duration)]):
            brick.speaker.play_notes(music[counter % len(music)], 100)
            counter += 1
Esempio n. 24
0
    def __init__(self):
        # Initialize the EV3 brick.
        self.ev3 = EV3Brick()

        # Initialize the motors connected to the back legs.
        self.left_leg_motor = Motor(Port.D, Direction.COUNTERCLOCKWISE)
        self.right_leg_motor = Motor(Port.A, Direction.COUNTERCLOCKWISE)

        # Initialize the motor connected to the head.
        # Worm gear moves 1 tooth per rotation. It is interfaced to a 24-tooth
        # gear. The 24-tooth gear is connected to parallel 12-tooth gears via
        # an axle. The 12-tooth gears interface with 36-tooth gears.
        self.head_motor = Motor(Port.C,
                                Direction.COUNTERCLOCKWISE,
                                gears=[[1, 24], [12, 36]])

        # Initialize the Color Sensor. It is used to detect the colors when
        # feeding the puppy.
        self.color_sensor = ColorSensor(Port.S4)

        # Initialize the touch sensor. It is used to detect when someone pets
        # the puppy.
        self.touch_sensor = TouchSensor(Port.S1)

        self.pet_count_timer = StopWatch()
        self.feed_count_timer = StopWatch()
        self.count_changed_timer = StopWatch()

        # These attributes are initialized later in the reset() method.
        self.pet_target = None
        self.feed_target = None
        self.pet_count = None
        self.feed_count = None

        # These attributes are used by properties.
        self._behavior = None
        self._behavior_changed = None
        self._eyes = None
        self._eyes_changed = None

        # These attributes are used in the eyes update
        self.eyes_timer_1 = StopWatch()
        self.eyes_timer_1_end = 0
        self.eyes_timer_2 = StopWatch()
        self.eyes_timer_2_end = 0
        self.eyes_closed = False

        # These attributes are used by the playful behavior.
        self.playful_timer = StopWatch()
        self.playful_bark_interval = None

        # These attributes are used in the update methods.
        self.prev_petted = None
        self.prev_color = None
Esempio n. 25
0
    def __init__(self, duration=0, wheel_diameter=55.5, axle_track=104):
        self.duration = duration
        self.wheel_diameter = wheel_diameter
        self.axle_track = axle_track

        self.ev3 = EV3Brick()

        self.left_motor, self.right_motor = Motor(Port.B), Motor(Port.C)
        self.line_sensor = ColorSensor(Port.S3)
        self.robot = DriveBase(self.left_motor, self.right_motor,
                               wheel_diameter, axle_track)
Esempio n. 26
0
    def __init__(self,
                 lever_motor_port: Port = Port.D,
                 touch_sensor_port: Port = Port.S1,
                 ir_sensor_port: Port = Port.S4):
        self.ev3_brick = EV3Brick()

        self.lever_motor = Motor(port=lever_motor_port,
                                 positive_direction=Direction.CLOCKWISE)

        self.touch_sensor = TouchSensor(port=touch_sensor_port)

        self.ir_sensor = InfraredSensor(port=ir_sensor_port)
Esempio n. 27
0
    def __init__(self):
        """ Initialization of Rover."""
        # Constants
        self._GAIN = 10
        self._speed = SPEED_FAST

        # Initialize the EV3 brick
        self.ev3 = EV3Brick()

        # Initialize the motors
        self.left_motor = Motor(Port.B)
        self.right_motor = Motor(Port.C)
Esempio n. 28
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)
Esempio n. 29
0
 def __init__(self):
     self.ev3 = EV3Brick()
     self.motorleft = Motor(Port.D)
     self.motorright = Motor(Port.A)
     self.right = ColorSensor(Port.S2)
     self.left = ColorSensor(Port.S3)
     #self.gyro = GyroSensor(Port.S4)
     self.leftambient = 0
     self.rightambient = 0
     self.currentambient = (self.left.ambient() + self.right.ambient()) / 2
     #self.delta = 0
     self.currentdelta = 0
Esempio n. 30
0
def turn(angle, max_speed, gyro_port, drive_base):
    gyro = GyroSensor(gyro_port, Direction.COUNTERCLOCKWISE)
    ev3 = EV3Brick()
    ev3.screen.clear()

    initial_error = gyro.angle() - angle

    while abs(gyro.angle() - angle) > 2:
        error = gyro.angle() - angle
        speed = max_speed * (error / initial_error)
        ev3.screen.print(gyro.angle(), error, speed)
        drive_base.drive(0, speed)
        wait(10)