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.ir_beacon_channel = ir_beacon_channel

        self.noise = Sound()
Esempio n. 2
0
class RemoteControlledTank(MoveTank):
    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

    def make_move(self, motor, dc_sp):
        def move(state):
            if state:
                motor.run_forever(speed_sp=dc_sp)
            else:
                motor.stop()

        return move

    def main(self):

        try:
            while True:
                self.remote.process()
                sleep(0.01)

        # Exit cleanly so that all motors are stopped
        except (KeyboardInterrupt, Exception) as e:
            log.exception(e)
            self.off()
Esempio n. 3
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()
    def __init__(self,
                 back_foot_motor_port: str = OUTPUT_B,
                 front_foot_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):
        self.tank_driver = MoveTank(left_motor_port=back_foot_motor_port,
                                    right_motor_port=front_foot_motor_port,
                                    motor_class=LargeMotor)

        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.ir_beacon_channel = ir_beacon_channel
    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.tank_driver = MoveTank(left_motor_port=left_motor_port,
                                    right_motor_port=right_motor_port,
                                    motor_class=LargeMotor)

        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.speaker = Sound()
    def __init__(
            self,
            left_foot_motor_port: str = OUTPUT_B, right_foot_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_foot_motor_port, right_motor_port=right_foot_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.speaker = Sound()
    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.touch_sensor = TouchSensor(address=touch_sensor_port)
        self.color_sensor = ColorSensor(address=color_sensor_port)

        self.dis = Display()
        self.speaker = Sound()
    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,
            polarity=Motor.POLARITY_NORMAL,
            speed=1000,
            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.speaker = Sound()
Esempio n. 9
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)
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Ev3dev initialization
        self.leds = Leds()
        self.sound = Sound()
        #self.left_motor = LargeMotor(OUTPUT_D)
        #self.hand_motor = MediumMotor(OUTPUT_A)
        # Gadget states
        self.bpm = 0
        self.trigger_bpm = "off"
        self.ir = InfraredSensor()
        self.ir.on_channel1_top_left = self.onRedTopChannel1
        self.ir.on_channel1_top_left = self.onRedTopChannel1
        self.ir.on_channel1_bottom_left = self.onRedBottomChannel1
        self.ir.on_channel1_top_right = self.onBlueTopChannel1
        self.ir.on_channel1_bottom_right = self.onBlueBottomChannel1
        threading.Thread(target=self._proximity_thread, daemon=True).start()
    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,
            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_port=left_motor_port, right_motor_port=right_motor_port,
            polarity=Motor.POLARITY_NORMAL,
            speed=1000,
            channel=ir_beacon_channel)

        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.speaker = Sound()
        self.dis = Display(desc='Display')
Esempio n. 13
0
    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, [])
Esempio n. 14
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
Esempio n. 15
0
class SUP3R_CAR(motors.BaseCar):
    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 main(self):
        while self.go:
            self.remote.process()

    def exit(self, state):
        self.go = False

    def rev(self, state):
        if state:
            self.run_timed(600, 600, 5000)

    def move(self, state):
        if state:
            self.run_timed(-800, -800, 10000)

    def turn(self, state, pos):
        if state:
            self.steer.run_to_rel_pos(speed_sp=400, position_sp=pos)
        else:
            self.steer.stop()

    def left(self, state):
        self.turn(state, 5)

    def right(self, state):
        self.turn(state, -5)
Esempio n. 16
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):
        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.screen = Display()
        self.speaker = Sound()
Esempio n. 17
0
def distance_to_beacon():
    sound = Sound()
    ir = InfraredSensor()

    while True:
        for i in range(10):
            # try replacing with ir.distance(), ir.heading()
            # or ir.heading_and_distance()
            distance = ir.heading_and_distance()
            if distance == None:
                # distance() returns None if no beacon detected
                print('Beacon off?', end=' ')
                print('Beacon off?', end=' ', file=stderr)
            else:
                # print to EV3 LCD screen
                # print a space instead of starting a new line
                print(distance, end=' ')
                # print to VS Code output panel
                print(distance, end=' ', file=stderr)
                sound.play_tone(1800 - 10 * distance, 0.4)
            sleep(0.5)
        print('')  # start new line on EV3 screen
        print('', file=stderr)  # start new line in VS Code
Esempio n. 18
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Gadget state
        
        self.isDoorOpen = False
        self.verified = True

        # Ev3dev initialization
        self.leds = Leds()
        self.sound = Sound()
        self.drive = MoveTank(OUTPUT_B, OUTPUT_C)
        
        self.ir_sensor = InfraredSensor()
        self.ir_sensor.mode = self.ir_sensor.MODE_IR_REMOTE
        self.color_sensor = ColorSensor()
        self.color_sensor.mode = 'COL-COLOR' # WHITE

        # Start threads
        threading.Thread(target=self._patrol_thread, daemon=True).start()
 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!')
Esempio n. 20
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)
Esempio n. 21
0
class Remote():
    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

    def beacon_channel_1_action(self, state):
        print(self.ir.beacon())
        if state:
            print("Beacon pressed, now stopping")
            self.drive.stop()

    def top_left_channel_1_action(self, state):
        print(self.ir.top_left())
        while state:
            self.drive.move_cm(5)
        self.drive.stop()

    def bot_left_channel_1_action(self, state):
        print(self.ir.bottom_left())
        while state:
            self.drive.move_neg_cm(5)
        self.drive.stop()

    def top_right_channel_1_action(self, state):
        print(self.ir.top_right())
        while state:
            self.drive.turn_degrees(10)
        self.drive.stop()

    def bot_right_channel_1_action(self, state):
        print(self.ir.bottom_right())
        while state:
            self.drive.turn_neg_degrees(10)
        self.drive.stop()

    def remote(self):
        try:
            while True:
                self.ir.process()
                time.sleep(0.01)
        except Exception as e:
            print(e)
            self.drive.stop()
Esempio n. 22
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.ir_beacon_channel = ir_beacon_channel

        self.screen = Display(desc='Display')
        self.speaker = Sound()
Esempio n. 23
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Robot state
        self.guard_mode = False

        # Connect two large motors on output ports A and D
        self.drive = MoveTank(OUTPUT_A, OUTPUT_D)
        self.mouth = MediumMotor(OUTPUT_B)
        self.sound = Sound()
        self.leds = Leds()
        self.ir = InfraredSensor()

        # Start threads
        threading.Thread(target=self._guard_thread, daemon=True).start()
Esempio n. 24
0
def sensors():
    # Connect infrared and touch sensors to any sensor ports
    ir = InfraredSensor()
    ts = TouchSensor()
    leds = Leds()

    leds.all_off()
    # stop the LEDs flashing (as well as turn them off)
    # is_pressed and proximity are not functions and do not need parentheses
    while not ts.is_pressed:  # Stop program by pressing the touch sensor button
        if ir.proximity < 40 * 1.4:  # to detect objects closer than about 40cm
            leds.set_color('LEFT', 'RED')
            leds.set_color('RIGHT', 'RED')
        else:
            leds.set_color('LEFT', 'GREEN')
            leds.set_color('RIGHT', 'GREEN')

        sleep(0.01)  # Give the CPU a rest
Esempio n. 25
0
    def measure(self):
        infra = InfraredSensor(INPUT_2)

        tank = CustomMoveTank(OUTPUT_B, OUTPUT_C)

        readings = []

        # Mittaa etäisyys kaikissa suunnissa
        tank.turn(-90)
        for i in range(0, 34):
            dist = infra.proximity
            readings.append(Reading(i * 5, self.sensor_turn_radius + dist))
            tank.turn(5)
            sleep(0.1)

        # Return to original position
        tank.turn(-90)

        return readings
    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.ir_beacon_channel = ir_beacon_channel

        self.button = Button()
        self.speaker = Sound()
Esempio n. 27
0
    def __init__(self):
        Config.update()

        self.sound = Sound()

        # sensor values
        self.sensLeft = ColorSensor(INPUT_1)
        self.sensRight = ColorSensor(INPUT_4)  # TODO: Sensoren anschließen
        self.sensIR = InfraredSensor(INPUT_2)
        self.sensTouch = TouchSensor(INPUT_3)

        self.btn = Button()

        self.sensValues = {}

        # Classes for features
        self.drive = Drive()
        self.cross = Cross()
        # statemachine
        self.fsm = StateMachine()
        # adding States
        self.fsm.states["followLine"] = State("followLine")
        self.fsm.states["followLine"].addFunc(self.drive.followLine,
                                              self.sensValues)

        self.fsm.states["brake"] = State("brake")

        self.fsm.states["crossFirstTurn"] = State("crossFirstTurn")
        self.fsm.states["crossFirstTurn"].addFunc(self.cross.firstTurn,
                                                  self.sensValues)

        self.fsm.states["checkNextExit"] = State("checkNextExit")
        self.fsm.states["checkNextExit"].addFunc(self.drive.followLine,
                                                 self.sensValues)

        # adding Transitions
        self.fsm.transitions["toFollowLine"] = Transition("followLine")

        self.fsm.transitions["toBrake"] = Transition("brake")
        self.fsm.transitions["toBrake"].addFunc(self.drive.brake)

        self.fsm.transitions["toCrossFirstTurn"] = Transition("crossFirstTurn")
Esempio n. 28
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Gadget state
        self.heel_mode = False
        self.patrol_mode = False
        self.sitting = False

        # Ev3dev initialization
        self.leds = Leds()
        self.sound = Sound()

        # Connect infrared and touch sensors.
        self.ir = InfraredSensor()
        self.ts = TouchSensor()
        # Init display
        self.screen = Display()
        self.dance = False
        self.sound = Sound()
        self.drive = MoveTank(OUTPUT_B, OUTPUT_C)
        self.sound.speak('Hello, my name is Beipas!')

        # Connect medium motor on output port A:
        self.medium_motor = MediumMotor(OUTPUT_A)
        # Connect two large motors on output ports B and C:
        self.left_motor = LargeMotor(OUTPUT_B)
        self.right_motor = LargeMotor(OUTPUT_C)

        # Gadget states
        self.bpm = 0
        self.trigger_bpm = "off"
        self.eyes = True

        # Start threads
        threading.Thread(target=self._dance_thread, daemon=True).start()
        threading.Thread(target=self._patrol_thread, daemon=True).start()
        threading.Thread(target=self._heel_thread, daemon=True).start()
        threading.Thread(target=self._touchsensor_thread, daemon=True).start()
        threading.Thread(target=self._eyes_thread, daemon=True).start()
Esempio n. 29
0
    def __init__(self):
        """
        Performs Alexa Gadget initialization routines and ev3dev resource allocation.
        """
        super().__init__()

        # Connect two large motors on output ports B and C
        self.drive = MoveTank(OUTPUT_B, OUTPUT_C)
        self.grip = MediumMotor(OUTPUT_A)
        self.sound = Sound()
        self.leds = Leds()
        self.ir = InfraredSensor()
        self.touch = TouchSensor()
        self.gyro = GyroSensor()
        self.isComing = False
        self.isTaking = False
        self.isBringing = False
        self.isTurning = False
        # Start threads
        threading.Thread(target=self._proximity_thread, daemon=True).start()
Esempio n. 30
0
def remote_control_one_button():
    steer_pair = MoveSteering(OUTPUT_B, OUTPUT_C)
    ir = InfraredSensor()

    # Set the remote to channel 1

    def top_left_channel_1_action(state):
        if state:  # state is True (pressed) or False
            steer_pair.on(steering=0, speed=40)
        else:
            steer_pair.off()

    def bottom_left_channel_1_action(state):
        if state:
            steer_pair.on(steering=0, speed=-40)
        else:
            steer_pair.off()

    def top_right_channel_1_action(state):
        if state:
            steer_pair.on(steering=100, speed=30)
        else:
            steer_pair.off()

    def bottom_right_channel_1_action(state):
        if state:
            steer_pair.on(steering=-100, speed=30)
        else:
            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

    while True:
        ir.process()
        sleep(0.01)