OpenFTC / OpenRC-Turbo

37 stars 100 forks source link

Hardware Map Appcontext outside of TeleOp/Autonomous Class, and gradle build versions. #14

Closed functionpointersuss closed 3 years ago

functionpointersuss commented 3 years ago

Hello, I am writing this issue due to the fact that the OpenRC could potentially be having problems with EasyOpenCV and other vision systems calling of appContext when passed as a parameter.

The code used to replicate this issue is shown below:

Class Auto:

package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;

@Autonomous
public class Auto extends LinearOpMode {

Test test = new Test(telemetry, hardwareMap);

@Override
public void runOpMode() throws InterruptedException {

    waitForStart();

    while (opModeIsActive()) {
        telemetry.addData("ID", test.getCameraMonitorViewId());
        telemetry.update();
    }
}

}

class Test:

package org.firstinspires.ftc.teamcode;

import com.qualcomm.robotcore.hardware.HardwareMap;

import org.firstinspires.ftc.robotcore.external.Telemetry;

public class Test {

private int cameraMonitorViewId;

public Test (Telemetry telemetry, HardwareMap hardwareMap)
{
    cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());
}

public int getCameraMonitorViewId() {
    return cameraMonitorViewId;
}

}

And this leads to the issue of the screenshot as shown below: Screenshot_20210302-113140

Additionally, this is being built with the android gradle plugin 4.1.2, and Gradle 6.5. this is due to the gradle daemon refusing to start when using the regular gradle versions copied from the git repository. Caches were invalidated, and also this was repeatable on another friend's computer.

Steps to Repeat: Change gradle-wrapper.properties distritbutionUrl to https\://services.gradle.org/distributions/gradle-6.5-bin.zip Add the lines android.useAndroidX=true android.enableJetifier=true to gradle.properties Change top level build.gradle classpath to 'com.android.tools.build:gradle:4.1.2' Follow EasyOpenCv install instructions: Add jcenter() to build.common.gradle and remove arm64-v8a Add implementation 'org.openftc:easyopencv:1.4.4' to build.gradle for TeamCode and Copy libOpenCvNative.so to FIRST Copy Code from above, and build with extremeTurboDebug Run the code.

If anyone could tell me how to proceed and whether this is reproducible. Note: this also is a problem with stock and turbo modes.

Windwoes commented 3 years ago

This is a problem with your user code. The hardwareMap and telemetry objects are not initialized by the SDK until it calls runOpMode(). Thus, you must do test = new Test(telemetry, hardwareMap); from inside runOpMode() (or a delegate called from it) instead of doing it in the context of the OpMode instance initializer.

functionpointersuss commented 3 years ago

Thank you for that answer, the issue is resolved, and I'm closing it.