Computer Science
Grade 6
20 min
Controlling Movement: Programming the Robot to Move Forward, Backward, and Turn
Students will program their robot to move forward, backward, and turn using block-based programming.
Tutorial Preview
1
Introduction & Learning Objectives
Learning Objectives
Write a line of code to make a robot move forward for a specific amount of time.
Write a line of code to make a robot move backward.
Program a robot to turn left and right by a specific angle (e.g., 90 degrees).
Explain what a parameter is and how it changes a robot's movement (e.g., time, speed, angle).
Combine forward, backward, and turn commands in a sequence to navigate a simple path.
Predict the path a robot will take by reading a short sequence of movement commands.
Debug a simple program where the robot does not move as intended.
Ever wished you could tell a robot exactly where to go? 🤖 Let's learn how to be the boss of its every move!
In this lesson, you'll learn the basic text commands to make your robot drive forward, reverse,...
2
Key Concepts & Vocabulary
TermDefinitionExample
Command (or Function)A named instruction that tells the computer or robot to perform a specific action.The command `robot.forward()` tells the robot to start moving its wheels to go forward.
ParameterA piece of information you give to a command to change how it runs. It goes inside the parentheses `()`. In the command `robot.forward(3)`, the number `3` is a parameter that could tell the robot to move forward for 3 seconds.
SequenceThe order in which commands are written and executed. The robot will follow your instructions one by one, from top to bottom.1. `robot.forward(2)`
2. `robot.stop()`
The robot moves forward for 2 seconds, and then after that, it stops.
MotorThe part of the robot that converts electricity into motion, making the wheels spin.When you run `robo...
3
Core Syntax & Patterns
Command Syntax
object.command_name(parameter)
To tell your robot to do something, you start with the robot's name (like `robot`), add a dot `.`, then the command's name (like `forward`), followed by parentheses `()`. Any details, called parameters, go inside the parentheses.
Sequential Execution
Code runs one line at a time, from top to bottom.
The robot will not move to the next instruction in your code until it has finished the current one. This is how you create a path of multiple steps.
Turning Logic
robot.turn_right(angle) or robot.turn_left(angle)
To turn, you must specify both the direction (left or right) and the angle (how much to turn). A 90-degree turn is a perfect corner. A 180-degree turn makes the robot face the opposite direction.
4 more steps in this tutorial
Sign up free to access the complete tutorial with worked examples and practice.
Sign Up Free to ContinueSample Practice Questions
Challenging
A robot needs to move along the perimeter of a rectangle that is 20 units long and 10 units wide. Which of these is the most efficient set of commands to do this?
A.moveForward(20); turnRight(90); moveForward(10); turnRight(90); moveForward(20); turnRight(90); moveForward(10);
B.moveForward(20); turnRight(90); moveForward(10);
C.moveForward(10); turnRight(90); moveForward(20); turnRight(90); moveForward(10); turnRight(90); moveForward(20);
D.moveForward(30); turnRight(90); moveForward(30); turnRight(90);
Challenging
A robot is programmed with this code: `repeat 3 times: { moveForward(5); turnRight(90); }`. What does the robot's path look like at the end?
A.straight line.
B.complete square.
C.'U' shape or three sides of a square.
D.triangle.
Challenging
A robot starts at position (0,0) facing North (up). It ends up at position (10, -10) facing East (right). Which sequence of commands could have caused this?
A.moveForward(10); turnLeft(90); moveForward(10);
B.turnRight(90); moveForward(10); turnRight(90); moveForward(10);
C.moveBackward(10); turnRight(90); moveForward(10);
D.turnLeft(90); moveForward(10); turnLeft(90); moveForward(10);
Want to practice and check your answers?
Sign up to access all questions with instant feedback, explanations, and progress tracking.
Start Practicing FreeMore from Introduction to Robotics: Building and Programming Simple Robots
What is Robotics? Exploring the World of Robots
Introduction to Robot Components: Sensors, Actuators, and Controllers
Building a Simple Robot: Assembling the Hardware
Introduction to Block-Based Programming: Programming the Robot's Behavior
Using Sensors: Programming the Robot to React to its Environment