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

Commit e9755b8

Browse files
authored
Merge pull request #38 from FIRST-Tech-Challenge/v5.2
SkyStone v5.2
2 parents c05584b + fa978b0 commit e9755b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1437
-258
lines changed

FtcRobotController/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.qualcomm.ftcrobotcontroller"
5-
android:versionCode="33"
6-
android:versionName="5.1">
5+
android:versionCode="34"
6+
android:versionName="5.2">
77

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

Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<QCARConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="qcar_config.xsd">
3+
<Tracking>
4+
<ImageTarget name="TargetElement" size="101.599998 95.250000" />
5+
<ImageTarget name="BridgeBlueRear" size="112.000000 47.740002" />
6+
<ImageTarget name="BridgeRedRear" size="112.000000 47.740002" />
7+
<ImageTarget name="BridgeRedFront" size="112.000000 47.740002" />
8+
<ImageTarget name="BridgeBlueFront" size="112.000000 47.740002" />
9+
<ImageTarget name="RedPerimeterTgt1" size="254.000000 168.116257" />
10+
<ImageTarget name="RedPerimeterTgt2" size="254.000000 169.227493" />
11+
<ImageTarget name="FrontPerimeterTgt1" size="254.000000 169.492188" />
12+
<ImageTarget name="FrontPerimeterTgt2" size="254.000000 103.504997" />
13+
<ImageTarget name="BluePerimeterTgt1" size="254.000000 169.386246" />
14+
<ImageTarget name="BluePerimeterTgt2" size="254.000000 106.362503" />
15+
<ImageTarget name="RearPerimeterTgt1" size="254.000000 169.239258" />
16+
<ImageTarget name="RearPerimeterTgt2" size="254.000000 142.875000" />
17+
</Tracking>
18+
</QCARConfig>

FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/ConceptTensorFlowObjectDetection.java

+28-36
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018 FIRST. All rights reserved.
1+
/* Copyright (c) 2019 FIRST. All rights reserved.
22
*
33
* Redistribution and use in source and binary forms, with or without modification,
44
* are permitted (subject to the limitations in the disclaimer below) provided that
@@ -40,8 +40,8 @@
4040
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
4141

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

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

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

98+
/**
99+
* Activate TensorFlow Object Detection before we wait for the start command.
100+
* Do it here so that the Camera Stream window will have the TensorFlow annotations visible.
101+
**/
102+
if (tfod != null) {
103+
tfod.activate();
104+
}
105+
97106
/** Wait for the game to begin */
98-
telemetry.addData(">", "Press Play to start tracking");
107+
telemetry.addData(">", "Press Play to start op mode");
99108
telemetry.update();
100109
waitForStart();
101110

102111
if (opModeIsActive()) {
103-
/** Activate TensorFlow Object Detection. */
104-
if (tfod != null) {
105-
tfod.activate();
106-
}
107-
108112
while (opModeIsActive()) {
109113
if (tfod != null) {
110114
// getUpdatedRecognitions() will return null if no new information is available since
111115
// the last time that call was made.
112116
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
113117
if (updatedRecognitions != null) {
114118
telemetry.addData("# Object Detected", updatedRecognitions.size());
115-
if (updatedRecognitions.size() == 3) {
116-
int goldMineralX = -1;
117-
int silverMineral1X = -1;
118-
int silverMineral2X = -1;
119-
for (Recognition recognition : updatedRecognitions) {
120-
if (recognition.getLabel().equals(LABEL_GOLD_MINERAL)) {
121-
goldMineralX = (int) recognition.getLeft();
122-
} else if (silverMineral1X == -1) {
123-
silverMineral1X = (int) recognition.getLeft();
124-
} else {
125-
silverMineral2X = (int) recognition.getLeft();
126-
}
127-
}
128-
if (goldMineralX != -1 && silverMineral1X != -1 && silverMineral2X != -1) {
129-
if (goldMineralX < silverMineral1X && goldMineralX < silverMineral2X) {
130-
telemetry.addData("Gold Mineral Position", "Left");
131-
} else if (goldMineralX > silverMineral1X && goldMineralX > silverMineral2X) {
132-
telemetry.addData("Gold Mineral Position", "Right");
133-
} else {
134-
telemetry.addData("Gold Mineral Position", "Center");
135-
}
136-
}
119+
120+
// step through the list of recognitions and display boundary info.
121+
int i = 0;
122+
for (Recognition recognition : updatedRecognitions) {
123+
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
124+
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
125+
recognition.getLeft(), recognition.getTop());
126+
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
127+
recognition.getRight(), recognition.getBottom());
137128
}
138129
telemetry.update();
139130
}
@@ -171,7 +162,8 @@ private void initTfod() {
171162
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
172163
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
173164
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
165+
tfodParameters.minimumConfidence = 0.8;
174166
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
175-
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_GOLD_MINERAL, LABEL_SILVER_MINERAL);
167+
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
176168
}
177169
}

FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/ConceptTensorFlowObjectDetectionWebcam.java

+28-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2018 FIRST. All rights reserved.
1+
/* Copyright (c) 2019 FIRST. All rights reserved.
22
*
33
* Redistribution and use in source and binary forms, with or without modification,
44
* are permitted (subject to the limitations in the disclaimer below) provided that
@@ -40,8 +40,8 @@
4040
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
4141

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

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

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

98+
/**
99+
* Activate TensorFlow Object Detection before we wait for the start command.
100+
* Do it here so that the Camera Stream window will have the TensorFlow annotations visible.
101+
**/
102+
if (tfod != null) {
103+
tfod.activate();
104+
}
105+
97106
/** Wait for the game to begin */
98-
telemetry.addData(">", "Press Play to start tracking");
107+
telemetry.addData(">", "Press Play to start op mode");
99108
telemetry.update();
100109
waitForStart();
101110

102111
if (opModeIsActive()) {
103-
/** Activate TensorFlow Object Detection. */
104-
if (tfod != null) {
105-
tfod.activate();
106-
}
107-
108112
while (opModeIsActive()) {
109113
if (tfod != null) {
110114
// getUpdatedRecognitions() will return null if no new information is available since
111115
// the last time that call was made.
112116
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
113117
if (updatedRecognitions != null) {
114118
telemetry.addData("# Object Detected", updatedRecognitions.size());
115-
if (updatedRecognitions.size() == 3) {
116-
int goldMineralX = -1;
117-
int silverMineral1X = -1;
118-
int silverMineral2X = -1;
119-
for (Recognition recognition : updatedRecognitions) {
120-
if (recognition.getLabel().equals(LABEL_GOLD_MINERAL)) {
121-
goldMineralX = (int) recognition.getLeft();
122-
} else if (silverMineral1X == -1) {
123-
silverMineral1X = (int) recognition.getLeft();
124-
} else {
125-
silverMineral2X = (int) recognition.getLeft();
126-
}
127-
}
128-
if (goldMineralX != -1 && silverMineral1X != -1 && silverMineral2X != -1) {
129-
if (goldMineralX < silverMineral1X && goldMineralX < silverMineral2X) {
130-
telemetry.addData("Gold Mineral Position", "Left");
131-
} else if (goldMineralX > silverMineral1X && goldMineralX > silverMineral2X) {
132-
telemetry.addData("Gold Mineral Position", "Right");
133-
} else {
134-
telemetry.addData("Gold Mineral Position", "Center");
135-
}
136-
}
119+
// step through the list of recognitions and display boundary info.
120+
int i = 0;
121+
for (Recognition recognition : updatedRecognitions) {
122+
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
123+
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
124+
recognition.getLeft(), recognition.getTop());
125+
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
126+
recognition.getRight(), recognition.getBottom());
137127
}
138128
telemetry.update();
139129
}
@@ -171,7 +161,8 @@ private void initTfod() {
171161
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
172162
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
173163
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
174-
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
175-
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_GOLD_MINERAL, LABEL_SILVER_MINERAL);
164+
tfodParameters.minimumConfidence = 0.8;
165+
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
166+
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
176167
}
177168
}

0 commit comments

Comments
 (0)