Servos
Last updated
Was this helpful?
Last updated
Was this helpful?
Servos are rotating motors that can rotate their output axle within a semicircular range. For more specific information, ask a member of the build team or visit ServoCity's introduction to Servos. A physical servo is represented by an instance of the Servo
class in the FTC SDK.
Most standard servos are only capable of moving within a semicircular range, or from to . The position of a servo is represented by a decimal in the FTC SDK, where represents and represents the largest angle possible, which is typically . The scale is linear, so represents , and so forth. Note that the club owns servos that can rotate ; for these servos, a position value of represents instead.
To have a servo move to a specific angle, call Servo.setPosition
with the desired position value , where . To retrieve the last value that was passed to setPosition
, call Servo.getPosition
. Note that this method does not reflect the servo's actual position at the instant of calling it. This means that the program cannot know for certain that the servo has reached the desired position value, so to compensate for the servo's rotation, we typically wait for a certain amount of time with Thread.sleep
before moving onto another action.
Like the DcMotor
, we can set the direction of a servo with Servo.setDirection
. Typically, the effect of setting the direction to Reverse is that any position value that is passed in causes the servo to move to the position , meaning that the angle corresponding to a position value of in the Forward direction corresponds to a position value of in the Reverse direction.
There are many situations where a servo that is capable of rotating 180 degrees has a smaller range during operation. The FTC SDK includes a method named Servo.scaleRange
, which allows you to restrict a servo's operating range to a subset of its capable range. Using scaleRange
also means that any position value that is passed to setPosition
is scaled within the given range. For example, if you call servo.scaleRange(0.3, 0.6)
, subsequently calling servo.setPosition(1)
will cause the servo to rotate to a position value of , and calling servo.setPosition(0)
will cause the servo to rotate to a position value of .
The following annotated examples demonstrate how to interact with the Servo
interface according to the expected behaviors above. Feel free to refer to FTC's official samples for more guidance.
Why do we use servos?
What is the range of motion of a standard servo?
What, precisely, does Servo.getPosition
return as a servo rotates to a target position?