This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
987 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
112 changes: 112 additions & 0 deletions
112
...main/java/org/firstinspires/ftc/robotcontroller/external/samples/ConceptRevSPARKMini.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* Copyright (c) 2018 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 | ||
* the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this list | ||
* of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
* list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* | ||
* Neither the name of FIRST nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS | ||
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package org.firstinspires.ftc.robotcontroller.external.samples; | ||
|
||
import com.qualcomm.robotcore.eventloop.opmode.Disabled; | ||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; | ||
import com.qualcomm.robotcore.hardware.DcMotorSimple; | ||
import com.qualcomm.robotcore.util.ElapsedTime; | ||
import com.qualcomm.robotcore.util.Range; | ||
|
||
|
||
/** | ||
* | ||
* This OpMode executes a basic Tank Drive Teleop for a two wheeled robot using two REV SPARK Minis. | ||
* To use this example, connect two REV SPARK Minis into servo ports on the Expansion Hub. On the | ||
* robot configuration, use the drop down list under 'Servos' to select 'REV SPARK Mini Controller' | ||
* and name them 'left_drive' and 'right_drive'. | ||
* | ||
* Use Android Studios 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 | ||
*/ | ||
|
||
@TeleOp(name="REV SPARK Mini Simple Drive Example", group="Concept") | ||
@Disabled | ||
public class ConceptRevSPARKMini extends LinearOpMode { | ||
|
||
// Declare OpMode members. | ||
private ElapsedTime runtime = new ElapsedTime(); | ||
private DcMotorSimple leftDrive = null; | ||
private DcMotorSimple rightDrive = null; | ||
|
||
@Override | ||
public void runOpMode() { | ||
telemetry.addData("Status", "Initialized"); | ||
telemetry.update(); | ||
|
||
// Initialize the hardware variables. Note that the strings used here as parameters | ||
// to 'get' must correspond to the names assigned during the robot configuration | ||
// step (using the FTC Robot Controller app on the phone). | ||
leftDrive = hardwareMap.get(DcMotorSimple.class, "left_drive"); | ||
rightDrive = hardwareMap.get(DcMotorSimple.class, "right_drive"); | ||
|
||
// Most robots need the motor on one side to be reversed to drive forward | ||
// Reverse the motor that runs backwards when connected directly to the battery | ||
leftDrive.setDirection(DcMotorSimple.Direction.FORWARD); | ||
rightDrive.setDirection(DcMotorSimple.Direction.REVERSE); | ||
|
||
// Wait for the game to start (driver presses PLAY) | ||
waitForStart(); | ||
runtime.reset(); | ||
|
||
// run until the end of the match (driver presses STOP) | ||
while (opModeIsActive()) { | ||
|
||
// Setup a variable for each drive wheel to save power level for telemetry | ||
double leftPower; | ||
double rightPower; | ||
|
||
// Choose to drive using either Tank Mode, or POV Mode | ||
// Comment out the method that's not used. The default below is POV. | ||
|
||
// POV Mode uses left stick to go forward, and right stick to turn. | ||
// - This uses basic math to combine motions and is easier to drive straight. | ||
double drive = -gamepad1.left_stick_y; | ||
double turn = gamepad1.right_stick_x; | ||
leftPower = Range.clip(drive + turn, -1.0, 1.0) ; | ||
rightPower = Range.clip(drive - turn, -1.0, 1.0) ; | ||
|
||
// Tank Mode uses one stick to control each wheel. | ||
// - This requires no math, but it is hard to drive forward slowly and keep straight. | ||
// leftPower = -gamepad1.left_stick_y ; | ||
// rightPower = -gamepad1.right_stick_y ; | ||
|
||
// Send calculated power to wheels | ||
leftDrive.setPower(leftPower); | ||
rightDrive.setPower(rightPower); | ||
|
||
// Show the elapsed game time and wheel power. | ||
telemetry.addData("Status", "Run Time: " + runtime.toString()); | ||
telemetry.addData("Motors", "left (%.2f), right (%.2f)", leftPower, rightPower); | ||
telemetry.update(); | ||
} | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...main/java/org/firstinspires/ftc/robotcontroller/external/samples/ConceptSoundsASJava.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* Copyright (c) 2018 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 | ||
* the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this list | ||
* of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
* list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* | ||
* Neither the name of FIRST nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS | ||
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package org.firstinspires.ftc.robotcontroller.external.samples; | ||
|
||
import com.qualcomm.ftccommon.SoundPlayer; | ||
import com.qualcomm.robotcore.eventloop.opmode.Disabled; | ||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* This file demonstrates how to play simple sounds on both the RC and DS phones. | ||
* It illustrates how to build sounds into your application as a resource. | ||
* This technique is best suited for use with Android Studio since it assumes you will be creating a new application | ||
* | ||
* If you are using OnBotJava, please see the ConceptSoundsOnBotJava sample | ||
* | ||
* Use Android Studios 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 | ||
* | ||
* Operation: | ||
* | ||
* Gamepad X & B buttons are used to trigger sounds in this example, but any event can be used. | ||
* Note: Time should be allowed for sounds to complete before playing other sounds. | ||
* | ||
* For sound files to be used as a compiled-in resource, they need to be located in a folder called "raw" under your "res" (resources) folder. | ||
* You can create your own "raw" folder from scratch, or you can copy the one from the FtcRobotController module. | ||
* | ||
* Android Studio coders will ultimately need a folder in your path as follows: | ||
* <project root>/TeamCode/src/main/res/raw | ||
* | ||
* Copy any .wav files you want to play into this folder. | ||
* Make sure that your files ONLY use lower-case characters, and have no spaces or special characters other than underscore. | ||
* | ||
* The name you give your .wav files will become the resource ID for these sounds. | ||
* eg: gold.wav becomes R.raw.gold | ||
* | ||
* If you wish to use the sounds provided for this sample, they are located in: | ||
* <project root>/FtcRobotController/src/main/res/raw | ||
* You can copy and paste the entire 'raw' folder using Android Studio. | ||
* | ||
*/ | ||
|
||
@TeleOp(name="Concept: Sound Resources", group="Concept") | ||
@Disabled | ||
public class ConceptSoundsASJava extends LinearOpMode { | ||
|
||
// Declare OpMode members. | ||
private boolean goldFound; // Sound file present flags | ||
private boolean silverFound; | ||
|
||
private boolean isX = false; // Gamepad button state variables | ||
private boolean isB = false; | ||
|
||
private boolean wasX = false; // Gamepad button history variables | ||
private boolean WasB = false; | ||
|
||
@Override | ||
public void runOpMode() { | ||
|
||
// Determine Resource IDs for sounds built into the RC application. | ||
int silverSoundID = hardwareMap.appContext.getResources().getIdentifier("silver", "raw", hardwareMap.appContext.getPackageName()); | ||
int goldSoundID = hardwareMap.appContext.getResources().getIdentifier("gold", "raw", hardwareMap.appContext.getPackageName()); | ||
|
||
// Determine if sound resources are found. | ||
// Note: Preloading is NOT required, but it's a good way to verify all your sounds are available before you run. | ||
if (goldSoundID != 0) | ||
goldFound = SoundPlayer.getInstance().preload(hardwareMap.appContext, goldSoundID); | ||
|
||
if (silverSoundID != 0) | ||
silverFound = SoundPlayer.getInstance().preload(hardwareMap.appContext, silverSoundID); | ||
|
||
// Display sound status | ||
telemetry.addData("gold resource", goldFound ? "Found" : "NOT found\n Add gold.wav to /src/main/res/raw" ); | ||
telemetry.addData("silver resource", silverFound ? "Found" : "Not found\n Add silver.wav to /src/main/res/raw" ); | ||
|
||
// Wait for the game to start (driver presses PLAY) | ||
telemetry.addData(">", "Press Start to continue"); | ||
telemetry.update(); | ||
waitForStart(); | ||
|
||
telemetry.addData(">", "Press X, B to play sounds."); | ||
telemetry.update(); | ||
|
||
// run until the end of the match (driver presses STOP) | ||
while (opModeIsActive()) { | ||
|
||
// say Silver each time gamepad X is pressed (This sound is a resource) | ||
if (silverFound && (isX = gamepad1.x) && !wasX) { | ||
SoundPlayer.getInstance().startPlaying(hardwareMap.appContext, silverSoundID); | ||
telemetry.addData("Playing", "Resource Silver"); | ||
telemetry.update(); | ||
} | ||
|
||
// say Gold each time gamepad B is pressed (This sound is a resource) | ||
if (goldFound && (isB = gamepad1.b) && !WasB) { | ||
SoundPlayer.getInstance().startPlaying(hardwareMap.appContext, goldSoundID); | ||
telemetry.addData("Playing", "Resource Gold"); | ||
telemetry.update(); | ||
} | ||
|
||
// Save last button states | ||
wasX = isX; | ||
WasB = isB; | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...n/java/org/firstinspires/ftc/robotcontroller/external/samples/ConceptSoundsOnBotJava.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* Copyright (c) 2018 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 | ||
* the following conditions are met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, this list | ||
* of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
* list of conditions and the following disclaimer in the documentation and/or | ||
* other materials provided with the distribution. | ||
* | ||
* Neither the name of FIRST nor the names of its contributors may be used to endorse or | ||
* promote products derived from this software without specific prior written permission. | ||
* | ||
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS | ||
* LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package org.firstinspires.ftc.robotcontroller.external.samples; | ||
|
||
import com.qualcomm.ftccommon.SoundPlayer; | ||
import com.qualcomm.robotcore.eventloop.opmode.Disabled; | ||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode; | ||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp; | ||
import java.io.File; | ||
|
||
/** | ||
* This file demonstrates how to play simple sounds on both the RC and DS phones. | ||
* It illustrates how to play sound files that have been copied to the RC Phone | ||
* This technique is best suited for use with OnBotJava since it does not require the app to be modified. | ||
* | ||
* Operation: | ||
* | ||
* Gamepad X & B buttons are used to trigger sounds in this example, but any event can be used. | ||
* Note: Time should be allowed for sounds to complete before playing other sounds. | ||
* | ||
* To play a new sound, you will need to copy the .wav files to the phone, and then provide the full path to them as part of your OpMode. | ||
* This is done in this sample for the two sound files. silver.wav and gold.wav | ||
* | ||
* You can put the files in a variety of soundPaths, but we recommend you put them in the /FIRST/blocks/sounds folder. | ||
* Your OpModes will have guaranteed access to this folder, and you can transfer files into this folder using the BLOCKS web page. | ||
* -- There is a link called "sounds" on the right hand side of the color bar on the BLOCKS page that can be used to send sound files to this folder by default. | ||
* Or you can use Windows File Manager, or ADB to transfer the sound files | ||
* | ||
* To get full use of THIS sample, you will need to copy two sound file called silver.wav and gold.wav to /FIRST/blocks/sounds on the RC phone. | ||
* They can be located here: | ||
* https://github.com/ftctechnh/ftc_app/tree/master/FtcRobotController/src/main/res/raw/gold.wav | ||
* https://github.com/ftctechnh/ftc_app/tree/master/FtcRobotController/src/main/res/raw/silver.wav | ||
*/ | ||
|
||
@TeleOp(name="Concept: Sound Files", group="Concept") | ||
@Disabled | ||
public class ConceptSoundsOnBotJava extends LinearOpMode { | ||
|
||
// Point to sound files on the phone's drive | ||
private String soundPath = "/FIRST/blocks/sounds"; | ||
private File goldFile = new File("/sdcard" + soundPath + "/gold.wav"); | ||
private File silverFile = new File("/sdcard" + soundPath + "/silver.wav"); | ||
|
||
// Declare OpMode members. | ||
private boolean isX = false; // Gamepad button state variables | ||
private boolean isB = false; | ||
|
||
private boolean wasX = false; // Gamepad button history variables | ||
private boolean WasB = false; | ||
|
||
@Override | ||
public void runOpMode() { | ||
|
||
// Make sure that the sound files exist on the phone | ||
boolean goldFound = goldFile.exists(); | ||
boolean silverFound = silverFile.exists(); | ||
|
||
// Display sound status | ||
telemetry.addData("gold sound", goldFound ? "Found" : "NOT Found \nCopy gold.wav to " + soundPath ); | ||
telemetry.addData("silver sound", silverFound ? "Found" : "NOT Found \nCopy silver.wav to " + soundPath ); | ||
|
||
// Wait for the game to start (driver presses PLAY) | ||
telemetry.addData(">", "Press Start to continue"); | ||
telemetry.update(); | ||
waitForStart(); | ||
|
||
telemetry.addData(">", "Press X or B to play sounds."); | ||
telemetry.update(); | ||
|
||
// run until the end of the match (driver presses STOP) | ||
while (opModeIsActive()) { | ||
|
||
// say Silver each time gamepad X is pressed (This sound is a resource) | ||
if (silverFound && (isX = gamepad1.x) && !wasX) { | ||
SoundPlayer.getInstance().startPlaying(hardwareMap.appContext, silverFile); | ||
telemetry.addData("Playing", "Silver File"); | ||
telemetry.update(); | ||
} | ||
|
||
// say Gold each time gamepad B is pressed (This sound is a resource) | ||
if (goldFound && (isB = gamepad1.b) && !WasB) { | ||
SoundPlayer.getInstance().startPlaying(hardwareMap.appContext, goldFile); | ||
telemetry.addData("Playing", "Gold File"); | ||
telemetry.update(); | ||
} | ||
|
||
// Save last button states | ||
wasX = isX; | ||
WasB = isB; | ||
} | ||
} | ||
} |
Oops, something went wrong.