Make a Servo Move to a Position
We have access to 2 different kinds of servos: regular or positional servos, and continuous rotation servos. From a code perspective, continuous rotation servos work exactly like motors have so far; you just need to declare their variables & their hardware map using the CRServo class instead of the DcMotor class. This exercise will use a positional servo.
Grab a servo, plug it into your robot, and add it to your robot hardware configuration.
Just like our motor, we need to import the Servo library:
import com.qualcomm.robotcore.hardware.Servo;
We also need to create an instance variable for our servo at the beginning of our class:
private Servo myServo = null;
Next, we need to get a reference to our servo out of the hardware map in our init method:
myServo = hardwareMap.get(Servo.class, "servo");
Standard servos only have one useful method, setPosition, that takes a number between 0 and 1. Add that to our loop method:
myServo.setPosition(0.5);
Build and run your OpMode. Try moving the servo to different positions.