def newSheet(): print("Add a new sheet. Press enter when ready.") feedPaperOut() Leds().set_color("LEFT", "GREEN") Leds().set_color("RIGHT", "GREEN") btn.wait_for_pressed('enter', 5000) Leds().all_off() feedPaperIn()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Robot state self.patrol_mode = False self.follow_mode = False # Internal Variables self.light_intensity = 0 self.batt_voltage = 0 # Connect two large motors on output ports B and C #self.drive = MoveTank(OUTPUT_D, OUTPUT_C) self.steerdrive = MoveSteering(OUTPUT_C, OUTPUT_D) self.leds = Leds() self.ir = InfraredSensor() self.ir.mode = 'IR-SEEK' self.touch = TouchSensor() self.light = ColorSensor(address='ev3-ports:in4') self.sound = Sound() # Start threads threading.Thread(target=self._patrol_thread, daemon=True).start() threading.Thread(target=self._follow_thread, daemon=True).start() threading.Thread(target=self._pat_thread, daemon=True).start() threading.Thread(target=self._power_thread, daemon=True).start() threading.Thread(target=self._light_sensor_thread, daemon=True).start()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() self.leds = Leds() self.sound = Sound()
def __init__(self, left_foot_motor_port: str = OUTPUT_B, right_foot_motor_port: str = OUTPUT_C, bazooka_blast_motor_port: str = OUTPUT_A, touch_sensor_port: str = INPUT_1, color_sensor_port: str = INPUT_3, ir_sensor_port: str = INPUT_4, ir_beacon_channel: int = 1): super().__init__(left_motor_port=left_foot_motor_port, right_motor_port=right_foot_motor_port, polarity=Motor.POLARITY_NORMAL, speed=1000, channel=ir_beacon_channel) self.tank_driver = MoveTank(left_motor_port=left_foot_motor_port, right_motor_port=right_foot_motor_port, motor_class=LargeMotor) self.bazooka_blast_motor = MediumMotor( address=bazooka_blast_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.color_sensor = ColorSensor(address=color_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.ir_beacon_channel = ir_beacon_channel self.leds = Leds() self.speaker = Sound()
def test(): button = Button() leds = Leds() console = Console(font='Lat15-TerminusBold20x10') count = 0 while True: leds.set_color('LEFT', 'BLACK') leds.set_color('RIGHT', "BLACK") sleep(1) leds.set_color('LEFT', 'GREEN') leds.set_color('RIGHT', 'GREEN') sleep(1) leds.set_color('LEFT', 'BLACK') leds.set_color('RIGHT', "BLACK") sleep(1) leds.set_color('LEFT', 'RED') leds.set_color('RIGHT', 'RED') sleep(1) count = count + 1 if button.enter: print("press enter", file=sys.stderr) break print(count) sleep(10)
def __init__(self): super().__init__() self.leds = Leds() self.motorOne = LargeMotor(OUTPUT_C) self.motorTwo = LargeMotor(OUTPUT_B) self.motorThree = MediumMotor(OUTPUT_A)
def test_leds_set_color(self): with patch('ev3dev2.DeviceConnector') as DeviceMock: with patch( 'ev3dev2simulator.connector.LedConnector.get_client_socket' ) as get_client_socketMock: mock_instance = MagicMock() get_client_socketMock.return_value = mock_instance leds = Leds() leds.set_color('LEFT', 'AMBER') self.assertEqual(len(mock_instance.mock_calls), 2) fn_name, args, kwargs = mock_instance.mock_calls[0] self.assertEqual(fn_name, 'send_command') self.assertDictEqual( args[0].serialize(), { 'type': 'LedCommand', 'address': 'led0:red:brick-status', 'brightness': 1 }) fn_name, args, kwargs = mock_instance.mock_calls[1] self.assertDictEqual( args[0].serialize(), { 'type': 'LedCommand', 'address': 'led0:green:brick-status', 'brightness': 1 })
def test_MoveTank(self): my_leds = Leds() my_leds.set_color('LEFT', (0.5, 0.3)) my_leds.set_color('RIGHT', 'AMBER') sleep(2) my_leds.all_off() my_leds.animate_cycle(('RED', 'GREEN', 'AMBER'), duration=5)
def test_ledsOff(self): my_leds = Leds() my_leds.set_color('LEFT', (0.5, 0.3)) my_leds.set_color('RIGHT', 'AMBER') sleep(5) my_leds.all_off() sleep(5)
def __init__(self): self.leds = Leds() self.tank_drive = MoveTank(OUTPUT_A, OUTPUT_B) self.tank_drive.set_polarity(LargeMotor.POLARITY_INVERSED) self.color = ColorSensor() self.ultra = UltrasonicSensor() self.sound = Sound()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Robot state self.patrol_mode = False self.enemy_not_detected = True print("+++++ self.patrol_mode = {} y self.enemy_not_detected = {}". format(self.patrol_mode, self.enemy_not_detected)) self.positionX = 0 self.positionY = 0 self.direction = ['forward', 'right', 'backward', 'left'] self.offset = [0, 1, 0, -1] self.index = 0 self.pointing = self.direction[self.index] # Connect two large motors on output ports B and C self.drive = MoveTank(OUTPUT_B, OUTPUT_C) self.weapon = MediumMotor(OUTPUT_A) self.sound = Sound() self.leds = Leds() self.ir = InfraredSensor() # Start threads threading.Thread(target=self._patrol_thread, daemon=True).start() threading.Thread(target=self._proximity_thread, daemon=True).start()
def __init__(self): super().__init__() self.leds = Leds() self.sound = Sound() self.tank = MoveTank(OUTPUT_A, OUTPUT_D)
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Gadget state self.in_progress = False # Ev3dev initialization self.leds = Leds() self.sound = Sound() self.drive = MoveTank(OUTPUT_B, OUTPUT_A) self.stick = MediumMotor(OUTPUT_C) self.cs = ColorSensor(INPUT_4) self.cs.mode = 'COL-REFLECT' self.floor_light = self.cs.value() print("floor light intensity = {}".format(self.floor_light)) self.speed = 20 self.kickAngle = 170 paho.Client.connected_flag = False self.client = paho.Client() self.client.loop_start() self.client.on_connect = self.mqtt_connected self.client.connect('broker.hivemq.com', 1883) while not self.client.connected_flag: time.sleep(1) self.client.subscribe('/hockeybot/game/over') self.client.on_message = self.mqtt_on_message # Start threads threading.Thread(target=self.check_for_obstacles_thread, daemon=True).start()
def backup(): """ Back away from an obstacle. """ # Sound backup alarm. spkr = Sound() spkr.tone([(1000, 500, 500)] * 3) # Turn backup lights on: leds = Leds() for light in (Leds.LEFT, Leds.RIGHT): leds.set_color(light, Leds.RED) # Stop both motors and reverse for 1.5 seconds. # `run-timed` command will return immediately, so we will have to wait # until both motors are stopped before continuing. for m in motors: m.stop(stop_action='brake') m.run_timed(speed_sp=-500, time_sp=1500) # When motor is stopped, its `state` attribute returns empty list. # Wait until both motors are stopped: while any(m.state for m in motors): sleep(0.1) # Turn backup lights off: for light in (Leds.LEFT, Leds.RIGHT): leds.set_color(light, Leds.GREEN)
def __init__(self): self.leds = Leds() self.arm_position = ArmPosition.CONTRACT self.color_arm = MediumMotor(OUTPUT_A) self.color_sensor = ColorSensor() self.color_scaned = ColorScanOptions.NONE self.sound = Sound()
def flashLEDs(self, color): my_leds = Leds() my_leds.all_off() my_leds.set_color("LEFT", color) my_leds.set_color("RIGHT", color) my_leds.all_off() my_leds.set_color("LEFT", "GREEN") my_leds.set_color("RIGHT", "GREEN")
def __init__(self): """ Performs Alexa Gadget initialization """ super().__init__() self.leds = Leds() self.sound = Sound()
def __init__(self): super().__init__() # initialize all of the motors print('Initializing devices') self.leds = Leds() self.motor_hand = LargeMotor(address='outA') self.motor_claw = MediumMotor(address='outC')
def leds(): leds = Leds() for i in range(3): leds.set_color('LEFT', 'AMBER') leds.set_color('RIGHT', 'GREEN') sleep(2) leds.set_color('LEFT', 'GREEN') leds.set_color('RIGHT', 'AMBER') sleep(2)
def __init__(self): self.scan_tower = LargeMotor(OUTPUT_B) #self.gyro_sensor = GyroSensor() #self.gyro_sensor.reset #self.ultrasonic_sensor = UltrasonicSensor() self.leds = Leds() self.sound = Sound() self.tower_position = TowerPosition.CENTER
def __init__(self, left_motor_port, right_motor_port, rot_motor_port, wheel_class, wheel_distance_mm, desc=None, motor_class=LargeMotor): MoveDifferential.__init__(self, left_motor_port, right_motor_port, wheel_class, wheel_distance_mm) """ LegoBot Class inherits all usefull stuff for differential drive and adds sound, LEDs, IRSensor which is rotated by Medium Motor """ self.leds = Leds() self.sound = Sound() self.leds.set_color("LEFT", "BLACK") self.leds.set_color("RIGHT", "BLACK") # Startup sequence self.sound.play_song((('C4', 'e'), ('D4', 'e'), ('E5', 'q'))) self.leds.set_color("LEFT", "GREEN") self.leds.set_color("RIGHT", "GREEN") # create IR sensors self.ir_sensor = InfraredSensor() self.sensor_rotation_point = Pose( 0.05, 0.0, np.radians(0)) self.sensor_rotation_radius = 0.04 self.sensor_thread_run = False self.sensor_thread_id = None # temporary storage for ir readings and poses until half rotation is fully made self.ir_sensors = None # initialize motion self.ang_velocity = (0.0,0.0) self.rot_motor = MediumMotor(rot_motor_port) self.rotate_thread_run = False self.rotate_thread_id = None self.rotation_degrees = 180 # information about robot for controller or supervisor self.info = Struct() self.info.wheels = Struct() self.info.wheels.radius = self.wheel.radius_mm /1000 self.info.wheels.base_length = wheel_distance_mm /1000 self.info.wheels.max_velocity = 2*pi*170/60 # 170 RPM self.info.wheels.min_velocity = 2*pi*30/60 # 30 RPM self.info.pose = None self.info.ir_sensors = Struct() self.info.ir_sensors.poses = None self.info.ir_sensors.readings = None self.info.ir_sensors.rmax = 0.7 self.info.ir_sensors.rmin = 0.04 # starting odometry thread self.odometry_start(0,0,0) # start measuring distance with IR Sensor in another thread while rotating self.sensor_update_start(self.rot_motor) # start rotating of medium motor self.rotate_and_update_sensors_start()
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Ev3dev initialization self.leds = Leds() self.sound = Sound() self.drive = MoveTank(OUTPUT_A, OUTPUT_B)
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Ev3dev initialization self.leds = Leds() self.sound = Sound() self.chainLift = MediumMotor(OUTPUT_A) self.color = ColorSensor()
def __init__(self): #Performs Alexa Gadget initialization routines and ev3dev resource allocation. super().__init__() self.leds = Leds() self.sound = Sound() #Connect the blue motor to Port A self.blueMotor = MediumMotor(OUTPUT_A) #Connect the red motor to Port B self.redMotor = MediumMotor(OUTPUT_B)
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Ev3dev initialization self.leds = Leds() self.sound = Sound() self.albert = ALBERT() self.plate_counter = 0
def __init__(self): """ Performs Alexa Gadget initialization routines and ev3dev resource allocation. """ super().__init__() # Ev3dev initialization self.leds = Leds() self.sound = Sound() self.drive = LargeMotor(OUTPUT_B) self.tail = MediumMotor(OUTPUT_A)
def __init__(self): """ Initializer for a Robot. """ self.cs = ColorSensor() self.left_touch = TouchSensor('ev3-ports:in1') self.right_touch = TouchSensor('ev3-ports:in4') self.us = UltrasonicSensor() self.tank_drive = Robot.get_tank_drive() self.sound = Sound() self.leds = Leds() self.setup_sensors()
def __init__( self, lever_motor_port: str = OUTPUT_D, touch_sensor_port: str = INPUT_1, ir_sensor_port: str = INPUT_4): self.lever_motor = MediumMotor(address=lever_motor_port) self.touch_sensor = TouchSensor(address=touch_sensor_port) self.ir_sensor = InfraredSensor(address=ir_sensor_port) self.leds = Leds() self.speaker = Sound()
def __init__(self, sensormap, bluetooth=None): """ Initializer for a Robot. """ self.bluetooth = bluetooth if bluetooth: self.bluetooth.initiate_connection() print('connected') if isinstance(bluetooth, BluetoothMaster): self.database = bluetooth.get_database() self.sensormap = sensormap self.sound = Sound() self.leds = Leds()
def calibrate(): global Calibrating Calibrating = True feedPaperIn() lowerPen() threading.Thread(target=sideScrollThread, daemon=True).start() btn.on_up = onButtonUp btn.on_down = onButtonDown btn.on_enter = onButtonExit btn.on_backspace = onButtonExit Leds().set_color("LEFT", "GREEN") Leds().set_color("RIGHT", "GREEN") while Calibrating: btn.process() time.sleep(0.1) Leds().all_off() raisePen() feedPaperOut()