Class PositionServo
java.lang.Object
com.crossbotics.ftchelper.mechanism.PositionServo
- All Implemented Interfaces:
Subsystem
A normal (positional) servo with named positions: a claw, a wrist, a hood, a gate.
Can also work in degrees, move slowly, and tell (by estimate) when it has arrived.
PositionServo claw = PositionServo.create(hardwareMap, "claw")
.position("OPEN", 0.20)
.position("CLOSED", 0.75)
.travelTime(0.3); // seconds for a full 0..1 move (measure it)
controls.bindPress(Pad.G2, Btn.RB, () -> claw.toggle("OPEN", "CLOSED"));
routine.step("Grab", claw.goToStep("CLOSED")); // waits until it should be closed
PositionServo hood = PositionServo.create(hardwareMap, "hood")
.degrees(0.10, 0, 0.90, 25); // servo 0.10 = 0 deg, 0.90 = 25 deg (measured)
hood.setDegrees(18);
Positions are raw servo positions (0 to 1). A servo cannot report where it really is, so
"arrived" is an estimate from travelTime(double). Docs: docs/modules/mechanism.md
(docs/images/servo-range.svg shows the 0 to 1 range).
-
Constructor Summary
ConstructorsConstructorDescriptionPositionServo(String name, com.qualcomm.robotcore.hardware.Servo servo) Wraps a servo you already have. -
Method Summary
Modifier and TypeMethodDescriptionvoidShows the target name; in debug mode also the raw position (and degrees, if set up).static PositionServoGets the servo.degrees(double posA, double degA, double posB, double degB) Lets you use degrees.doubleThe angle sent last, in degrees (needsdegrees(double, double, double, double); without it the number means nothing).doubleThe raw position sent last (NaN before the first move).com.qualcomm.robotcore.hardware.ServogetServo()The FTC servo inside, for anything this helper does not do.doubleThe angle it is GOING to, in degrees (after the limits), or NaN before the first command.The named position it is at or going to, or "-" ."" or the last command problem (unknown position name).voidGoes to a named position.A step (autonomous): go to a named position and wait until it should have arrived.booleanisDone()True when the servo should have arrived (an estimate: a servo cannot tell us where it is).limits(double min, double max) Never goes belowminor abovemax(raw positions).maxSpeed(double positionsPerSecond) Moves slowly: at most this many raw positions per second (e.g.name()The name shown in telemetry and in the hardware check.voidnext()The next named position in the order you added them (wraps around).Adds a named raw position, 0 to 1.voidprevious()The previous named position (wraps around).reversed()Position 0 and 1 swap ends.voidset(double position) Goes to a raw position (0 to 1, kept inside the limits).voidsetDegrees(double deg) Goes to an angle in degrees (needsdegrees(double, double, double, double)).voidstop()Stops all motion.voidGoes tobif at (or going to)a, else toa.travelTime(double seconds) Seconds the servo needs for a full 0..1 move.Puts every named position in the tuning menu as "prefix/NAME" (steps of 0.01, kept 0 to 1).voidupdate()Once per loop.
-
Constructor Details
-
PositionServo
Wraps a servo you already have.
-
-
Method Details
-
create
public static PositionServo create(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap, String name) Gets the servo. Does not move it. -
reversed
Position 0 and 1 swap ends. -
limits
Never goes belowminor abovemax(raw positions). Keeps it off the frame. -
position
Adds a named raw position, 0 to 1. -
degrees
Lets you use degrees. Measure two points: raw positionposAisdegAdegrees, rawposBisdegBdegrees. In between is a straight line. -
travelTime
Seconds the servo needs for a full 0..1 move. Used to guess when it has arrived. Default 0.5. -
maxSpeed
Moves slowly: at most this many raw positions per second (e.g. 0.5). 0 = full speed. -
tunable
Puts every named position in the tuning menu as "prefix/NAME" (steps of 0.01, kept 0 to 1). Call it LAST. See docs/modules/tuning.md. -
goTo
Goes to a named position. An unknown name (a typo) does nothing and shows a warning. -
getWarning
"" or the last command problem (unknown position name). -
set
public void set(double position) Goes to a raw position (0 to 1, kept inside the limits). -
setDegrees
public void setDegrees(double deg) Goes to an angle in degrees (needsdegrees(double, double, double, double)). -
toggle
Goes tobif at (or going to)a, else toa. -
next
public void next()The next named position in the order you added them (wraps around). -
previous
public void previous()The previous named position (wraps around). -
update
public void update()Once per loop. At full speed there is nothing to do (the servo was already told where to go). For a slow move (maxSpeed), it sends a position a little closer to the target each loop. -
stop
public void stop()Description copied from interface:SubsystemStops all motion. Called at the end of every OpMode. -
isDone
public boolean isDone()True when the servo should have arrived (an estimate: a servo cannot tell us where it is). We guess from the time since the move started andtravelTime(double). -
goToStep
A step (autonomous): go to a named position and wait until it should have arrived. -
getPosition
public double getPosition()The raw position sent last (NaN before the first move). -
getDegrees
public double getDegrees()The angle sent last, in degrees (needsdegrees(double, double, double, double); without it the number means nothing). -
getTargetDegrees
public double getTargetDegrees()The angle it is GOING to, in degrees (after the limits), or NaN before the first command. Differs fromgetDegrees()only during a slow move (maxSpeed). -
getTargetName
The named position it is at or going to, or "-" . -
getServo
public com.qualcomm.robotcore.hardware.Servo getServo()The FTC servo inside, for anything this helper does not do. -
name
Description copied from interface:SubsystemThe name shown in telemetry and in the hardware check. -
addTelemetry
Shows the target name; in debug mode also the raw position (and degrees, if set up).- Specified by:
addTelemetryin interfaceSubsystem
-