Skip to content

Commit

Permalink
Gradle not synced?!
Browse files Browse the repository at this point in the history
  • Loading branch information
Reschivon committed Jan 20, 2020
1 parent 237a09b commit eeab09f
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@
Enjoy!
Below is the code to display to the RC; thanks DogeCV! I tried easyOpenCV, but it was lagging and stuttering. (??)
If it crashes after about a minute, it's probably because OpenCV is using too much native memory. My solution
is to call System.gc() whenever it reaches 70% (works on my g4 play) , but if someone knows more please contact me.
Below is the code to display to the RC; Thanks, EasyOpenCV!
If it crashes after about a minute, it's probably because OpenCV is using too much native memory.
That should not happen much because the MatAllocator recycles all Mats (but not MatofInt)
*/

@TeleOp(name = "CV Simulator", group = "Auto")
@TeleOp(name = "CV test", group = "Auto")
public class OpenCVDetection extends OpMode {

OpenCvDetector fieldElementDetector;

@Override
public void init() {

telemetry.setAutoClear(true);
fieldElementDetector = new OpenCvDetector(this);
}

Expand All @@ -52,7 +50,7 @@ public void start() {
*/
@Override
public void loop() {
telemetry.update();

}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Enjoy!
*/

@TeleOp(name = "CV Simulator", group = "Auto")
@TeleOp(name = "CV Align", group = "Auto")
public class SimpleAlign extends OpMode {

OpenCvDetector fieldElementDetector;
Expand Down
36 changes: 36 additions & 0 deletions bluejay/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apply plugin: 'com.android.library'

apply from: '../moduleFlavors.gradle'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
flatDir {
dirs '../libs'
}
}
dependencies {
// implementation project(path: ':openCVLibrary3')
// implementation (name: 'RobotCore-release', ext: 'aar')

implementation project(':FtcRobotController')


//THESE 2
api 'org.openftc:easyopencv:1.3.2'
api 'org.openftc:opencv-repackaged:4.1.0-B'

}
10 changes: 10 additions & 0 deletions bluejay/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="org.futurerobotics.bluejay">

<application android:allowBackup="true" android:label="@string/app_name"
android:supportsRtl="true">

</application>

</manifest>
3 changes: 2 additions & 1 deletion bluejay/src/main/java/detectors/OpenCvDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.openftc.easyopencv.OpenCvCameraRotation;
import org.openftc.easyopencv.OpenCvInternalCamera;
import org.openftc.easyopencv.OpenCvPipeline;
import org.openftc.opencvrepackaged.DynamicOpenCvNativeLibLoader;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,7 +27,7 @@ public class OpenCvDetector extends StartStoppable {

//Originally in RobotControllerActivity, but caused the camera shutter to make weird noises, so now it lives here
static {
//OpenCVLoader.initDebug();
//DynamicOpenCvNativeLibLoader.loadNativeLibOnStartRobot();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}

Expand Down
122 changes: 122 additions & 0 deletions bluejay/src/main/java/localizers/IMU.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//package localizers;
//
//import com.qualcomm.robotcore.eventloop.opmode.OpMode;
//import org.firstinspires.ftc.robotcore.external.navigation.*;
//
//public class IMU implements deltaLocalizer {
// BNO055IMU imu;
// OpMode opmode;
//
// Orientation lastAngle = new Orientation();
// Position lastPos = new Position();
//
// double deltaAngle;
// Position deltaPos;
//
// volatile boolean activated = false;
//
// public IMU(OpMode opMode) {
//
// this.opmode = opMode;
//
// BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
//
// parameters.mode = BNO055IMU.SensorMode.IMU;
// parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
// parameters.accelUnit = BNO055IMU.AccelUnit.METERS_PERSEC_PERSEC;
// parameters.loggingEnabled = false;
//
// //TODO assumption that that thing is named "imu"
// imu = opmode.hardwareMap.get(BNO055IMU.class, "imu");
//
// imu.initialize(parameters);
//
// //watchdog
// long start = System.currentTimeMillis();
// //make sure the imu gyro is calibrated before continuing.
// while (!imu.isGyroCalibrated()) {
// if (System.currentTimeMillis() - start > 500) {
// opmode.telemetry.addData("IMU", "watchdig quit");
// opmode.telemetry.update();
//
// break;
// }
//
// //wait
// opmode.telemetry.addData("IMU", ("Loading" + Math.random()));
// opmode.telemetry.update();
// }
//
// opmode.telemetry.addData("IMU", "startup done");
// opmode.telemetry.update();
// }
//
// public void start() {
// resetAngle();
// }
//
// /**
// * Resets the cumulative angle tracking to zero.
// */
// private void resetAngle() {
// lastAngle = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
// lastPos = imu.getPosition();
//
// deltaAngle = 0;
// deltaPos = new Position();
// }
//
// public void stop() {
// }
//
// /**
// * call this as fast as you can!
// * return difference in orientation to when you last called it
// * (x,y) is currently broken. But it isn't accurate so you should never use it
// *
// * @return defaults to mm for position x and y
// */
// public PoseOrientation getDeltaPosition() {
// updatePos();
// return new PoseOrientation(deltaPos.x, deltaPos.y, deltaAngle);
// }
//
// /**
// * Based on the last time we called get angle, take the smallest possible rotation difference
// * trig angles
// */
// private void updatePos() {
// //z axis is the one we want
//
// Orientation angle = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
// Position pos = imu.getPosition();
//
// //=========ANGLE=============
// double deltaAngle = angle.firstAngle - lastAngle.firstAngle;
//
// if (deltaAngle < -180)
// deltaAngle += 360;
//
// else if (deltaAngle > 180)
// deltaAngle -= 360;
//
// this.deltaAngle = deltaAngle;
//
// lastAngle = angle;
// //========POSITION==========
// opmode.telemetry.addData("imu raw read", pos.x);
//
// deltaPos.x = pos.x - lastPos.x;
// deltaPos.y = pos.y - lastPos.y;
//
// lastPos = pos;
// }
//
// public void printposition(PoseOrientation toprint) {
// if (toprint != null) {
// opmode.telemetry.addData("IMU-Position (mm) (rot)", toprint.x + " " + toprint.y + " " + toprint.rot);
// } else {
// opmode.telemetry.addData("IMU", "offline");
// }
// }
//}
68 changes: 68 additions & 0 deletions bluejay/src/main/java/localizers/LocalizationManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package localizers;

import java.util.ArrayList;
import java.util.List;

public class LocalizationManager {
List<deltaLocalizer> delta = new ArrayList<>();
List<Localizer> absolute = new ArrayList<>();

PoseOrientation lastknowpos = new PoseOrientation(0, 0, 0);

volatile boolean activated = false;

Thread run = new Thread() {
@Override
public void run() {
while (activated) {
lastknowpos = getPosition();
}
}
};

/**
* Gives a position based on the best combined guess of all localizers given to this class
* Priority is as follows: absolute localizers first, first added to last added
* relative localizers next, first added to last added
*/
public PoseOrientation getPosition() {

for (Localizer loc : absolute) {
PoseOrientation o;
if ((o = loc.getPosition()) != null) {
lastknowpos = o;
return o;
}
}

for (deltaLocalizer loc : delta) {
PoseOrientation o;
if ((o = loc.getDeltaPosition()) != null) {
lastknowpos.x += o.x;
lastknowpos.y += o.y;
lastknowpos.rot += o.rot;
return o;
}
}

return null;
}

public void start() {
activated = true;
run.start();
}

public void stop() {
activated = false;
}

public void addLocalizer(deltaLocalizer l) {
delta.add(l);
}

public void addLocalizer(Localizer l) {
absolute.add(l);
}
}

6 changes: 6 additions & 0 deletions bluejay/src/main/java/localizers/Localizer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package localizers;


public interface Localizer {
PoseOrientation getPosition();
}
16 changes: 16 additions & 0 deletions bluejay/src/main/java/localizers/PoseOrientation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package localizers;

/**
* Units in mm and degrees.
*/
public class PoseOrientation {
public double x;
public double y;
public double rot;

public PoseOrientation(double x, double y, double rot) {
this.x = x;
this.y = y;
this.rot = rot;
}
}
5 changes: 5 additions & 0 deletions bluejay/src/main/java/localizers/deltaLocalizer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package localizers;

public interface deltaLocalizer {
PoseOrientation getDeltaPosition();
}
36 changes: 36 additions & 0 deletions bluejay/src/main/java/util/FileReadUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package util;

import android.os.Environment;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class FileReadUtil {
public static String readFromSD(){
File sdcard = Environment.getExternalStorageDirectory();

//Get the text file
File file= new File(sdcard,"Vuforia Key.txt");

//Read text from file
StringBuilder text = new StringBuilder();

try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;

while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
}
catch (IOException e) {
}

return text.toString();
}

}
Loading

0 comments on commit eeab09f

Please sign in to comment.