Package com.crossbotics.ftchelper.vision
Interface TargetSource
- All Superinterfaces:
Subsystem
- All Known Implementing Classes:
LimelightTags,WebcamTags
A camera that finds targets.
WebcamTags and LimelightTags are two kinds; the rest
of your code only talks to this interface, so you can switch cameras (or seasons) by changing
ONE line. A new kind of camera next year? Write a class with these methods.
An interface is a list of methods that a class promises to have, without saying how
they work. Any class that "implements TargetSource" can be used wherever a TargetSource is
asked for. It also "extends Subsystem", so a camera can be added to your robot's group of
mechanisms and gets update(), stop() and telemetry like the others
(see core/Subsystem.java and docs/guides/architecture.md).
TargetSource camera = useLimelight
? LimelightTags.create(hardwareMap, "limelight").pipeline(0)
: WebcamTags.create(hardwareMap, "Webcam 1");
camera.start();
// every loop:
camera.update();
TargetObservation goal = camera.target("RED SCORING"); // a tag group, by name (null if not seen)
TargetObservation tag = camera.target(31); // one tag, by its number
Docs: docs/modules/vision.md. How to write your own: docs/guides/extending.md-
Method Summary
Modifier and TypeMethodDescriptiondefault voidShows a warning if the camera is not working, and, when debug lines are on (the PRACTICE profile), its status and every target it sees.voidclose()Stops the camera and frees it.booleanTrue if the camera is working (connected and streaming).voidstart()Starts the camera.status()A short status for telemetry, e.g.default voidstop()Stopping a camera means closing it, so the next OpMode can use it.default TargetObservationtarget(int id) The target with this id in the latest picture, or null (nothing: not seen now).default TargetObservationThe target with this name (e.g.targets()Everything seen in the latest picture (empty if nothing, or if the latest picture is too old).
-
Method Details
-
start
void start()Starts the camera. Call in INIT (a webcam needs about 1-2 s). -
targets
List<TargetObservation> targets()Everything seen in the latest picture (empty if nothing, or if the latest picture is too old). -
target
The target with this id in the latest picture, or null (nothing: not seen now). Always check for null before using it. (defaultmeans the interface already gives this method a body, so each camera class gets it for free and does not have to write it.) -
target
The target with this name (e.g. an AprilTag cluster's name), or null. -
isWorking
boolean isWorking()True if the camera is working (connected and streaming). -
status
String status()A short status for telemetry, e.g. "STREAMING 28 fps" or "not connected". -
close
void close()Stops the camera and frees it. Called bystop(). -
stop
default void stop()Stopping a camera means closing it, so the next OpMode can use it. -
addTelemetry
Shows a warning if the camera is not working, and, when debug lines are on (the PRACTICE profile), its status and every target it sees.@Overridemeans this fills in a method that Subsystem asks for.- Specified by:
addTelemetryin interfaceSubsystem
-