Class PositionServo
java.lang.Object
com.crossbotics.ftchelper.mechanism.PositionServo
- All Implemented Interfaces:
Subsystem,AngleDevice
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.fence(double lo, double hi) A second, temporary range (raw positions) set every loop by an interlock rule: the servo is not sent past it.Uses the servo's whole turn: positions 0 to 1 send 500 to 2500 microseconds instead of the SDK's normal 600 to 2400 (seeServoSetup.fullRange()).doubleThe angle sent last, in degrees (needsdegrees(double, double, double, double); without it the number means nothing).doublegetEstimatedPosition()in degrees (needsdegrees(double, double, double, double)); NaN before the first command.doubleWhere the servo probably is now (raw), from the last position sent and the travel time; NaN before the first command.doublegetMax()The highest raw position it is ever sent (limits(double, double)).doublegetMin()The lowest raw position it is ever sent (limits(double, double)).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.double[]getSweep()The raw positions the servo may be at now, {lowest, highest}: everything between where its last move started and where it was sent, until it should have arrived; then just that position.double[]getSweep()in degrees ({lowest, highest}; needsdegrees(double, double, double, double)), or null before the first command.doubleWhere it was told to go, raw (NaN before the first command): it may still be on its way, or held by a fence.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 "-" .doubleSeconds for a full 0..1 move (travelTime(double))."" 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).booleanTrue iffullRange()orpulseRange(double, double)changed this servo's pulse range.booleanisHeld()True while the fence keeps it from its target.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).pulseRange(double lowUs, double highUs) Sets the pulse for positions 0 and 1 (microseconds), e.g.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.doubletoDegrees(double position) A raw position in degrees (needsdegrees(double, double, double, double)).voidGoes tobif at (or going to)a, else toa.doubletoPosition(double deg) An angle in degrees as a raw position (needsdegrees(double, double, double, double)).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.withServo(com.qualcomm.robotcore.hardware.Servo other, DoubleSupplier trim) A second servo that moves with this one, to the same positions plustrim: the other side of a two-servo part (a claw's other finger, an arm's other side).
-
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. -
fullRange
Uses the servo's whole turn: positions 0 to 1 send 500 to 2500 microseconds instead of the SDK's normal 600 to 2400 (seeServoSetup.fullRange()). A goBILDA 2000 servo then turns 300 degrees over 0 to 1 instead of 270. Set it BEFORE measuring positions and degrees: the same number points somewhere else after the change. Does not move the servo.- Returns:
- this servo, for the next setting
-
pulseRange
Sets the pulse for positions 0 and 1 (microseconds), e.g.pulseRange(500, 2500). A servo that cannot change its pulse keeps the normal range and shows a warning on the Driver Station.- Parameters:
lowUs- microseconds for position 0 (100 to 3000)highUs- microseconds for position 1 (more than lowUs, at most 3000)- Returns:
- this servo, for the next setting
-
isFullRange
public boolean isFullRange()True iffullRange()orpulseRange(double, double)changed this servo's pulse range. -
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. -
withServo
A second servo that moves with this one, to the same positions plustrim: the other side of a two-servo part (a claw's other finger, an arm's other side). Set its direction yourself (a servo mounted facing the other way: REVERSE). The trim is read at each move.- Parameters:
other- the other servotrim- raw position added for the other servo (0 = none), so two horns that do not line up still meet; the result is kept between 0 and 1- Returns:
- this
-
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)).- Specified by:
setDegreesin interfaceAngleDevice
-
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).- Specified by:
isDonein interfaceAngleDevice
-
goToStep
A step (autonomous): go to a named position and wait until it should have arrived. -
fence
A second, temporary range (raw positions) set every loop by an interlock rule: the servo is not sent past it. A target outside it waits at its edge (isHeld()) and goes on when the fence moves.fence(-inf, +inf)removes it. -
isHeld
public boolean isHeld()True while the fence keeps it from its target. -
getEstimatedPosition
public double getEstimatedPosition()Where the servo probably is now (raw), from the last position sent and the travel time; NaN before the first command. -
getSweep
public double[] getSweep()The raw positions the servo may be at now, {lowest, highest}: everything between where its last move started and where it was sent, until it should have arrived; then just that position. Its whole range (the limits) before the first command, and during the first move (it could have been anywhere). Used by interlock rules. -
getSweepDegrees
public double[] getSweepDegrees()getSweep()in degrees ({lowest, highest}; needsdegrees(double, double, double, double)), or null before the first command. -
getEstimatedDegrees
public double getEstimatedDegrees()getEstimatedPosition()in degrees (needsdegrees(double, double, double, double)); NaN before the first command. -
toDegrees
public double toDegrees(double position) A raw position in degrees (needsdegrees(double, double, double, double)). -
toPosition
public double toPosition(double deg) An angle in degrees as a raw position (needsdegrees(double, double, double, double)). -
getMin
public double getMin()The lowest raw position it is ever sent (limits(double, double)). -
getMax
public double getMax()The highest raw position it is ever sent (limits(double, double)). -
getTravelTime
public double getTravelTime()Seconds for a full 0..1 move (travelTime(double)). -
getTarget
public double getTarget()Where it was told to go, raw (NaN before the first command): it may still be on its way, or held by a fence. -
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).- Specified by:
getTargetDegreesin interfaceAngleDevice
-
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
-