I have a Lego Mindstorms EV3 running MicroPython. When I try to use this code, it does not work:
#!/usr/bin/env pybricks-micropython
from pybricks.robotics import DriveBase, Stop
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor, InfraredSensor
from pybricks.parameters import Port, Direction
from pybricks.tools import wait
# Initialize the EV3 Brick.
ev3 = EV3Brick()
# Initialize Wheels
RightWheel = Motor(Port.B)
LeftWheel = Motor(Port.C)
Robot = DriveBase(LeftWheel, RightWheel, 275.2, 165)
Robot.settings(straight_speed=1000)
# Initialize Motors and Sensors
blade_motor = Motor(Port.D, positive_direction=Direction.CLOCKWISE, gears=None)
infrared_sensor = InfraredSensor(Port.S1)
pressed = infrared_sensor.keypad()
# Play a sound to tell us when we are ready to start moving
ev3.speaker.beep()
LeftWheel.run(1000)
If I replace python LeftWheel.run(1000)
with python LeftWheel.run_time(1000, 5000)
It works perfectly.
I have no idea why this would happen, I have looked everywhere, and it seems to be just me that is having this issue.
When the program ends, the motors stop.
So if LeftWheel.run(1000)
is the last thing in your program, nothing appears to happen because the motors stop right away.
It is not recommended to restart run
over and over in a loop with the same speed as suggested in another answer. This is only useful if you want to change the speed continuously, like when following a line.
Instead, try putting something else after the motor command, like waiting or sounds. Anything that prevents the program from ending right away will do.
LeftWheel.run(1000)
for i in range(10):
ev3.speaker.beep()
wait(1000)