Package edu.wpi.first.vision
Class VisionRunner<P extends VisionPipeline>
java.lang.Object
edu.wpi.first.vision.VisionRunner<P>
- Type Parameters:
P
- Vision pipeline type.
public class VisionRunner<P extends VisionPipeline> extends Object
A vision runner is a convenient wrapper object to make it easy to run vision pipelines from robot
code. The easiest way to use this is to run it in a
VisionThread
and use the listener to
take snapshots of the pipeline's outputs.- See Also:
VisionPipeline
,VisionThread
, vision
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
VisionRunner.Listener<P extends VisionPipeline>
Listener interface for a callback that should run after a pipeline has processed its input. -
Constructor Summary
Constructors Constructor Description VisionRunner(VideoSource videoSource, P pipeline, VisionRunner.Listener<? super P> listener)
Creates a new vision runner. -
Method Summary
Modifier and Type Method Description void
runForever()
A convenience method that callsrunOnce()
in an infinite loop.void
runOnce()
Runs the pipeline one time, giving it the next image from the video source specified in the constructor.void
stop()
Stop a RunForever() loop.
-
Constructor Details
-
VisionRunner
public VisionRunner(VideoSource videoSource, P pipeline, VisionRunner.Listener<? super P> listener)Creates a new vision runner. It will take images from thevideoSource
, send them to thepipeline
, and call thelistener
when the pipeline has finished to alert user code when it is safe to access the pipeline's outputs.- Parameters:
videoSource
- the video source to use to supply images for the pipelinepipeline
- the vision pipeline to runlistener
- a function to call after the pipeline has finished running
-
-
Method Details
-
runOnce
Runs the pipeline one time, giving it the next image from the video source specified in the constructor. This will block until the source either has an image or throws an error. If the source successfully supplied a frame, the pipeline's image input will be set, the pipeline will run, and the listener specified in the constructor will be called to notify it that the pipeline ran.This method is exposed to allow teams to add additional functionality or have their own ways to run the pipeline. Most teams, however, should just use
runForever()
in its own thread using aVisionThread
. -
runForever
A convenience method that callsrunOnce()
in an infinite loop. This must be run in a dedicated thread, and cannot be used in the main robot thread because it will freeze the robot program.Do not call this method directly from the main thread.
- Throws:
IllegalStateException
- if this is called from the main robot thread- See Also:
VisionThread
-
stop
Stop a RunForever() loop.
-