Announcement

Collapse
No announcement yet.

Autonomous programs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Autonomous programs

    OK, for the first time we have a webcam program and need some help. We can identify "non objects detected", "Single" and "Quad". We also added a line to move a motor if "no objects detected". Now we can't figure out where to put a statement to move a different motor if the telemetry shows "quad". Would it be

    if recognition_item="Quad" ;
    robot.shooter.setPower(.7);

    If so, where would we put that? below is the code we have so far (we made the line we added bold):

    @Autonomous(name = "webcam Copy")
    public class webcam_Copy extends LinearOpMode {

    private VuforiaCurrentGame vuforiaUltimateGoal;
    private TfodCurrentGame tfodUltimateGoal;

    Recognition recognition;

    /**
    * This function is executed when this Op Mode is selected from the Driver Station.
    */
    @Override
    public void runOpMode() {
    List<Recognition> recognitions;
    double index;

    vuforiaUltimateGoal = new VuforiaCurrentGame();
    tfodUltimateGoal = new TfodCurrentGame();
    /* Declare OpMode members. */
    HardwarePushbot robot = new HardwarePushbot(); // Utilize RobotHardware to Access OpMode Members

    robot.init(hardwareMap);

    // Sample TFOD Op Mode
    // Initialize Vuforia.
    vuforiaUltimateGoal.initialize(
    "", // vuforiaLicenseKey
    hardwareMap.get(WebcamName.class, "Webcam 1"), // cameraName
    "", // webcamCalibrationFilename
    false, // useExtendedTracking
    false, // enableCameraMonitoring
    VuforiaLocalizer.Parameters.CameraMonitorFeedback. AXES, // cameraMonitorFeedback
    0, // dx
    0, // dy
    0, // dz
    0, // xAngle
    0, // yAngle
    0, // zAngle
    true); // useCompetitionFieldTargetLocations
    // Set min confidence threshold to 0.7
    tfodUltimateGoal.initialize(vuforiaUltimateGoal, 0.7F, true, true);
    // Initialize TFOD before waitForStart.
    // Init TFOD here so the object detection labels are visible
    // in the Camera Stream preview window on the Driver Station.
    tfodUltimateGoal.activate();
    // Enable following block to zoom in on target.
    tfodUltimateGoal.setZoom(2.5, 16 / 9);
    telemetry.addData(">", "Press Play to start");
    telemetry.update();
    // Wait for start command from Driver Station.
    waitForStart();
    if (opModeIsActive()) {
    // Put run blocks here.
    while (opModeIsActive()) {
    // Put loop blocks here.
    // Get a list of recognitions from TFOD.
    recognitions = tfodUltimateGoal.getRecognitions();
    // If list is empty, inform the user. Otherwise, go
    // through list and display info for each recognition.
    if (recognitions.size() == 0) {
    telemetry.addData("TFOD", "No items detected.");

    robot.shooter.setPower(.7);

    } else {
    index = 0;
    // Iterate through list and call a function to
    // display info for each recognized object.
    for (Recognition recognition_item : recognitions) {
    recognition = recognition_item;
    // Display info.
    displayInfo(index);
    // Increment index.
    index = index + 1;
    }
    }
    telemetry.update();
    }
    }
    // Deactivate TFOD.
    tfodUltimateGoal.deactivate();

    vuforiaUltimateGoal.close();
    tfodUltimateGoal.close();
    }

    /**
    * Display info (using telemetry) for a recognized object.
    */
    private void displayInfo(double i) {
    // Display label info.
    // Display the label and index number for the recognition.
    telemetry.addData("label " + i, recognition.getLabel());
    // Display upper corner info.
    // Display the location of the top left corner
    // of the detection boundary for the recognition
    telemetry.addData("Left, Top " + i, recognition.getLeft() + ", " + recognition.getTop());
    // Display lower corner info.
    // Display the location of the bottom right corner
    // of the detection boundary for the recognition
    telemetry.addData("Right, Bottom " + i, recognition.getRight() + ", " + recognition.getBottom());
    }
    }

  • #2
    You want
    if (recognition_item.getLabel().equals("Quad")) {
    robot.shooter.setPower(.7);
    }
    And you want to put that between these 2 lines:
    recognition = recognition_item;
    // Display info.

    Comment


    • #3
      Comrade 17 Thank You!!!

      Comment

      Working...
      X