|
| 1 | +/* Copyright (c) 2024 FIRST. All rights reserved. |
| 2 | + * |
| 3 | + * Redistribution and use in source and binary forms, with or without modification, |
| 4 | + * are permitted (subject to the limitations in the disclaimer below) provided that |
| 5 | + * the following conditions are met: |
| 6 | + * |
| 7 | + * Redistributions of source code must retain the above copyright notice, this list |
| 8 | + * of conditions and the following disclaimer. |
| 9 | + * |
| 10 | + * Redistributions in binary form must reproduce the above copyright notice, this |
| 11 | + * list of conditions and the following disclaimer in the documentation and/or |
| 12 | + * other materials provided with the distribution. |
| 13 | + * |
| 14 | + * Neither the name of FIRST nor the names of its contributors may be used to endorse or |
| 15 | + * promote products derived from this software without specific prior written permission. |
| 16 | + * |
| 17 | + * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS |
| 18 | + * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 20 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
| 22 | + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + */ |
| 29 | + |
| 30 | +package org.firstinspires.ftc.robotcontroller.external.samples; |
| 31 | + |
| 32 | +import com.qualcomm.robotcore.eventloop.opmode.Disabled; |
| 33 | +import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; |
| 34 | +import com.qualcomm.robotcore.eventloop.opmode.TeleOp; |
| 35 | + |
| 36 | +import org.firstinspires.ftc.robotcore.external.hardware.camera.BuiltinCameraDirection; |
| 37 | +import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName; |
| 38 | +import org.firstinspires.ftc.vision.VisionPortal; |
| 39 | +import org.firstinspires.ftc.vision.apriltag.AprilTagProcessor; |
| 40 | + |
| 41 | +/** |
| 42 | + * This OpMode demonstrates the basics of using multiple vision portals simultaneously |
| 43 | + */ |
| 44 | +@TeleOp(name = "Concept: AprilTagMultiPortal", group = "Concept") |
| 45 | +@Disabled |
| 46 | +public class ConceptAprilTagMultiPortal extends LinearOpMode |
| 47 | +{ |
| 48 | + VisionPortal portal1; |
| 49 | + VisionPortal portal2; |
| 50 | + |
| 51 | + AprilTagProcessor aprilTagProcessor1; |
| 52 | + AprilTagProcessor aprilTagProcessor2; |
| 53 | + |
| 54 | + @Override |
| 55 | + public void runOpMode() throws InterruptedException |
| 56 | + { |
| 57 | + // Because we want to show two camera feeds simultaneously, we need to inform |
| 58 | + // the SDK that we want it to split the camera monitor area into two smaller |
| 59 | + // areas for us. It will then give us View IDs which we can pass to the individual |
| 60 | + // vision portals to allow them to properly hook into the UI in tandem. |
| 61 | + int[] viewIds = VisionPortal.makeMultiPortalView(2, VisionPortal.MultiPortalLayout.VERTICAL); |
| 62 | + |
| 63 | + // We extract the two view IDs from the array to make our lives a little easier later. |
| 64 | + // NB: the array is 2 long because we asked for 2 portals up above. |
| 65 | + int portal1ViewId = viewIds[0]; |
| 66 | + int portal2ViewId = viewIds[1]; |
| 67 | + |
| 68 | + // If we want to run AprilTag detection on two portals simultaneously, |
| 69 | + // we need to create two distinct instances of the AprilTag processor, |
| 70 | + // one for each portal. If you want to see more detail about different |
| 71 | + // options that you have when creating these processors, go check out |
| 72 | + // the ConceptAprilTag OpMode. |
| 73 | + aprilTagProcessor1 = AprilTagProcessor.easyCreateWithDefaults(); |
| 74 | + aprilTagProcessor2 = AprilTagProcessor.easyCreateWithDefaults(); |
| 75 | + |
| 76 | + // Now we build both portals. The CRITICAL thing to notice here is the call to |
| 77 | + // setLiveViewContainerId(), where we pass in the IDs we received earlier from |
| 78 | + // makeMultiPortalView(). |
| 79 | + portal1 = new VisionPortal.Builder() |
| 80 | + .setCamera(hardwareMap.get(WebcamName.class, "Webcam 1")) |
| 81 | + .setLiveViewContainerId(portal1ViewId) |
| 82 | + .addProcessor(aprilTagProcessor1) |
| 83 | + .build(); |
| 84 | + portal2 = new VisionPortal.Builder() |
| 85 | + .setCamera(hardwareMap.get(WebcamName.class, "Webcam 2")) |
| 86 | + .setLiveViewContainerId(portal2ViewId) |
| 87 | + .addProcessor(aprilTagProcessor2) |
| 88 | + .build(); |
| 89 | + |
| 90 | + waitForStart(); |
| 91 | + |
| 92 | + // Main Loop |
| 93 | + while (opModeIsActive()) |
| 94 | + { |
| 95 | + // Just show some basic telemetry to demonstrate both processors are working in parallel |
| 96 | + // on their respective cameras. If you want to see more detail about the information you |
| 97 | + // can get back from the processor, you should look at ConceptAprilTag. |
| 98 | + telemetry.addData("Number of tags in Camera 1", aprilTagProcessor1.getDetections().size()); |
| 99 | + telemetry.addData("Number of tags in Camera 2", aprilTagProcessor2.getDetections().size()); |
| 100 | + telemetry.update(); |
| 101 | + sleep(20); |
| 102 | + } |
| 103 | + } |
| 104 | +} |
0 commit comments