Posted September 25, 20204 yr I'm busy with automating a LEGO railway crossing and have therefore written the code below. This code works fine, but motor D starts only when motor A is finished. Are there possibilities to start both motors at the same time? #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # Initialize the EV3 Brick. ev3 = EV3Brick() sensor_1 = UltrasonicSensor(Port.S1) motor_A = Motor(Port.A) motor_D = Motor(Port.D) # parameters speed = 6*165*10 # [deg/s] rotation_angle = 24*90 # gear ratio 24:1 dis_track_1 = 65 # [mm] t1 = 10*1000 # [sec] while True: if sensor_1.distance() < dis_track_1: # close railway crossing ev3.light.on(Color.RED) motor_A.run_angle(speed=speed, rotation_angle=-rotation_angle, then=Stop.HOLD, wait=True) motor_D.run_angle(speed=speed, rotation_angle=-rotation_angle, then=Stop.HOLD, wait=True) # wait 10 seconds wait(t1) # open railway crossing motor_A.run_angle(speed=speed, rotation_angle=rotation_angle, then=Stop.HOLD, wait=True) motor_D.run_angle(speed=speed, rotation_angle=rotation_angle, then=Stop.HOLD, wait=True) ev3.light.on(Color.GREEN)
September 25, 20204 yr Hi at a fist glance: have a look at the "wait=true", what does the help function say?
September 25, 20204 yr Author Thank you Lok24, that was indeed the solution, I have read over it when I read the documentation.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.