Skip to content

Turret Mechanism

The Turret class provided an algorithm and public API for tracking an april tag with the turret. Tracking is done via a four stage state machine consisting of a search, acquire, lock, and idle state.

Property Value
Package Path org.firstinspires.ftc.teamcode.systemsControls.Turret
Type Utility / Subsystem
Argument Type Description
camera Limelight3A Reference to the limelight camera
tele Telemetry Reference to the the opModes Telemetry
turretServo Servo Reference to the servo which controls the location of the turret
public void update()

Updates the turret state machine. This method should be called once every control loop.

Type Description
void Processes turret tracking and state transitions.

public void startTracking(AprilTags targetTag)

Begins tracking the specified AprilTag. This initializes the turret state machine and starts the search process.

Name Type Description
targetTag AprilTags The AprilTag that the turret should track.
Type Description
void Starts the tracking process.

public void stopTracking()

Stops all active tracking. The turret will return to the idle state during the next update cycle.

Type Description
void Stops target tracking.

public boolean setTurretAngle(float theta)

Commands the turret to rotate to the specified angle while respecting the configured mechanical limits.

Name Type Description
theta float Desired turret angle in radians.
Type Description
boolean true once the turret has had sufficient time to reach the requested position.

public void displayDeveloperTelemetry(Telemetry tele)

Displays diagnostic information about the turret for debugging purposes.

Name Type Description
tele Telemetry Telemetry instance used to display diagnostic information.
Type Description
void Adds developer telemetry data.

public float getAprilTagRange(AprilTags tag)

Returns the measured distance from the camera to the specified AprilTag.

Name Type Description
tag AprilTags The AprilTag whose distance should be measured.
Type Description
float Distance to the specified AprilTag.

public float getTargetRange()

Returns the measured distance to the currently tracked AprilTag.

Type Description
float Distance to the active target.

public TurretState getState()

Returns the current operating state of the turret.

Type Description
TurretState Current state of the turret state machine.

public boolean isTracking(AprilTags tag)

Determines whether the specified AprilTag is currently being tracked.

Name Type Description
tag AprilTags The AprilTag to compare against the active target.
Type Description
boolean true if the supplied tag is the current tracking target; otherwise false.

Value Description
IDLE The turret is inactive and not tracking a target.
SEARCHING The turret estimates the target’s location using the robot’s field position.
ACQUIRING The turret performs a small sweep to visually locate the target.
LOCKED The turret actively keeps the target centered in the camera using PID control.