Robot Commands
- robot.move_forward() – Moves robot 1m forward.
- robot.turn_right() – Turns right 90 degrees.
- robot.turn_left() – Turns left 90 degrees.
- robot.move_backward() – Moves robot 1m backward.
- robot.is_ok() – True if the simulation is running.
Checkpoints
Checkpoint #1 – First while loop
- Open the code file ‘Node: test_node’, which is under NODES. Pay attention to punctuation and indents. Add the following code in the code file under the section:
#Your code starts here
while robot.is_ok():
robot.turn_right() - After adding the code, let’s run the simulation (click Reset).
- Observe the motion of the robot. The robot is continuously rotating. This is because the while loop is repeating infinitely. In this respect, below and above codes works the same.
robot.turn_right()
robot.turn_right()
robot.turn_right()
robot.turn_right()
… continuous indefinitely
Checkpoint #2 – While loop with multiple commands
Let’s update our code in the code file as below. Pay attention to punctuation and indents:
while robot.is_ok():
robot.turn_right()
- robot.turn_right()
robot.turn_right() - After adding the code, let’s run the simulation again (click Reset)
- Did you notice that this code behaves the same as the previous examples?
Checkpoint #3 – Clean all pink dirt.
To help you understand while loops, have a look at this diagram: