Ejemplo n.º 1
0
def test():

    button = Button()
    leds = Leds()
    console = Console(font='Lat15-TerminusBold20x10')

    count = 0

    while True:
        leds.set_color('LEFT', 'BLACK')
        leds.set_color('RIGHT', "BLACK")
        sleep(1)
        leds.set_color('LEFT', 'GREEN')
        leds.set_color('RIGHT', 'GREEN')
        sleep(1)
        leds.set_color('LEFT', 'BLACK')
        leds.set_color('RIGHT', "BLACK")
        sleep(1)
        leds.set_color('LEFT', 'RED')
        leds.set_color('RIGHT', 'RED')
        sleep(1)
        count = count + 1
        if button.enter:
            print("press enter", file=sys.stderr)
            break

    print(count)

    sleep(10)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def randomWalk(tank: MoveDifferential, touchSensor: TouchSensor):
    btn = Button()
    while not btn.any():
        if touchSensor.is_pressed:
            tank.off()
        else:
            tank.on(left_speed = 45, right_speed = 45)
Ejemplo n.º 4
0
def command_loop():
    btn = Button()
    btn.on_up = up_pressed
    btn.on_down = down_pressed
    while not btn.enter:
        btn.process()
        sleep(0.01)
Ejemplo n.º 5
0
def colourAttachment_values():
    button = Button()
    stop = False
    os.system('setfont Lat15-TerminusBold14')
    # os.system('setfont Lat15-TerminusBold32x16')  # Try this larger font

    print('insert black', file=stderr)
    print('insert black')
    button.wait_for_pressed(['enter'])
    black = colourAttachment.raw

    print('insert green', file=stderr)
    print('insert green')
    Delay_seconds(lambda: stop, 2)
    green = colourAttachment.raw

    print('insert red', file=stderr)
    print('insert red')
    Delay_seconds(lambda: stop, 2)
    red = colourAttachment.raw

    print('insert yellow', file=stderr)
    print('insert yellow')
    Delay_seconds(lambda: stop, 2)
    yellow = colourAttachment.raw

    print('insert white', file=stderr)
    print('insert white')
    Delay_seconds(lambda: stop, 2)
    white = colourAttachment.raw

    attachment_values = [black, green, red, yellow, white]
    print(black[0], file=stderr)
    return attachment_values
Ejemplo n.º 6
0
def main():
    snake_body = [[6, 3],[6, 4],[6, 5], [6, 6]]
    lcd = Display()
    btn = Button()
    snake_dir = 0  # 0 stop, 1=up, 2=right, 3=down, 4=left
    draw_play_field(lcd)
    rows = 15
    columne = 20
    s = snake(snake_body)
    flag = True
    draw_grid(lcd)
    
    while flag:
        s.draw(lcd)
        if (btn.up and snake_dir != 3):
            snake_dir = 1
        if (btn.down and snake_dir !=1):
            snake_dir = 3
        if (btn.right and snake_dir !=4):
            snake_dir = 2
        if (btn.left and snake_dir !=2):
            snake_dir = 4
        s.move(snake_dir)
        time.sleep(0.3)
        redraw_widow(lcd)
Ejemplo n.º 7
0
    def __init__(self, output_a, output_d):
        self.right_motor = LargeMotor(output_a)
        self.left_motor = LargeMotor(output_d)

        self.btn = Button()

        self.cl = ColorSensor()

        self.us = UltrasonicSensor()
        self.us.mode='US-DIST-CM'

        self.gy = GyroSensor()
        self.gy.mode='GYRO-ANG'

        self.defaultSpeed = 450

        self.right_sp = 450
        self.left_sp = 450

        self.lastColor1 = None
        self.lastColor2 = None
        self.lastColor3 = None
        self.node = [(0,0)]
        # self.direction = None
        self.directionStr = ['top', 'right', 'bottom', 'left']
Ejemplo n.º 8
0
 def __init__(self):
     self.speed_data = []
     self.motor_l = ev3.LargeMotor(ev3.OUTPUT_B)
     self.motor_r = ev3.LargeMotor(ev3.OUTPUT_C)
     self.btn = Button()
     self.measure = False
     threading.Thread.__init__(self)
Ejemplo n.º 9
0
 def flip_boolean_setting(self, setting):
     """Flip a boolean true/false setting named `settings`"""
     btn = Button()
     self.wait_for_button_press(btn)
     # flip the gyro setting
     self.settings.settings[setting] = not self.settings.get(setting)
     self.settings.write()
     return self.settings.get(setting)
Ejemplo n.º 10
0
    def __init__(self):
        self.btn = Button()
        self.LLight = LightSensor(INPUT_1)
        self.RLight = LightSensor(INPUT_4)
        self.drive = MoveTank(OUTPUT_B, OUTPUT_C)
        os.system('setfont Lat15-TerminusBold14')

        thread = threading.Thread(target=self.run, args=())
        thread.daemon = True
        thread.start()
Ejemplo n.º 11
0
def choose_motor_loop():
    """
    while the back button is not pressed
    loop and set the active motor to control
    based on the button pressed.
    """
    btn = Button()
    btn.on_change = change_motor
    while True:
        btn.process()
        sleep(0.01)
Ejemplo n.º 12
0
    def __init__(self):
        self.button = Button()

        self.tank = MoveSteering(OUTPUT_C, OUTPUT_B)

        self.cs = ColorSensor()
        self.cs.mode = ColorSensor.MODE_COL_REFLECT

        self.gs = GyroSensor()
        self.gs.reset()
        self.before_direction = self.gyro()
Ejemplo n.º 13
0
 def __init__(self,
              left_motor_port,
              right_motor_port,
              desc=None,
              motor_class=LargeMotor):
     self.cur_turn_i = 0
     self.button = Button()
     super().__init__(left_motor_port,
                      right_motor_port,
                      desc=None,
                      motor_class=LargeMotor)
Ejemplo n.º 14
0
def main():
    # remove the following line and replace with your code

    btn = Button() # we will use any button to stop script
    cl = ColorSensor()
    cl.mode = 'COL-AMBIENT'

    while not btn.any():  # exit loop when any button pressed
        print("Ambient light reading:")
        print(cl.value())

        sleep(1)  # wait for 0.1 seconds
Ejemplo n.º 15
0
 def Launchrun():
     Sound.speak("ready to go")
     btn = Button()
     #adjust the while statement for however long you want it to go.
     while True:
         # V if up button is pressed, wait 1 second. if button is still pressed run program 1 if else run program 2 (repeat for each button)
         if btn.up:
             sleep(1)
             if btn.up:
                 Program2()
             else:
                 Program1()
Ejemplo n.º 16
0
 def display_gyro_sensor(self, which_gyro_sensor):
     """Display reflected light intensity of said sensor"""
     gyro = self.choose_gyro_sensor(which_gyro_sensor)
     gyro.mode = gyro.MODE_GYRO_ANG
     btn = Button()
     angle = gyro.angle
     while True: 
         self.write_to_console(str(angle), column=5, row=2, reset_console=True, inverse=True, alignment='C', font_size='L')
         angle = gyro.angle
         self.sleep_in_loop()
         if btn.any():
             break
Ejemplo n.º 17
0
 def display_color_sensor(self, which_color_sensor):
     """Display reflected light intensity of said sensor"""
     cs = self.choose_color_sensor(which_color_sensor)
     cs.MODE_COL_REFLECT = 'COL-REFLECT'
     btn = Button()
     light = cs.reflected_light_intensity
     while True: 
         self.write_to_console(str(light), column=5, row=2, reset_console=True, inverse=True, alignment='C', font_size='L')
         light = cs.reflected_light_intensity
         self.sleep_in_loop()
         if btn.any():
             break
Ejemplo n.º 18
0
 def __init__(self):
     self.sound = Sound()
     self.direction_motor = MediumMotor(OUTPUT_D)
     self.swing_motorL = LargeMotor(OUTPUT_A)
     self.swing_motorC = LargeMotor(OUTPUT_B)
     self.swing_motorR = LargeMotor(OUTPUT_C)
     self.swing_motors = [
         self.swing_motorL, self.swing_motorC, self.swing_motorR
     ]
     self.touch_sensor = TouchSensor(INPUT_1)
     self.console = Console(DEFAULT_FONT)
     self.buttons = Button()
     self.beeps_enabled = True
Ejemplo n.º 19
0
    def Launchrun():
        Sound.speak("ready to go")
        btn = Button()
        #adjust the while statement for however long you want it to go.
        while True:
            # V if up button is pressed, wait 1 second. if button is still pressed run program 1 if else run program 2 (repeat for each button)
            if btn.up:
                sleep(1)
                if btn.up:
                    Sound.speak("Run krab")
                    Krab()
                else:
                    Sound.speak("Run krab")
                    Krab()

            if btn.down:
                sleep(1)
                if btn.down:
                    Sound.speak("Run spider")
                    Spider()
                else:
                    Sound.speak("Run spider")
                    Spider()

            if btn.left:
                sleep(1)
                if btn.left:
                    Sound.speak("Run crane")
                    Crane()
                else:
                    Sound.speak("Run crane")
                    Crane()

            if btn.right:
                sleep(1)
                if btn.right:
                    Sound.speak("Run bulldozer")
                    Bulldozer()
                else:
                    Sound.speak("Run bulldozer")
                    Bulldozer()

            if btn.enter:
                sleep(1)
                if btn.enter:
                    Sound.speak("Run traffic")
                    Traffic()
                else:
                    Sound.speak("Run red circle")
                    Redcircle()
Ejemplo n.º 20
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!')
Ejemplo n.º 22
0
 def __init__(self):
     self.steer = MoveSteering(OUTPUT_B, OUTPUT_C)
     self.tank_pair = MoveTank(OUTPUT_B, OUTPUT_C)
     self.touch_sensor = TouchSensor()
     self.cl = ColorSensor()
     self.s = Sound()
     self.btn = Button()
     self.c_switch = True  # True: Turning left, comp right, False: opposite.
     self.col_switch = True  # True: black, False: white.
     self.tile_count = 0
     self.tile_length = 230
     # Sets up offset for variable light
     self.off_set = self.cl.reflected_light_intensity - 13
     self.black_range = range(0, 30)
     self.white_range = range(30, 100)
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
    def __init__(self):
        self.btn = Button()
        self.LLight = LightSensor(INPUT_1)
        self.RLight = LightSensor(INPUT_4)
        self.cs = ColorSensor()

        self.drive = MoveTank(OUTPUT_A, OUTPUT_D)
        self.steer = MoveSteering(OUTPUT_A, OUTPUT_D)
        self.heightmotor = LargeMotor(OUTPUT_B)
        self.clawactuator = MediumMotor(OUTPUT_C)

        os.system('setfont Lat15-TerminusBold14')

        self.speed = 40
        self.sectionCache = 0
        self.orient = {'N': "1", 'E': "1", 'S': "1", 'W': "1"}
Ejemplo n.º 25
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)])
Ejemplo n.º 26
0
 def read_from_color_sensor(self, which_color_sensor='right', read_white=True):
     """
     Will show the value of the color sensor on the screen
     and return when any button is pressed
     TODO: Fix console display of light value which is changing size and location
     """
     cs = self.choose_color_sensor(which_color_sensor)
     cs.MODE_COL_REFLECT = 'COL-REFLECT'
     btn = Button()
     light = cs.reflected_light_intensity
     while True: 
         self.write_to_console(str(light), column=5, row=2, reset_console=True, inverse=(not read_white), alignment='C', font_size='L')
         light = cs.reflected_light_intensity
         self.sleep_in_loop()
         if btn.any():
             break
     return light
Ejemplo n.º 27
0
def runWhiteLine():

    # valkoinen mitattu 70, harmaa mitattu 12, keskiarvo ^40

    # taustavari
    #ridColor = 20 # maalarinteippi
    ridColor = 40 # valkoinen paperi


    # Nopeus
    speed = 25
    counter_max = 5

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

    # ajaa eteenpain
    tank_pair = MoveTank(OUTPUT_A, OUTPUT_D)
    # kaantyy 2 sekunttia

    tank_pair.off()

    sound.beep()

    # Suoritussilmukka
    while True:
        intensity = colorS.reflected_light_intensity

        while (intensity > ridColor):  # viivalla
            intensity = colorS.reflected_light_intensity
            tank_pair.on(50, 50)  # Eteenpäin
            counter_max = 5 # alustetaan viivanhaun sektorin leveys
        
        
        if (intensity <= ridColor): #Ei viivalla -> alusta viivanhakumuuttujat
            speed = -speed
        
        i = 0
        while (intensity <= ridColor and i < counter_max): # Ei viivalla -> 
            intensity = colorS.reflected_light_intensity
            tank_pair.on(speed, -speed) # vasemman ja oikean nopeudet, kääntyy vasemmalle
            i += 1

        counter_max += counter_max
        
Ejemplo n.º 28
0
 def __init__(self, config):
     threading.Thread.__init__(self)
     self.roboId = config['id']
     self.threadID = 1
     self.name = 'ui-thread'
     self.isRunning = True
     self.messageText = '-'
     self.statusText = '-'
     self.powerSupplyText = '-'
     self.lcd = Display()
     self.btn = Button()
     self.sound = Sound()
     self.leds = Leds()
     self.theFont = fonts.load(Ui.M_FONT)
     self.lcd.clear()
     self.drawText()
     self.lcd.update()
Ejemplo n.º 29
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.ir_beacon_channel = ir_beacon_channel

        self.button = Button()
        self.speaker = Sound()
Ejemplo n.º 30
0
    def __init__(self):
        super().__init__(gadget_config_path='./auth.ini')

        # order queue
        self.queue = Queue()

        self.button = Button()
        self.leds = Leds()
        self.sound = Sound()
        self.console = Console()
        self.console.set_font("Lat15-TerminusBold16.psf.gz", True)

        self.dispense_motor = LargeMotor(OUTPUT_A)
        self.pump_motor = LargeMotor(OUTPUT_B)
        self.touch_sensor = TouchSensor(INPUT_1)

        # Start threads
        threading.Thread(target=self._handle_queue, daemon=True).start()
        threading.Thread(target=self._test, daemon=True).start()