Lesson 1: Drive forward
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Meet the robot
- The robot drives on a playground: a square floor, 2000 mm on each side, with walls round the edge.
- You program it in Python, with the same commands as VEXcode VR (vr.vex.com). Code from here also works there.
- Press Run: the robot drives your program on the playground above the console.
Words for this lesson
| Word | Meaning |
|---|---|
| drivetrain | the wheels and motors that move the robot |
| FORWARD / REVERSE | drive to the front / drive backwards |
| mm | millimetres; 1000 mm = 1 metre |
| goal | the green square the robot must stop in |
Your first program
from vexcode_vr import *
def main():
drivetrain.drive_for(FORWARD, 400, MM)
vr_thread(main)
from vexcode_vr import *gives you the robot:drivetrain, its sensors and its pen.- Your commands go inside
main().vr_thread(main)starts it. VEXcode VR writes these lines for you, too. drivetrain.drive_for(FORWARD, 400, MM)drives 400 mm to the front, then stops.- Each square on the floor is 250 mm.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
The goal is 600 mm in front of the robot. Drive into the green goal square and stop there.
Click Run to see the output here.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
This time the goal is behind the robot. Drive backwards 500 mm into the goal.
Click Run to see the output here.