Skip to content
Week 2 · Lesson 2 50 min

Motors, Servos and Sensors

Learn how DC motors, gearboxes, encoders and servos create motion, and how sensors let the robot measure itself and the world around it.

In this lesson you will

  • Explain why DC motors are combined with gearboxes.
  • Describe what an encoder measures and how ticks relate to rotations.
  • Compare standard servos and continuous rotation servos and choose the right one.
  • Identify what an IMU, distance sensor, color sensor and touch sensor measure.
  • Write a simple OpMode that drives a motor, moves a servo and reads a sensor.

Lesson

A robot needs two kinds of electrical parts. Actuators create motion: DC motors and servos. Sensors collect information: how far a wheel has turned, which way the robot is facing, whether a game element is in the intake. Good robots combine both, so the code can move something and then check that it moved the right amount.

DC motors and gearboxes

A DC motor spins continuously when you give it power. In code you set power from -1.0 (full reverse) to 1.0 (full forward), with 0 meaning stop. A bare FTC motor spins very fast, around 6000 RPM, but with very little twisting force, or torque. That is too fast and too weak to drive a robot directly, so almost every FTC motor has a gearbox attached. The gearbox trades speed for torque. You choose the gearbox based on the job.

Gearbox reductionApprox. output speedTypical use
1:1 (no gearbox)6000 RPMFlywheels and shooters
about 5:11150 RPMFast intakes
about 13.7:1435 RPMFast drivetrains
about 19.2:1312 RPMGeneral drivetrains
about 50.9:1117 RPMLifts and arms
about 188:130 RPMHeavy arms that must hold position

Encoders: counting rotation

Most FTC motors include an encoder, a sensor on the motor that counts small steps of rotation called ticks. Your code reads the count with getCurrentPosition(). For example, if the encoder gives 28 ticks per turn of the motor shaft and the gearbox is 20:1, the output shaft makes one full turn every 28 x 20 = 560 ticks. If you know the wheel size, you can turn ticks into distance travelled. Encoders let you drive a set distance in Autonomous or move an arm to an exact angle with RUN_TO_POSITION.

dWheelCircumferenceC = π × dTicks per revolutionTPR × gearTicks per inchTPI = (TPR × gear) / (π × d)Example only — use your motor's datasheet
From encoder ticks to wheel rotations to distance travelled.

Servos: standard and continuous rotation

TypeHow it movesCodeGood for
Standard servoTurns to a commanded angle and holds it, within a limited rangeservo.setPosition(0.0 to 1.0)Claws, flaps, latches, wrist joints
Continuous rotation servoSpins freely in either direction like a small, weak motorcrServo.setPower(-1.0 to 1.0)Small intake rollers, light conveyors

A standard servo does not tell your code where it really is. getPosition() only returns the last position you asked for. If something blocks the servo, the code will not know. A continuous rotation servo cannot be told to go to an angle at all. Some servos, such as the REV Smart Robot Servo, can be switched between the two modes with a programmer tool.

Common sensors

  • Encoder: counts motor rotation. Used for distance, arm angle and speed.
  • IMU (inertial measurement unit): measures rotation and tilt. The Control Hub has one built in, and it is mostly used to read the robot's heading (which way it is facing).
  • Distance sensor: measures how far away an object or wall is, for example in centimetres.
  • Color sensor: measures the color and brightness of a nearby surface, useful for detecting game elements or lines on the field.
  • Touch sensor or limit switch: reports pressed or not pressed. Often used to stop a lift at the bottom or detect when a mechanism reaches its end.
JAVA
1package org.firstinspires.ftc.teamcode;
2
3import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
4import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
5import com.qualcomm.robotcore.hardware.DcMotor;
6import com.qualcomm.robotcore.hardware.Servo;
7import com.qualcomm.robotcore.hardware.TouchSensor;
8
9@TeleOp(name = "Hardware Test")
10public class HardwareTest extends LinearOpMode {
11    @Override
12    public void runOpMode() {
13        DcMotor motor = hardwareMap.get(DcMotor.class, "test_motor");
14        Servo servo = hardwareMap.get(Servo.class, "test_servo");
15        TouchSensor touch = hardwareMap.get(TouchSensor.class, "touch");
16
17        motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
18        motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
19
20        waitForStart();
21
22        while (opModeIsActive()) {
23            // Pushing the stick up gives a negative value, so flip it
24            motor.setPower(-gamepad1.left_stick_y * 0.5);
25
26            if (gamepad1.a) servo.setPosition(0.2);
27            if (gamepad1.b) servo.setPosition(0.8);
28
29            telemetry.addData("Encoder ticks", motor.getCurrentPosition());
30            telemetry.addData("Touch pressed", touch.isPressed());
31            telemetry.update();
32        }
33    }
34}
A test OpMode: the left stick drives a motor, A and B move a servo, and telemetry shows encoder and touch sensor values.

Key terms

DC motor
An electric motor that spins continuously when powered, with speed and direction set by its power value.
Gearbox
A set of gears attached to a motor that reduces speed and increases torque at the output shaft.
Encoder
A sensor that counts rotation in small steps called ticks, so code can measure how far something turned.
Servo
A small actuator that moves to a commanded position, or spins freely if it is a continuous rotation servo.
IMU
An inertial measurement unit that measures rotation and tilt, mainly used to know which way the robot faces.

Practical exercise

Build a Hardware Test Bench

  1. 1Plug one motor (with its encoder cable), one servo and one touch sensor into the Control Hub and write down each port.
  2. 2On the Driver Hub, create a configuration that names them test_motor, test_servo and touch, and save it.
  3. 3Type in the Hardware Test OpMode from this lesson, build it and run it with the motor secured and nothing attached to the servo.
  4. 4Reset the encoder, then turn the motor output shaft exactly one full turn by hand (with the robot powered on) and record the tick count.
  5. 5Compare your measured ticks per revolution with the value on the motor's product page or datasheet and explain any difference.
Deliverable: A notebook page with your port list, a photo of the test setup, the measured ticks per output revolution and a one-paragraph comparison with the official value.

Knowledge check

Answer every question, then check your answers.

  1. Q1Why do almost all FTC drive motors have a gearbox?
  2. Q2You need a small roller that spins constantly to pull in a light game element. Which actuator fits best?
  3. Q3A motor's encoder gives 28 ticks per motor revolution and the gearbox is 20:1. How many ticks is one output revolution?
  4. Q4Which sensor would you use to know which direction the robot is facing?

Further resources

Mark lesson complete