Class TrcServo
- All Implemented Interfaces:
TrcExclusiveSubsystem
- Direct Known Subclasses:
FtcServo
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static enum
static class
Nested classes/interfaces inherited from interface trclib.robotcore.TrcExclusiveSubsystem
TrcExclusiveSubsystem.OwnershipParams
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final TrcServo.ActionParams
private double
private static final double
private static final double
private static final double
private static final double
private final String
private TrcPresets
private Double
private final TrcServo.Params
protected static TrcElapsedTimer
private final TrcTaskMgr.TaskObject
private final TrcTimer
final TrcDbgTrace
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor: Creates an instance of the object.TrcServo
(String instanceName, TrcServo.Params params) Constructor: Creates an instance of the object. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
addFollower
(TrcServo followingServo) This method adds a following servo to the followers list.void
cancel()
This method cancels previous servo operation if applicable.void
This method cancels previous servo operation if applicable.private void
This method finishes previous servo operation if applicable.void
This method sets this servo to follow the specified servo.abstract double
This method returns the logical position of the servo.double
This method returns the physical position value of the servo.double
getPower()
This method returns the last set power value.abstract boolean
This method checks if the servo direction is inverted.private boolean
This method checks if the task is enabled.private void
performSetPosition
(Object context) This method performs the setPosition action.private void
performSetPositionWithStepRate
(Object context) This method performs the setPositionWithStepRate action.private void
performSetPower
(Object context) This method performs the setPower action.void
presetPositionDown
(String owner) This method sets the actuator to the next preset position down from the current position.void
presetPositionUp
(String owner) This method sets the actuator to the next preset position up from the current position.static void
printElapsedTime
(TrcDbgTrace msgTracer) This method prints the elapsed time info.private void
servoTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check whether the servo has reached target.static void
setElapsedTimerEnabled
(boolean enabled) This method enables/disables the elapsed timers for performance monitoring.abstract void
setInverted
(boolean inverted) This method inverts the servo direction.abstract void
setLogicalPosition
(double position) This method sets the logical position of the servo.void
setLogicalPosRange
(double logicalMin, double logicalMax) This method sets the logical range of the servo motor.void
setMaxStepRate
(double maxStepRate) This method sets the maximum stepping rate of the servo.private void
setNextPresetPosition
(String owner, boolean presetUp) This method sets the actuator to the next preset position up or down from the current position.void
setPhysicalPosRange
(double physicalMin, double physicalMax) This method sets the physical range of the servo motor.void
setPosition
(double position) This method sets the servo position.void
setPosition
(double position, double stepRate) This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.void
setPosition
(double delay, double position, double stepRate, TrcEvent completionEvent) This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.void
setPosition
(double position, double stepRate, TrcEvent completionEvent) This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.void
setPosition
(double delay, double position, TrcEvent completionEvent, double timeout) This method sets the servo position.void
setPosition
(double position, TrcEvent completionEvent, double timeout) This method sets the servo position.void
setPosition
(String owner, double delay, double position, double stepRate, TrcEvent completionEvent) This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.void
setPosition
(String owner, double delay, double position, TrcEvent completionEvent, double timeout) This method sets the servo position.void
setPosPresets
(double tolerance, double... presets) This method sets an array of preset positions for the motor.void
setPower
(double power) This method speed controls the servo with stepping.void
setPower
(double delay, double power) This method speed controls the servo with stepping.void
setPower
(double power, double minPos, double maxPos) This method speed controls the servo with stepping.void
setPower
(double delay, double power, double minPos, double maxPos) This method speed controls the servo with stepping.void
This method speed controls the servo with stepping.void
This method speed controls the servo with stepping.void
setPresetPosition
(String owner, double delay, int presetIndex, TrcEvent event, double timeout) This method sets the servo to the specified preset position.private void
setTaskEnabled
(boolean enabled) This method enables/disables the enhanced servo task for performing step rate speed control or zero calibration.private void
stopTask
(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called when the competition mode is about to end so it will stop the servo if necessary.double
toLogicalPosition
(double physicalPosition) This method is called to convert a physical position to a logical position.double
toPhysicalPosition
(double logicalPosition) This method is called to convert a logical position to a physical position.toString()
This method returns the instance name.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface trclib.robotcore.TrcExclusiveSubsystem
acquireExclusiveAccess, acquireOwnership, cancelExclusiveAccess, getCurrentOwner, hasOwnership, releaseExclusiveAccess, releaseOwnership, validateOwnership
-
Field Details
-
DEF_LOGICAL_MIN
private static final double DEF_LOGICAL_MIN- See Also:
-
DEF_LOGICAL_MAX
private static final double DEF_LOGICAL_MAX- See Also:
-
DEF_PHYSICAL_MIN
private static final double DEF_PHYSICAL_MIN- See Also:
-
DEF_PHYSICAL_MAX
private static final double DEF_PHYSICAL_MAX- See Also:
-
servoSetPosElapsedTimer
-
followers
-
actionParams
-
tracer
-
instanceName
-
servoParams
-
timer
-
servoTaskObj
-
posPresets
-
currPower
private double currPower -
prevLogicalPos
-
-
Constructor Details
-
TrcServo
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name of the servo.params
- specifies the parameters of the servo.
-
TrcServo
Constructor: Creates an instance of the object.- Parameters:
instanceName
- specifies the instance name of the servo.
-
-
Method Details
-
setInverted
public abstract void setInverted(boolean inverted) This method inverts the servo direction.- Parameters:
inverted
- specifies true to invert the servo direction, false otherwise.
-
isInverted
public abstract boolean isInverted()This method checks if the servo direction is inverted.- Returns:
- true if the servo direction is inverted, false otherwise.
-
setLogicalPosition
public abstract void setLogicalPosition(double position) This method sets the logical position of the servo.- Parameters:
position
- specifies the logical position of the servo in the range of [0.0, 1.0].
-
getLogicalPosition
public abstract double getLogicalPosition()This method returns the logical position of the servo. In general, servo do not provide real time position feedback. Therefore, it will return the position set by the last setLogicalPosition call.- Returns:
- logical position of the servo in the range of [0.0, 1.0].
-
toString
This method returns the instance name. -
setLogicalPosRange
public void setLogicalPosRange(double logicalMin, double logicalMax) This method sets the logical range of the servo motor. This is typically used to limit the logical range of the servo to less than the 0.0 to 1.0 range. For example, one may limit the logical range to 0.2 to 0.8.- Parameters:
logicalMin
- specifies the minimum value of the logical range.logicalMax
- specifies the maximum value of the logical range.
-
setPhysicalPosRange
public void setPhysicalPosRange(double physicalMin, double physicalMax) This method sets the physical range of the servo motor. This is typically used to set a 180-degree servo to have a range of 0.0 to 180.0 instead of the logical range of 0.0 to 1.0. By default physical range is set to the range of 0.0 to 1.0, same as logical range. The physical range is used for map physical position units to logical position unit between 0.0 to 1.0.- Parameters:
physicalMin
- specifies the minimum value of the physical range.physicalMax
- specifies the maximum value of the physical range.
-
setMaxStepRate
public void setMaxStepRate(double maxStepRate) This method sets the maximum stepping rate of the servo. This enables setPower to speed control the servo.- Parameters:
maxStepRate
- specifies the maximum stepping rate (physicalPos/sec).
-
toLogicalPosition
public double toLogicalPosition(double physicalPosition) This method is called to convert a physical position to a logical position. It will make sure the physical position is within the physical range and scale it to the logical range.- Parameters:
physicalPosition
- specifies the physical position to be converted- Returns:
- converted logical position.
-
toPhysicalPosition
public double toPhysicalPosition(double logicalPosition) This method is called to convert a logical position to a physical position. It will make sure the logical position is within the logical range and scale it to the physical range. Note: this method is only callable by classes extending this class.- Parameters:
logicalPosition
- specifies the logical position to be converted.- Returns:
- converted physical position.
-
addFollower
This method adds a following servo to the followers list.- Parameters:
followingServo
- specifies the following servo.- Returns:
- true if the servo is added successfully, false if it is already in the list.
-
follow
This method sets this servo to follow the specified servo.- Parameters:
servo
- specifies the other servo to follow.
-
finish
This method finishes previous servo operation if applicable.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.canceled
- specifies true if the operation was canceled.
-
cancel
This method cancels previous servo operation if applicable.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.
-
cancel
public void cancel()This method cancels previous servo operation if applicable. -
getPosition
public double getPosition()This method returns the physical position value of the servo. Generally, servo do not provide real time position feedback. Therefore, it will only return the position set by the last setPosition call.- Returns:
- physical position of the servo, could be in degrees if setPhysicalPosRange is called to set the range in degrees.
-
performSetPosition
This method performs the setPosition action.- Parameters:
context
- not used.
-
setPosition
public void setPosition(String owner, double delay, double position, TrcEvent completionEvent, double timeout) This method sets the servo position. By default, the servo maps its physical position the same as its logical position [0.0, 1.0]. However, if setPhysicalPosRange was called, it could map a real world physical range (e.g. [0.0, 180.0] degrees) to the logical range of [0.0, 1.0]. If an event is given, it sets event after the given amount of time has expired.Servo operates on logical position. On a 180-degree servo, 0.0 is at 0-degree and 1.0 is at 180-degree. For a 90-degree servo, 0->0deg, 1->90deg. If servo direction is inverted, then 0.0 is at 180-degree and 1.0 is at 0-degree.
- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies the delay in seconds before setting the position of the servo, can be zero if no delay.position
- specifies the physical position of the servo motor. This value may be in degrees if setPhysicalPosRange is called with the degree range.completionEvent
- specifies an event object to signal when the timeout event has expired.timeout
- specifies a maximum time value the operation should be completed in seconds.
-
setPosition
This method sets the servo position. By default, the servo maps its physical position the same as its logical position [0.0, 1.0]. However, if setPhysicalPosRange was called, it could map a real world physical range (e.g. [0.0, 180.0] degrees) to the logical range of [0.0, 1.0]. If an event is given, it sets event after the given amount of time has expired.Servo operates on logical position. On a 180-degree servo, 0.0 is at 0-degree and 1.0 is at 180-degree. For a 90-degree servo, 0->0deg, 1->90deg. If servo direction is inverted, then 0.0 is at 180-degree and 1.0 is at 0-degree.
- Parameters:
delay
- specifies the delay in seconds before setting the position of the servo, can be zero if no delay.position
- specifies the physical position of the servo motor. This value may be in degrees if setPhysicalPosRange is called with the degree range.completionEvent
- specifies an event object to signal when the timeout event has expired.timeout
- specifies a maximum time value the operation should be completed in seconds.
-
setPosition
This method sets the servo position. By default, the servo maps its physical position the same as its logical position [0.0, 1.0]. However, if setPhysicalPosRange was called, it could map a real world physical range (e.g. [0.0, 180.0] degrees) to the logical range of [0.0, 1.0]. If an event is given, it sets event after the given amount of time has expired.Servo operates on logical position. On a 180-degree servo, 0.0 is at 0-degree and 1.0 is at 180-degree. For a 90-degree servo, 0->0deg, 1->90deg. If servo direction is inverted, then 0.0 is at 180-degree and 1.0 is at 0-degree.
- Parameters:
position
- specifies the physical position of the servo motor. This value may be in degrees if setPhysicalPosRange is called with the degree range.completionEvent
- specifies an event object to signal when the timeout event has expired.timeout
- specifies a maximum time value the operation should be completed in seconds.
-
setPosition
public void setPosition(double position) This method sets the servo position. By default, the servo maps its physical position the same as its logical position [0.0, 1.0]. However, if setPhysicalPosRange was called, it could map a real world physical range (e.g. [0.0, 180.0] degrees) to the logical range of [0.0, 1.0]. If an event is given, it sets event after the given amount of time has expired.Servo operates on logical position. On a 180-degree servo, 0.0 is at 0-degree and 1.0 is at 180-degree. For a 90-degree servo, 0->0deg, 1->90deg. If servo direction is inverted, then 0.0 is at 180-degree and 1.0 is at 0-degree.
- Parameters:
position
- specifies the physical position of the servo motor. This value may be in degrees if setPhysicalPosRange is called with the degree range.
-
performSetPositionWithStepRate
This method performs the setPositionWithStepRate action.- Parameters:
context
- not used.
-
setPosition
public void setPosition(String owner, double delay, double position, double stepRate, TrcEvent completionEvent) This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies the delay in seconds before setting the position of the servo, can be zero if no delay.position
- specifies the target position.stepRate
- specifies the stepping rate to get there (physicalPos/sec).completionEvent
- specifies an event object to signal when the servo reaches the position..
-
setPosition
This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.- Parameters:
delay
- specifies the delay in seconds before setting the position of the servo, can be zero if no delay.position
- specifies the target position.stepRate
- specifies the stepping rate to get there (physicalPos/sec).completionEvent
- specifies an event object to signal when the servo reaches the position..
-
setPosition
This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.- Parameters:
position
- specifies the target position.stepRate
- specifies the stepping rate to get there (physicalPos/sec).completionEvent
- specifies an event object to signal when the servo reaches the position..
-
setPosition
public void setPosition(double position, double stepRate) This method sets the servo to the specifies position but with the specified step rate in effect controlling the speed to get there.- Parameters:
position
- specifies the target position.stepRate
- specifies the stepping rate to get there (physicalPos/sec).
-
performSetPower
This method performs the setPower action.- Parameters:
context
- not used.
-
setPower
This method speed controls the servo with stepping.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies the delay in seconds before setting the power of the servo, can be zero if no delay.power
- specifies how fast the servo will turn.minPos
- specifies the minimum position the servo can move to.maxPos
- specifies the maximum position the servo can move to.
-
setPower
This method speed controls the servo with stepping.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies the delay in seconds before setting the power of the servo, can be zero if no delay.power
- specifies how fast the servo will turn.
-
setPower
public void setPower(double delay, double power, double minPos, double maxPos) This method speed controls the servo with stepping.- Parameters:
delay
- specifies the delay in seconds before setting the power of the servo, can be zero if no delay.power
- specifies how fast the servo will turn.minPos
- specifies the minimum position the servo can move to.maxPos
- specifies the maximum position the servo can move to.
-
setPower
public void setPower(double delay, double power) This method speed controls the servo with stepping.- Parameters:
delay
- specifies the delay in seconds before setting the power of the servo, can be zero if no delay.power
- specifies how fast the servo will turn.
-
setPower
public void setPower(double power, double minPos, double maxPos) This method speed controls the servo with stepping.- Parameters:
power
- specifies how fast the servo will turn.minPos
- specifies the minimum position the servo can move to.maxPos
- specifies the maximum position the servo can move to.
-
setPower
public void setPower(double power) This method speed controls the servo with stepping.- Parameters:
power
- specifies how fast the servo will turn.
-
getPower
public double getPower()This method returns the last set power value.- Returns:
- last power set to the motor.
-
setTaskEnabled
private void setTaskEnabled(boolean enabled) This method enables/disables the enhanced servo task for performing step rate speed control or zero calibration.- Parameters:
enabled
- specifies true to enable task, false to disable.
-
isTaskEnabled
private boolean isTaskEnabled()This method checks if the task is enabled.- Returns:
- true if task is enabled, false otherwise.
-
servoTask
private void servoTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called periodically to check whether the servo has reached target. If not, it will calculate the next position to set the servo to according to its step rate.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running. (e.g. Autonomous, TeleOp, Test).slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
stopTask
private void stopTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop) This method is called when the competition mode is about to end so it will stop the servo if necessary.- Parameters:
taskType
- specifies the type of task being run.runMode
- specifies the competition mode that is running. (e.g. Autonomous, TeleOp, Test).slowPeriodicLoop
- specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.
-
setPosPresets
public void setPosPresets(double tolerance, double... presets) This method sets an array of preset positions for the motor.- Parameters:
tolerance
- specifies the preset tolerance.presets
- specifies an array of preset positions in scaled unit.
-
setPresetPosition
public void setPresetPosition(String owner, double delay, int presetIndex, TrcEvent event, double timeout) This method sets the servo to the specified preset position.- Parameters:
owner
- specifies the owner ID to check if the caller has ownership of the subsystem.delay
- specifies delay time in seconds before setting position, can be zero if no delay.presetIndex
- specifies the index to the preset position array.event
- specifies the event to signal when done, can be null if not provided.timeout
- specifies a timeout value in seconds. If the operation is not completed without the specified timeout, the operation will be canceled and the event will be signaled. If no timeout is specified, it should be set to zero.
-
setNextPresetPosition
This method sets the actuator to the next preset position up or down from the current position.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the actuator movement is coompleted, can be null if no ownership is required.presetUp
- specifies true to move to next preset up, false to move to next preset down.
-
presetPositionUp
This method sets the actuator to the next preset position up from the current position.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the actuator movement is completed, can be null if no ownership is required.
-
presetPositionDown
This method sets the actuator to the next preset position down from the current position.- Parameters:
owner
- specifies the owner ID that will acquire ownership before setting the preset position and will automatically release ownership when the actuator movement is coompleted, can be null if no ownership is required.
-
setElapsedTimerEnabled
public static void setElapsedTimerEnabled(boolean enabled) This method enables/disables the elapsed timers for performance monitoring.- Parameters:
enabled
- specifies true to enable elapsed timers, false to disable.
-
printElapsedTime
This method prints the elapsed time info.- Parameters:
msgTracer
- specifies the tracer to be used to print the info.
-