OpModes in EOCV-Sim
Last updated
Last updated
To enable usage of the VisionPortal API within EOCV-Sim, newer versions of the simulator enable the usage of so-called "OpMode
s"; FIRST Tech Challenge teams should be already familiar with this concept, where they work as "executable units" that allow users to write and run their custom robot code in a logical and simple manner, splitting robot operation into different "programs" that can be selected and switched to perfom different tasks depending on what is needed through the different stages of a robot match.
Due to the way VisionPortal works specifically, it is ideal to call this API within said OpMode
s, where setup code tells the API which cameras to use, the resolution of the camera stream, whether we want a live preview or not, running multiple VisionProcessors at once, or even perform development and testing of AprilTag localization math within these executable units.
OpMode
s have a very specific and simple flow of execution:
The init()
method which is executed when you press init after selecting the OpMode
The loop()
method which is executed repeatedly after init()
has passed you press start
The OpMode should be able to stop anytime when requested, pressing the stop button that is available right after starting.
Just like OpenCvPipeline
, OpMode
is a class that you can extend and inherit basic methods from:
@Autonomous
vs @TeleOp
You might have noticed this particular declaration in the example code earlier, which are known as "annotations" within Java. In this specific case, this annotation helps the program find your custom-created OpMode
s. The key difference between @Autonomous and @TeleOp simply consists of where your program will be classified within the user interface of the station controls;
Both annotations take a name
parameter which aid in displaying a more user-friendly name for your OpMode
s when selecting them;
LinearOpMode has a different structure than OpMode, but it is basically the same idea;
There is an overridden method called runOpMode
. Every op mode of typeLinearOpMode
must implement this method, as it gets called when a user selects and initializes your OpMode within the UI. Note that all linear op modes should have a waitForStart()
statement to ensure that the robot will not begin executing the op mode until the driver pushes the start button.
After a start command has been received, the op mode enters a while loop and keeps iterating in this loop until the op mode is no longer active (i.e., until the user pushes the stop button on the Driver Station).