Beispiel #1
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
Beispiel #2
0
 def __initSensors(self):
     '''Sub-method for initializing Sensors.'''
     self.logger.debug(self, "Starting sensor initialisation...")
     try:
         self.__gyro = GyroSensor(self.__conf2port[self.__config['gyroSensorPort']], Direction.CLOCKWISE if not self.__config['gyroInverted'] else Direction.COUNTERCLOCKWISE) if self.__config['gyroSensorPort'] != 0 else 0
         self.logger.debug(self, 'Gyrosensor initialized sucessfully on port %s' % self.__config['gyroSensorPort'])
     except Exception as exception:
         self.__gyro = 0
         self.logger.error(self, "Failed to initialize the Gyro-Sensor - Are u sure it's connected to Port %s?" % exception, exception)
     try:
         self.__rLight = ColorSensor(
             self.__conf2port[self.__config['rightLightSensorPort']]) if self.__config['rightLightSensorPort'] != 0 else 0
         self.logger.debug(self, 'Colorsensor initialized sucessfully on port %s' % self.__config['rightLightSensorPort'])
     except Exception as exception:
         self.logger.error(self, "Failed to initialize the right Color-Sensor - Are u sure it's connected to Port %s?" % exception, exception)
     try:
         self.__lLight = ColorSensor(
             self.__conf2port[self.__config['leftLightSensorPort']]) if self.__config['leftLightSensorPort'] != 0 else 0
         self.logger.debug(self, 'Colorsensor initialized sucessfully on port %s' % self.__config['leftLightSensorPort'])
     except Exception as exception:
         self.logger.error(self, "Failed to initialize the left Color-Sensor - Are u sure it's connected to Port %s?" % exception, exception)
     try:
         self.__touch = TouchSensor(self.__conf2port[self.__config['backTouchSensor']]) if self.__config['backTouchSensor'] != 0 else 0
         self.logger.debug(self, 'Touchsensor initialized sucessfully on port %s' % self.__config['backTouchSensor'])
     except Exception as exception:
         self.logger.error(self, "Failed to initialize the Touch-Sensor - Are u sure it's connected to Port %s?" % exception, exception)
     self.logger.debug(self, "Sensor initialisation done")
Beispiel #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
Beispiel #4
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)
Beispiel #5
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)
Beispiel #6
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
Beispiel #7
0
def runDiagnose():
    brick.display.clear()
    success = True
    #---
    try:
        motor_r = Motor(Port.C)
    except OSError:
        brick.display.text("motor_r port C", (30, 20))
        success = False
    #---
    try:
        motor_l = Motor(Port.B)
    except OSError:
        brick.display.text("motor_l port B", (30, 30))
        success = False
    #---
    try:
        function_r = Motor(Port.D)
    except OSError:
        brick.display.text("function_r port D", (30, 40))
        success = False
    #---
    try:
        function_l = Motor(Port.A)
    except OSError:
        brick.display.text("function_l port A", (30, 50))
        success = False
    #---
    try:
        col_l = ColorSensor(Port.S2)
    except OSError:
        brick.display.text("col_l port 3", (30, 60))
        success = False
    #---
    try:
        col_r = ColorSensor(Port.S3)
    except OSError:
        brick.display.text("col_r port 4", (30, 70))
        success = False
    #---
    # brick.light(Color.PURPLE)
    # #battery
    # if brick.battery.voltage() < 7000:
    #     brick.display.text("battery",(30,80))
    if success == False:
        brick.light(Color.ORANGE)
        for i in range(2):
            brick.sound.beep(500, 50, 25)
            brick.sound.beep(500, 50, 0)
            brick.sound.beep(750, 50, 25)
            brick.sound.beep(500, 50, 0)
    else:
        brick.light(Color.GREEN)

    return success
 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
Beispiel #9
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)
Beispiel #10
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
Beispiel #11
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)
Beispiel #12
0
def move_to_black_for_square( power, port1, port2, brake ):
    move_forever( power )
    light_sensor1=ColorSensor( port1 )
    light_sensor2=ColorSensor( port2 )
    print(str(light_sensor1.reflection())+ " " + str(light_sensor2.reflection()))

    while light_sensor1.reflection() > 15 and light_sensor2.reflection() > 15:
        print(str(light_sensor1.reflection())+ " " + str(light_sensor2.reflection()))
        wait(0.1)

    print(str(light_sensor1.reflection())+ " " + str(light_sensor2.reflection()))
    
    stop( brake )
    brick.sound.beep()
Beispiel #13
0
class Kate_Skills:

    color_sensor_left = ColorSensor(Port.S3)
    color_sensor_right = ColorSensor(Port.S4)
    
    def __init__(self, robot):
        self.robot=robot

    def tell_me_about_your_skills(self):
        print("Check out these skills from Kate:")
        print("Left color sensor RGB reading is",self.color_sensor_left.rgb())
        print("Left color sensor color is",self.color_sensor_left.color())
        print("Right color sensor RGB reading is",self.color_sensor_right.rgb())
        print("Right color sensor color is",self.color_sensor_right.color())
        print("My Gyro is reading",self.robot.gyro.angle())
Beispiel #14
0
class Richard_Skills:

    color_sensor_left = ColorSensor(Port.S3)
    color_sensor_right = ColorSensor(Port.S4)

    def __init__(self, robot):
        self.robot = robot

    def tell_me_about_your_skills(self):
        print("SKILLS - I can Dance, Wiggle, Big Wiggle, and Shuffle")
        print("SKILLS - I have access to information like wheel diameter, see",
              self.robot.wheel_diameter)
        print()

    def dance(self, number_of_dances):
        print("SKILLS - Perform", number_of_dances, "dance moves.")
        y = 1
        while y <= number_of_dances:
            self.robot.turn(360)
            y = y + 1

    def wiggle(self, number_of_wiggles):
        print("SKILLS - Wiggle", number_of_wiggles, "times.")
        z = 1
        while z <= number_of_wiggles:
            self.robot.turn(45)
            self.robot.turn(-45)
            z = z + 1

    def shuffle(self, number_of_shuffles):
        print("SKILLS - Shuffle", number_of_shuffles, "times.")
        a = 1
        while a <= number_of_shuffles:
            self.robot.move_forward(50)
            self.robot.move_backwards(50)
            a = a + 1

    def big_wiggle(self, number_of_big_wiggles):
        print("SKILLS - Big Wiggle", number_of_big_wiggles, "times")
        b = 1
        while b <= number_of_big_wiggles:
            self.robot.turn(45)
            self.robot.turn(-15)
            b = b + 1

    def detect_color(self):
        print("I can see left", self.color_sensor_left.color(), " and right",
              self.color_sensor_right.color(), ".")
Beispiel #15
0
 def run():
     left_colour_sensor = ColorSensor(Port.S1)
     right_colour_sensor = ColorSensor(Port.S2)
     # movement.move(0, 500, 1000)
     left_attachment.run_angle(30, 30, Stop.BRAKE, False)
     right_attachment.run_angle(30, 30, Stop.BRAKE, False)
     movement.accelerate(0, 150, 0.01, 500, 10, False, False)
     print("following")
     line_follow = movement.lineFollow(True, 32, 9)
     movement.move(-10, 0, 65)
     while left_colour_sensor.color != Color.BLACK or right_colour_sensor.color != Color.BLACK:
         movement.move(0, 10, 5)
     line_follow = movement.lineFollow(True, 1, 9)
     movement.move(0, 150, 300)
     line_follow = 60
     print("stopped")
Beispiel #16
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
Beispiel #17
0
 def __init__(self, controller):
     self.leftMotor = Motor(Port.B,
                            positive_direction=Direction.COUNTERCLOCKWISE)
     self.rightMotor = Motor(Port.C,
                             positive_direction=Direction.COUNTERCLOCKWISE)
     self.lightSensor = ColorSensor(Port.S3)
     self.controller = controller
Beispiel #18
0
    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.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
Beispiel #19
0
    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
Beispiel #20
0
    def __init__(self):

        self.sensor = ColorSensor(Port.S3)

        self.dominantColorTab = []  #List used for dominantSortingColor

        self.logColors = []  #List used to store recently found colors
Beispiel #21
0
def displayColorValues(port):
    "Continously prints color values at given port"
    print("displayColorValues")
    # creat the sensor object from the ColorSensor class
    sensor = ColorSensor(port)
    i = 0
    while True:
        # have four different ways of using this
        # sensor!
        color = sensor.color()
        print(i)
        i += 1
        # Color.BLACK, Color.BLUE, Color.GREEN, Color.YELLOW, Color.RED, Color.WHITE, Color.BROWN or None
        if color == Color.BLACK:
            c = "Black"
        elif color == Color.BLUE:
            c = "Blue"
        elif color == Color.GREEN:
            c = "Green"
        elif color == Color.YELLOW:
            c = "Yellow"
        elif color == Color.RED:
            c = "Red"
        elif color == Color.WHITE:
            c = "White"
        else:
            c = "Unknown"
        print("color = ", c)
        wait(1000)
Beispiel #22
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)
Beispiel #23
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)
Beispiel #24
0
def init_robot():
    #####Initialization###########################################################################
    logging.info("####################################")

    logging.info("Initializing the robot.")

    #Define Global Variables
    global Left_Motor
    global Right_Motor
    global Med_Motor_1
    global Med_Motor_2
    global Right_Color_Sensor
    global Left_Color_Sensor
    global Gyro
    global Touch_Sensor
    global Robot
    global Max_Speed
    global Target_Reflection
    Target_Reflection = 35

    #initialize Motors
    Left_Motor = Motor(Port.C)
    Right_Motor = Motor(Port.D)
    Med_Motor_1 = Motor(Port.A)
    Med_Motor_2 = Motor(Port.B)
    #Left_Motor.set_run_settings(1000, 100)
    #Right_Motor.set_run_settings(1000, 100)

    #Initialize Sensors
    Left_Color_Sensor = ColorSensor(Port.S2)
    Right_Color_Sensor = ColorSensor(Port.S3)

    #Set Wheel Diameters and Axle Length
    WheelDiameter = 55  #42 # diameter of the wheel in mm
    AxleLength = 128  #112 # distance between the middle of the two wheels in mm

    #####The drivebase function helps to drive the robot. This is initialization of the drivebase
    Robot = DriveBase(Left_Motor, Right_Motor, WheelDiameter, AxleLength)

    Max_Speed = 70
    Robot.stop(0)

    brick.sound.file('/home/robot/FLL2019/boing_spring.wav')

    logging.info("Initializing complete.")
    logging.info("####################################")
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)
Beispiel #26
0
    def __init__(self):
        """Class that represents the robot
        """
        try:

            self.state = "Port 1: Right Color"
            self.right_color = ColorSensor(Port.S1)

            self.state = "Port 2: Center Color"
            self.center_color = ColorSensor(Port.S2)

            self.state = "Port 3: Left Color"
            self.left_color = ColorSensor(Port.S3)

            self.state = "Port 4: Gyro"
            self.gyro = GyroSensor(Port.S4, Direction.COUNTERCLOCKWISE)

            self.state = "Port A: Left Motor"
            self.left_motor = Motor(Port.A)

            self.state = "Port B: Right Motor"
            self.right_motor = Motor(Port.B)

            self.state = "Port C: Linear Gear"
            self.linear_attachment_motor = Motor(Port.C)

            self.state = "Port D: Block Dropper"
            self.dropper_attachment_motor = Motor(Port.D)

            self.wheel_diameter = 55
            self.axle_track = 123
            self.drive_base = DriveBase(self.left_motor, self.right_motor,
                                        self.wheel_diameter, self.axle_track)
            self.state = "OK"
            self.clock = StopWatch()
            self.dance_clock = 0
            self.sign = 1
        except:
            brick.screen.clear()
            big_font = Font(size=18)
            brick.screen.set_font(big_font)
            brick.screen.draw_text(0, 20, "Error!")
            brick.screen.draw_text(0, 40, self.state)
Beispiel #27
0
def move_to_white( power, port, brake ):
    move_forever( power )
    color_sensor=ColorSensor( port )
    print(color_sensor.reflection())

    while color_sensor.reflection()<90:
        print(color_sensor.reflection())
        wait(0.1)
    stop( brake )
    brick.sound.beep()
Beispiel #28
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)
    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
Beispiel #30
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)