Пример #1
0
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 medium_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_motor_port,
                         right_motor_port=right_motor_port,
                         ir_sensor_port=ir_sensor_port,
                         ir_beacon_channel=ir_beacon_channel)

        self.medium_motor = MediumMotor(address=medium_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.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.dis = Screen()
        self.noise = Sound()
Пример #2
0
def MAIN():
    global lastTagTime

    print("Starting RFID reader...")
    rfidReader.start()
    sleep(4)  # time for the RFID reader to start up

    findLineNearby(robot)

    while not brickButton.any() and not finishedExploration:
        if (robot.getDistanceAhead() is None) or (robot.getDistanceAhead() >= 20):
            #go ahead
            robot.followLine(200)
        else:
            #shock prevention
            print("Obstacle at distance ", robot.getDistanceAhead(), "! Waiting...")  #IDEIA: este para, e o outro robo desvia
            robot.stopMotors()
            while robot.getDistanceAhead() < 20:
                sleep(0.1)
            print(" - clear to go...")
            robot.followLine(200)

        if (time() - lastTagTime > 3) and rfidReader.getCurrentTagId() is not None:
            robot.stopMotors()
            Sound.beep()
            print("Tag detected - id", rfidReader.getCurrentTagId())
            dbgSleep()
            onNodeAction(rfidReader.getCurrentTagId())

    robot.stopMotors()
    rfidReader.stop()
    return
Пример #3
0
def TEST2():
    brickButton = Button()
    rfidReader = RfidSerialThread("COM5" if (platform.system() == "Windows") else "/dev/ttyUSB0")

    print("FOLLOWING LINES, DETECTING TAGS:")
    rfidReader.start()
    sleep(4)
    robot.resetOrientation()

    while not brickButton.any():
        robot.followLine(200)

        if rfidReader.getCurrentTagId() is not None:
            robot.stopMotors()
            print("TAG FOUND - id", rfidReader.getCurrentTagId())
            Sound.beep()
            sleep(1)
            robot.runMotorsDistance(-5.7, 150)
            sleep(4)
            robot.runMotorsDistance(12.0, 150) #to go past the tag

        if (robot.getDistanceAhead() is not None and robot.getDistanceAhead() < 20):
            print("Obstacle! Dist =", robot.getDistanceAhead(), "Exiting...")
            break

    robot.stopMotors()
    rfidReader.stop()
Пример #4
0
def virar(dir):
	m_left.stop()
	m_right.stop()

	pos0 = gyro.value()

	Sound.beep()

	if(dir == ESQUERDA):
		m_left.run_to_rel_pos(position_sp=-55, speed_sp=900, stop_action="hold")
		m_right.run_to_rel_pos(position_sp=-55, speed_sp=900, stop_action="hold")
		sleep(0.1)

		while gyro.value() > pos0 - 67:
			m_left.run_forever(speed_sp=250)
			m_right.run_forever(speed_sp=-500)

		m_left.stop()
		m_right.stop()
	elif(dir == DIREITA):
		m_left.run_to_rel_pos(position_sp=-55, speed_sp=900, stop_action="hold")
		m_right.run_to_rel_pos(position_sp=-55, speed_sp=900, stop_action="hold")
		sleep(0.1)

		while gyro.value() < pos0 + 67:
			m_left.run_forever(speed_sp=-500)
			m_right.run_forever(speed_sp=250)
		m_left.stop()
		m_right.stop()
	andarEmCm(2)
	sleep(0.5)
class Gripp3r(IRBeaconRemoteControlledTank):
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 grip_motor_port: str = OUTPUT_A,
                 touch_sensor_port: str = INPUT_1,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        super().__init__(left_motor_port=left_motor_port,
                         right_motor_port=right_motor_port,
                         ir_sensor_port=ir_sensor_port,
                         ir_beacon_channel=ir_beacon_channel)

        self.grip_motor = MediumMotor(address=grip_motor_port)

        self.touch_sensor = TouchSensor(address=touch_sensor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.ir_beacon_channel = ir_beacon_channel
        self.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.speaker = Sound()

    def grip_or_release_by_ir_beacon(self, speed: float = 50):
        while True:
            if self.beacon.beacon:
                if self.touch_sensor.is_pressed:
                    self.speaker.play(
                        wav_file='/home/robot/sound/Air release.wav')

                    self.grip_motor.run_timed(
                        speed_sp=500,
                        time_sp=1000,
                        stop_action=Motor.STOP_ACTION_BRAKE)
                    self.grip_motor.wait_while(Motor.STATE_RUNNING)

                else:
                    self.speaker.play(
                        wav_file='/home/robot/sound/Airbrake.wav')

                    self.grip_motor.run_forever(speed_sp=-500)

                    while not self.touch_sensor.is_pressed:
                        pass

                    self.grip_motor.stop(stop_action=Motor.STOP_ACTION_BRAKE)

                while self.beacon.beacon:
                    pass

    def main(self, speed: float = 1000):
        self.grip_motor.run_timed(speed_sp=-500,
                                  time_sp=1000,
                                  stop_action=Motor.STOP_ACTION_BRAKE)
        self.grip_motor.wait_while(Motor.STATE_RUNNING)

        Process(target=self.grip_or_release_by_ir_beacon, daemon=True).start()

        self.keep_driving_by_ir_beacon(speed=speed)
Пример #6
0
 def play(self, song):
     """Play the song"""
     file_name = song.get('file_name')
     with open(file_name) as data_file:
         lyrics = data_file.read()
         from ev3dev.ev3 import Sound
         Sound.beep(lyrics).wait()
Пример #7
0
 def play(self, song):
     """Play the song"""
     from ev3dev.ev3 import Sound
     file_name = song.get('file_name')
     with open(file_name) as data_file:
         lyrics = json.load(data_file)
         Sound.tone(self.convert_lyrics(lyrics)).wait()
Пример #8
0
    def update(self):
        self.x += self.xv
        self.y += self.yv

        if self.x - self.radius <= racket_left.thickness + racket_left.distance_from_edge:
            if self.y < racket_left.pos - racket_left.width / 2 or self.y > racket_left.pos + racket_left.width:
                Sound.tone(250, 100).wait()
                Sound.tone(500, 100).wait()
                self.reset()
            else:
                self.xv = -self.xv
                self.yv += 1 if self.y > racket_left.pos else -1
                m1.run_timed(time_sp=20,
                             speed_sp=900 * self.yv /
                             abs(1 if self.yv == 0 else self.yv))

        if self.x + self.radius >= screen_width - racket_left.thickness - racket_left.distance_from_edge:
            if self.y < racket_right.pos - racket_right.width / 2 or self.y > racket_right.pos + racket_right.width:
                Sound.tone(250, 100).wait()
                Sound.tone(500, 100).wait()
                self.reset()
            else:
                self.xv = -self.xv
                self.yv += 1 if self.y > racket_right.pos else -1
                m2.run_timed(time_sp=20,
                             speed_sp=900 * self.yv /
                             abs(1 if self.yv == 0 else self.yv))

        if self.y + self.radius >= screen_height or self.y - self.radius <= 0:
            self.yv = -self.yv
            Sound.tone(2000, 5)
Пример #9
0
    def __init__(self,
                 init_pose,
                 soc=None,
                 port_motor_rear=OUTPUT_A,
                 port_motor_steer=OUTPUT_B,
                 port_sensor_gyro='in1'):

        # initialization of devices
        self.__button_halt = Button()
        self.__motor_rear = LargeMotor(port_motor_rear)
        self.__motor_steer = LargeMotor(port_motor_steer)
        self.__sensor_gyro = GyroSensor(port_sensor_gyro)

        self.__velocity_controller = VelocityController(self,
                                                        0,
                                                        0,
                                                        adaptation=False)
        self.s = soc
        # NOTE: possible using other controllers. Change only here!
        self.__trajectory_controller = ControllerWithLinearization()
        self.__path_controller = PathController()

        self.__localization = Localization(self, init_pose)
        self.__robot_state = [0, 0, 0, 0, 0, 0]  # x,y, dx,dy, theta,omega

        self.reset()
        Sound.speak('Ready').wait()
Пример #10
0
    def __init__(self,
                 port_motor_rear=OUTPUT_A,
                 port_motor_steer=OUTPUT_B,
                 port_sensor_gyro='in1',
                 port_sensor_us_front='in2',
                 port_sensor_us_rear='in3'):

        # initialization of devices
        self.__button_halt = Button()

        self.__motor_rear = LargeMotor(port_motor_rear)
        self.__motor_steer = LargeMotor(port_motor_steer)

        self.__sensor_gyro = GyroSensor(port_sensor_gyro)
        self.__sensor_us_rear = UltrasonicSensor(port_sensor_us_rear)
        self.__sensor_us_front = UltrasonicSensor(port_sensor_us_front)

        self.__velocity_controller = VelocityController(self, 0, 0)

        # NOTE: possible using other controllers. Change only here!
        self.__trajectory_controller = ControllerWithLinearization()

        self.__localization = Localization(self)
        self.__robot_state = [0, 0, 0, 0, 0, 0]  # x,y, dx,dy, theta,omega

        self.reset()
        Sound.speak('Initialization complete!').wait()
class Rov3r(RemoteControlledTank):
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 gear_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=left_motor_port,
                         right_motor=right_motor_port,
                         polarity=Motor.POLARITY_NORMAL)

        self.gear_motor = MediumMotor(address=gear_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.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.speaker = Sound()
        self.dis = Screen()

    def spin_gears(self, speed: float = 1000):
        while True:
            if self.beacon.beacon:
                self.gear_motor.run_forever(speed_sp=speed)

            else:
                self.gear_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)

    def change_screen_when_touched(self):
        while True:
            if self.touch_sensor.is_pressed:
                self.dis.image.paste(
                    im=Image.open('/home/robot/image/Angry.bmp'))
            else:
                self.dis.image.paste(
                    im=Image.open('/home/robot/image/Fire.bmp'))
            self.dis.update()

    def make_noise_when_seeing_black(self):
        while True:
            if self.color_sensor.color == ColorSensor.COLOR_BLACK:
                self.speaker.play(wav_file='/home/robot/sound/Ouch.wav').wait()

    def main(self):
        self.speaker.play(wav_file='/home/robot/sound/Yes.wav').wait()

        Thread(target=self.make_noise_when_seeing_black, daemon=True).start()

        Thread(target=self.spin_gears, daemon=True).start()

        Thread(target=self.change_screen_when_touched, daemon=True).start()

        super().main()  # RemoteControlledTank.main()
class Ev3rstorm(IRBeaconRemoteControlledTank):
    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,
                         ir_sensor_port=ir_sensor_port,
                         ir_beacon_channel=ir_beacon_channel)

        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.screen = Screen()
        self.speaker = Sound()

    def blast_bazooka_whenever_touched(self):
        while True:
            if self.touch_sensor.is_pressed:
                if self.color_sensor.ambient_light_intensity < 5:  # 15 not dark enough
                    self.speaker.play(
                        wav_file='/home/robot/sound/Up.wav').wait()

                    self.bazooka_blast_motor.run_to_rel_pos(
                        speed_sp=1000,  # degrees per second
                        position_sp=-3 * 360,  # degrees
                        stop_action=Motor.STOP_ACTION_HOLD)

                else:
                    self.speaker.play(
                        wav_file='/home/robot/sound/Down.wav').wait()

                    self.bazooka_blast_motor.run_to_rel_pos(
                        speed_sp=1000,  # degrees per second
                        position_sp=3 * 360,  # degrees
                        stop_action=Motor.STOP_ACTION_HOLD)

                while self.touch_sensor.is_pressed:
                    pass

    def main(
            self,
            driving_speed: float = 1000  # degrees per second
    ):
        self.screen.image.paste(im=Image.open('/home/robot/image/Target.bmp'))
        self.screen.update()

        Thread(target=self.blast_bazooka_whenever_touched, daemon=True).start()

        self.keep_driving_by_ir_beacon(speed=driving_speed)
class CuriosityRov3r(IRBeaconRemoteControlledTank):
    def __init__(
            self,
            left_motor_port: str = OUTPUT_B, right_motor_port: str = OUTPUT_C,
            medium_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_motor_port, right_motor_port=right_motor_port,
            ir_sensor_port=ir_sensor_port, ir_beacon_channel=ir_beacon_channel)
            
        self.medium_motor = MediumMotor(address=medium_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.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.dis = Screen()
        self.noise = Sound()

    
    def spin_fan(self, speed: float = 1000):
        while True:
            if self.color_sensor.reflected_light_intensity > 20:
                self.medium_motor.run_forever(speed_sp=speed)

            else:
                self.medium_motor.stop(stop_action=Motor.STOP_ACTION_HOLD)

            
    def say_when_touched(self):
        while True:
            if self.touch_sensor.is_pressed:
                self.dis.image.paste(im=Image.open('/home/robot/image/Angry.bmp'))
                self.dis.update()

                self.noise.play(wav_file='/home/robot/sound/No.wav').wait()

                self.medium_motor.run_timed(
                    speed_sp=-500,
                    time_sp=3000,
                    stop_action=Motor.STOP_ACTION_BRAKE)
                self.medium_motor.wait_while(Motor.STATE_RUNNING)


    def main(self, speed: float = 1000):
        Thread(target=self.say_when_touched,
               daemon=True).start()

        Thread(target=self.spin_fan,
               daemon=True).start()

        self.keep_driving_by_ir_beacon(speed=speed)
Пример #14
0
def robot_die():
    """
    Končaj s programom na robotu. Ustavi motorje.
    """
    print('KONEC')
    motor_left.stop(stop_action='brake')
    motor_right.stop(stop_action='brake')
    Sound.play_song((('D4', 'e'), ('C4', 'e'), ('A3', 'h')))
    sys.exit(0)
class Ev3rstorm(RemoteControlledTank):
    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):
        super().__init__(
            left_motor=left_foot_motor_port, right_motor=right_foot_motor_port,
            polarity=Motor.POLARITY_NORMAL)
        
        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.screen = Screen()
        self.speaker = Sound()


    def blast_bazooka_whenever_touched(self):
        while True:
            if self.touch_sensor.is_pressed:
                if self.color_sensor.ambient_light_intensity < 5:   # 15 not dark enough
                    self.speaker.play(wav_file='/home/robot/sound/Up.wav').wait()

                    self.bazooka_blast_motor.run_to_rel_pos(
                        speed_sp=1000,   # degrees per second
                        position_sp=-3 * 360,   # degrees
                        stop_action=Motor.STOP_ACTION_HOLD)

                else:
                    self.speaker.play(wav_file='/home/robot/sound/Down.wav').wait()

                    self.bazooka_blast_motor.run_to_rel_pos(
                        speed_sp=1000,   # degrees per second
                        position_sp=3 * 360,   # degrees
                        stop_action=Motor.STOP_ACTION_HOLD)

                while self.touch_sensor.is_pressed:
                    pass


    def main(self):
        self.screen.image.paste(im=Image.open('/home/robot/image/Target.bmp'))
        self.screen.update()
    
        Process(target=self.blast_bazooka_whenever_touched,
                daemon=True).start()
        
        super().main()   # RemoteControlledTank.main()
Пример #16
0
    def turnWheel(self, phi_desired):
        """ Turns front wheels on the desired angle 'phi_desired' """
        pid_phi = PID(100.0, 500.0, 5.0, 100, -100)
        t = 0
        clock = Clock()
        while t < 1:  # FIXME: seems that need steady state condition
            t, dt = clock.getTandDT()

            phi_current = self.__motor_steer.position
            error_phi = radians(phi_desired - phi_current)

            u_phi = pid_phi.getControl(error_phi, dt)
            self.__motor_steer.run_direct(duty_cycle_sp=u_phi)
        Sound.speak('Wheels were turned!')
Пример #17
0
def verificarSilverTap(dados):
	if (dados['esquerdo']['silverTape']['refl'] - 10 < cl_left.value() < dados['esquerdo']['silverTape']['refl'] + 10 and 
			dados['direito']['silverTape']['refl'] - 10 < cl_right.value() < dados['direito']['silverTape']['refl'] + 10):

		print("possivel silver tape")
		cl_left.mode = 'RGB-RAW'
		cl_right.mode = 'RGB-RAW'

		if(dados['esquerdo']['silverTape']['rgb'] - 20 < cl_left.value() < dados['esquerdo']['silverTape']['rgb'] + 20 and 
				dados['direito']['silverTape']['rgb'] - 20 < cl_right.value() < dados['direito']['silverTape']['rgb'] + 20):
			cl_left.mode = 'COL-REFLECT'
			cl_right.mode = 'COL-REFLECT'
			Sound.beep()
			rotina3Piso(dados)
Пример #18
0
def all_green():
    process = robot.scan(200)
    g_count = 0
    for i, j in process:
        if i == Color.GREEN:
            g_count += 1

    if g_count == len(process):
        Leds.set_color(Leds.RIGHT, Leds.GREEN)
        Leds.set_color(Leds.LEFT, Leds.GREEN)
        Sound.speak("good to go, all green").wait()
        Leds.all_off()
        return True
    else:
        return False
    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):
        super().__init__(
            left_motor=left_foot_motor_port, right_motor=right_foot_motor_port,
            polarity=Motor.POLARITY_NORMAL)
        
        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.screen = Screen()
        self.speaker = Sound()
Пример #20
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,
            ir_sensor_port=ir_sensor_port, ir_beacon_channel=ir_beacon_channel)
        
        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.leds = Leds()
        self.screen = Screen()
        self.speaker = Sound()
Пример #21
0
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 grip_motor_port: str = OUTPUT_A,
                 touch_sensor_port: str = INPUT_1,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        self.left_motor = LargeMotor(address=left_motor_port)
        self.right_motor = LargeMotor(address=right_motor_port)
        self.grip_motor = MediumMotor(address=grip_motor_port)

        self.touch_sensor = TouchSensor(address=touch_sensor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.ir_beacon_channel = ir_beacon_channel
        self.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.speaker = 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):
        self.left_foot_motor = LargeMotor(address=left_foot_motor_port)
        self.right_foot_motor = LargeMotor(address=right_foot_motor_port)
        
        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.remote_control = RemoteControl(sensor=self.ir_sensor,
                                            channel=ir_beacon_channel)

        self.screen = Screen()
        self.speaker = Sound()
Пример #23
0
    def __init__(self,
                 turn_motor_port: str = OUTPUT_A,
                 move_motor_port: str = OUTPUT_B,
                 scare_motor_port: str = OUTPUT_D,
                 touch_sensor_port: str = INPUT_1,
                 color_sensor_port: str = INPUT_3,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        self.turn_motor = MediumMotor(address=turn_motor_port)
        self.move_motor = LargeMotor(address=move_motor_port)
        self.scare_motor = LargeMotor(address=scare_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.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.noise = Sound()
Пример #24
0
def FOLLOW_PATH(path):
    global lastTagTime

    print("Starting RFID reader...")
    rfidReader.start()
    sleep(4)  # time for the RFID reader to start up

    findLineNearby(robot)

    nd = 0
    lastNodeId = None # ATENCAO: precisa soltar do no anterior em direcao ao no que você deseja começar o caminho
    while not brickButton.any() and not finishedExploration:
        if (robot.getDistanceAhead() is None) or (robot.getDistanceAhead() >= 20):
            #go ahead
            robot.followLine(200)
        else:
            #shock prevention
            print("Obstacle at distance ", robot.getDistanceAhead(), "! Waiting...")  #IDEIA: este para, e o outro robo desvia
            robot.stopMotors()
            while robot.getDistanceAhead() < 20:
                sleep(0.1)
            print(" - clear to go...")
            robot.followLine(200)

        currentNodeId = rfidReader.getCurrentTagId()
        if (time() - lastTagTime > 3) and currentNodeId is not None:
            robot.stopMotors()
            Sound.beep()
            print("Tag detected - id", currentNodeId)
            dbgSleep()
            if lastNodeId is None:
                lastNodeId = currentNodeId
            else:
                assert currentNodeId == path[nd]
                nd = nd + 1
                onNodeActionFollowPath(lastNodeId, currentNodeId, path[nd])
                lastNodeId = currentNodeId

    robot.stopMotors()
    rfidReader.stop()
    return
Пример #25
0
def virar(dir):
    m_left.stop()
    m_right.stop()

    pos0 = gyro.value()

    Sound.beep()

    if (dir == DIREITA):
        m_left.run_to_rel_pos(position_sp=-45,
                              speed_sp=900,
                              stop_action="hold")
        m_right.run_to_rel_pos(position_sp=-45,
                               speed_sp=900,
                               stop_action="hold")
        sleep(0.1)

        print(pos0)
        while gyro.value() > pos0 - 70:
            print(gyro.value())
            m_left.run_forever(speed_sp=-500)
            m_right.run_forever(speed_sp=250)

        m_left.stop()
        m_right.stop()
    elif (dir == ESQUERDA):
        m_left.run_to_rel_pos(position_sp=-45,
                              speed_sp=900,
                              stop_action="hold")
        m_right.run_to_rel_pos(position_sp=-45,
                               speed_sp=900,
                               stop_action="hold")
        sleep(0.1)

        print(pos0)
        while gyro.value() < pos0 + 70:
            print(gyro.value())
            m_left.run_forever(speed_sp=250)
            m_right.run_forever(speed_sp=-500)
        m_left.stop()
        m_right.stop()
Пример #26
0
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 grip_motor_port: str = OUTPUT_A,
                 touch_sensor_port: str = INPUT_1,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        super().__init__(left_motor=left_motor_port,
                         right_motor=right_motor_port,
                         polarity=Motor.POLARITY_NORMAL)

        self.grip_motor = MediumMotor(address=grip_motor_port)

        self.touch_sensor = TouchSensor(address=touch_sensor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.ir_beacon_channel = ir_beacon_channel
        self.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.speaker = Sound()
Пример #27
0
    def __init__(self,
                 sting_motor_port: str = OUTPUT_D,
                 go_motor_port: str = OUTPUT_B,
                 claw_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):
        self.sting_motor = LargeMotor(address=sting_motor_port)
        self.go_motor = LargeMotor(address=go_motor_port)
        self.claw_motor = MediumMotor(address=claw_motor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.ir_beacon_channel = ir_beacon_channel
        self.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=self.ir_beacon_channel)

        self.touch_sensor = TouchSensor(address=touch_sensor_port)
        self.color_sensor = ColorSensor(address=color_sensor_port)

        self.dis = Screen()
        self.speaker = Sound()
Пример #28
0
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 jaw_motor_port: str = OUTPUT_A,
                 touch_sensor_port: str = INPUT_1,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        super().__init__(left_motor_port=left_motor_port,
                         right_motor_port=right_motor_port,
                         ir_sensor_port=ir_sensor_port,
                         ir_beacon_channel=ir_beacon_channel)

        self.jaw_motor = MediumMotor(address=jaw_motor_port)

        self.touch_sensor = TouchSensor(address=touch_sensor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.beacon = RemoteControl(sensor=self.ir_sensor,
                                    channel=ir_beacon_channel)

        self.button = Button()
        self.speaker = Sound()
Пример #29
0
    def __init__(self,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 medium_motor_port: str = OUTPUT_A,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        super().__init__(left_motor_port=left_motor_port,
                         right_motor_port=right_motor_port,
                         ir_sensor_port=ir_sensor_port,
                         ir_beacon_channel=ir_beacon_channel)

        self.medium_motor = MediumMotor(address=medium_motor_port)

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.remote_control = RemoteControl(sensor=self.ir_sensor,
                                            channel=ir_beacon_channel)

        self.screen = Screen()
        self.speaker = Sound()
Пример #30
0
    def playTone(hz, seconds, wait = False):
        process = _Sound.tone([(hz, seconds * 1000)])

        if wait:
            process.wait()
Пример #31
0
    def speak(text, wait = False):
        process = _Sound.speak(text)

        if wait:
            process.wait()
Пример #32
0
def beep(duration=1000, freq=440):
    """
    Potrobi s frekvenco `freq` za čas `duration`. Klic ne blokira.
    """
    Sound.tone(freq, duration)
Пример #33
0
    def playFile(filename, wait = False):
        process = _Sound.play(filename)

        if wait:
            process.wait()