This example program shows how to use remote control values to move the robot.
- A V5 Smart Motor, on Port 1, named leftMotor
- A V5 Smart Motor, on Port 10, named rightMotor
How it works
when (STARTED) block tells the robot to run this code when the program starts.
Next, the program will enter a
while loop, which causes the program to run forever.
Then, the leftMotor and rightMotor velocities are set using the data from the joystick's
Axis values to calculate the velocity.
Because only one joystick is used to move the robot in Arcade mode, it is necessary to calculate the final velocity for each motor independently.
Axis3 corresponds to the y-coordinate value of the joystick. So whether you push the joystick all of the way up to +100 or all of the way down to -100, it spins both motors the same direction.
Axis4 corresponds to the x-coordinate value of the joystick, so it works differently. If you push the joystick all of the way right to +100, then the left motor should have a positive velocity and the right motor should have a negative velocity so that the robot turns to the right. If you push the joystick all of the way left to -100, then the left motor should have a negative velocity and the right motor should have a positive velocity so that the robot turns to the left.
.spin commands tell each motor to move along with the velocity specified in the previous commands.