A servo functions as an actuator or device designed for moving. With a typical servo, you can specify a target position. The servo will turn its motor shaft to move to the target position, and then maintain that position, even if moderate forces are applied to try and disturb its position.
For Hello Robot, the Smart Robot Servo is used, which can switch between a continuous and angular mode.
While most common servos have a range of 180 degrees for motion, the Smart Robot Servo has a range of 270 degrees due to its ability to switch between modes. When programming, the 0 and 1 positions may differ from typical expectations.
When the servo is at default position 0, it will be at -135 degrees. At position 1, the servo moves to +135 degrees. Therefore, to return to 0 degrees, you would need to program it to move to position 0.5.
A servo horn attachment connected to your Smart Robot Servo may affect where 0 degrees appears. Using a SRS programmer to set the servo to zero before adding attachments is recommended.
| Programmed Position | Degrees |
| ------------------- | ------- |
| 0 | -135 |
| 0.5 | 0 |
| 1 | 135 |
Consider these two questions:
1. If you wanted your servo to move to -67.5 degrees, what position would you program it to move to?
2. If you have programmed your servo to move to position 0.7, what would that equal in degrees?
1. Breaking it down, -67.5 degrees is halfway of the movement between 0 degrees and -135 degrees. Therefore, set the position to halfway between 0 and 0.5, equaling 0.25.
2. This requires additional calculation. Each 0.1 of position equals 27 degrees (270 degrees divided by 10). Starting from the 0 degrees at position 0.5, moving to position 0.7 equals 54 degrees.
For Hello Robot programming, only positions are used. Understanding their translation to degrees remains important for designing a mechanism.
In the following sections, you will learn to program your servo to first move automatically to different requested positions, then in response to your gamepad's input.
The next sections include:
A servo functions as a device designed for moving where users can specify target positions. The shaft maintains that position despite moderate external forces.
The Hello Robot implementation uses the Smart Robot Servo with two operational modes:
| Position | Degrees |
|----------|---------|
| 0 | -135 |
| 0.5 | 0 |
| 1 | 135 |
When programming this means our 0 and 1 position might be a little different than what you'd expect.
1. Position needed for -67.5 degree movement: 0.25 (halfway between 0 and 0.5)
2. Degree equivalent of position 0.7: 54 degrees (calculated using 0.1 position = 27 degrees formula)
@TeleOp
public class HelloRobot_TeleOp extends LinearOpMode {
private Blinker control_Hub;
private DcMotor test_motor;
private Servo test_servo;
private TouchSensor test_touch;
@Override
public void runOpMode() {
control_Hub = hardwareMap.get(Blinker.class, "Control Hub");
test_motor = hardwareMap.get(DcMotor.class, "test_motor");
test_servo = hardwareMap.get(Servo.class, "test_servo");
test_touch = hardwareMap.get(TouchSensor.class, "test_touch");
test_servo.setPosition(0);
telemetry.addData("Status", "Initialized");
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
// run until the end of the match (driver presses STOP)
while (opModeIsActive()) {
if (gamepad1.y){
//move to position 0
test_servo.setPosition(0);
} else if (gamepad1.x || gamepad1.b) {
//move to position 0.5
test_servo.setPosition(0.5);
} else if (gamepad1.a) {
//move to position 1
test_servo.setPosition(1);
}
telemetry.addData("Servo Position", test_servo.getPosition());
telemetry.addData("Status", "Running");
telemetry.update();
}
}
}