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

Commit b8ebf98

Browse files
authored
Merge pull request #261 from FIRST-Tech-Challenge/20200824-090813-release-candidate
SkyStone v5.5
2 parents 27239cc + ba4c97d commit b8ebf98

File tree

425 files changed

+791
-163780
lines changed

Some content is hidden

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

425 files changed

+791
-163780
lines changed

FtcRobotController/build.gradle

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import java.text.SimpleDateFormat
2+
13
//
24
// build.gradle in FtcRobotController
35
//
@@ -6,8 +8,9 @@ apply plugin: 'com.android.library'
68
android {
79

810
defaultConfig {
9-
minSdkVersion 19
11+
minSdkVersion 23
1012
targetSdkVersion 28
13+
buildConfigField "String", "BUILD_TIME", '"' + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ROOT).format(new Date())) + '"'
1114
}
1215

1316
compileSdkVersion 28
@@ -19,6 +22,8 @@ android {
1922
}
2023

2124
repositories {
25+
maven { url = "https://dl.bintray.com/first-tech-challenge/ftcsdk/" }
26+
2227
flatDir {
2328
dirs '../libs'
2429
}
+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
dependencies {
2-
implementation (name:'Inspection-release', ext: 'aar')
3-
implementation (name:'Blocks-release', ext: 'aar')
4-
implementation (name:'RobotCore-release', ext: 'aar')
5-
implementation (name:'RobotServer-release', ext: 'aar')
6-
implementation (name:'OnBotJava-release', ext: 'aar')
7-
implementation (name:'Hardware-release', ext: 'aar')
8-
implementation (name:'FtcCommon-release', ext: 'aar')
2+
implementation 'org.firstinspires.ftc:Inspection:5.5'
3+
implementation 'org.firstinspires.ftc:Blocks:5.5'
4+
implementation 'org.firstinspires.ftc:RobotCore:5.5'
5+
implementation 'org.firstinspires.ftc:RobotServer:5.5'
6+
implementation 'org.firstinspires.ftc:OnBotJava:5.5'
7+
implementation 'org.firstinspires.ftc:Hardware:5.5'
8+
implementation 'org.firstinspires.ftc:FtcCommon:5.5'
99
implementation (name:'WirelessP2p-release', ext:'aar')
10-
implementation 'com.android.support:support-compat:28.0.0'
10+
implementation 'androidx.appcompat:appcompat:1.2.0'
1111
}

FtcRobotController/src/main/AndroidManifest.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
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="36"
6-
android:versionName="5.4">
5+
android:versionCode="37"
6+
android:versionName="5.5">
77

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

1010
<application
1111
android:allowBackup="true"
1212
android:largeHeap="true"
13+
android:extractNativeLibs="true"
1314
android:icon="@drawable/ic_launcher"
1415
android:label="@string/app_name"
1516
android:theme="@style/AppThemeRedRC" >
@@ -61,4 +62,4 @@
6162

6263
</application>
6364

64-
</manifest>
65+
</manifest>

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ public void runOpMode() {
8888
// The TFObjectDetector uses the camera frames from the VuforiaLocalizer, so we create that
8989
// first.
9090
initVuforia();
91-
92-
if (ClassFactory.getInstance().canCreateTFObjectDetector()) {
93-
initTfod();
94-
} else {
95-
telemetry.addData("Sorry!", "This device is not compatible with TFOD");
96-
}
91+
initTfod();
9792

9893
/**
9994
* Activate TensorFlow Object Detection before we wait for the start command.
@@ -162,7 +157,7 @@ private void initTfod() {
162157
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
163158
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
164159
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
165-
tfodParameters.minimumConfidence = 0.8;
160+
tfodParameters.minResultConfidence = 0.8f;
166161
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
167162
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
168163
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/* Copyright (c) 2020 FIRST. All rights reserved.
2+
*
3+
* Redistribution and use in source and binary forms, with or without modification,
4+
* are permitted (subject to the limitations in the disclaimer below) provided that
5+
* the following conditions are met:
6+
*
7+
* Redistributions of source code must retain the above copyright notice, this list
8+
* of conditions and the following disclaimer.
9+
*
10+
* Redistributions in binary form must reproduce the above copyright notice, this
11+
* list of conditions and the following disclaimer in the documentation and/or
12+
* other materials provided with the distribution.
13+
*
14+
* Neither the name of FIRST nor the names of its contributors may be used to endorse or
15+
* promote products derived from this software without specific prior written permission.
16+
*
17+
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
18+
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20+
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
package org.firstinspires.ftc.robotcontroller.external.samples;
31+
32+
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
33+
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
34+
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
35+
import java.util.List;
36+
import org.firstinspires.ftc.robotcore.external.ClassFactory;
37+
import org.firstinspires.ftc.robotcore.external.hardware.camera.SwitchableCamera;
38+
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
39+
import org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer;
40+
import org.firstinspires.ftc.robotcore.external.tfod.TFObjectDetector;
41+
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
42+
43+
/**
44+
* This 2019-2020 OpMode illustrates the basics of using the TensorFlow Object Detection API to
45+
* determine the position of the Skystone game elements.
46+
*
47+
* Use Android Studio to Copy this Class, and Paste it into your team's code folder with a new name.
48+
* Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list.
49+
*
50+
* IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
51+
* is explained below.
52+
*/
53+
@TeleOp(name = "Concept: TensorFlow Object Detection Switchable Cameras", group = "Concept")
54+
@Disabled
55+
public class ConceptTensorFlowObjectDetectionSwitchableCameras extends LinearOpMode {
56+
private static final String TFOD_MODEL_ASSET = "Skystone.tflite";
57+
private static final String LABEL_FIRST_ELEMENT = "Stone";
58+
private static final String LABEL_SECOND_ELEMENT = "Skystone";
59+
60+
/*
61+
* IMPORTANT: You need to obtain your own license key to use Vuforia. The string below with which
62+
* 'parameters.vuforiaLicenseKey' is initialized is for illustration only, and will not function.
63+
* A Vuforia 'Development' license key, can be obtained free of charge from the Vuforia developer
64+
* web site at https://developer.vuforia.com/license-manager.
65+
*
66+
* Vuforia license keys are always 380 characters long, and look as if they contain mostly
67+
* random data. As an example, here is a example of a fragment of a valid key:
68+
* ... yIgIzTqZ4mWjk9wd3cZO9T1axEqzuhxoGlfOOI2dRzKS4T0hQ8kT ...
69+
* Once you've obtained a license key, copy the string from the Vuforia web site
70+
* and paste it in to your code on the next line, between the double quotes.
71+
*/
72+
private static final String VUFORIA_KEY =
73+
" -- YOUR NEW VUFORIA KEY GOES HERE --- ";
74+
75+
/**
76+
* {@link #vuforia} is the variable we will use to store our instance of the Vuforia
77+
* localization engine.
78+
*/
79+
private VuforiaLocalizer vuforia;
80+
81+
/**
82+
* Variables used for switching cameras.
83+
*/
84+
private WebcamName webcam1, webcam2;
85+
private SwitchableCamera switchableCamera;
86+
private boolean oldLeftBumper;
87+
private boolean oldRightBumper;
88+
89+
/**
90+
* {@link #tfod} is the variable we will use to store our instance of the TensorFlow Object
91+
* Detection engine.
92+
*/
93+
private TFObjectDetector tfod;
94+
95+
@Override
96+
public void runOpMode() {
97+
// The TFObjectDetector uses the camera frames from the VuforiaLocalizer, so we create that
98+
// first.
99+
initVuforia();
100+
initTfod();
101+
102+
/**
103+
* Activate TensorFlow Object Detection before we wait for the start command.
104+
* Do it here so that the Camera Stream window will have the TensorFlow annotations visible.
105+
**/
106+
if (tfod != null) {
107+
tfod.activate();
108+
}
109+
110+
/** Wait for the game to begin */
111+
telemetry.addData(">", "Press Play to start op mode");
112+
telemetry.update();
113+
waitForStart();
114+
115+
if (opModeIsActive()) {
116+
while (opModeIsActive()) {
117+
if (tfod != null) {
118+
doCameraSwitching();
119+
List<Recognition> recognitions = tfod.getRecognitions();
120+
telemetry.addData("# Object Detected", recognitions.size());
121+
// step through the list of recognitions and display boundary info.
122+
int i = 0;
123+
for (Recognition recognition : recognitions) {
124+
telemetry.addData(String.format("label (%d)", i), recognition.getLabel());
125+
telemetry.addData(String.format(" left,top (%d)", i), "%.03f , %.03f",
126+
recognition.getLeft(), recognition.getTop());
127+
telemetry.addData(String.format(" right,bottom (%d)", i), "%.03f , %.03f",
128+
recognition.getRight(), recognition.getBottom());
129+
}
130+
telemetry.update();
131+
}
132+
}
133+
}
134+
135+
if (tfod != null) {
136+
tfod.shutdown();
137+
}
138+
}
139+
140+
/**
141+
* Initialize the Vuforia localization engine.
142+
*/
143+
private void initVuforia() {
144+
/*
145+
* Configure Vuforia by creating a Parameter object, and passing it to the Vuforia engine.
146+
*/
147+
VuforiaLocalizer.Parameters parameters = new VuforiaLocalizer.Parameters();
148+
149+
parameters.vuforiaLicenseKey = VUFORIA_KEY;
150+
151+
// Indicate that we wish to be able to switch cameras.
152+
webcam1 = hardwareMap.get(WebcamName.class, "Webcam 1");
153+
webcam2 = hardwareMap.get(WebcamName.class, "Webcam 2");
154+
parameters.cameraName = ClassFactory.getInstance().getCameraManager().nameForSwitchableCamera(webcam1, webcam2);
155+
156+
// Instantiate the Vuforia engine
157+
vuforia = ClassFactory.getInstance().createVuforia(parameters);
158+
159+
// Set the active camera to Webcam 1.
160+
switchableCamera = (SwitchableCamera) vuforia.getCamera();
161+
switchableCamera.setActiveCamera(webcam1);
162+
163+
// Loading trackables is not necessary for the TensorFlow Object Detection engine.
164+
}
165+
166+
/**
167+
* Initialize the TensorFlow Object Detection engine.
168+
*/
169+
private void initTfod() {
170+
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
171+
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
172+
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
173+
tfodParameters.minResultConfidence = 0.8f;
174+
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
175+
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
176+
}
177+
178+
private void doCameraSwitching() {
179+
// If the left bumper is pressed, use Webcam 1.
180+
// If the right bumper is pressed, use Webcam 2.
181+
boolean newLeftBumper = gamepad1.left_bumper;
182+
boolean newRightBumper = gamepad1.right_bumper;
183+
if (newLeftBumper && !oldLeftBumper) {
184+
switchableCamera.setActiveCamera(webcam1);
185+
} else if (newRightBumper && !oldRightBumper) {
186+
switchableCamera.setActiveCamera(webcam2);
187+
}
188+
oldLeftBumper = newLeftBumper;
189+
oldRightBumper = newRightBumper;
190+
191+
if (switchableCamera.getActiveCamera().equals(webcam1)) {
192+
telemetry.addData("activeCamera", "Webcam 1");
193+
telemetry.addData("Press RightBumper", "to switch to Webcam 2");
194+
} else {
195+
telemetry.addData("activeCamera", "Webcam 2");
196+
telemetry.addData("Press LeftBumper", "to switch to Webcam 1");
197+
}
198+
}
199+
}

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,7 @@ public void runOpMode() {
8888
// The TFObjectDetector uses the camera frames from the VuforiaLocalizer, so we create that
8989
// first.
9090
initVuforia();
91-
92-
if (ClassFactory.getInstance().canCreateTFObjectDetector()) {
93-
initTfod();
94-
} else {
95-
telemetry.addData("Sorry!", "This device is not compatible with TFOD");
96-
}
91+
initTfod();
9792

9893
/**
9994
* Activate TensorFlow Object Detection before we wait for the start command.
@@ -161,7 +156,7 @@ private void initTfod() {
161156
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
162157
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
163158
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
164-
tfodParameters.minimumConfidence = 0.8;
159+
tfodParameters.minResultConfidence = 0.8f;
165160
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
166161
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABEL_FIRST_ELEMENT, LABEL_SECOND_ELEMENT);
167162
}

0 commit comments

Comments
 (0)