A servo is a form of actuator or a 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 we will be using the Smart Robot Servo, which is able to switch between a continuous and angular mode.
Continuous mode allows for the servo to rotate a full 360°, either direction, indefinitely similar to a standard motor.
Angular mode sets the servo to move to specified positions within a 270° range of motion.
Let's take a look at how to program our servo while it is on angular mode:

While most common servos have a range of 180° for motion, the Smart Robot Servo has a range of 270° due to its ability to switch between modes. When programming this means our 0 and 1 position might be a little different than what you'd expect.
Looking at the image above we can see that on default when asking our servo to move to its position 0 it will be at -135° . On the opposite end, moving to its position 1 takes our servo to +135° . Therefore if we wanted to return to 0° we would need to program it to move to its position 0.5.
Let's review quick our basic positions:
0
-135°
0.5
0°
1
135°
Based on what we've learned so far, think about the following two questions:
If we wanted our servo to move to -67.5° what position would we program it move to?
If we have programmed our servo to move to position 0.7, what would that equal in degrees?
In the next few sections, we will be learning to program our servo to first move automatically to different requested positions then in response to our gamepad's input.
Below is a sneak peek of our final full code:

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.

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
Add this block to the op mode code within the
.
Click on the number block to change from to
.
Select Save OpMode in the upper lefthand corner in the programming interface.
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?
The intent of the is to set the position of the servo. If the servo is already in the set position when a code is run, it will not change positions. Lets try adding another block and see what changes.
In this case, we do not want our servo to reset to 0 every time our code repeats. Because of this where do you think we would snap in our block?
Recall when we discussed the section marked by the comment during Programming Essentials. Since we only want our servo to reset ONCE we will request it do so during the initialization process when the code is first activated, but before play is pressed.
Go ahead and click a
block into place to match the code below:
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!
Telemetry is the process of collecting and transmitting data. In robotics ,telemetry is used to output internal data from the actuators and sensors to the Driver Hub. It is a way for the robot to communicate back to you the programmer what the robot thinks its doing or seeing. This information can then be used to improve your code, make adjustments to a mechanism, or to strategize when driving around the field if competing.
Telemetry blocks in Blocks can be found under the Utilities dropdown menu:

The most useful telemetry from the servo is the position of the servo along its 270° range.
From the telemetry menu, select the block.
Drag the block and place it beneath the if/else if block set. In this scenario, we want our telemetry to be constantly providing output rather than waiting for a designated check.
From the Servo menu pullout the block Drag the Block and attach it to the number parameter on the telemetry blocks.
Change the key parameter to "Servo Position"
Give your program a go!



Having our robot able to rotate the servo automatically can be incredibly useful, especially when writing an autonomous program, but what if I want to control the positions with my gamepad?
Let's take a look at how we can add input commands to our code!
For this example the known state will stay at position 0, so that after initialization the servo will be a the -135 degree position of the servo range. The following list shows what buttons correspond with which servo position:
Button
Degree Position
Blocks for adding controller inputs can be found in the "Gamepad" menu:
One of the most common logic statements used in programming is an if/else statement, also known as an if/then statement. This block can be found under the "Logic" menu in Blocks:
In its most simple format we will be asking our robot to check IF something is happening and if the answer is yes, or true in our robot's mind, THEN it will DO what has been asked.
During this section we are going to be asking "If the Y button is pressed on our controller then move our servo to position 0."
If our servo will move to position 0 when the previous statement is TRUE, what do expect to happen when the answer is FALSE (or the Y button is not pressed)?
Our if/else statement can come in many forms that includes multiple different conditional statements. Blocks allows for our base block to be easily added to add as many conditional statements as we need by clicking the blue gear on our block.
Adding an block by clicking and dragging to our existing if statement converts it into becoming an if/else if statement. Using our previous example we can see how this may look in Blocks:
Now our statement is checking first if Y is being pressed to move to position 0, but has added now the option to look for something else, such as another button being pressed.
Let's add to our existing logic statement the ability to move our servo to position 1 when A is pressed on our controller. Give it a try first before revealing the answer below!
How would our full logic statement be read once our new blocks are added?
To add all of our gamepad inputs we need to further extend our if/else if statement:
Now there are three different paths in our if/else if block that our robot may follow based on each input request. We've previously added our ability to move to position 0 and 1, but what about 0.5?
You may have noticed in our gamepad chart at the beginning of this section that we are going to have two buttons able to move our servo to position 0.5. This is so we can practice using a logical operator like the block in our program!
From the Logic Menu in Blocks select the block.
Add this block to the if/else if block, as shown in the image below. Use the dropdown menu on the block to change it from an block to an block.
Add each button block to the if/else if block as seen in the image below.
Now to finish by adding our blocks to each section of the If/else if block. Set the servo position to correspond with the assigned gamepad button.
There are three different paths in this if/else if statement. If the first conditional statement is true (the Y button is pressed) the servo moves to code position 0 and the other conditional statements are ignored.
If the first condition is false (the Y button is not pressed) the second condition is analyzed. This means the order we add our pathways DOES matter. If X and A are pressed at the same time, the robot will will try to prioritize the X button first.
Give it a try!
Code Position
Y/Triangle
-135
0
X/Square
0
0.5
B/Circle
0
0.5
A/Cross
135
1













