Programming Servo Basics

Locating the Servo Blocks

Let's start by reviewing how to access servos within Blocks. At the top of the Categorize Blocks section there is a drop down menu for Actuators. When the menu is selected it will drop down two choices: DcMotor or Servo. Selecting Servo will open a side window filled with various servo related blocks.

The block above will change names depending on the name of the servo in a configuration file. If there are multiple servos in a configuration file the arrow next to test_servo will drop down a menu of all the servos in a configuration.

Different block options will appear when using a continuous rotation servo.

Programming Position Movements

Let's start by programming our servo to rotate to the default 1 position!

From the Servo menu, we will primarily be using the block

Select Save OpMode in the upper lefthand corner in the programming interface.

Quick Check!

Let's give our program a try. Take a moment to observe what happens.

When running our program for the first time, we should have seen our servo move itself to position 1 and maintain that position. But what happens if we run it again? Does the servo move?

Running our program a second time

Likely, on a second run our servo did not move since it is already at the correct position. Now check what happens if you first manually rotate the servo while the robot is disabled. Once the code is activated again by pressing play we should see it move again!

Note: Servos are designed to maintain their position so long as the robot's program is enabled. Trying to forcibly move the servo while ON may damage it and is not recommended.

If your servo did not move as expected, double check your wiring and port are correct compared to your configuration.

Resetting Back to Zero

Try running this op mode on the test bed and consider the following question:

  • What is different from the previous run?

In many applications starting the servo in a known state, like at position zero, is beneficial to the operation of a mechanism. Setting the servo to the known state in the initialization ensures it is in the correct position when the OpMode runs.

Take a moment to think about where setting the servo to a known state during initialization may be helpful before moving to the next section!

Last updated