Skip to content

Instantly share code, notes, and snippets.

@5484Enderbots
Created October 1, 2017 17:37
Show Gist options
  • Save 5484Enderbots/772584ae3fc53fda99c0f8f51dc1a9f9 to your computer and use it in GitHub Desktop.
Save 5484Enderbots/772584ae3fc53fda99c0f8f51dc1a9f9 to your computer and use it in GitHub Desktop.
A drop-in replacement for VuforiaLocalizer that can be detached from the camera before the opmode ends.
package org.firstinspires.ftc.teamcode;
import org.firstinspires.ftc.robotcore.internal.vuforia.VuforiaLocalizerImpl;
/**
* Copyright (c) 2017 FTC Team 5484 Enderbots
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* This is a VuforiaLocalizer replacement, as it can do everything it does, as well as detach from the camera.
* To use, one can replace statements like:
*
* VuforiaLocalizer vuforia = ClassFactory.createVuforiaLocalizer(parameters);
*
* with
*
* ClosableVuforiaLocalizer vuforia = new ClosableVuforiaLocalizer(parameters);
*
* To close vuforia, simply call vuforia.close();
*/
public class ClosableVuforiaLocalizer extends VuforiaLocalizerImpl {
boolean closed = false;
public ClosableVuforiaLocalizer(Parameters parameters) {
super(parameters);
}
@Override
public void close() {
if (!closed) super.close();
closed = true;
}
}
@HavishNetla
Copy link

I am having errors with the ClosableVuforia
12-23 12:29:31.041 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: Event loop threw an exception 12-23 12:29:31.043 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: java.lang.NullPointerException: Attempt to invoke virtual method 'org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackables org.firstinspires.ftc.teamcode.ClosableVuforiaLocalizer.loadTrackablesFromAsset(java.lang.String)' on a null object reference 12-23 12:29:31.043 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at org.firstinspires.ftc.teamcode.JewelVumark.runOpMode(JewelVumark.java:73) 12-23 12:29:31.044 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at com.qualcomm.robotcore.eventloop.opmode.LinearOpMode$LinearOpModeHelper$1.run(LinearOpMode.java:305) 12-23 12:29:31.044 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at com.qualcomm.robotcore.util.ThreadPool.logThreadLifeCycle(ThreadPool.java:709) 12-23 12:29:31.045 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at com.qualcomm.robotcore.eventloop.opmode.LinearOpMode$LinearOpModeHelper.run(LinearOpMode.java:300) 12-23 12:29:31.046 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 12-23 12:29:31.046 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 12-23 12:29:31.047 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at com.qualcomm.robotcore.util.ThreadPool$ThreadFactoryImpl$1.run(ThreadPool.java:764) 12-23 12:29:31.047 13820-15111/com.qualcomm.ftcrobotcontroller E/EventLoopManager: at java.lang.Thread.run(Thread.java:818)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment