Skip to content

Commit c05584b

Browse files
authored
Merge pull request FIRST-Tech-Challenge#22 from FIRST-Tech-Challenge/v5.1
SkyStone v5.1
2 parents cc40cce + 4b1491d commit c05584b

File tree

115 files changed

+15512
-258
lines changed

Some content is hidden

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

115 files changed

+15512
-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="32"
6-
android:versionName="5.0">
5+
android:versionCode="33"
6+
android:versionName="5.1">
77

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939

4040
/**
4141
*
42-
* This OpMode executes a basic Tank Drive Teleop for a two wheeled robot using two REV SPARK Minis.
43-
* To use this example, connect two REV SPARK Minis into servo ports on the Expansion Hub. On the
44-
* robot configuration, use the drop down list under 'Servos' to select 'REV SPARK Mini Controller'
42+
* This OpMode executes a basic Tank Drive Teleop for a two wheeled robot using two REV SPARKminis.
43+
* To use this example, connect two REV SPARKminis into servo ports on the Expansion Hub. On the
44+
* robot configuration, use the drop down list under 'Servos' to select 'REV SPARKmini Controller'
4545
* and name them 'left_drive' and 'right_drive'.
4646
*
4747
* Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
4848
* Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list
4949
*/
5050

51-
@TeleOp(name="REV SPARK Mini Simple Drive Example", group="Concept")
51+
@TeleOp(name="REV SPARKmini Simple Drive Example", group="Concept")
5252
@Disabled
5353
public class ConceptRevSPARKMini extends LinearOpMode {
5454

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/* Copyright (c) 2018 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 android.content.Context;
33+
34+
import com.qualcomm.ftccommon.SoundPlayer;
35+
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
36+
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
37+
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
38+
39+
/**
40+
* This file demonstrates how to play one of the several SKYSTONE/Star Wars sounds loaded into the SDK.
41+
* It does this by creating a simple "chooser" controlled by the gamepad Up Down buttons.
42+
* This code also prevents sounds from stacking up by setting a "playing" flag, which is cleared when the sound finishes playing.
43+
*
44+
* Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
45+
* Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list
46+
*
47+
* Operation:
48+
* Use the DPAD to change the selected sound, and the Right Bumper to play it.
49+
*/
50+
51+
@TeleOp(name="SKYSTONE Sounds", group="Concept")
52+
@Disabled
53+
public class ConceptSoundsSKYSTONE extends LinearOpMode {
54+
55+
// List of available sound resources
56+
String sounds[] = {"ss_alarm", "ss_bb8_down", "ss_bb8_up", "ss_darth_vader", "ss_fly_by",
57+
"ss_mf_fail", "ss_laser", "ss_laser_burst", "ss_light_saber", "ss_light_saber_long", "ss_light_saber_short",
58+
"ss_light_speed", "ss_mine", "ss_power_up", "ss_r2d2_up", "ss_roger_roger", "ss_siren", "ss_wookie" };
59+
boolean soundPlaying = false;
60+
61+
@Override
62+
public void runOpMode() {
63+
64+
// Variables for choosing from the available sounds
65+
int soundIndex = 0;
66+
int soundID = -1;
67+
boolean was_dpad_up = false;
68+
boolean was_dpad_down = false;
69+
70+
Context myApp = hardwareMap.appContext;
71+
72+
// create a sound parameter that holds the desired player parameters.
73+
SoundPlayer.PlaySoundParams params = new SoundPlayer.PlaySoundParams();
74+
params.loopControl = 0;
75+
params.waitForNonLoopingSoundsToFinish = true;
76+
77+
// In this sample, we will skip waiting for the user to press play, and start displaying sound choices right away
78+
while (!isStopRequested()) {
79+
80+
// Look for DPAD presses to change the selection
81+
if (gamepad1.dpad_down && !was_dpad_down) {
82+
// Go to next sound (with list wrap) and display it
83+
soundIndex = (soundIndex + 1) % sounds.length;
84+
}
85+
86+
if (gamepad1.dpad_up && !was_dpad_up) {
87+
// Go to previous sound (with list wrap) and display it
88+
soundIndex = (soundIndex + sounds.length - 1) % sounds.length;
89+
}
90+
91+
// Look for trigger to see if we should play sound
92+
// Only start a new sound if we are currently not playing one.
93+
if (gamepad1.right_bumper && !soundPlaying) {
94+
95+
// Determine Resource IDs for the sounds you want to play, and make sure it's valid.
96+
if ((soundID = myApp.getResources().getIdentifier(sounds[soundIndex], "raw", myApp.getPackageName())) != 0){
97+
98+
// Signal that the sound is now playing.
99+
soundPlaying = true;
100+
101+
// Start playing, and also Create a callback that will clear the playing flag when the sound is complete.
102+
SoundPlayer.getInstance().startPlaying(myApp, soundID, params, null,
103+
new Runnable() {
104+
public void run() {
105+
soundPlaying = false;
106+
}} );
107+
}
108+
}
109+
110+
// Remember the last state of the dpad to detect changes.
111+
was_dpad_up = gamepad1.dpad_up;
112+
was_dpad_down = gamepad1.dpad_down;
113+
114+
// Display the current sound choice, and the playing status.
115+
telemetry.addData("", "Use DPAD up/down to choose sound.");
116+
telemetry.addData("", "Press Right Bumper to play sound.");
117+
telemetry.addData("", "");
118+
telemetry.addData("Sound >", sounds[soundIndex]);
119+
telemetry.addData("Status >", soundPlaying ? "Playing" : "Stopped");
120+
telemetry.update();
121+
}
122+
}
123+
}

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,22 @@ public class SensorREVColorDistance extends LinearOpMode {
5858

5959
/**
6060
* Note that the REV Robotics Color-Distance incorporates two sensors into one device.
61-
* It has a light/distance (range) sensor. It also has an RGB color sensor.
62-
* The light/distance sensor saturates at around 2" (5cm). This means that targets that are 2"
61+
* It has an IR proximity sensor which is used to calculate distance and an RGB color sensor.
62+
*
63+
* There will be some variation in the values measured depending on whether you are using a
64+
* V3 color sensor versus the older V2 and V1 sensors, as the V3 is based around a different chip.
65+
*
66+
* For V1/V2, the light/distance sensor saturates at around 2" (5cm). This means that targets that are 2"
6367
* or closer will display the same value for distance/light detected.
6468
*
69+
* For V3, the distance sensor as configured can handle distances between 0.25" (~0.6cm) and 6" (~15cm).
70+
* Any target closer than 0.25" will dislay as 0.25" and any target farther than 6" will display as 6".
71+
*
72+
* Note that the distance sensor function of both chips is built around an IR proximity sensor, which is
73+
* sensitive to ambient light and the reflectivity of the surface against which you are measuring. If
74+
* very accurate distance is required you should consider calibrating the raw optical values read from the
75+
* chip to your exact situation.
76+
*
6577
* Although you configure a single REV Robotics Color-Distance sensor in your configuration file,
6678
* you can treat the sensor as two separate sensors that share the same name in your op mode.
6779
*
@@ -70,7 +82,7 @@ public class SensorREVColorDistance extends LinearOpMode {
7082
* color of the screen to match the detected color.
7183
*
7284
* In this example, we also use the distance sensor to display the distance
73-
* to the target object. Note that the distance sensor saturates at around 2" (5 cm).
85+
* to the target object.
7486
*
7587
*/
7688
ColorSensor sensorColor;

FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/internal/FtcRobotControllerActivity.java

+30-5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
8888
import com.qualcomm.robotcore.eventloop.opmode.OpModeRegister;
8989
import com.qualcomm.robotcore.hardware.configuration.LynxConstants;
9090
import com.qualcomm.robotcore.hardware.configuration.Utility;
91+
import com.qualcomm.robotcore.robot.Robot;
92+
import com.qualcomm.robotcore.robot.RobotState;
9193
import com.qualcomm.robotcore.util.Device;
9294
import com.qualcomm.robotcore.util.Dimmer;
9395
import com.qualcomm.robotcore.util.ImmersiveMode;
@@ -100,7 +102,6 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
100102
import org.firstinspires.ftc.ftccommon.external.SoundPlayingRobotMonitor;
101103
import org.firstinspires.ftc.ftccommon.internal.FtcRobotControllerWatchdogService;
102104
import org.firstinspires.ftc.ftccommon.internal.ProgramAndManageActivity;
103-
import org.firstinspires.ftc.onbotjava.OnBotJavaClassLoader;
104105
import org.firstinspires.ftc.onbotjava.OnBotJavaHelperImpl;
105106
import org.firstinspires.ftc.onbotjava.OnBotJavaProgrammingMode;
106107
import org.firstinspires.ftc.robotcore.external.navigation.MotionDetection;
@@ -544,6 +545,26 @@ public boolean onCreateOptionsMenu(Menu menu) {
544545
return true;
545546
}
546547

548+
private boolean isRobotRunning() {
549+
if (controllerService == null) {
550+
return false;
551+
}
552+
553+
Robot robot = controllerService.getRobot();
554+
555+
if ((robot == null) || (robot.eventLoopManager == null)) {
556+
return false;
557+
}
558+
559+
RobotState robotState = robot.eventLoopManager.state;
560+
561+
if (robotState != RobotState.RUNNING) {
562+
return false;
563+
} else {
564+
return true;
565+
}
566+
}
567+
547568
@Override
548569
public boolean onOptionsItemSelected(MenuItem item) {
549570
int id = item.getItemId();
@@ -562,10 +583,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
562583
}
563584
return true;
564585
} else if (id == R.id.action_program_and_manage) {
565-
Intent programmingModeIntent = new Intent(AppUtil.getDefContext(), ProgramAndManageActivity.class);
566-
RobotControllerWebInfo webInfo = programmingModeManager.getWebServer().getConnectionInformation();
567-
programmingModeIntent.putExtra(LaunchActivityConstantsList.RC_WEB_INFO, webInfo.toJson());
568-
startActivity(programmingModeIntent);
586+
if (isRobotRunning()) {
587+
Intent programmingModeIntent = new Intent(AppUtil.getDefContext(), ProgramAndManageActivity.class);
588+
RobotControllerWebInfo webInfo = programmingModeManager.getWebServer().getConnectionInformation();
589+
programmingModeIntent.putExtra(LaunchActivityConstantsList.RC_WEB_INFO, webInfo.toJson());
590+
startActivity(programmingModeIntent);
591+
} else {
592+
AppUtil.getInstance().showToast(UILocation.ONLY_LOCAL, context.getString(R.string.toastWifiUpBeforeProgrammingMode));
593+
}
569594
} else if (id == R.id.action_inspection_mode) {
570595
Intent inspectionModeIntent = new Intent(AppUtil.getDefContext(), RcInspectionActivity.class);
571596
startActivity(inspectionModeIntent);

FtcRobotController/src/main/res/values/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5555
<string name="toastWifiConfigurationComplete">Configuration Complete</string>
5656
<string name="toastRestartingRobot">Restarting Robot</string>
5757
<string name="toastConfigureRobotBeforeProgrammingMode">You must Configure Robot before starting Programming Mode.</string>
58+
<string name="toastWifiUpBeforeProgrammingMode">The Robot Controller must be fully up and running before starting Programming Mode. Is Wifi turned on in settings?</string>
5859

5960
<!-- for interpreting pref_app_theme contents. may be override in merged resources -->
6061
<integer-array name="app_theme_ids">

0 commit comments

Comments
 (0)