Exemple #1
0
from ev3dev2.motor import SpeedDPS, SpeedRPM, SpeedRPS, SpeedDPM
from ev3dev2.sensor import INPUT_1, INPUT_2
from ev3dev2.sensor.lego import ColorSensor, InfraredSensor

mt = MoveTank(OUTPUT_A, OUTPUT_D)
irs = InfraredSensor(INPUT_2)

######## MANUAL CONTROLS (copy-paste it in main()) ##################################################

manual_controls = True

if manual_controls:
    irs.on_channel1_top_left = turn_left
    irs.on_channel1_top_right = turn_right
    irs.on_channel1_bottom_left = reverse
    irs.on_channel1_beacon = straight_forward


def turn_left(state):
    while state:
        mt.on(-50, 90)
    mt.off()


def turn_right(state):
    while state:
        mt.on(90, -50)
    mt.off()


def reverse(state):
Exemple #2
0
def bottom_right_channel_2_action(state):
    if state:
        medium_motor.on(speed=-5)
    else:
        medium_motor.off()


def beacon_channel_1_action(state):
    if state:
        sys.exit()
    else:
        cont = False


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

infra.on_channel2_top_left = top_left_channel_1_action
infra.on_channel2_bottom_left = bottom_left_channel_1_action
infra.on_channel2_top_right = top_right_channel_2_action
infra.on_channel2_bottom_right = bottom_right_channel_2_action

infra.on_channel1_beacon = beacon_channel_1_action

while cont:
    infra.process()
    sleep(0.01)
Exemple #3
0

def knife_swipe(state):
    if state:
        mm.on(-90)
    else:
        mm.off()


manual_controls = True

if manual_controls:
    irs.on_channel1_top_left = straight_forward
    irs.on_channel1_top_right = turn_right
    irs.on_channel1_bottom_left = reverse
    irs.on_channel1_beacon = knife_swipe
    irs.on_channel1_bottom_right = turn_left


# lets keep this on top of the file for easy editing
def main():
    '''The main function of our program'''

    setup_brick_console()
    battery_check()

    while True:
        irs.process()
        time.sleep(0.01)

    # print something to the output panel in VS Code