Computer Science Grade 7 20 min

Lesson 5: Basic Robot Movements: Controlling Motors and Actuators

Learn how to control basic robot movements using programming commands (e.g., move forward, turn left, stop).

Tutorial Preview

1

Introduction & Learning Objectives

Learning Objectives Define the terms 'motor' and 'actuator' and explain their role in a robot. Write a program to turn a DC motor on and off using code. Control the speed and direction (forward/reverse) of a robot's wheels. Program a robot to move for a specific duration of time. Design and use a simple function to create a reusable movement command (e.g., `moveForward()`). Program a sequence of movements, such as moving forward and then turning. Explain the difference between a pivot turn and a swing turn. Ever wonder how a robot vacuum cleaner knows how to move around your room, or how a rover explores Mars? 🤖 It all starts with telling its 'muscles' what to do! In this lesson, we'll learn how to be the 'brain' for our...
2

Key Concepts & Vocabulary

TermDefinitionExample ActuatorA component of a robot that is responsible for moving or controlling a mechanism. It's the 'muscle' of the robot.A motor that spins a wheel is an actuator. A small arm that opens and closes a gripper is also an actuator. DC MotorA common type of motor that spins continuously in one direction when power is applied. Reversing the power makes it spin the other way.The motors that spin the wheels on your robot are DC motors. They are great for driving and continuous motion. Servo MotorA special type of motor that can rotate to a specific angle (like 0, 90, or 180 degrees) and hold that position.Used for a robot's arm to raise it to a precise height, or for a steering mechanism in a robotic car. PortA physical socket on the robot's control...
3

Core Syntax & Patterns

Single Motor Control motor.run(port, speed) This is the fundamental command to control one motor. You must specify which `port` the motor is connected to (e.g., 'A', 'B') and the `speed` you want (e.g., from -100 for full reverse to 100 for full forward). A speed of 0 stops the motor. Timed Movement Pattern motor.run(port, speed) wait(seconds) motor.stop(port) To make a robot move for a specific amount of time, you must (1) start the motor, (2) tell the program to wait for a set duration, and then (3) explicitly command the motor to stop. This is the most common pattern for creating predictable movements. Movement Function Design function moveForward(speed, duration): leftMotor.run('A', speed) rightMotor.run('B', speed) wai...

4 more steps in this tutorial

Sign up free to access the complete tutorial with worked examples and practice.

Sign Up Free to Continue

Sample Practice Questions

Challenging
The right motor on Port 'B' was accidentally wired backward. To fix this in the code for a `moveForward(speed)` command without touching the wires, what change must be made?
A.The code should be `leftMotor.run('A', speed); rightMotor.run('B', speed);`
B.The code should be `leftMotor.run('A', -speed); rightMotor.run('B', -speed);`
C.The code should be `leftMotor.run('A', speed); rightMotor.run('B', -speed);`
D.The code should be `leftMotor.run('A', 0); rightMotor.run('B', speed);`
Challenging
Given the functions `moveForward(duration)` and `pivotRight(duration)`, which sequence of calls would make the robot trace a path resembling the letter 'L'?
A.moveForward(2); pivotRight(0.5);
B.moveForward(2); moveForward(2); pivotRight(0.5);
C.pivotRight(0.5); moveForward(2); pivotRight(0.5);
D.moveForward(2); pivotRight(0.5); moveForward(2);
Challenging
A robot's pivot turn is not precise. Sometimes it over-turns, sometimes it under-turns, even with the same code. What is the most likely cause and best solution?
A.The code is wrong; rewrite the turn function from scratch.
B.The motors are broken; they need to be replaced.
C.The battery level is fluctuating, causing motor speed to vary; use a sensor to make turns more reliable instead of relying only on time.
D.The floor surface is too slippery; the program cannot be fixed.

Want to practice and check your answers?

Sign up to access all questions with instant feedback, explanations, and progress tracking.

Start Practicing Free

More from Chapter 5: Robotics: Building and Programming Autonomous Machines

Ready to find your learning gaps?

Take a free diagnostic test and get a personalized learning plan in minutes.