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")
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 __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
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
def read_colors(motor: Motor, color: ColorSensor): detected = color.color() detected_colors = [] global scan_done global scan_started while not len(detected_colors) == 4: detected_colors.clear() scan_started = False scan_done = False scan.start() while (not (scan_started)): pass while (not (scan_done)): detected = color.color() if (detected in POSSIBLE_COLORS and detected not in detected_colors): detected_colors.append(detected) if len(detected_colors) < 4: reset(motor) return detected_colors
def __init__(self): self.sensor = ColorSensor(Port.S3) self.dominantColorTab = [] #List used for dominantSortingColor self.logColors = [] #List used to store recently found colors
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)
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
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)
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)
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)
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
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()
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 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): # 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
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
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)
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
def drehe_bis_dizzy(): """ become dizzy by rotating based on color sensor input """ farbsensor = ColorSensor(Port.S3) ev3.screen.load_image(ImageFile.DIZZY) while (farbsensor.color() != Color.GREEN): time.sleep(0.1) db.drive(speed=0, turn_rate=5) while (farbsensor.color() != Color.RED): time.sleep(0.1) db.stop()
def main(): # sound test log.info('test beep') brick.sound.beep() # color sensor test sensor_color = ColorSensor(ROBOT['sensor_color_port']) log.debug('color sensor: color=%s' % sensor_color.color()) # gyro sensor test sensor_gyro = GyroSensor(ROBOT['sensor_gyro_port']) log.debug('gyro sensor: speed=%d, angle=%d' % (sensor_gyro.speed(), sensor_gyro.angle()))
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)
class Parts(): 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 #self.arrayturnleft = [0, 0, 0, 0, 0] #self.arrayturnright = [0, 0, 0, 0, 0] #self.savefile = open("testcheck.txt", "a") def check(self): self.leftambient = self.left.ambient() self.rightambient = self.right.ambient() self.delta = self.leftambient - self.rightambient #return [self.leftambient, self.rightambient] return self.delta #print("LEFT: %d | RIGHT: %d" % (self.leftambient, self.rightambient)) def checkGyro(self): print(self.gyro) def whileCheck(self): #for x in range(5): # self.arrayturnleft[x], self.arrayturnleft[x] = self.check() # time.sleep(0.1) #self.delta = (sum(self.arrayturnleft)/len(self.arrayturnleft) - sum(self.arrayturnright)/len(self.arrayturnright)) #print(self.delta) if (self.check() > 0.5): #self.delta if (self.motorright.angle() > 45): print("OVERRIDE") else: self.motorright.run_angle(10, -10) #10 left print("TURNED THIS WAY") elif (self.check() < -0.5): #self.delta if (self.motorright.angle() < -45): print("OVERRIDE") else: self.motorright.run_angle(10, 10) #-10 right print("TURNED THAT WAY") #brickthing.savefile.write("LEFT: %d | RIGHT: %d" % (brickthing.leftambient, brickthing.rightambient))''' def rapidcheck(self): while brickthing.check() > 1 or brickthing.check( ) < -1: #while True: | self.delta, self.delta brickthing.whileCheck() print(brickthing.check()) print("BREAK") time.sleep(5)
def __init__(self): self.resetY_Sensor = TouchSensor(Port.S2) self.chromoSensor = ColorSensor(Port.S1) self.claw_Motor = Motor(Port.A) self.y_Motor = Motor(Port.B) self.x_Motor1 = Motor(Port.C) self.x_Motor1.set_run_settings(200, 100) self.x_Motor2 = Motor(Port.D) self.x_Motor2.set_run_settings(200, 100) self.xAxisMotors = DriveBase(self.x_Motor1, self.x_Motor2, 50, 100) self.reset()
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())
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(), ".")
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")
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)
def __init__( self, left_leg_motor_port: Port = Port.B, right_leg_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): super().__init__( wheel_diameter=self.WHEEL_DIAMETER, axle_track=self.AXLE_TRACK, left_motor_port=left_leg_motor_port, right_motor_port=right_leg_motor_port, ir_sensor_port=ir_sensor_port, ir_beacon_channel=ir_beacon_channel) 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)
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