Skip to content
This repository has been archived by the owner on Oct 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #38 from FIRST-Tech-Challenge/v5.2
Browse files Browse the repository at this point in the history
SkyStone v5.2
  • Loading branch information
CalKestis authored Sep 9, 2019
2 parents c05584b + fa978b0 commit e9755b8
Show file tree
Hide file tree
Showing 50 changed files with 1,437 additions and 258 deletions.
4 changes: 2 additions & 2 deletions FtcRobotController/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.qualcomm.ftcrobotcontroller"
android:versionCode="33"
android:versionName="5.1">
android:versionCode="34"
android:versionName="5.2">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Expand Down
Binary file added FtcRobotController/src/main/assets/Skystone.dat
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions FtcRobotController/src/main/assets/Skystone.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<QCARConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="qcar_config.xsd">
<Tracking>
<ImageTarget name="TargetElement" size="101.599998 95.250000" />
<ImageTarget name="BridgeBlueRear" size="112.000000 47.740002" />
<ImageTarget name="BridgeRedRear" size="112.000000 47.740002" />
<ImageTarget name="BridgeRedFront" size="112.000000 47.740002" />
<ImageTarget name="BridgeBlueFront" size="112.000000 47.740002" />
<ImageTarget name="RedPerimeterTgt1" size="254.000000 168.116257" />
<ImageTarget name="RedPerimeterTgt2" size="254.000000 169.227493" />
<ImageTarget name="FrontPerimeterTgt1" size="254.000000 169.492188" />
<ImageTarget name="FrontPerimeterTgt2" size="254.000000 103.504997" />
<ImageTarget name="BluePerimeterTgt1" size="254.000000 169.386246" />
<ImageTarget name="BluePerimeterTgt2" size="254.000000 106.362503" />
<ImageTarget name="RearPerimeterTgt1" size="254.000000 169.239258" />
<ImageTarget name="RearPerimeterTgt2" size="254.000000 142.875000" />
</Tracking>
</QCARConfig>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018 FIRST. All rights reserved.
/* Copyright (c) 2019 FIRST. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted (subject to the limitations in the disclaimer below) provided that
Expand Down Expand Up @@ -40,8 +40,8 @@
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;

/**
* This 2018-2019 OpMode illustrates the basics of using the TensorFlow Object Detection API to
* determine the position of the gold and silver minerals.
* This 2019-2020 OpMode illustrates the basics of using the TensorFlow Object Detection API to
* determine the position of the Skystone game elements.
*
* Use Android Studio to Copy this Class, and Paste it into your team's code folder with a new name.
* Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list.
Expand All @@ -52,9 +52,9 @@
@TeleOp(name = "Concept: TensorFlow Object Detection", group = "Concept")
@Disabled
public class ConceptTensorFlowObjectDetection extends LinearOpMode {
private static final String TFOD_MODEL_ASSET = "RoverRuckus.tflite";
private static final String LABEL_GOLD_MINERAL = "Gold Mineral";
private static final String LABEL_SILVER_MINERAL = "Silver Mineral";
private static final String TFOD_MODEL_ASSET = "Skystone.tflite";
private static final String LABEL_FIRST_ELEMENT = "Stone";
private static final String LABEL_SECOND_ELEMENT = "Skystone";

/*
* IMPORTANT: You need to obtain your own license key to use Vuforia. The string below with which
Expand All @@ -68,7 +68,8 @@ public class ConceptTensorFlowObjectDetection extends LinearOpMode {
* Once you've obtained a license key, copy the string from the Vuforia web site
* and paste it in to your code on the next line, between the double quotes.
*/
private static final String VUFORIA_KEY = " -- YOUR NEW VUFORIA KEY GOES HERE --- ";
private static final String VUFORIA_KEY =
" -- YOUR NEW VUFORIA KEY GOES HERE --- ";

/**
* {@link #vuforia} is the variable we will use to store our instance of the Vuforia
Expand All @@ -94,46 +95,36 @@ public void runOpMode() {
telemetry.addData("Sorry!", "This device is not compatible with TFOD");
}

/**
* Activate TensorFlow Object Detection before we wait for the start command.
* Do it here so that the Camera Stream window will have the TensorFlow annotations visible.
**/
if (tfod != null) {
tfod.activate();
}

/** Wait for the game to begin */
telemetry.addData(">", "Press Play to start tracking");
telemetry.addData(">", "Press Play to start op mode");
telemetry.update();
waitForStart();

if (opModeIsActive()) {
/** Activate TensorFlow Object Detection. */
if (tfod != null) {
tfod.activate();
}

while (opModeIsActive()) {
if (tfod != null) {
// getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made.
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
if (updatedRecognitions != null) {
telemetry.addData("# Object Detected", updatedRecognitions.size());
if (updatedRecognitions.size() == 3) {
int goldMineralX = -1;
int silverMineral1X = -1;
int silverMineral2X = -1;
for (Recognition recognition : updatedRecognitions) {
if (recognition.getLabel().equals(LABEL_GOLD_MINERAL)) {
goldMineralX = (int) recognition.getLeft();
} else if (silverMineral1X == -1) {
silverMineral1X = (int) recognition.getLeft();
} else {
silverMineral2X = (int) recognition.getLeft();
}
}
if (goldMineralX != -1 && silverMineral1X != -1 && silverMineral2X != -1) {
if (goldMineralX < silverMineral1X && goldMineralX < silverMineral2X) {
telemetry.addData("Gold Mineral Position", "Left");
} else if (goldMineralX > silverMineral1X && goldMineralX > silverMineral2X) {
telemetry.addData("Gold Mineral Position", "Right");
} else {
telemetry.addData("Gold Mineral Position", "Center");
}
}

// step through the list of recognitions and display boundary info.
int i = 0;
for (Recognition recognition : updatedRecognitions) {
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
recognition.getLeft(), recognition.getTop());
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
recognition.getRight(), recognition.getBottom());
}
telemetry.update();
}
Expand Down Expand Up @@ -171,7 +162,8 @@ private void initTfod() {
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
tfodParameters.minimumConfidence = 0.8;
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_GOLD_MINERAL, LABEL_SILVER_MINERAL);
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018 FIRST. All rights reserved.
/* Copyright (c) 2019 FIRST. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted (subject to the limitations in the disclaimer below) provided that
Expand Down Expand Up @@ -40,8 +40,8 @@
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;

/**
* This 2018-2019 OpMode illustrates the basics of using the TensorFlow Object Detection API to
* determine the position of the gold and silver minerals.
* This 2019-2020 OpMode illustrates the basics of using the TensorFlow Object Detection API to
* determine the position of the Skystone game elements.
*
* Use Android Studio to Copy this Class, and Paste it into your team's code folder with a new name.
* Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list.
Expand All @@ -52,9 +52,9 @@
@TeleOp(name = "Concept: TensorFlow Object Detection Webcam", group = "Concept")
@Disabled
public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
private static final String TFOD_MODEL_ASSET = "RoverRuckus.tflite";
private static final String LABEL_GOLD_MINERAL = "Gold Mineral";
private static final String LABEL_SILVER_MINERAL = "Silver Mineral";
private static final String TFOD_MODEL_ASSET = "Skystone.tflite";
private static final String LABEL_FIRST_ELEMENT = "Stone";
private static final String LABEL_SECOND_ELEMENT = "Skystone";

/*
* IMPORTANT: You need to obtain your own license key to use Vuforia. The string below with which
Expand All @@ -68,7 +68,8 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
* Once you've obtained a license key, copy the string from the Vuforia web site
* and paste it in to your code on the next line, between the double quotes.
*/
private static final String VUFORIA_KEY = " -- YOUR NEW VUFORIA KEY GOES HERE --- ";
private static final String VUFORIA_KEY =
" -- YOUR NEW VUFORIA KEY GOES HERE --- ";

/**
* {@link #vuforia} is the variable we will use to store our instance of the Vuforia
Expand All @@ -94,46 +95,35 @@ public void runOpMode() {
telemetry.addData("Sorry!", "This device is not compatible with TFOD");
}

/**
* Activate TensorFlow Object Detection before we wait for the start command.
* Do it here so that the Camera Stream window will have the TensorFlow annotations visible.
**/
if (tfod != null) {
tfod.activate();
}

/** Wait for the game to begin */
telemetry.addData(">", "Press Play to start tracking");
telemetry.addData(">", "Press Play to start op mode");
telemetry.update();
waitForStart();

if (opModeIsActive()) {
/** Activate TensorFlow Object Detection. */
if (tfod != null) {
tfod.activate();
}

while (opModeIsActive()) {
if (tfod != null) {
// getUpdatedRecognitions() will return null if no new information is available since
// the last time that call was made.
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
if (updatedRecognitions != null) {
telemetry.addData("# Object Detected", updatedRecognitions.size());
if (updatedRecognitions.size() == 3) {
int goldMineralX = -1;
int silverMineral1X = -1;
int silverMineral2X = -1;
for (Recognition recognition : updatedRecognitions) {
if (recognition.getLabel().equals(LABEL_GOLD_MINERAL)) {
goldMineralX = (int) recognition.getLeft();
} else if (silverMineral1X == -1) {
silverMineral1X = (int) recognition.getLeft();
} else {
silverMineral2X = (int) recognition.getLeft();
}
}
if (goldMineralX != -1 && silverMineral1X != -1 && silverMineral2X != -1) {
if (goldMineralX < silverMineral1X && goldMineralX < silverMineral2X) {
telemetry.addData("Gold Mineral Position", "Left");
} else if (goldMineralX > silverMineral1X && goldMineralX > silverMineral2X) {
telemetry.addData("Gold Mineral Position", "Right");
} else {
telemetry.addData("Gold Mineral Position", "Center");
}
}
// step through the list of recognitions and display boundary info.
int i = 0;
for (Recognition recognition : updatedRecognitions) {
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
recognition.getLeft(), recognition.getTop());
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
recognition.getRight(), recognition.getBottom());
}
telemetry.update();
}
Expand Down Expand Up @@ -171,7 +161,8 @@ private void initTfod() {
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_GOLD_MINERAL, LABEL_SILVER_MINERAL);
tfodParameters.minimumConfidence = 0.8;
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
}
}
Loading

0 comments on commit e9755b8

Please sign in to comment.