![]() ![]() wait ( TARGET_LOOP_PERIOD - single_loop_timer. The output power # calculation above depends on having a certain amount of time in each # loop. action = next ( action_task ) if action is not None : drive_speed, steering = action # Make sure loop time is at least TARGET_LOOP_PERIOD. time () gyro_maximum_rate : gyro_maximum_rate = gyro_sensor_value if gyro_sensor_value 100 : output_power = 100 if output_power 1000 : break # This runs update_action() until the next "yield" statement. reset () # Drive forward for 4 seconds to leave stand, then stop. Instead, we yield # to the control loop while we are waiting for a certain thing to happen like # this: # while not condition: # yield # We also use yield to update the drive speed and steering values in the main # control loop: # yield action # def update_action (): arm_motor. # It is important that no blocking calls are made in this function, otherwise # it will affect the control loop time in the main program. ACTION_MAP = # This function monitors the color sensor and ultrasonic sensor. Action = namedtuple ( 'Action ', ) # These are the pre-defined actions STOP = Action ( drive_speed = 0, steering = 0 ) FORWARD_FAST = Action ( drive_speed = 150, steering = 0 ) FORWARD_SLOW = Action ( drive_speed = 40, steering = 0 ) BACKWARD_FAST = Action ( drive_speed =- 75, steering = 0 ) BACKWARD_SLOW = Action ( drive_speed =- 10, steering = 0 ) TURN_RIGHT = Action ( drive_speed = 0, steering = 70 ) TURN_LEFT = Action ( drive_speed = 0, steering =- 70 ) # The colors that the color sensor can detect are mapped to actions that the # robot can perform. GYRO_CALIBRATION_LOOP_COUNT = 200 GYRO_OFFSET_FACTOR = 0.0005 TARGET_LOOP_PERIOD = 15 # ms ARM_MOTOR_SPEED = 600 # deg/s # Actions will be used to change which way the robot drives. ![]() ![]() fall_timer = StopWatch () single_loop_timer = StopWatch () control_loop_timer = StopWatch () action_timer = StopWatch () # The following (UPPERCASE names) are constants that control how the program # behaves. ultrasonic_sensor = UltrasonicSensor ( Port. ![]() It is used to detect when the robot gets # too close to an obstruction. It is used to provide feedback for balancing the # robot. It is used to detect the colors that command # which way the robot should move. A ) # Initialize the motor connected to the arms. ev3 = EV3Brick () # Initialize the motors connected to the drive wheels. Download: Building instructions can be found at: """ from ucollections import namedtuple import urandom from pybricks.hubs import EV3Brick from pybricks.ev3devices import Motor, UltrasonicSensor, ColorSensor, GyroSensor from pybricks.parameters import Port, Color, ImageFile, SoundFile from pybricks.tools import wait, StopWatch # Initialize the EV3 brick. #!/usr/bin/env pybricks-micropython """ Example LEGO® MINDSTORMS® EV3 Gyro Boy Program - This program requires LEGO® EV3 MicroPython v2.0. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |