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 reduction | Approx. output speed | Typical use |
|---|---|---|
| 1:1 (no gearbox) | 6000 RPM | Flywheels and shooters |
| about 5:1 | 1150 RPM | Fast intakes |
| about 13.7:1 | 435 RPM | Fast drivetrains |
| about 19.2:1 | 312 RPM | General drivetrains |
| about 50.9:1 | 117 RPM | Lifts and arms |
| about 188:1 | 30 RPM | Heavy 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.
Servos: standard and continuous rotation
| Type | How it moves | Code | Good for |
|---|---|---|---|
| Standard servo | Turns to a commanded angle and holds it, within a limited range | servo.setPosition(0.0 to 1.0) | Claws, flaps, latches, wrist joints |
| Continuous rotation servo | Spins freely in either direction like a small, weak motor | crServo.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.
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}
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
- 1Plug one motor (with its encoder cable), one servo and one touch sensor into the Control Hub and write down each port.
- 2On the Driver Hub, create a configuration that names them
test_motor,test_servoandtouch, and save it. - 3Type in the Hardware Test OpMode from this lesson, build it and run it with the motor secured and nothing attached to the servo.
- 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.
- 5Compare your measured ticks per revolution with the value on the motor's product page or datasheet and explain any difference.
Knowledge check
Answer every question, then check your answers.