Esempio n. 1
0
 def __init__(self):
     """
     Performs Alexa Gadget initialization routines and ev3dev resource allocation.
     """
     super().__init__()
     self.leds = Leds()
     self.sound = Sound()
Esempio n. 2
0
 def __init__(self):
     
     super().__init__()
     self.leds = Leds()
     self.motorOne = LargeMotor(OUTPUT_C)
     self.motorTwo = LargeMotor(OUTPUT_B)
     self.motorThree = MediumMotor(OUTPUT_A)
Esempio n. 3
0
 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)
Esempio n. 4
0
    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 __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()
Esempio n. 6
0
    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()
Esempio n. 7
0
    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 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
                    })
Esempio n. 9
0
    def __init__(self):

        super().__init__()
        
        self.leds = Leds()
        self.sound = Sound()
        self.tank = MoveTank(OUTPUT_A, OUTPUT_D)
Esempio n. 10
0
 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()
Esempio n. 11
0
    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')
Esempio n. 12
0
    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()
Esempio n. 13
0
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()
Esempio n. 14
0
    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
Esempio n. 15
0
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)
Esempio n. 16
0
    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()
Esempio n. 17
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 = MoveTank(OUTPUT_A, OUTPUT_B)
class El3ctricGuitar:
    NOTES = [1318, 1174, 987, 880, 783, 659, 587, 493, 440, 392, 329, 293]
    N_NOTES = len(NOTES)

    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 start_up(self):
        self.leds.animate_flash(
            color='ORANGE',
            groups=('LEFT', 'RIGHT'),
            sleeptime=0.5,
            duration=3,
            block=True)

        self.lever_motor.on_for_seconds(
            speed=5,
            seconds=1,
            brake=False,
            block=True)

        self.lever_motor.on_for_degrees(
            speed=-5,
            degrees=30,
            brake=True,
            block=True)

        sleep(0.1)

        self.lever_motor.reset()

    def play_music(self):
        if self.touch_sensor.is_released:
            raw = sum(self.ir_sensor.proximity for _ in range(4)) / 4

            self.speaker.tone(
                self.NOTES[min(round(raw / 5), self.N_NOTES - 1)]
                - 11 * self.lever_motor.position,
                100,
                play_type=Sound.PLAY_WAIT_FOR_COMPLETE)

    def main(self):
        self.start_up()
        while True:
            self.play_music()
    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()
Esempio n. 20
0
    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)
Esempio n. 21
0
    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
Esempio n. 22
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, 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()
Esempio n. 24
0
def touchLeds():
    ts = TouchSensor()
    leds = Leds()

    print("Press the touch sensor to change the LED color!")

    while True:
        if ts.is_pressed:
            leds.set_color("LEFT", "GREEN")
            leds.set_color("RIGHT", "GREEN")
        else:
            leds.set_color("LEFT", "RED")
            leds.set_color("RIGHT", "RED")
Esempio n. 25
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Robot initial position
        self.botposition = RobotPosition.ROBOT_AT_BASE.value

        self.sound = Sound()
        self.leds = Leds()

        self.nav_map = NavegationMap()
Esempio n. 26
0
def test_touch():
    ts = TouchSensor(INPUT_4)
    leds = Leds()

    print("Press the touch sensor to change the LED color!")

    while not button.any():
        if ts.is_pressed:
            leds.set_color("LEFT", "GREEN")
            leds.set_color("RIGHT", "GREEN")
        else:
            leds.set_color("LEFT", "RED")
            leds.set_color("RIGHT", "RED")
Esempio n. 27
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Gadget state
        self.patrol_mode = False

        # Ev3dev initialization
        self.leds = Leds()
        self.sound = Sound()
        self.switch = LargeMotor(OUTPUT_D)
Esempio n. 28
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Gadget state
        self.patrol_mode = False

        # Ev3dev initialization
        self.leds = Leds()
        self.sound = Sound()
        self.drive = MoveTank(OUTPUT_A,OUTPUT_A)  # Band """
        self.deliver = MoveTank(OUTPUT_B,OUTPUT_B) # Deliver """
Esempio n. 29
0
 def __init__(self, wheel_radius, wheel_spacing):
     self._container_motor = MediumMotor(OUTPUT_C)
     self._steering_drive = MoveSteering(OUTPUT_D, OUTPUT_A)
     self._touch_sensor_front = TouchSensor(INPUT_1)
     self._touch_sensor_top = TouchSensor(INPUT_2)
     #self._ultrasonic_sensor = UltrasonicSensor(INPUT_2)
     self._color_sensor = ColorSensor(INPUT_3)
     #self._color_sensor.calibrate_white()
     #self._color_sensor.mode = "RGB-RAW"
     self._color_sensor.mode = "COL-REFLECT"
     self._leds = Leds()
     self._sound = Sound()
     self.WHEEL_RADIUS = wheel_radius
     self.WHEEL_SPACING = wheel_spacing
Esempio n. 30
0
 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)