def execute_command(command):
    if command == 'go':
        steer.on_for_rotations(0, ev3.SpeedPercent(default.speed_percent),
                               default.rotation)
    elif command == 'right':
        steer.on_for_rotations(100, ev3.SpeedPercent(default.speed_percent),
                               default.rotation)
    elif command == 'left':
        steer.on_for_rotations(-100, ev3.SpeedPercent(default.speed_percent),
                               default.rotation)
    elif command == 'down':
        steer.on_for_rotations(0, ev3.SpeedPercent(default.speed_percent),
                               -default.rotation)
    elif command == 'stop':
        sound.speak('stop')
    else:
        sound.speak('no valid command received')
예제 #2
0
#!/usr/bin/micropython
#testing motor
import ev3dev2.motor as em
import ev3dev2 as e
import utime as t
from ev3dev2.led import Leds
from ev3dev2.sound import Sound
spkr = Sound()
leds = Leds()
leds.set_color("LEFT", "GREEN")
leds.set_color("RIGHT", "GREEN")

m1= em.LargeMotor(em.OUTPUT_A)
m1.on(em.SpeedPercent(25))
t.sleep(1)
m1.off()
leds.set_color("LEFT", "GREEN")
leds.set_color("RIGHT", "RED")
t.sleep(0.1)
leds.set_color("LEFT", "RED")
leds.set_color("RIGHT", "GREEN")
t.sleep(0.1)
leds.set_color("LEFT", "GREEN")
leds.set_color("RIGHT", "GREEN")
spkr.play_song((
    ('D4', 'e3'),
    ('D4', 'e3'),
    ('D4', 'e3'),
    ('G4', 'h'),
    ('D5', 'h')
),tempo=220)
def getCoarseDistance(sensor, distSensor, bins):
    if distSensor == 'Ultrasonic':
        rawDist = sensor.distance_centimeters
    else:
        rawDist = sensor.proximity
    dist = np.digitize(
        [rawDist],
        bins)[0]  # Discretize distance returns bins from 1 to number of bins
    return (dist - 1)  # Subtract 1 to index arrays from 0


## EV3 Tank movement actions

cycle_time = 990
speed = motors.SpeedPercent(10)
block = True  # should the program wait until the move finishes?


def forward():
    tank.on(speed, speed)


def turnleft():
    tank.on(speed / 2, speed)


def turnright():
    tank.on(speed, speed / 2)

예제 #4
0
#!/usr/bin/python3
#testing motor
import ev3dev2.motor as em
import time as t
m1= em.LargeMotor(em.OUTPUT_A)
m2= em.LargeMotor(em.OUTPUT_B)
m3= em.LargeMotor(em.OUTPUT_C)
m4= em.LargeMotor(em.OUTPUT_D)
m1.on(em.SpeedPercent(25))
m2.on(em.SpeedPercent(25))
m3.on(em.SpeedPercent(25))
m4.on(em.SpeedPercen(25))
t.sleep(1)
m1.off()
m2.off()
m3.off()
m4.off()