Exemple #1
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 test_infrared_sensor(self):
        clean_arena()
        populate_arena([('infrared_sensor', 0, 'in1')])

        s = InfraredSensor()

        self.assertEqual(s.device_index, 0)
        self.assertEqual(s.bin_data_format, 's8')
        self.assertEqual(s.bin_data('<b'), (16, ))
        self.assertEqual(s.num_values, 1)
        self.assertEqual(s.address, 'in1')
        self.assertEqual(s.value(0), 16)
        self.assertEqual(s.mode, "IR-PROX")

        s.mode = "IR-REMOTE"
        self.assertEqual(s.mode, "IR-REMOTE")

        val = s.proximity
        # Our test environment writes to actual files on disk, so while "seek(0) write(...)" works on the real device, it leaves trailing characters from previous writes in tests. "s.mode" returns "IR-PROXTE" here.
        self.assertEqual(s.mode, "IR-PROX")
        self.assertEqual(val, 16)

        val = s.buttons_pressed()
        self.assertEqual(s.mode, "IR-REMOTE")
        self.assertEqual(val, [])
    def __init__(self,
                 jaw_motor_port: str = OUTPUT_A,
                 left_motor_port: str = OUTPUT_B,
                 right_motor_port: str = OUTPUT_C,
                 touch_sensor_port: str = INPUT_1,
                 color_sensor_port: str = INPUT_3,
                 ir_sensor_port: str = INPUT_4,
                 ir_beacon_channel: int = 1):
        self.jaw_motor = MediumMotor(address=jaw_motor_port)

        self.left_motor = LargeMotor(address=left_motor_port)
        self.right_motor = LargeMotor(address=right_motor_port)
        self.tank_driver = MoveTank(left_motor_port=left_motor_port,
                                    right_motor_port=right_motor_port,
                                    motor_class=LargeMotor)
        self.steer_driver = MoveSteering(left_motor_port=left_motor_port,
                                         right_motor_port=right_motor_port,
                                         motor_class=LargeMotor)

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

        self.roaring = False
        self.walk_speed = self.NORMAL_WALK_SPEED
Exemple #4
0
    def __init__(
        self,
        left_motor_port: str = OUTPUT_B,
        right_motor_port: str = OUTPUT_C,
        motor_class=LargeMotor,
        polarity: str = Motor.POLARITY_NORMAL,
        ir_sensor_port: str = INPUT_4,
        # sites.google.com/site/ev3devpython/learn_ev3_python/using-sensors
        ir_beacon_channel: int = 1):
        self.left_motor = LargeMotor(address=left_motor_port)
        self.right_motor = LargeMotor(address=right_motor_port)

        self.tank_driver = \
            MoveTank(
                left_motor_port=left_motor_port,
                right_motor_port=right_motor_port,
                motor_class=motor_class)

        self.steer_driver = \
            MoveSteering(
                left_motor_port=left_motor_port,
                right_motor_port=right_motor_port,
                motor_class=motor_class)

        self.left_motor.polarity = self.right_motor.polarity = \
            self.tank_driver.left_motor.polarity = \
            self.tank_driver.right_motor.polarity = \
            self.steer_driver.left_motor.polarity = \
            self.steer_driver.right_motor.polarity = polarity

        self.ir_sensor = InfraredSensor(address=ir_sensor_port)
        self.tank_drive_ir_beacon_channel = ir_beacon_channel
Exemple #5
0
    def __init__(self):
        self.shutdown = False
        self.flipper = LargeMotor(OUTPUT_A)
        self.turntable = LargeMotor(OUTPUT_B)
        self.colorarm = MediumMotor(OUTPUT_C)
        self.color_sensor = ColorSensor()
        self.color_sensor.mode = self.color_sensor.MODE_RGB_RAW
        self.infrared_sensor = InfraredSensor()
        self.init_motors()
        self.state = ['U', 'D', 'F', 'L', 'B', 'R']
        self.rgb_solver = None
        signal.signal(signal.SIGTERM, self.signal_term_handler)
        signal.signal(signal.SIGINT, self.signal_int_handler)

        filename_max_rgb = 'max_rgb.txt'

        if os.path.exists(filename_max_rgb):
            with open(filename_max_rgb, 'r') as fh:
                for line in fh:
                    (color, value) = line.strip().split()

                    if color == 'red':
                        self.color_sensor.red_max = int(value)
                        log.info("red max is %d" % self.color_sensor.red_max)
                    elif color == 'green':
                        self.color_sensor.green_max = int(value)
                        log.info("green max is %d" %
                                 self.color_sensor.green_max)
                    elif color == 'blue':
                        self.color_sensor.blue_max = int(value)
                        log.info("blue max is %d" % self.color_sensor.blue_max)
Exemple #6
0
def main():
    '''The main function of our program'''

    # set the console just how we want it
    reset_console()
    set_cursor(OFF)
    set_font('Lat15-Terminus24x12')

    print('How are you?')
    print("")
    print("Hello Selina.")
    print("Hello Ethan.")
    STUD_MM = 8
    tank = MoveDifferential(OUTPUT_A, OUTPUT_B, EV3Tire, 16 * STUD_MM)
    motorLift = MediumMotor(OUTPUT_D)
    sound = Sound()

    # sound.speak('How are you master!')
   # sound.speak("I like my family")
   # sound.speak("I like my sister and i like my brother.")
    sound.beep()

    eye = InfraredSensor(INPUT_1)
    robot = Robot(tank, None, eye)
    botton = Button()
    while not botton.any():
        distance = eye.distance(channel=1)
        heading = eye.heading(channel=1)
        print('distance: {}, heading: {}'.format(distance, heading))

        motorLift.on_to_position(speed=40, position=-7200, block=True)  #20 Rounds

        if distance is None:
            sound.speak("I am lost, there is no beacon!")
        else:
            if (distance < 14):
                tank.off()
                sound.speak("I am very close to the beacon!")
                motorLift.on_to_position(speed=40, position=7200, block=True)
                sound.speak("I had to get some more rubbish.")
                sound.speak("Please wait while I lift up my fork.")
                tank.turn_right(speed=20, degrees=random.randint(290, 340))  # random.randint(150, 210)
                tank.on_for_seconds(left_speed=20, right_speed=20, seconds=20)
                tank.turn_right(speed=20, degrees=330)
                motorLift.on_to_position(speed=40, position=0, block=True)

            elif distance >= 100:
                sound.speak("I am too faraway from the beacon")
            elif (distance  < 99) and (-4 <= heading <= 4):  # in right heading
                sound.speak("Moving farward")
                tank.on(left_speed=20, right_speed=20)
            else:
                if heading > 0:
                    tank.turn_left(speed=20, degrees=20)
                else:
                    tank.turn_right(speed=20, degrees=20)
                sound.speak("I am finding the beacon.")


        time.sleep(0.1)
    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()
Exemple #8
0
    def __init__(self,
                 drive_motor_port=OUTPUT_B,
                 strike_motor_port=OUTPUT_D,
                 steer_motor_port=OUTPUT_A,
                 drive_speed_pct=60):

        self.drive_motor = LargeMotor(drive_motor_port)
        self.strike_motor = LargeMotor(strike_motor_port)
        self.steer_motor = MediumMotor(steer_motor_port)
        self.speaker = Sound()
        STEER_SPEED_PCT = 30

        self.remote = InfraredSensor()
        self.remote.on_channel1_top_left = self.make_move(self.drive_motor, drive_speed_pct)
        self.remote.on_channel1_bottom_left = self.make_move(self.drive_motor, drive_speed_pct * -1)
        self.remote.on_channel1_top_right = self.make_move(self.steer_motor, STEER_SPEED_PCT)
        self.remote.on_channel1_bottom_right = self.make_move(self.steer_motor, STEER_SPEED_PCT * -1)

        self.shutdown_event = Event()
        self.mrc = MonitorRemoteControl(self)

        # Register our signal_term_handler() to be called if the user sends
        # a 'kill' to this process or does a Ctrl-C from the command line
        signal.signal(signal.SIGTERM, self.signal_term_handler)
        signal.signal(signal.SIGINT, self.signal_int_handler)
 def __init__(self,
              ms=MoveSteering(OUTPUT_A, OUTPUT_B),
              cs=ColorSensor(address=INPUT_1),
              isensor=InfraredSensor(INPUT_2)):
     self.steering_drive = ms
     self.color_sensor = cs
     self.infrared_sensor = isensor
def returnWhenObjectWithinXcm(debug, stop, distance):

    ir = InfraredSensor(constants.INPUT_INFRARED_SENSOR)

    if debug:
        print("Start returnWhenObjectWithinXcm({}), thread {}".format(
            distance,
            threading.current_thread().ident),
              file=stderr)

    while True:

        if debug:
            #print(ir.proximity / constants.IR_PROMIXITY_TO_CM_RATIO, file = stderr)
            pass

        if ir.proximity < distance * constants.IR_PROMIXITY_TO_CM_RATIO:
            if debug:
                print("End returnWhenObjectWithinXcm({}), thread {}.".format(
                    distance,
                    threading.current_thread().ident),
                      file=stderr)
            break

        if stop():
            if debug:
                print("Kill returnWhenObjectWithinXcm({}), thread {}.".format(
                    distance,
                    threading.current_thread().ident),
                      file=stderr)
            break
Exemple #11
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()
Exemple #12
0
    def __init__(self, fetchColor, fetchDistance=20):
        self.leftColorSensor = ColorSensor(INPUT_1)
        self.rightColorSensor = ColorSensor(INPUT_2)
        self.infraredSensor = InfraredSensor(INPUT_3)

        self.fetchColor = fetchColor
        self.fetchDistance = fetchDistance
def main():
  global stopInfraredSensor
  global stopMotorSensor
  global stopGiraSensor
  # global stopProxSensor
  global infrared_sensor

  infrared_sensor = InfraredSensor(INPUT_1)

  stopInfraredSensor=False
  stopMotorSensor=False
  stopGiraSensor=False
  # stopProxSensor=False

  # t1 = threading.Thread(target=robotDetectWorker)
  # t1.start()
  #
  # t2 = threading.Thread(target=onlyWalkWithStopWorker)
  # t2.start()

  walkSeconds(0,100,6)

  # tp = threading.Thread(target=patrulha)
  # tp.start()

  patrulha()
 def __init__(self):
     self.server_address = (str(sys.argv[1]), 5000)
     self.sensor = InfraredSensor()
     self.motor = MediumMotor(OUTPUT_D)
     self.drive_motor = MoveTank(OUTPUT_B, OUTPUT_C)
     self.turn_motor = MoveSteering(OUTPUT_B, OUTPUT_C)
     self.moved = 0
     self.turned = 0
 def __init__(self, left_motor_port, right_motor_port, infra_sensor_mode,
              color_sensor_mode):
     self.__movesteering = MoveSteering(left_motor_port, right_motor_port)
     self.__mediummotor = MediumMotor()
     self.__cs = ColorSensor()
     self.__cs.mode = color_sensor_mode
     self.__ir = InfraredSensor()
     self.__ir.mode = infra_sensor_mode
Exemple #16
0
 def __init__(self):
     self.shut_down = False
     # self.claw_motor
     # self.left_motor = LargeMotor('outB')
     # self.right_motor = LargeMotor('outC')
     self.both_motors = MoveTank('outB', 'outC')
     self.cs = ColorSensor()
     self.irs = InfraredSensor()
 def __init__(self, left_motor_port, right_motor_port, infra_mode,
              ultra_mode):
     self.__moveSteering = MoveSteering(left_motor_port, right_motor_port)
     self.__mediumMotor = MediumMotor()
     self.__ir = InfraredSensor()
     self.__ir.mode = infra_mode
     self.__us = UltrasonicSensor()
     self.__us.mode = ultra_mode
Exemple #18
0
 def __init__(self):
     self.ir = InfraredSensor()
     self.ir.mode = 'IR-REMOTE'
     self.drive = Driver()
     self.ir.on_channel1_beacon = self.beacon_channel_1_action
     self.ir.on_channel1_top_left = self.top_left_channel_1_action
     self.ir.on_channel1_bottom_left = self.bot_left_channel_1_action
     self.ir.on_channel1_top_right = self.top_right_channel_1_action
     self.ir.on_channel1_bottom_right = self.bot_right_channel_1_action
Exemple #19
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()
Exemple #20
0
 def __init__(self):
     motors.BaseCar.__init__(self)
     self.remote = InfraredSensor()
     self.remote.on_channel1_top_left = self.left
     self.remote.on_channel1_top_right = self.right
     self.remote.on_channel1_beacon = self.move
     self.remote.on_channel1_bottom_left = self.stop
     self.remote.on_channel1_bottom_right = self.rev
     self.remote.on_channel4_beacon = self.exit
     self.go = True
    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 test_infrared_sensor(self):
        clean_arena()
        populate_arena([('infrared_sensor', 0, 'in1')])

        s = InfraredSensor()

        self.assertEqual(s.device_index, 0)
        self.assertEqual(s.bin_data_format, 's8')
        self.assertEqual(s.bin_data('<b'), (16, ))
        self.assertEqual(s.num_values, 1)
        self.assertEqual(s.address, 'in1')
        self.assertEqual(s.value(0), 16)
Exemple #23
0
def runIrController():
    rc = InfraredSensor(INPUT_1)
    leftMotor = LargeMotor(OUTPUT_D)
    rightMotor = LargeMotor(OUTPUT_A)

    rc.on_channel1_top_left = steer(leftMotor, 1)
    rc.on_channel1_top_right = steer(rightMotor, 1)
    rc.on_channel1_bottom_left = steer(leftMotor, -1)
    rc.on_channel1_bottom_right = steer(rightMotor, -1)

    while True:
        rc.process()
        sleep(0.01)
Exemple #24
0
    def __init__(self, left_motor_port, right_motor_port, polarity='inversed', speed=400, channel=1):
        MoveTank.__init__(self, left_motor_port, right_motor_port)
        self.set_polarity(polarity)

        left_motor = self.motors[left_motor_port]
        right_motor = self.motors[right_motor_port]
        self.speed_sp = speed
        self.remote = InfraredSensor()
        self.remote.on_channel1_top_left = self.make_move(left_motor, self.speed_sp)
        self.remote.on_channel1_bottom_left = self.make_move(left_motor, self.speed_sp * -1)
        self.remote.on_channel1_top_right = self.make_move(right_motor, self.speed_sp)
        self.remote.on_channel1_bottom_right = self.make_move(right_motor, self.speed_sp * -1)
        self.channel = channel
Exemple #25
0
def init_hardware():
    global button, display, leds, drive, infraredSensor

    drive = LargeMotor(OUTPUT_B)
    infraredSensor = InfraredSensor(INPUT_3)
    infraredSensor.mode = InfraredSensor.MODE_IR_PROX
    leds = Leds()

    # ultrasonicSensor = UltrasonicSensor(INPUT_2)
    # ultrasonicSensor.mode = UltrasonicSensor.MODE_US_DIST_CM

    display = Display()
    button = Button()
    button.on_enter = btn_on_enter
 def __init__(self):
     self.exit = True
     self.callback_exit = True
     # Connect sensors and buttons.
     self.btn = Button()
     self.ir = InfraredSensor()
     self.ts = TouchSensor()
     self.power = PowerSupply()
     self.tank_drive = MoveTank(OUTPUT_A, OUTPUT_B)
     print('EV3 Node init starting')
     rospy.init_node('ev3_robot', anonymous=True, log_level=rospy.DEBUG)
     print('EV3 Node init complete')
     rospy.Subscriber('ev3/active_mode', String, self.active_mode_callback, queue_size=1)
     self.power_init()
     print('READY!')
Exemple #27
0
def main():
    ''' main function to initialize settings'''

    # initialize tank drive
    tank_drive = MoveTank(OUTPUT_B, OUTPUT_C)

    # initialize infrared sensor in proximity mode
    infrared = InfraredSensor()
    infrared.mode = 'IR-PROX'

    # intialize sounds
    sounds = Sound()

    # call run function
    run(tank_drive, infrared, sounds)
Exemple #28
0
def remote_control_two_buttons():
    steer_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
    medium_motor = MediumMotor()
    ir = InfraredSensor()

    # Set the remote to channel 1

    def top_left_channel_1_action(state):
        move()

    def bottom_left_channel_1_action(state):
        move()

    def top_right_channel_1_action(state):
        move()

    def bottom_right_channel_1_action(state):
        move()

    def move():
        buttons = ir.buttons_pressed()  # a list
        if len(buttons) == 1:
            medium_motor.off()
            if buttons == ['top_left']:
                steer_pair.on(steering=0, speed=40)
            elif buttons == ['bottom_left']:
                steer_pair.on(steering=0, speed=-40)
            elif buttons == ['top_right']:
                steer_pair.on(steering=100, speed=30)
            elif buttons == ['bottom_right']:
                steer_pair.on(steering=-100, speed=30)
        elif len(buttons) == 2:
            steer_pair.off()
            if buttons == ['top_left', 'top_right']:
                medium_motor.on(speed_pct=10)
            elif buttons == ['bottom_left', 'bottom_right']:
                medium_motor.on(speed_pct=-10)
        else:  # len(buttons)==0
            medium_motor.off()
            steer_pair.off()

    # Associate the event handlers with the functions defined above
    ir.on_channel1_top_left = top_left_channel_1_action
    ir.on_channel1_bottom_left = bottom_left_channel_1_action
    ir.on_channel1_top_right = top_right_channel_1_action
    ir.on_channel1_bottom_right = bottom_right_channel_1_action

    return ir
Exemple #29
0
def runCalibrator():

    speed = 25
    counter_max = 5
    # todo: adjust scale
    proximityScale = 0.7

    button = Button()
    colorS = ColorSensor(INPUT_3)
    sound = Sound()

    moveTank = CustomMoveTank(OUTPUT_A, OUTPUT_D)
    infrared = InfraredSensor()

    def moveWithDistance(moveLengthCm, distance):
        movedLength = 0
        step = 10
        turn = 0.5

        while movedLength < moveLengthCm:
            proximity = proximityScale * infrared.proximity

            debug("proximity cm " + str(proximity) + " movedLength " +
                  str(movedLength))

            if proximity < distance:
                moveTank.move_cm_lopsided(step + turn, step - turn, True)
            else:
                moveTank.move_cm_lopsided(step - turn, step + turn, True)

            movedLength += step

    # 70cm forward
    # turn 90 degrees
    # keep 10cm distance from edge
    # drive forward 240cm
    # stop to wait for usb

    debug("calibrator: move forward")
    moveTank.move_cm(30, True)
    debug("calibrator: turn 90")
    moveTank.turn(90, True)
    debug("calibrator: move forward with distance from left edge")
    moveWithDistance(140, 10)
    debug("calibrator: wait for usb drop")
    sleep(3)
    debug("calibrator: move forward with distance from left edge")
    moveWithDistance(40, 10)
Exemple #30
0
    def play(self):
        delay = 0
        step = [5, 10, 15, 20, 25, 30, 35, 40, 45, 55, 60, 65, 70]

        button = Button()
        button.on_up = self.volumeUp
        button.on_down = self.volumeDown
        button.on_left = self.multiplyUp
        button.on_right = self.multiplyDown
        button.on_enter = self.togglePause
        button.on_backspace = self.backButton

        ir = InfraredSensor()
        ts = TouchSensor()
        servo = MediumMotor()

        while True:
            self.volume = self.getVolume()
            button.process()

            if self.pause == True:
                continue

            distance = int(math.fabs(ir.value()))
            position = int(math.fabs(servo.position))

            for x in step:
                if distance <= x:
                    hertz = int(x * 15)
                    # print("Hertz - " + str(hertz))
                    break

            for x in step:
                if position <= x:
                    duration = int(x * 5 * self.multiply)
                    # print("Duration - " + str(duration))
                    break

            if ts.is_pressed:
                if delay == 200:
                    delay = 0
            else:
                if delay == 0:
                    delay = 200

            # play sound
            self.sound.tone([(hertz, duration, delay)])