Announcement

Collapse
No announcement yet.

How to use Vuforia VuMark

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

  • How to use Vuforia VuMark

    Hi all,
    I had a question over programming with the Vuforia Vumarks
    In the autonomous program, I want my robot to stop and look at the Vumark and check which one it is, however it's not scanning for the Vumark and I do not know what function I'm supposed to use to do that.
    Can anyone help me out?
    Thanks!

  • #2
    OK I put the below into Wordpad and pasted it back in. Preview shows it all compressed.


    Have you looked at the example program to see how it works?

    This is the line in the example program that updates your variable vuMark -

    RelicRecoveryVuMark vuMark = RelicRecoveryVuMark.from(relicTemplate);

    The next line shows you how to use vuMark. It compares what's in vuMark on the left to one of the possible values on the right.
    Your choices are - UNKNOWN, LEFT, RIGHT, CENTER.
    if (vuMark != RelicRecoveryVuMark.UNKNOWN)
    So you can do
    if (vuMark == RelicRecoveryVuMark.LEFT) doRobotCodeForLeftCryptoKey

    Here are the comments in the example code explaining it.

    * See if any of the instances of {@link relicTemplate} are currently visible.
    * {@link RelicRecoveryVuMark} is an enum which can have the following values:
    * UNKNOWN, LEFT, CENTER, and RIGHT. When a VuMark is visible, something other than
    * UNKNOWN will be returned by {@link RelicRecoveryVuMark#from(VuforiaTrackable)}.
    */
    RelicRecoveryVuMark vuMark = RelicRecoveryVuMark.from(relicTemplate);
    if (vuMark != RelicRecoveryVuMark.UNKNOWN) {

    /* Found an instance of the template. In the actual game, you will probably
    * loop until this condition occurs, then move on to act accordingly depending
    * on which VuMark was visible. */
    telemetry.addData("VuMark", "%s visible", vuMark);

    Comment


    • #3
      Okay with this code, it's not getting a reading whatsoever and its skipping past the if else statements for the vuforia related code and then turning right into the cryptobox, why is this happening?

      package org.firstinspires.ftc.teamcode;
      import com.qualcomm.robotcore.eventloop.opmode.Autonomous ;
      import com.qualcomm.robotcore.eventloop.opmode.LinearOpMo de;
      import com.qualcomm.robotcore.hardware.ColorSensor;
      import com.qualcomm.robotcore.hardware.DcMotor;
      import com.qualcomm.robotcore.hardware.DcMotorSimple;
      import com.qualcomm.robotcore.hardware.I2cAddr;
      import com.qualcomm.robotcore.hardware.Servo;
      import com.qualcomm.robotcore.util.ElapsedTime;

      import org.firstinspires.ftc.robotcore.external.ClassFact ory;
      import org.firstinspires.ftc.robotcore.external.matrices. OpenGLMatrix;
      import org.firstinspires.ftc.robotcore.external.matrices. VectorF;
      import org.firstinspires.ftc.robotcore.external.navigatio n.AngleUnit;
      import org.firstinspires.ftc.robotcore.external.navigatio n.AxesOrder;
      import org.firstinspires.ftc.robotcore.external.navigatio n.AxesReference;
      import org.firstinspires.ftc.robotcore.external.navigatio n.Orientation;
      import org.firstinspires.ftc.robotcore.external.navigatio n.RelicRecoveryVuMark;
      import org.firstinspires.ftc.robotcore.external.navigatio n.VuforiaLocalizer;
      import org.firstinspires.ftc.robotcore.external.navigatio n.VuforiaTrackable;
      import org.firstinspires.ftc.robotcore.external.navigatio n.VuforiaTrackableDefaultListener;
      import org.firstinspires.ftc.robotcore.external.navigatio n.VuforiaTrackables;

      import static com.sun.tools.javac.util.Constants.format;

      @Autonomous(name="vuforia autonomous")
      public class wtf extends LinearOpMode {

      public DcMotor leftDrive, rightDrive;
      public ColorSensor colorSensor;
      public Servo leftServo, rightServo, leftJewel, rightJewel;
      int blue_colorsensor = 0;
      int red_colorsensor = 0;
      double jewel_position = 0.26;

      VuforiaLocalizer vuforia;

      @Override
      public void runOpMode() {
      //Initialization
      telemetry.addData("Status", "Initialized");
      telemetry.update();

      leftDrive = hardwareMap.dcMotor.get("left_drive");
      rightDrive = hardwareMap.dcMotor.get("right_drive");

      leftServo = hardwareMap.servo.get("left_arm");
      rightServo = hardwareMap.servo.get("right_arm");

      leftJewel = hardwareMap.servo.get("left_jewel");
      rightJewel = hardwareMap.servo.get("right_jewel");

      colorSensor = hardwareMap.colorSensor.get("color_sensor");
      colorSensor.setI2cAddress(I2cAddr.create8bit(0x3c) );

      leftDrive.setDirection(DcMotorSimple.Direction.FOR WARD);
      rightDrive.setDirection(DcMotorSimple.Direction.RE VERSE);
      leftServo.setDirection(Servo.Direction.FORWARD);
      rightServo.setDirection(Servo.Direction.REVERSE);

      int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifie r("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());
      VuforiaLocalizer.Parameters parameters = new VuforiaLocalizer.Parameters(cameraMonitorViewId);


      parameters.vuforiaLicenseKey = "AXet0BT/////AAAAmSxPbdBbvUOboapH4nTH1Bg9h4DDJRY/GjcufPlqOwLQ+VfrDENQCYquL/wjRk0wnnWRzoISjpfzy/5rB7Ms17ku3OzUCGWxgcpqViqEJbXr2DTlcRYs8EOgRMiVC3wS Ka5ItWY9Iiol41IjHi9SiL1IWhTMBp9VNwZd3hDlrwkYJ6ZaXT 1ihq5i84MJBYb3x7thgJpfW+O1nj2p7sZreGIOf5vdxRjTswOU CdkPzE1AhQL1JacQa6fvf2ra8foOtm5ztajxocbJQdCs+m62Zf yjHa6X6Y8GZH0DS+/VCWAP4Gwq1hF4s8uKfhU+3DxVGqicTWupXYTVCvPQ59ijcradB M6rcR50oZ7jakDtSC/y\n";


      parameters.cameraDirection = VuforiaLocalizer.CameraDirection.BACK;
      this.vuforia = ClassFactory.createVuforiaLocalizer(parameters);


      VuforiaTrackables relicTrackables = this.vuforia.loadTrackablesFromAsset("RelicVuMark" );
      VuforiaTrackable relicTemplate = relicTrackables.get(0);
      relicTemplate.setName("relicVuMarkTemplate");


      telemetry.addData(">", "Press Play to start");
      telemetry.update();

      waitForStart();

      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);

      leftServo.setPosition(0.6);
      rightServo.setPosition(0.6);

      leftJewel.setPosition(0.0);
      rightJewel.setPosition(0.0);

      ElapsedTime eTime = new ElapsedTime();

      eTime.reset();

      while (eTime.time() < 0.0) {
      }
      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);

      leftServo.setPosition(0.6);
      rightServo.setPosition(0.6);

      leftJewel.setPosition(0.0);
      rightJewel.setPosition(jewel_position);

      while (eTime.time() < 1.0) {

      }
      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);

      leftServo.setPosition(0.6);
      rightServo.setPosition(0.6);

      leftJewel.setPosition(0.0);
      rightJewel.setPosition(jewel_position);

      blue_colorsensor = colorSensor.blue();
      red_colorsensor = colorSensor.red();
      while (eTime.time() < 1.10) {
      telemetry.addData("red ", red_colorsensor);
      telemetry.addData("blue ", blue_colorsensor);
      telemetry.update();
      }

      rightJewel.setPosition(jewel_position);
      if (red_colorsensor > blue_colorsensor) {
      leftDrive.setPower(1.0);
      rightDrive.setPower(1.0);
      leftJewel.setPosition(0.0);
      rightJewel.setPosition(jewel_position);
      leftServo.setPosition(0.6);
      rightServo.setPosition(0.6);

      /* Knock off the red jewel */
      while (eTime.time() < 1.35) {
      }

      } else if (blue_colorsensor > red_colorsensor) {
      leftDrive.setPower(-1.0);
      rightDrive.setPower(-1.0);
      leftJewel.setPosition(0.0);
      rightJewel.setPosition(jewel_position);
      leftServo.setPosition(0.6);
      rightServo.setPosition(0.6);

      /* Knock off the blue jewel */
      while (eTime.time() < 1.26) {
      }
      }


      /* Stop the Robot and bring the arm back*/

      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);
      leftJewel.setPosition(0.0);
      rightJewel.setPosition(jewel_position);

      while (eTime.time() < 2.0) {
      }
      leftDrive.setPower(1.0);
      rightDrive.setPower(1.0);
      rightJewel.setPosition(1.0);

      while (eTime.time() < 3.0) {
      }
      leftDrive.setPower(-0.5);
      rightDrive.setPower(-0.5);

      while (eTime.time() < 4.0) {
      }
      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);
      relicTrackables.activate();
      RelicRecoveryVuMark vuMark = RelicRecoveryVuMark.from(relicTemplate);

      while (eTime.time() < 7.5) {
      }
      if (vuMark != RelicRecoveryVuMark.UNKNOWN) {


      telemetry.addData("VuMark", "%s visible", vuMark);

      } else {
      telemetry.addData("VuMark", "not visible");
      }

      if (vuMark == RelicRecoveryVuMark.RIGHT) {
      while (eTime.time() < 7.75) {
      leftDrive.setPower(1.0);
      rightDrive.setPower(1.0);
      }

      } else if (vuMark == RelicRecoveryVuMark.CENTER) {
      while (eTime.time() < 8.0) {
      leftDrive.setPower(1.0);
      rightDrive.setPower(1.0);

      }
      }
      if (vuMark == RelicRecoveryVuMark.LEFT) {
      while (eTime.time() < 8.25) {
      leftDrive.setPower(1.0);
      rightDrive.setPower(1.0);
      }
      }
      while (eTime.time() < 8.25) {
      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);
      }
      while (eTime.time() < 9.0) {
      leftDrive.setPower(1.0);
      rightDrive.setPower(-1.0);
      }
      while (eTime.time() < 9.5) {
      leftDrive.setPower(1.0);
      rightDrive.setPower(1.0);
      }
      while (eTime.time() < 9.75) {
      leftDrive.setPower(-0.5);
      rightDrive.setPower(-0.5);
      }
      while (eTime.time() < 9.9) {
      leftDrive.setPower(0.0);
      rightDrive.setPower(0.0);
      }
      }

      }

      Comment


      • #4
        In your statement:

        if (vuMark != RelicRecoveryVuMark.UNKNOWN){
        ...
        }else if {
        ...
        }

        you are adding data to telemetry, but you never update telemetry, so it doesn't appear on the driver station.

        I'm somewhat confused by your drive code after that point. If you want to drive for specific time intervals, it might be easier to reset your elapsed time object before each new step in the process, rather than trying to keep track of the cumulative time.

        Comment


        • #5
          To troubleshoot you have to get feedback as to where the program is actually getting to.
          Just testing the one segment of code you're trying to figure out is usually faster than running the entire program each time.
          As above you don't have update, but you have to be careful because update erases the previous screen.
          One of the things I do is create an infinite loop at the end of the program that displays any of the variables I'm interested in.
          while (opModeActive) showVariables


          A guess is that the result of your read is that the result is UNKNOWN since you say it's blowing through.
          Does it sometimes read UNKNOWN when it's right in front? Does it sometimes take several reads before it decides it has seen a Vumark?
          You'll need to insert some test code to find out what will work.


          Here's a link to text to speech. Maybe that would help with troubleshooting as well.

          https://ftcforum.usfirst.org/forum/f...text-to-speech

          Comment


          • #6
            well beside the telemetry showing up, its just not taking a reading in general, the program runs the same way every time

            Comment


            • #7
              Originally posted by Fantom-234 View Post
              well beside the telemetry showing up, its just not taking a reading in general, the program runs the same way every time
              How do you know it isn't taking a reading? It might be taking a reading every time. It might not. My guess that it is reading unknown. I don't know until you get some feedback to find out what your program is actually doing.

              Sometimes you have to back up and write a short test code to see how something new works. You're reading the vumark once Do you know that it always detects the picture right away in time for the first read? There could be a variety of reasons it doesn't work.

              Comment


              • #8
                See I already ran the example program that FTC gives and it picks up the pictures almost immediately, and after adding in the telemetry.update statement its reading unknown and it stays there for 3.5 seconds "reading" the vumark

                Comment


                • #9
                  OK here's an example of testing how things work and writing some simple test code that gives you feedback.

                  I took the example vumark program and replaced everything after waitforstart with below.
                  (I also created a global int cnt = 0; in the appropriate place.)

                  I ran the given example program to make sure I was holding the phone where the vumark would be detected. I then ran this program without moving the phone.
                  I'll be interested in hearing what this program tells you.

                  Code:
                  relicTrackables.activate();
                  RelicRecoveryVuMark vuMark = RelicRecoveryVuMark.from(relicTemplate);
                  while (opModeIsActive() && vuMark == RelicRecoveryVuMark.UNKNOWN) {
                      vuMark = RelicRecoveryVuMark.from(relicTemplate);
                      cnt+=1;
                  }
                  while (opModeIsActive()){
                      telemetry.addData("1", "cnt= " + cnt);
                      telemetry.update();
                  }

                  Comment


                  • #10
                    Originally posted by Fantom-234 View Post
                    See I already ran the example program that FTC gives and it picks up the pictures almost immediately, and after adding in the telemetry.update statement its reading unknown and it stays there for 3.5 seconds "reading" the vumark
                    As I said in my first post this line -

                    RelicRecoveryVuMark vuMark = RelicRecoveryVuMark.from(relicTemplate);

                    is the one that grabs a new data point, you only get new data for the vumark once.

                    Your if statement testing the variable also only runs once, and the vumark in the if conditional is not grabbing new data, you are only comparing what is currently in the vumark variable.

                    Your time statements almost all are {} so the program is sitting doing nothing. Your lines of code run once then the while time churns running nothing until the time expires.


                    Comment


                    • #11
                      Comment out the "vuMark = RelicRecoveryVuMark.from(relicTemplate);" line as I have done below in the test program I posted above. What does the program do now?

                      while (opModeIsActive() && vuMark == RelicRecoveryVuMark.UNKNOWN) { //vuMark = RelicRecoveryVuMark.from(relicTemplate); cnt+=1;

                      Comment


                      • #12
                        Forgot to clean it up.

                        Code:
                        while (opModeIsActive() && vuMark == RelicRecoveryVuMark.UNKNOWN) {
                            //vuMark = RelicRecoveryVuMark.from(relicTemplate);
                            cnt+=1;
                        }

                        Comment


                        • #13
                          Originally posted by Fantom-234 View Post
                          See I already ran the example program that FTC gives and it picks up the pictures almost immediately, and after adding in the telemetry.update statement its reading unknown and it stays there for 3.5 seconds "reading" the vumark
                          As indicated above by 3805Mentor, your existing code is only attempting to read the VuMark once. The fact that it tells you it's "UNKNOWN" indicates that it tried, and failed. That "while(eTime.time()){}" statement doesn't result in any additional attempts at reading the VuMark. Two thoughts as to why it might have failed:

                          a) trying to read too soon after your relicTrackables.activate() statement. I don't know if this would cause a problem. We always activate trackables before our waitForStart(), just in case.

                          b) phone doesn't have adequate view of target, or lighting conditions are not satisfactory.

                          Here's a troubleshooting suggestion similar to those proposed above:

                          RelicRecoveryVuMark vuMark = RelicRecoveryVuMark.from(relicTemplate);
                          int count = 0;
                          ElapsedTime et = new ElapsedTime();
                          while(opModeIsActive()){
                          telemetry.addData("Vumark Reading"," %d : %.0f ms %s ", count, et.milliseconds(), vuMark.toString());
                          count++;
                          vuMark = RelicRecoveryVuMark.from(relicTemplate);
                          }


                          If you find that the vuMark remains UNKNOWN after numerous readings, look at the robot controller phone screen while the op mode is still running, to see if the axis markings are showing over the target. If not, you may need to reposition the phone, or turn on the flashlight in order to see the target.

                          On the other hand, suppose the VuMark gets recognized after 200 milliseconds. Then you can use code like this in your opMode:

                          while (opModeIsActive() && et.milliseconds() < 500 && vuMark == RelicRecoveryVuMark.UNKNOWN) {
                          vuMark = RelicRecoveryVuMark.from(relicTemplate); }

                          Comment


                          • #14
                            So I moved the relicTrackables statement and it started reading and running the program in different ways based on the VuMark it scanned.

                            Comment

                            Working...
                            X