Control the Technic Off-Road Buggy with the Powered Up Remote.
In this project we’ll show you how to control the Technic Off-Road buggy with the Powered Up remote.
This program is similar to most driving vehicles in the Technic series. Check out the Technic X-treme Off-Roader examples for additional tips and tricks.
When the program starts, it connects to your remote and the steering mechanism is calibrated. Then you are ready to drive.
The left channel controls the steering and right channel drives the car.
from pybricks.pupdevices import Motor, Remote from pybricks.parameters import Port, Direction, Stop, Button from pybricks.tools import wait # Initialize the motors. steer = Motor(Port.B) front = Motor(Port.A, Direction.COUNTERCLOCKWISE) # Lower the acceleration so the car starts and stops realistically. front.control.limits(acceleration=1000) # Connect to the remote. remote = Remote() # Find the steering endpoint on the left and right. # The middle is in between. left_end = steer.run_until_stalled(-200, then=Stop.HOLD) right_end = steer.run_until_stalled(200, then=Stop.HOLD) # We are now at the right. Reset this angle to be half the difference. # That puts zero in the middle. steer.reset_angle((right_end - left_end) / 2) steer.run_target(speed=200, target_angle=0, wait=False) # Now we can start driving! while True: # Check which buttons are pressed. pressed = remote.buttons.pressed() # Choose the steer angle based on the right controls. steer_angle = 0 if Button.RIGHT_MINUS in pressed: steer_angle -= 75 if Button.RIGHT_PLUS in pressed: steer_angle += 75 # Steer to the selected angle. steer.run_target(500, steer_angle, wait=False) # Choose the drive speed based on the left controls. drive_speed = 0 if Button.LEFT_PLUS in pressed: drive_speed += 1000 if Button.LEFT_MINUS in pressed: drive_speed -= 1000 # Apply the selected speed. front.run(drive_speed) # Wait. wait(10)
This project was submitted by Jorge Pereira.