Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
2390680ce6 | |||
e0282fcbd3 | |||
aba72e566c | |||
fe758edbd4 | |||
e945da24e6 | |||
439a5bf491 |
@ -20,6 +20,7 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
targetCompatibility JavaVersion.VERSION_1_7
|
||||
}
|
||||
namespace = 'com.qualcomm.ftcrobotcontroller'
|
||||
}
|
||||
|
||||
apply from: '../build.dependencies.gradle'
|
||||
|
@ -1,16 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.qualcomm.ftcrobotcontroller"
|
||||
android:versionCode="42"
|
||||
android:versionName="7.0">
|
||||
android:versionCode="47"
|
||||
android:versionName="8.0">
|
||||
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:largeHeap="true"
|
||||
android:extractNativeLibs="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppThemeRedRC"
|
||||
|
0
FtcRobotController/src/main/assets/qcar_config.xsd
Normal file
0
FtcRobotController/src/main/assets/qcar_config.xsd
Normal file
@ -0,0 +1,167 @@
|
||||
/* Copyright (c) 2021 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.DcMotor;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
/**
|
||||
* This file contains an example of a Linear "OpMode".
|
||||
* An OpMode is a 'program' that runs in either the autonomous or the teleop period of an FTC match.
|
||||
* The names of OpModes appear on the menu of the FTC Driver Station.
|
||||
* When a selection is made from the menu, the corresponding OpMode is executed.
|
||||
*
|
||||
* This particular OpMode illustrates driving a 4-motor Omni-Directional (or Holonomic) robot.
|
||||
* This code will work with either a Mecanum-Drive or an X-Drive train.
|
||||
* Both of these drives are illustrated at https://gm0.org/en/latest/docs/robot-design/drivetrains/holonomic.html
|
||||
* Note that a Mecanum drive must display an X roller-pattern when viewed from above.
|
||||
*
|
||||
* Also note that it is critical to set the correct rotation direction for each motor. See details below.
|
||||
*
|
||||
* Holonomic drives provide the ability for the robot to move in three axes (directions) simultaneously.
|
||||
* Each motion axis is controlled by one Joystick axis.
|
||||
*
|
||||
* 1) Axial: Driving forward and backward Left-joystick Forward/Backward
|
||||
* 2) Lateral: Strafing right and left Left-joystick Right and Left
|
||||
* 3) Yaw: Rotating Clockwise and counter clockwise Right-joystick Right and Left
|
||||
*
|
||||
* This code is written assuming that the right-side motors need to be reversed for the robot to drive forward.
|
||||
* When you first test your robot, if it moves backward when you push the left stick forward, then you must flip
|
||||
* the direction of all 4 motors (see code below).
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@TeleOp(name="Basic: Omni Linear OpMode", group="Linear Opmode")
|
||||
@Disabled
|
||||
public class BasicOmniOpMode_Linear extends LinearOpMode {
|
||||
|
||||
// Declare OpMode members for each of the 4 motors.
|
||||
private ElapsedTime runtime = new ElapsedTime();
|
||||
private DcMotor leftFrontDrive = null;
|
||||
private DcMotor leftBackDrive = null;
|
||||
private DcMotor rightFrontDrive = null;
|
||||
private DcMotor rightBackDrive = null;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// Initialize the hardware variables. Note that the strings used here must correspond
|
||||
// to the names assigned during the robot configuration step on the DS or RC devices.
|
||||
leftFrontDrive = hardwareMap.get(DcMotor.class, "left_front_drive");
|
||||
leftBackDrive = hardwareMap.get(DcMotor.class, "left_back_drive");
|
||||
rightFrontDrive = hardwareMap.get(DcMotor.class, "right_front_drive");
|
||||
rightBackDrive = hardwareMap.get(DcMotor.class, "right_back_drive");
|
||||
|
||||
// ########################################################################################
|
||||
// !!! IMPORTANT Drive Information. Test your motor directions. !!!!!
|
||||
// ########################################################################################
|
||||
// Most robots need the motors on one side to be reversed to drive forward.
|
||||
// The motor reversals shown here are for a "direct drive" robot (the wheels turn the same direction as the motor shaft)
|
||||
// If your robot has additional gear reductions or uses a right-angled drive, it's important to ensure
|
||||
// that your motors are turning in the correct direction. So, start out with the reversals here, BUT
|
||||
// when you first test your robot, push the left joystick forward and observe the direction the wheels turn.
|
||||
// Reverse the direction (flip FORWARD <-> REVERSE ) of any wheel that runs backward
|
||||
// Keep testing until ALL the wheels move the robot forward when you push the left joystick forward.
|
||||
leftFrontDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
leftBackDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightFrontDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
rightBackDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// Wait for the game to start (driver presses PLAY)
|
||||
telemetry.addData("Status", "Initialized");
|
||||
telemetry.update();
|
||||
|
||||
waitForStart();
|
||||
runtime.reset();
|
||||
|
||||
// run until the end of the match (driver presses STOP)
|
||||
while (opModeIsActive()) {
|
||||
double max;
|
||||
|
||||
// POV Mode uses left joystick to go forward & strafe, and right joystick to rotate.
|
||||
double axial = -gamepad1.left_stick_y; // Note: pushing stick forward gives negative value
|
||||
double lateral = gamepad1.left_stick_x;
|
||||
double yaw = gamepad1.right_stick_x;
|
||||
|
||||
// Combine the joystick requests for each axis-motion to determine each wheel's power.
|
||||
// Set up a variable for each drive wheel to save the power level for telemetry.
|
||||
double leftFrontPower = axial + lateral + yaw;
|
||||
double rightFrontPower = axial - lateral - yaw;
|
||||
double leftBackPower = axial - lateral + yaw;
|
||||
double rightBackPower = axial + lateral - yaw;
|
||||
|
||||
// Normalize the values so no wheel power exceeds 100%
|
||||
// This ensures that the robot maintains the desired motion.
|
||||
max = Math.max(Math.abs(leftFrontPower), Math.abs(rightFrontPower));
|
||||
max = Math.max(max, Math.abs(leftBackPower));
|
||||
max = Math.max(max, Math.abs(rightBackPower));
|
||||
|
||||
if (max > 1.0) {
|
||||
leftFrontPower /= max;
|
||||
rightFrontPower /= max;
|
||||
leftBackPower /= max;
|
||||
rightBackPower /= max;
|
||||
}
|
||||
|
||||
// This is test code:
|
||||
//
|
||||
// Uncomment the following code to test your motor directions.
|
||||
// Each button should make the corresponding motor run FORWARD.
|
||||
// 1) First get all the motors to take to correct positions on the robot
|
||||
// by adjusting your Robot Configuration if necessary.
|
||||
// 2) Then make sure they run in the correct direction by modifying the
|
||||
// the setDirection() calls above.
|
||||
// Once the correct motors move in the correct direction re-comment this code.
|
||||
|
||||
/*
|
||||
leftFrontPower = gamepad1.x ? 1.0 : 0.0; // X gamepad
|
||||
leftBackPower = gamepad1.a ? 1.0 : 0.0; // A gamepad
|
||||
rightFrontPower = gamepad1.y ? 1.0 : 0.0; // Y gamepad
|
||||
rightBackPower = gamepad1.b ? 1.0 : 0.0; // B gamepad
|
||||
*/
|
||||
|
||||
// Send calculated power to wheels
|
||||
leftFrontDrive.setPower(leftFrontPower);
|
||||
rightFrontDrive.setPower(rightFrontPower);
|
||||
leftBackDrive.setPower(leftBackPower);
|
||||
rightBackDrive.setPower(rightBackPower);
|
||||
|
||||
// Show the elapsed game time and wheel power.
|
||||
telemetry.addData("Status", "Run Time: " + runtime.toString());
|
||||
telemetry.addData("Front left/Right", "%4.2f, %4.2f", leftFrontPower, rightFrontPower);
|
||||
telemetry.addData("Back left/Right", "%4.2f, %4.2f", leftBackPower, rightBackPower);
|
||||
telemetry.update();
|
||||
}
|
||||
}}
|
@ -40,13 +40,13 @@ import com.qualcomm.robotcore.util.Range;
|
||||
* This file contains an example of an iterative (Non-Linear) "OpMode".
|
||||
* An OpMode is a 'program' that runs in either the autonomous or the teleop period of an FTC match.
|
||||
* The names of OpModes appear on the menu of the FTC Driver Station.
|
||||
* When an selection is made from the menu, the corresponding OpMode
|
||||
* When a selection is made from the menu, the corresponding OpMode
|
||||
* class is instantiated on the Robot Controller and executed.
|
||||
*
|
||||
* This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot
|
||||
* It includes all the skeletal structure that all iterative OpModes contain.
|
||||
*
|
||||
* Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@ -72,10 +72,11 @@ public class BasicOpMode_Iterative extends OpMode
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.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(DcMotor.Direction.FORWARD);
|
||||
rightDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// Tell the driver that initialization is complete.
|
||||
telemetry.addData("Status", "Initialized");
|
||||
|
@ -40,13 +40,13 @@ import com.qualcomm.robotcore.util.Range;
|
||||
/**
|
||||
* This file contains an minimal example of a Linear "OpMode". An OpMode is a 'program' that runs in either
|
||||
* the autonomous or the teleop period of an FTC match. The names of OpModes appear on the menu
|
||||
* of the FTC Driver Station. When an selection is made from the menu, the corresponding OpMode
|
||||
* of the FTC Driver Station. When a selection is made from the menu, the corresponding OpMode
|
||||
* class is instantiated on the Robot Controller and executed.
|
||||
*
|
||||
* This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot
|
||||
* It includes all the skeletal structure that all linear OpModes contain.
|
||||
*
|
||||
* Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@ -70,10 +70,11 @@ public class BasicOpMode_Linear extends LinearOpMode {
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.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(DcMotor.Direction.FORWARD);
|
||||
rightDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// Wait for the game to start (driver presses PLAY)
|
||||
waitForStart();
|
||||
|
@ -33,13 +33,11 @@ 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.CompassSensor;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of calibrating a MR Compass
|
||||
* It uses the common Pushbot hardware class to define the drive on the robot.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* This code assumes there is a compass configured with the name "compass"
|
||||
*
|
||||
* This code will put the compass into calibration mode, wait three seconds and then attempt
|
||||
@ -57,7 +55,8 @@ import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
public class ConceptCompassCalibration extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // Use a Pushbot's hardware
|
||||
public DcMotor leftDrive = null;
|
||||
public DcMotor rightDrive = null;
|
||||
private ElapsedTime runtime = new ElapsedTime();
|
||||
CompassSensor compass;
|
||||
|
||||
@ -68,10 +67,15 @@ public class ConceptCompassCalibration extends LinearOpMode {
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
/* Initialize the drive system variables.
|
||||
* The init() method of the hardware class does all the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
// Initialize the drive system variables.
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// get a reference to our Compass Sensor object.
|
||||
compass = hardwareMap.get(CompassSensor.class, "compass");
|
||||
@ -93,8 +97,8 @@ public class ConceptCompassCalibration extends LinearOpMode {
|
||||
// Start the robot rotating clockwise
|
||||
telemetry.addData("Compass", "Calibration mode. Turning the robot...");
|
||||
telemetry.update();
|
||||
robot.leftDrive.setPower(MOTOR_POWER);
|
||||
robot.rightDrive.setPower(-MOTOR_POWER);
|
||||
leftDrive.setPower(MOTOR_POWER);
|
||||
rightDrive.setPower(-MOTOR_POWER);
|
||||
|
||||
// run until time expires OR the driver presses STOP;
|
||||
runtime.reset();
|
||||
@ -103,8 +107,8 @@ public class ConceptCompassCalibration extends LinearOpMode {
|
||||
}
|
||||
|
||||
// Stop all motors and turn off claibration
|
||||
robot.leftDrive.setPower(0);
|
||||
robot.rightDrive.setPower(0);
|
||||
leftDrive.setPower(0);
|
||||
rightDrive.setPower(0);
|
||||
compass.setMode(CompassSensor.CompassMode.MEASUREMENT_MODE);
|
||||
telemetry.addData("Compass", "Returning to measurement mode");
|
||||
telemetry.update();
|
||||
|
@ -1,103 +0,0 @@
|
||||
/* Copyright (c) 2017 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.DeviceInterfaceModule;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
/**
|
||||
* This OpMode illustrates using the Device Interface Module as a signalling device.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* This code assumes a DIM name "dim".
|
||||
*
|
||||
* There are many examples where the robot might like to signal the driver, without requiring them
|
||||
* to look at the driver station. This might be something like a "ball in hopper" condition or a
|
||||
* "ready to shoot" condition.
|
||||
*
|
||||
* The DIM has two user settable indicator LEDs (one red one blue). These can be controlled
|
||||
* directly from your program.
|
||||
*
|
||||
* 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 = "Concept: DIM As Indicator", group = "Concept")
|
||||
@Disabled
|
||||
public class ConceptDIMAsIndicator extends LinearOpMode {
|
||||
|
||||
static final int BLUE_LED = 0; // Blue LED channel on DIM
|
||||
static final int RED_LED = 1; // Red LED Channel on DIM
|
||||
|
||||
// Create timer to toggle LEDs
|
||||
private ElapsedTime runtime = new ElapsedTime();
|
||||
|
||||
// Define class members
|
||||
DeviceInterfaceModule dim;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// Connect to motor (Assume standard left wheel)
|
||||
// Change the text in quotes to match any motor name on your robot.
|
||||
dim = hardwareMap.get(DeviceInterfaceModule.class, "dim");
|
||||
|
||||
// Toggle LEDs while Waiting for the start button
|
||||
telemetry.addData(">", "Press Play to test LEDs." );
|
||||
telemetry.update();
|
||||
|
||||
while (!isStarted()) {
|
||||
// Determine if we are on an odd or even second
|
||||
boolean even = (((int)(runtime.time()) & 0x01) == 0);
|
||||
dim.setLED(RED_LED, even); // Red for even
|
||||
dim.setLED(BLUE_LED, !even); // Blue for odd
|
||||
idle();
|
||||
}
|
||||
|
||||
// Running now
|
||||
telemetry.addData(">", "Press X for Blue, B for Red." );
|
||||
telemetry.update();
|
||||
|
||||
// Now just use red and blue buttons to set red and blue LEDs
|
||||
while(opModeIsActive()){
|
||||
dim.setLED(BLUE_LED, gamepad1.x);
|
||||
dim.setLED(RED_LED, gamepad1.b);
|
||||
idle();
|
||||
}
|
||||
|
||||
// Turn off LEDs;
|
||||
dim.setLED(BLUE_LED, false);
|
||||
dim.setLED(RED_LED, false);
|
||||
telemetry.addData(">", "Done");
|
||||
telemetry.update();
|
||||
}
|
||||
}
|
@ -0,0 +1,142 @@
|
||||
/* Copyright (c) 2022 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.util.Range;
|
||||
|
||||
/**
|
||||
* This OpMode Sample illustrates how to use an external "hardware" class to modularize all the robot's sensors and actuators.
|
||||
* This approach is very efficient because the same hardware class can be used by all of your teleop and autonomous OpModes
|
||||
* without requiring many copy & paste operations. Once you have defined and tested the hardware class with one OpMode,
|
||||
* it is instantly available to other OpModes.
|
||||
*
|
||||
* The real benefit of this approach is that as you tweak your robot hardware, you only need to make changes in ONE place (the Hardware Class).
|
||||
* So, to be effective you should put as much or your hardware setup and access code as possible in the hardware class.
|
||||
* Essentially anything you do with hardware in BOTH Teleop and Auto should likely go in the hardware class.
|
||||
*
|
||||
* The Hardware Class is created in a separate file, and then an "instance" of this class is created in each OpMode.
|
||||
* In order for the class to do typical OpMode things (like send telemetry data) it must be passed a reference to the
|
||||
* OpMode object when it's created, so it can access all core OpMode functions. This is illustrated below.
|
||||
*
|
||||
* In this concept sample, the hardware class file is called RobotHardware.java and it must accompany this sample OpMode.
|
||||
* So, if you copy ConceptExternalHardwareClass.java into TeamCode (using Android Studio or OnBotJava) then RobotHardware.java
|
||||
* must also be copied to the same location (maintaining its name).
|
||||
*
|
||||
* For comparison purposes, this sample and its accompanying hardware class duplicates the functionality of the
|
||||
* RobotTelopPOV_Linear opmode. It assumes three motors (left_drive, right_drive and arm) and two servos (left_hand and right_hand)
|
||||
*
|
||||
* View the RobotHardware.java class file for more details
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* In OnBot Java, add a new OpMode, drawing from this Sample; select TeleOp.
|
||||
* Also add another new file named RobotHardware.java, drawing from the Sample with that name; select Not an OpMode.
|
||||
*/
|
||||
|
||||
@TeleOp(name="Concept: Robot Hardware Class", group="Robot")
|
||||
@Disabled
|
||||
public class ConceptExternalHardwareClass extends LinearOpMode {
|
||||
|
||||
// Create a RobotHardware object to be used to access robot hardware.
|
||||
// Prefix any hardware functions with "robot." to access this class.
|
||||
RobotHardware robot = new RobotHardware(this);
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
double drive = 0;
|
||||
double turn = 0;
|
||||
double arm = 0;
|
||||
double handOffset = 0;
|
||||
|
||||
// initialize all the hardware, using the hardware class. See how clean and simple this is?
|
||||
robot.init();
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
// Wait for the game to start (driver presses PLAY)
|
||||
waitForStart();
|
||||
|
||||
// run until the end of the match (driver presses STOP)
|
||||
while (opModeIsActive()) {
|
||||
|
||||
// Run wheels in POV mode (note: The joystick goes negative when pushed forward, so negate it)
|
||||
// In this mode the Left stick moves the robot fwd and back, the Right stick turns left and right.
|
||||
// This way it's also easy to just drive straight, or just turn.
|
||||
drive = -gamepad1.left_stick_y;
|
||||
turn = gamepad1.right_stick_x;
|
||||
|
||||
// Combine drive and turn for blended motion. Use RobotHardware class
|
||||
robot.driveRobot(drive, turn);
|
||||
|
||||
// Use gamepad left & right Bumpers to open and close the claw
|
||||
// Use the SERVO constants defined in RobotHardware class.
|
||||
// Each time around the loop, the servos will move by a small amount.
|
||||
// Limit the total offset to half of the full travel range
|
||||
if (gamepad1.right_bumper)
|
||||
handOffset += robot.HAND_SPEED;
|
||||
else if (gamepad1.left_bumper)
|
||||
handOffset -= robot.HAND_SPEED;
|
||||
handOffset = Range.clip(handOffset, -0.5, 0.5);
|
||||
|
||||
// Move both servos to new position. Use RobotHardware class
|
||||
robot.setHandPositions(handOffset);
|
||||
|
||||
// Use gamepad buttons to move arm up (Y) and down (A)
|
||||
// Use the MOTOR constants defined in RobotHardware class.
|
||||
if (gamepad1.y)
|
||||
arm = robot.ARM_UP_POWER;
|
||||
else if (gamepad1.a)
|
||||
arm = robot.ARM_DOWN_POWER;
|
||||
else
|
||||
arm = 0;
|
||||
|
||||
robot.setArmPower(arm);
|
||||
|
||||
// Send telemetry messages to explain controls and show robot status
|
||||
telemetry.addData("Drive", "Left Stick");
|
||||
telemetry.addData("Turn", "Right Stick");
|
||||
telemetry.addData("Arm Up/Down", "Y & A Buttons");
|
||||
telemetry.addData("Hand Open/Closed", "Left and Right Bumpers");
|
||||
telemetry.addData("-", "-------");
|
||||
|
||||
telemetry.addData("Drive Power", "%.2f", drive);
|
||||
telemetry.addData("Turn Power", "%.2f", turn);
|
||||
telemetry.addData("Arm Power", "%.2f", arm);
|
||||
telemetry.addData("Hand Position", "Offset = %.2f", handOffset);
|
||||
telemetry.update();
|
||||
|
||||
// Pace this loop so hands move at a reasonable speed.
|
||||
sleep(50);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,223 +0,0 @@
|
||||
/* Copyright (c) 2017 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.hardware.modernrobotics.ModernRoboticsUsbDeviceInterfaceModule;
|
||||
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.DeviceInterfaceModule;
|
||||
import com.qualcomm.robotcore.hardware.I2cAddr;
|
||||
import com.qualcomm.robotcore.util.RobotLog;
|
||||
import com.qualcomm.robotcore.util.TypeConversion;
|
||||
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
||||
/**
|
||||
* An example of a linear op mode that shows how to change the I2C address.
|
||||
*/
|
||||
@TeleOp(name = "Concept: I2c Address Change", group = "Concept")
|
||||
@Disabled
|
||||
public class ConceptI2cAddressChange extends LinearOpMode {
|
||||
|
||||
public static final int ADDRESS_SET_NEW_I2C_ADDRESS = 0x70;
|
||||
// trigger bytes used to change I2C address on ModernRobotics sensors.
|
||||
public static final byte TRIGGER_BYTE_1 = 0x55;
|
||||
public static final byte TRIGGER_BYTE_2 = (byte) 0xaa;
|
||||
|
||||
// Expected bytes from the Modern Robotics IR Seeker V3 memory map
|
||||
public static final byte IR_SEEKER_V3_FIRMWARE_REV = 0x12;
|
||||
public static final byte IR_SEEKER_V3_SENSOR_ID = 0x49;
|
||||
public static final I2cAddr IR_SEEKER_V3_ORIGINAL_ADDRESS = I2cAddr.create8bit(0x38);
|
||||
|
||||
// Expected bytes from the Modern Robotics Color Sensor memory map
|
||||
public static final byte COLOR_SENSOR_FIRMWARE_REV = 0x10;
|
||||
public static final byte COLOR_SENSOR_SENSOR_ID = 0x43;
|
||||
public static final byte COLOR_SENSOR_ORIGINAL_ADDRESS = 0x3C;
|
||||
|
||||
public static final byte MANUFACTURER_CODE = 0x4d;
|
||||
// Currently, this is set to expect the bytes from the IR Seeker.
|
||||
// If you change these values so you're setting "FIRMWARE_REV" to
|
||||
// COLOR_SENSOR_FIRMWARE_REV, and "SENSOR_ID" to "COLOR_SENSOR_SENSOR_ID",
|
||||
// you'll be able to change the I2C address of the ModernRoboticsColorSensor.
|
||||
// If the bytes you're expecting are different than what this op mode finds,
|
||||
// a comparison will be printed out into the logfile.
|
||||
public static final byte FIRMWARE_REV = IR_SEEKER_V3_FIRMWARE_REV;
|
||||
public static final byte SENSOR_ID = IR_SEEKER_V3_SENSOR_ID;
|
||||
|
||||
// These byte values are common with most Modern Robotics sensors.
|
||||
public static final int READ_MODE = 0x80;
|
||||
public static final int ADDRESS_MEMORY_START = 0x0;
|
||||
public static final int TOTAL_MEMORY_LENGTH = 0x0c;
|
||||
public static final int BUFFER_CHANGE_ADDRESS_LENGTH = 0x03;
|
||||
|
||||
// The port where your sensor is connected.
|
||||
int port = 5;
|
||||
|
||||
byte[] readCache;
|
||||
Lock readLock;
|
||||
byte[] writeCache;
|
||||
Lock writeLock;
|
||||
|
||||
I2cAddr currentAddress = IR_SEEKER_V3_ORIGINAL_ADDRESS;
|
||||
// I2c addresses on Modern Robotics devices must be divisible by 2, and between 0x7e and 0x10
|
||||
// Different hardware may have different rules.
|
||||
// Be sure to read the requirements for the hardware you're using!
|
||||
// If you use an invalid address, you may make your device completely unusable.
|
||||
I2cAddr newAddress = I2cAddr.create8bit(0x42);
|
||||
|
||||
DeviceInterfaceModule dim;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// set up the hardware devices we are going to use
|
||||
dim = hardwareMap.get(DeviceInterfaceModule.class, "dim");
|
||||
|
||||
readCache = dim.getI2cReadCache(port);
|
||||
readLock = dim.getI2cReadCacheLock(port);
|
||||
writeCache = dim.getI2cWriteCache(port);
|
||||
writeLock = dim.getI2cWriteCacheLock(port);
|
||||
|
||||
// I2c addresses on Modern Robotics devices must be divisible by 2, and between 0x7e and 0x10
|
||||
// Different hardware may have different rules.
|
||||
// Be sure to read the requirements for the hardware you're using!
|
||||
ModernRoboticsUsbDeviceInterfaceModule.throwIfModernRoboticsI2cAddressIsInvalid(newAddress);
|
||||
|
||||
// wait for the start button to be pressed
|
||||
waitForStart();
|
||||
|
||||
performAction("read", port, currentAddress, ADDRESS_MEMORY_START, TOTAL_MEMORY_LENGTH);
|
||||
|
||||
while(!dim.isI2cPortReady(port)) {
|
||||
telemetry.addData("I2cAddressChange", "waiting for the port to be ready...");
|
||||
telemetry.update();
|
||||
sleep(1000);
|
||||
}
|
||||
|
||||
// update the local cache
|
||||
dim.readI2cCacheFromController(port);
|
||||
|
||||
// make sure the first bytes are what we think they should be.
|
||||
int count = 0;
|
||||
int[] initialArray = {READ_MODE, currentAddress.get8Bit(), ADDRESS_MEMORY_START, TOTAL_MEMORY_LENGTH, FIRMWARE_REV, MANUFACTURER_CODE, SENSOR_ID};
|
||||
while (!foundExpectedBytes(initialArray, readLock, readCache)) {
|
||||
telemetry.addData("I2cAddressChange", "Confirming that we're reading the correct bytes...");
|
||||
telemetry.update();
|
||||
dim.readI2cCacheFromController(port);
|
||||
sleep(1000);
|
||||
count++;
|
||||
// if we go too long with failure, we probably are expecting the wrong bytes.
|
||||
if (count >= 10) {
|
||||
telemetry.addData("I2cAddressChange", String.format("Looping too long with no change, probably have the wrong address. Current address: 8bit=0x%02x", currentAddress.get8Bit()));
|
||||
hardwareMap.irSeekerSensor.get(String.format("Looping too long with no change, probably have the wrong address. Current address: 8bit=0x%02x", currentAddress.get8Bit()));
|
||||
telemetry.update();
|
||||
}
|
||||
}
|
||||
|
||||
// Enable writes to the correct segment of the memory map.
|
||||
performAction("write", port, currentAddress, ADDRESS_SET_NEW_I2C_ADDRESS, BUFFER_CHANGE_ADDRESS_LENGTH);
|
||||
|
||||
// Write out the trigger bytes, and the new desired address.
|
||||
writeNewAddress();
|
||||
dim.setI2cPortActionFlag(port);
|
||||
dim.writeI2cCacheToController(port);
|
||||
|
||||
telemetry.addData("I2cAddressChange", "Giving the hardware 60 seconds to make the change...");
|
||||
telemetry.update();
|
||||
|
||||
// Changing the I2C address takes some time.
|
||||
sleep(60000);
|
||||
|
||||
// Query the new address and see if we can get the bytes we expect.
|
||||
dim.enableI2cReadMode(port, newAddress, ADDRESS_MEMORY_START, TOTAL_MEMORY_LENGTH);
|
||||
dim.setI2cPortActionFlag(port);
|
||||
dim.writeI2cCacheToController(port);
|
||||
|
||||
int[] confirmArray = {READ_MODE, newAddress.get8Bit(), ADDRESS_MEMORY_START, TOTAL_MEMORY_LENGTH, FIRMWARE_REV, MANUFACTURER_CODE, SENSOR_ID};
|
||||
while (!foundExpectedBytes(confirmArray, readLock, readCache)) {
|
||||
telemetry.addData("I2cAddressChange", "Have not confirmed the changes yet...");
|
||||
telemetry.update();
|
||||
dim.readI2cCacheFromController(port);
|
||||
sleep(1000);
|
||||
}
|
||||
|
||||
telemetry.addData("I2cAddressChange", "Successfully changed the I2C address. New address: 8bit=0x%02x", newAddress.get8Bit());
|
||||
telemetry.update();
|
||||
RobotLog.i("Successfully changed the I2C address." + String.format("New address: 8bit=0x%02x", newAddress.get8Bit()));
|
||||
|
||||
/**** IMPORTANT NOTE ******/
|
||||
// You need to add a line like this at the top of your op mode
|
||||
// to update the I2cAddress in the driver.
|
||||
//irSeeker.setI2cAddress(newAddress);
|
||||
/***************************/
|
||||
|
||||
}
|
||||
|
||||
private boolean foundExpectedBytes(int[] byteArray, Lock lock, byte[] cache) {
|
||||
try {
|
||||
lock.lock();
|
||||
boolean allMatch = true;
|
||||
StringBuilder s = new StringBuilder(300 * 4);
|
||||
String mismatch = "";
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
s.append(String.format("expected: %02x, got: %02x \n", TypeConversion.unsignedByteToInt( (byte) byteArray[i]), cache[i]));
|
||||
if (TypeConversion.unsignedByteToInt(cache[i]) != TypeConversion.unsignedByteToInt( (byte) byteArray[i])) {
|
||||
mismatch = String.format("i: %d, byteArray[i]: %02x, cache[i]: %02x", i, byteArray[i], cache[i]);
|
||||
allMatch = false;
|
||||
}
|
||||
}
|
||||
RobotLog.e(s.toString() + "\n allMatch: " + allMatch + ", mismatch: " + mismatch);
|
||||
return allMatch;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private void performAction(String actionName, int port, I2cAddr i2cAddress, int memAddress, int memLength) {
|
||||
if (actionName.equalsIgnoreCase("read")) dim.enableI2cReadMode(port, i2cAddress, memAddress, memLength);
|
||||
if (actionName.equalsIgnoreCase("write")) dim.enableI2cWriteMode(port, i2cAddress, memAddress, memLength);
|
||||
|
||||
dim.setI2cPortActionFlag(port);
|
||||
dim.writeI2cCacheToController(port);
|
||||
dim.readI2cCacheFromController(port);
|
||||
}
|
||||
|
||||
private void writeNewAddress() {
|
||||
try {
|
||||
writeLock.lock();
|
||||
writeCache[4] = (byte) newAddress.get8Bit();
|
||||
writeCache[5] = TRIGGER_BYTE_1;
|
||||
writeCache[6] = TRIGGER_BYTE_2;
|
||||
} finally {
|
||||
writeLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
@ -46,21 +46,28 @@ import java.util.List;
|
||||
|
||||
Three scenarios are tested:
|
||||
Cache Mode = OFF This is the normal default, where no cache is used, and every read produces a discrete transaction with
|
||||
an expansion hub, which is the slowest approach.
|
||||
an expansion hub, which is the slowest approach, but guarentees that the value is as fresh (recent) as possible..
|
||||
|
||||
Cache Mode = AUTO This mode will attempt to minimize the number of discrete read commands, by performing bulk-reads
|
||||
and then returning values that have been cached. The cache is updated automatically whenever a specific read operation is repeated.
|
||||
This mode will always return fresh data, but it may perform more bulk-reads than absolutely required.
|
||||
Extra reads will be performed if multiple identical encoder/velocity reads are performed in one control cycle.
|
||||
and then returning values that have been cached. The cache is updated automatically whenever any specific encoder is re-read.
|
||||
This mode will always return new data, but it may perform more bulk-reads than absolutely required.
|
||||
Extra reads will be performed if multiple encoder/velocity reads are performed on the same encoder in one control cycle.
|
||||
This mode is a good compromise between the OFF and MANUAL modes.
|
||||
Cache Mode = MANUAL This mode enables the user's code to determine the best time to refresh the cached bulk-read data.
|
||||
Well organized code can place all the sensor reads in one location, and then just reset the cache once per control cycle.
|
||||
The approach will produce the shortest cycle times, but it does require the user to manually clear the cache.
|
||||
Note: If there are significant user-program delays between encoder reads, the cached value may not be fresh (recent).
|
||||
You can issue a clearBulkCache() call at any time force a fresh bulk-read on the next encoder read.
|
||||
|
||||
Cache Mode = MANUAL This mode requires the user's code to determine the best time to clear the cached bulk-read data.
|
||||
Well organized code will reset the cache once at the beginning of the control cycle, and then immediately read and store all the encoder values.
|
||||
This approach will produce the shortest cycle times, but it does require the user to manually clear the cache.
|
||||
Since NO automatic Bulk-Reads are performed, neglecting to clear the bulk cache will result in the same values being returned
|
||||
each time an encoder read is performed.
|
||||
|
||||
-------------------------------------
|
||||
|
||||
General tip to speed up your control cycles:
|
||||
|
||||
No matter what method you use to read encoders and other inputs, you should try to
|
||||
avoid reading the same input multiple times around a control loop.
|
||||
avoid reading the same encoder input multiple times around a control loop.
|
||||
Under normal conditions, this will slow down the control loop.
|
||||
The preferred method is to read all the required inputs ONCE at the beginning of the loop,
|
||||
and save the values in variable that can be used by other parts of the control code.
|
||||
|
@ -38,7 +38,7 @@ import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
* This OpMode ramps a single motor speed up and down repeatedly until Stop is pressed.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* This code assumes a DC motor configured with the name "left_drive" as is found on a pushbot.
|
||||
* This code assumes a DC motor configured with the name "left_drive" as is found on a Robot.
|
||||
*
|
||||
* INCREMENT sets how much to increase/decrease the power each cycle
|
||||
* CYCLE_MS sets the update period.
|
||||
|
@ -44,8 +44,8 @@ import com.qualcomm.robotcore.util.Range;
|
||||
* robot configuration, use the drop down list under 'Servos' to select 'REV SPARKmini 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
|
||||
* 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
|
||||
*/
|
||||
|
||||
@TeleOp(name="REV SPARKmini Simple Drive Example", group="Concept")
|
||||
@ -69,7 +69,7 @@ public class ConceptRevSPARKMini extends LinearOpMode {
|
||||
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
|
||||
// Reverse the motor that runs backward when connected directly to the battery
|
||||
leftDrive.setDirection(DcMotorSimple.Direction.FORWARD);
|
||||
rightDrive.setDirection(DcMotorSimple.Direction.REVERSE);
|
||||
|
||||
|
@ -35,12 +35,12 @@ import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
|
||||
/**
|
||||
* This OpMode scans a single servo back and forwards until Stop is pressed.
|
||||
* This OpMode scans a single servo back and forward until Stop is pressed.
|
||||
* The code is structured as a LinearOpMode
|
||||
* INCREMENT sets how much to increase/decrease the servo position each cycle
|
||||
* CYCLE_MS sets the update period.
|
||||
*
|
||||
* This code assumes a Servo configured with the name "left_hand" as is found on a pushbot.
|
||||
* This code assumes a Servo configured with the name "left_hand" as is found on a Robot.
|
||||
*
|
||||
* NOTE: When any servo position is set, ALL attached servos are activated, so ensure that any other
|
||||
* connected servos are able to move freely before running this test.
|
||||
@ -66,7 +66,7 @@ public class ConceptScanServo extends LinearOpMode {
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// Connect to servo (Assume PushBot Left Hand)
|
||||
// Connect to servo (Assume Robot Left Hand)
|
||||
// Change the text in quotes to match any servo name on your robot.
|
||||
servo = hardwareMap.get(Servo.class, "left_hand");
|
||||
|
||||
|
@ -43,7 +43,7 @@ import java.io.File;
|
||||
*
|
||||
* 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.
|
||||
* 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
|
||||
*
|
||||
* Operation:
|
||||
|
@ -41,8 +41,8 @@ import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
* It does this by creating a simple "chooser" controlled by the gamepad Up Down buttons.
|
||||
* This code also prevents sounds from stacking up by setting a "playing" flag, which is cleared when the sound finishes playing.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
*
|
||||
* Operation:
|
||||
* Use the DPAD to change the selected sound, and the Right Bumper to play it.
|
||||
|
@ -40,11 +40,11 @@ import org.firstinspires.ftc.robotcore.external.tfod.TFObjectDetector;
|
||||
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
|
||||
/**
|
||||
* This 2020-2021 OpMode illustrates the basics of using the TensorFlow Object Detection API to
|
||||
* determine the position of the Freight Frenzy game elements.
|
||||
* This 2022-2023 OpMode illustrates the basics of using the TensorFlow Object Detection API to
|
||||
* determine which image is being presented to the robot.
|
||||
*
|
||||
* 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.
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list.
|
||||
*
|
||||
* IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
|
||||
* is explained below.
|
||||
@ -52,23 +52,21 @@ import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
@TeleOp(name = "Concept: TensorFlow Object Detection", group = "Concept")
|
||||
@Disabled
|
||||
public class ConceptTensorFlowObjectDetection extends LinearOpMode {
|
||||
/* Note: This sample uses the all-objects Tensor Flow model (FreightFrenzy_BCDM.tflite), which contains
|
||||
* the following 4 detectable objects
|
||||
* 0: Ball,
|
||||
* 1: Cube,
|
||||
* 2: Duck,
|
||||
* 3: Marker (duck location tape marker)
|
||||
*
|
||||
* Two additional model assets are available which only contain a subset of the objects:
|
||||
* FreightFrenzy_BC.tflite 0: Ball, 1: Cube
|
||||
* FreightFrenzy_DM.tflite 0: Duck, 1: Marker
|
||||
*/
|
||||
private static final String TFOD_MODEL_ASSET = "FreightFrenzy_BCDM.tflite";
|
||||
|
||||
/*
|
||||
* Specify the source for the Tensor Flow Model.
|
||||
* If the TensorFlowLite object model is included in the Robot Controller App as an "asset",
|
||||
* the OpMode must to load it using loadModelFromAsset(). However, if a team generated model
|
||||
* has been downloaded to the Robot Controller's SD FLASH memory, it must to be loaded using loadModelFromFile()
|
||||
* Here we assume it's an Asset. Also see method initTfod() below .
|
||||
*/
|
||||
private static final String TFOD_MODEL_ASSET = "PowerPlay.tflite";
|
||||
// private static final String TFOD_MODEL_FILE = "/sdcard/FIRST/tflitemodels/CustomTeamModel.tflite";
|
||||
|
||||
private static final String[] LABELS = {
|
||||
"Ball",
|
||||
"Cube",
|
||||
"Duck",
|
||||
"Marker"
|
||||
"1 Bolt",
|
||||
"2 Bulb",
|
||||
"3 Panel"
|
||||
};
|
||||
|
||||
/*
|
||||
@ -114,11 +112,11 @@ public class ConceptTensorFlowObjectDetection extends LinearOpMode {
|
||||
|
||||
// The TensorFlow software will scale the input images from the camera to a lower resolution.
|
||||
// This can result in lower detection accuracy at longer distances (> 55cm or 22").
|
||||
// If your target is at distance greater than 50 cm (20") you can adjust the magnification value
|
||||
// If your target is at distance greater than 50 cm (20") you can increase the magnification value
|
||||
// to artificially zoom in to the center of image. For best results, the "aspectRatio" argument
|
||||
// should be set to the value of the images used to create the TensorFlow Object Detection model
|
||||
// (typically 16/9).
|
||||
tfod.setZoom(2.5, 16.0/9.0);
|
||||
tfod.setZoom(1.0, 16.0/9.0);
|
||||
}
|
||||
|
||||
/** Wait for the game to begin */
|
||||
@ -133,19 +131,22 @@ public class ConceptTensorFlowObjectDetection extends LinearOpMode {
|
||||
// the last time that call was made.
|
||||
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
|
||||
if (updatedRecognitions != null) {
|
||||
telemetry.addData("# Object Detected", updatedRecognitions.size());
|
||||
telemetry.addData("# Objects Detected", updatedRecognitions.size());
|
||||
|
||||
// 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());
|
||||
i++;
|
||||
}
|
||||
telemetry.update();
|
||||
// step through the list of recognitions and display image position/size information for each one
|
||||
// Note: "Image number" refers to the randomized image orientation/number
|
||||
for (Recognition recognition : updatedRecognitions) {
|
||||
double col = (recognition.getLeft() + recognition.getRight()) / 2 ;
|
||||
double row = (recognition.getTop() + recognition.getBottom()) / 2 ;
|
||||
double width = Math.abs(recognition.getRight() - recognition.getLeft()) ;
|
||||
double height = Math.abs(recognition.getTop() - recognition.getBottom()) ;
|
||||
|
||||
telemetry.addData(""," ");
|
||||
telemetry.addData("Image", "%s (%.0f %% Conf.)", recognition.getLabel(), recognition.getConfidence() * 100 );
|
||||
telemetry.addData("- Position (Row/Col)","%.0f / %.0f", row, col);
|
||||
telemetry.addData("- Size (Width/Height)","%.0f / %.0f", width, height);
|
||||
}
|
||||
telemetry.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,8 +167,6 @@ public class ConceptTensorFlowObjectDetection extends LinearOpMode {
|
||||
|
||||
// Instantiate the Vuforia engine
|
||||
vuforia = ClassFactory.getInstance().createVuforia(parameters);
|
||||
|
||||
// Loading trackables is not necessary for the TensorFlow Object Detection engine.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -177,10 +176,14 @@ public class ConceptTensorFlowObjectDetection extends LinearOpMode {
|
||||
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
|
||||
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
|
||||
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
|
||||
tfodParameters.minResultConfidence = 0.8f;
|
||||
tfodParameters.minResultConfidence = 0.75f;
|
||||
tfodParameters.isModelTensorFlow2 = true;
|
||||
tfodParameters.inputSize = 320;
|
||||
tfodParameters.inputSize = 300;
|
||||
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
|
||||
|
||||
// Use loadModelFromAsset() if the TF Model is built in as an asset by Android Studio
|
||||
// Use loadModelFromFile() if you have downloaded a custom team model to the Robot Controller's FLASH.
|
||||
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABELS);
|
||||
// tfod.loadModelFromFile(TFOD_MODEL_FILE, LABELS);
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ import org.firstinspires.ftc.robotcore.external.tfod.TFObjectDetector;
|
||||
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
|
||||
/**
|
||||
* This 2020-2021 OpMode illustrates the basics of using the TensorFlow Object Detection API to
|
||||
* determine the position of the Freight Frenzy game elements.
|
||||
* This 2022-2023 OpMode illustrates the basics of using the TensorFlow Object Detection API to
|
||||
* determine which image is being presented to the robot.
|
||||
*
|
||||
* 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.
|
||||
@ -53,23 +53,21 @@ import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
@TeleOp(name = "Concept: TensorFlow Object Detection Switchable Cameras", group = "Concept")
|
||||
@Disabled
|
||||
public class ConceptTensorFlowObjectDetectionSwitchableCameras extends LinearOpMode {
|
||||
/* Note: This sample uses the all-objects Tensor Flow model (FreightFrenzy_BCDM.tflite), which contains
|
||||
* the following 4 detectable objects
|
||||
* 0: Ball,
|
||||
* 1: Cube,
|
||||
* 2: Duck,
|
||||
* 3: Marker (duck location tape marker)
|
||||
*
|
||||
* Two additional model assets are available which only contain a subset of the objects:
|
||||
* FreightFrenzy_BC.tflite 0: Ball, 1: Cube
|
||||
* FreightFrenzy_DM.tflite 0: Duck, 1: Marker
|
||||
*/
|
||||
private static final String TFOD_MODEL_ASSET = "FreightFrenzy_BCDM.tflite";
|
||||
|
||||
/*
|
||||
* Specify the source for the Tensor Flow Model.
|
||||
* If the TensorFlowLite object model is included in the Robot Controller App as an "asset",
|
||||
* the OpMode must to load it using loadModelFromAsset(). However, if a team generated model
|
||||
* has been downloaded to the Robot Controller's SD FLASH memory, it must to be loaded using loadModelFromFile()
|
||||
* Here we assume it's an Asset. Also see method initTfod() below .
|
||||
*/
|
||||
private static final String TFOD_MODEL_ASSET = "PowerPlay.tflite";
|
||||
// private static final String TFOD_MODEL_FILE = "/sdcard/FIRST/tflitemodels/CustomTeamModel.tflite";
|
||||
|
||||
private static final String[] LABELS = {
|
||||
"Ball",
|
||||
"Cube",
|
||||
"Duck",
|
||||
"Marker"
|
||||
"1 Bolt",
|
||||
"2 Bulb",
|
||||
"3 Panel"
|
||||
};
|
||||
|
||||
/*
|
||||
@ -123,11 +121,11 @@ public class ConceptTensorFlowObjectDetectionSwitchableCameras extends LinearOpM
|
||||
|
||||
// The TensorFlow software will scale the input images from the camera to a lower resolution.
|
||||
// This can result in lower detection accuracy at longer distances (> 55cm or 22").
|
||||
// If your target is at distance greater than 50 cm (20") you can adjust the magnification value
|
||||
// If your target is at distance greater than 50 cm (20") you can increase the magnification value
|
||||
// to artificially zoom in to the center of image. For best results, the "aspectRatio" argument
|
||||
// should be set to the value of the images used to create the TensorFlow Object Detection model
|
||||
// (typically 16/9).
|
||||
tfod.setZoom(2.5, 16.0/9.0);
|
||||
tfod.setZoom(1.0, 16.0/9.0);
|
||||
}
|
||||
|
||||
/** Wait for the game to begin */
|
||||
@ -140,16 +138,19 @@ public class ConceptTensorFlowObjectDetectionSwitchableCameras extends LinearOpM
|
||||
if (tfod != null) {
|
||||
doCameraSwitching();
|
||||
List<Recognition> recognitions = tfod.getRecognitions();
|
||||
telemetry.addData("# Object Detected", recognitions.size());
|
||||
// step through the list of recognitions and display boundary info.
|
||||
int i = 0;
|
||||
telemetry.addData("# Objects Detected", recognitions.size());
|
||||
// step through the list of recognitions and display image size and position
|
||||
// Note: "Image number" refers to the randomized image orientation/number
|
||||
for (Recognition recognition : recognitions) {
|
||||
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());
|
||||
i++;
|
||||
double col = (recognition.getLeft() + recognition.getRight()) / 2 ;
|
||||
double row = (recognition.getTop() + recognition.getBottom()) / 2 ;
|
||||
double width = Math.abs(recognition.getRight() - recognition.getLeft()) ;
|
||||
double height = Math.abs(recognition.getTop() - recognition.getBottom()) ;
|
||||
|
||||
telemetry.addData(""," ");
|
||||
telemetry.addData("Image", "%s (%.0f %% Conf.)", recognition.getLabel(), recognition.getConfidence() * 100 );
|
||||
telemetry.addData("- Position (Row/Col)","%.0f / %.0f", row, col);
|
||||
telemetry.addData("- Size (Width/Height)","%.0f / %.0f", width, height);
|
||||
}
|
||||
telemetry.update();
|
||||
}
|
||||
@ -179,8 +180,6 @@ public class ConceptTensorFlowObjectDetectionSwitchableCameras extends LinearOpM
|
||||
// Set the active camera to Webcam 1.
|
||||
switchableCamera = (SwitchableCamera) vuforia.getCamera();
|
||||
switchableCamera.setActiveCamera(webcam1);
|
||||
|
||||
// Loading trackables is not necessary for the TensorFlow Object Detection engine.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,11 +189,15 @@ public class ConceptTensorFlowObjectDetectionSwitchableCameras extends LinearOpM
|
||||
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
|
||||
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
|
||||
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
|
||||
tfodParameters.minResultConfidence = 0.8f;
|
||||
tfodParameters.minResultConfidence = 0.75f;
|
||||
tfodParameters.isModelTensorFlow2 = true;
|
||||
tfodParameters.inputSize = 320;
|
||||
tfodParameters.inputSize = 300;
|
||||
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
|
||||
|
||||
// Use loadModelFromAsset() if the TF Model is built in as an asset by Android Studio
|
||||
// Use loadModelFromFile() if you have downloaded a custom team model to the Robot Controller's FLASH.
|
||||
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABELS);
|
||||
// tfod.loadModelFromFile(TFOD_MODEL_FILE, LABELS);
|
||||
}
|
||||
|
||||
private void doCameraSwitching() {
|
||||
|
@ -40,8 +40,8 @@ import org.firstinspires.ftc.robotcore.external.tfod.TFObjectDetector;
|
||||
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
|
||||
/**
|
||||
* This 2020-2021 OpMode illustrates the basics of using the TensorFlow Object Detection API to
|
||||
* determine the position of the Freight Frenzy game elements.
|
||||
* This 2022-2023 OpMode illustrates the basics of using the TensorFlow Object Detection API to
|
||||
* determine which image is being presented to the robot.
|
||||
*
|
||||
* 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.
|
||||
@ -52,23 +52,22 @@ import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
|
||||
@TeleOp(name = "Concept: TensorFlow Object Detection Webcam", group = "Concept")
|
||||
@Disabled
|
||||
public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
|
||||
/* Note: This sample uses the all-objects Tensor Flow model (FreightFrenzy_BCDM.tflite), which contains
|
||||
* the following 4 detectable objects
|
||||
* 0: Ball,
|
||||
* 1: Cube,
|
||||
* 2: Duck,
|
||||
* 3: Marker (duck location tape marker)
|
||||
*
|
||||
* Two additional model assets are available which only contain a subset of the objects:
|
||||
* FreightFrenzy_BC.tflite 0: Ball, 1: Cube
|
||||
* FreightFrenzy_DM.tflite 0: Duck, 1: Marker
|
||||
*/
|
||||
private static final String TFOD_MODEL_ASSET = "FreightFrenzy_BCDM.tflite";
|
||||
|
||||
/*
|
||||
* Specify the source for the Tensor Flow Model.
|
||||
* If the TensorFlowLite object model is included in the Robot Controller App as an "asset",
|
||||
* the OpMode must to load it using loadModelFromAsset(). However, if a team generated model
|
||||
* has been downloaded to the Robot Controller's SD FLASH memory, it must to be loaded using loadModelFromFile()
|
||||
* Here we assume it's an Asset. Also see method initTfod() below .
|
||||
*/
|
||||
private static final String TFOD_MODEL_ASSET = "PowerPlay.tflite";
|
||||
// private static final String TFOD_MODEL_FILE = "/sdcard/FIRST/tflitemodels/CustomTeamModel.tflite";
|
||||
|
||||
|
||||
private static final String[] LABELS = {
|
||||
"Ball",
|
||||
"Cube",
|
||||
"Duck",
|
||||
"Marker"
|
||||
"1 Bolt",
|
||||
"2 Bulb",
|
||||
"3 Panel"
|
||||
};
|
||||
|
||||
/*
|
||||
@ -114,11 +113,11 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
|
||||
|
||||
// The TensorFlow software will scale the input images from the camera to a lower resolution.
|
||||
// This can result in lower detection accuracy at longer distances (> 55cm or 22").
|
||||
// If your target is at distance greater than 50 cm (20") you can adjust the magnification value
|
||||
// If your target is at distance greater than 50 cm (20") you can increase the magnification value
|
||||
// to artificially zoom in to the center of image. For best results, the "aspectRatio" argument
|
||||
// should be set to the value of the images used to create the TensorFlow Object Detection model
|
||||
// (typically 16/9).
|
||||
tfod.setZoom(2.5, 16.0/9.0);
|
||||
tfod.setZoom(1.0, 16.0/9.0);
|
||||
}
|
||||
|
||||
/** Wait for the game to begin */
|
||||
@ -133,18 +132,22 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
|
||||
// the last time that call was made.
|
||||
List<Recognition> updatedRecognitions = tfod.getUpdatedRecognitions();
|
||||
if (updatedRecognitions != null) {
|
||||
telemetry.addData("# Object Detected", updatedRecognitions.size());
|
||||
// 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());
|
||||
i++;
|
||||
}
|
||||
telemetry.update();
|
||||
telemetry.addData("# Objects Detected", updatedRecognitions.size());
|
||||
|
||||
// step through the list of recognitions and display image position/size information for each one
|
||||
// Note: "Image number" refers to the randomized image orientation/number
|
||||
for (Recognition recognition : updatedRecognitions) {
|
||||
double col = (recognition.getLeft() + recognition.getRight()) / 2 ;
|
||||
double row = (recognition.getTop() + recognition.getBottom()) / 2 ;
|
||||
double width = Math.abs(recognition.getRight() - recognition.getLeft()) ;
|
||||
double height = Math.abs(recognition.getTop() - recognition.getBottom()) ;
|
||||
|
||||
telemetry.addData(""," ");
|
||||
telemetry.addData("Image", "%s (%.0f %% Conf.)", recognition.getLabel(), recognition.getConfidence() * 100 );
|
||||
telemetry.addData("- Position (Row/Col)","%.0f / %.0f", row, col);
|
||||
telemetry.addData("- Size (Width/Height)","%.0f / %.0f", width, height);
|
||||
}
|
||||
telemetry.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,8 +168,6 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
|
||||
|
||||
// Instantiate the Vuforia engine
|
||||
vuforia = ClassFactory.getInstance().createVuforia(parameters);
|
||||
|
||||
// Loading trackables is not necessary for the TensorFlow Object Detection engine.
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,10 +177,14 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
|
||||
int tfodMonitorViewId = hardwareMap.appContext.getResources().getIdentifier(
|
||||
"tfodMonitorViewId", "id", hardwareMap.appContext.getPackageName());
|
||||
TFObjectDetector.Parameters tfodParameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
|
||||
tfodParameters.minResultConfidence = 0.8f;
|
||||
tfodParameters.isModelTensorFlow2 = true;
|
||||
tfodParameters.inputSize = 320;
|
||||
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
|
||||
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABELS);
|
||||
tfodParameters.minResultConfidence = 0.75f;
|
||||
tfodParameters.isModelTensorFlow2 = true;
|
||||
tfodParameters.inputSize = 300;
|
||||
tfod = ClassFactory.getInstance().createTFObjectDetector(tfodParameters, vuforia);
|
||||
|
||||
// Use loadModelFromAsset() if the TF Model is built in as an asset by Android Studio
|
||||
// Use loadModelFromFile() if you have downloaded a custom team model to the Robot Controller's FLASH.
|
||||
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABELS);
|
||||
// tfod.loadModelFromFile(TFOD_MODEL_FILE, LABELS);
|
||||
}
|
||||
}
|
||||
|
@ -49,20 +49,20 @@ import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackables;
|
||||
/**
|
||||
* This OpMode illustrates the basics of using the Vuforia engine to determine
|
||||
* the identity of Vuforia VuMarks encountered on the field. The code is structured as
|
||||
* a LinearOpMode. It shares much structure with {@link ConceptVuforiaNavigation}; we do not here
|
||||
* a LinearOpMode. It shares much structure with {@link ConceptVuforiaFieldNavigation}; we do not here
|
||||
* duplicate the core Vuforia documentation found there, but rather instead focus on the
|
||||
* differences between the use of Vuforia for navigation vs VuMark identification.
|
||||
*
|
||||
* @see ConceptVuforiaNavigation
|
||||
* @see ConceptVuforiaFieldNavigation
|
||||
* @see VuforiaLocalizer
|
||||
* @see VuforiaTrackableDefaultListener
|
||||
* see ftc_app/doc/tutorial/FTC_FieldCoordinateSystemDefinition.pdf
|
||||
*
|
||||
* 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.
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list.
|
||||
*
|
||||
* IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
|
||||
* is explained in {@link ConceptVuforiaNavigation}.
|
||||
* is explained below.
|
||||
*/
|
||||
|
||||
@TeleOp(name="Concept: VuMark Id", group ="Concept")
|
||||
|
@ -50,20 +50,20 @@ import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackables;
|
||||
/**
|
||||
* This OpMode illustrates the basics of using the Vuforia engine to determine
|
||||
* the identity of Vuforia VuMarks encountered on the field. The code is structured as
|
||||
* a LinearOpMode. It shares much structure with {@link ConceptVuforiaNavigationWebcam}; we do not here
|
||||
* a LinearOpMode. It shares much structure with {@link ConceptVuforiaFieldNavigationWebcam}; we do not here
|
||||
* duplicate the core Vuforia documentation found there, but rather instead focus on the
|
||||
* differences between the use of Vuforia for navigation vs VuMark identification.
|
||||
*
|
||||
* @see ConceptVuforiaNavigationWebcam
|
||||
* @see ConceptVuforiaFieldNavigationWebcam
|
||||
* @see VuforiaLocalizer
|
||||
* @see VuforiaTrackableDefaultListener
|
||||
* see ftc_app/doc/tutorial/FTC_FieldCoordinateSystemDefinition.pdf
|
||||
*
|
||||
* 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.
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list.
|
||||
*
|
||||
* IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
|
||||
* is explained in {@link ConceptVuforiaNavigationWebcam}.
|
||||
* is explained below
|
||||
*/
|
||||
|
||||
@TeleOp(name="Concept: VuMark Id Webcam", group ="Concept")
|
||||
|
@ -96,14 +96,14 @@ public class ConceptVuforiaDriveToTargetWebcam extends LinearOpMode
|
||||
this.vuforia = ClassFactory.getInstance().createVuforia(parameters);
|
||||
|
||||
// Load the trackable objects from the Assets file, and give them meaningful names
|
||||
VuforiaTrackables targetsFreightFrenzy = this.vuforia.loadTrackablesFromAsset("FreightFrenzy");
|
||||
targetsFreightFrenzy.get(0).setName("Blue Storage");
|
||||
targetsFreightFrenzy.get(1).setName("Blue Alliance Wall");
|
||||
targetsFreightFrenzy.get(2).setName("Red Storage");
|
||||
targetsFreightFrenzy.get(3).setName("Red Alliance Wall");
|
||||
VuforiaTrackables targetsPowerPlay = this.vuforia.loadTrackablesFromAsset("PowerPlay");
|
||||
targetsPowerPlay.get(0).setName("Red Audience Wall");
|
||||
targetsPowerPlay.get(1).setName("Red Rear Wall");
|
||||
targetsPowerPlay.get(2).setName("Blue Audience Wall");
|
||||
targetsPowerPlay.get(3).setName("Blue Rear Wall");
|
||||
|
||||
// Start tracking targets in the background
|
||||
targetsFreightFrenzy.activate();
|
||||
targetsPowerPlay.activate();
|
||||
|
||||
// Initialize the hardware variables. Note that the strings used here as parameters
|
||||
// to 'get' must correspond to the names assigned during the robot configuration
|
||||
@ -112,9 +112,10 @@ public class ConceptVuforiaDriveToTargetWebcam extends LinearOpMode
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
leftDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
rightDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
// When run, this OpMode should start both motors driving forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
telemetry.addData(">", "Press Play to start");
|
||||
telemetry.update();
|
||||
@ -131,7 +132,7 @@ public class ConceptVuforiaDriveToTargetWebcam extends LinearOpMode
|
||||
{
|
||||
// Look for first visible target, and save its pose.
|
||||
targetFound = false;
|
||||
for (VuforiaTrackable trackable : targetsFreightFrenzy)
|
||||
for (VuforiaTrackable trackable : targetsPowerPlay)
|
||||
{
|
||||
if (((VuforiaTrackableDefaultListener) trackable.getListener()).isVisible())
|
||||
{
|
||||
|
@ -67,7 +67,7 @@ import static org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocaliz
|
||||
* To learn more about the FTC field coordinate model, see FTC_FieldCoordinateSystemDefinition.pdf in this folder
|
||||
*
|
||||
* 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.
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list.
|
||||
*
|
||||
* IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
|
||||
* is explained below.
|
||||
@ -100,7 +100,7 @@ public class ConceptVuforiaFieldNavigation extends LinearOpMode {
|
||||
" -- YOUR NEW VUFORIA KEY GOES HERE --- ";
|
||||
|
||||
// Since ImageTarget trackables use mm to specifiy their dimensions, we must use mm for all the physical dimension.
|
||||
// We will define some constants and conversions here. These are useful for the Freight Frenzy field.
|
||||
// We will define some constants and conversions here. These are useful for the FTC competition field.
|
||||
private static final float mmPerInch = 25.4f;
|
||||
private static final float mmTargetHeight = 6 * mmPerInch; // the height of the center of the target image above the floor
|
||||
private static final float halfField = 72 * mmPerInch;
|
||||
@ -136,9 +136,8 @@ public class ConceptVuforiaFieldNavigation extends LinearOpMode {
|
||||
// Instantiate the Vuforia engine
|
||||
vuforia = ClassFactory.getInstance().createVuforia(parameters);
|
||||
|
||||
// Load the data sets for the trackable objects. These particular data
|
||||
// sets are stored in the 'assets' part of our application.
|
||||
targets = this.vuforia.loadTrackablesFromAsset("FreightFrenzy");
|
||||
// Load the trackable assets.
|
||||
targets = this.vuforia.loadTrackablesFromAsset("PowerPlay");
|
||||
|
||||
// For convenience, gather together all the trackable objects in one easily-iterable collection */
|
||||
List<VuforiaTrackable> allTrackables = new ArrayList<VuforiaTrackable>();
|
||||
@ -163,10 +162,10 @@ public class ConceptVuforiaFieldNavigation extends LinearOpMode {
|
||||
*/
|
||||
|
||||
// Name and locate each trackable object
|
||||
identifyTarget(0, "Blue Storage", -halfField, oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(1, "Blue Alliance Wall", halfTile, halfField, mmTargetHeight, 90, 0, 0);
|
||||
identifyTarget(2, "Red Storage", -halfField, -oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(3, "Red Alliance Wall", halfTile, -halfField, mmTargetHeight, 90, 0, 180);
|
||||
identifyTarget(0, "Red Audience Wall", -halfField, -oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(1, "Red Rear Wall", halfField, -oneAndHalfTile, mmTargetHeight, 90, 0, -90);
|
||||
identifyTarget(2, "Blue Audience Wall", -halfField, oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(3, "Blue Rear Wall", halfField, oneAndHalfTile, mmTargetHeight, 90, 0, -90);
|
||||
|
||||
/*
|
||||
* Create a transformation matrix describing where the phone is on the robot.
|
||||
|
@ -69,7 +69,7 @@ import static org.firstinspires.ftc.robotcore.external.navigation.AxesReference.
|
||||
* To learn more about the FTC field coordinate model, see FTC_FieldCoordinateSystemDefinition.pdf in this folder
|
||||
*
|
||||
* 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.
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list.
|
||||
*
|
||||
* IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
|
||||
* is explained below.
|
||||
@ -137,7 +137,7 @@ public class ConceptVuforiaFieldNavigationWebcam extends LinearOpMode {
|
||||
|
||||
// Load the data sets for the trackable objects. These particular data
|
||||
// sets are stored in the 'assets' part of our application.
|
||||
targets = this.vuforia.loadTrackablesFromAsset("FreightFrenzy");
|
||||
targets = this.vuforia.loadTrackablesFromAsset("PowerPlay");
|
||||
|
||||
// For convenience, gather together all the trackable objects in one easily-iterable collection */
|
||||
List<VuforiaTrackable> allTrackables = new ArrayList<VuforiaTrackable>();
|
||||
@ -162,10 +162,10 @@ public class ConceptVuforiaFieldNavigationWebcam extends LinearOpMode {
|
||||
*/
|
||||
|
||||
// Name and locate each trackable object
|
||||
identifyTarget(0, "Blue Storage", -halfField, oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(1, "Blue Alliance Wall", halfTile, halfField, mmTargetHeight, 90, 0, 0);
|
||||
identifyTarget(2, "Red Storage", -halfField, -oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(3, "Red Alliance Wall", halfTile, -halfField, mmTargetHeight, 90, 0, 180);
|
||||
identifyTarget(0, "Red Audience Wall", -halfField, -oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(1, "Red Rear Wall", halfField, -oneAndHalfTile, mmTargetHeight, 90, 0, -90);
|
||||
identifyTarget(2, "Blue Audience Wall", -halfField, oneAndHalfTile, mmTargetHeight, 90, 0, 90);
|
||||
identifyTarget(3, "Blue Rear Wall", halfField, oneAndHalfTile, mmTargetHeight, 90, 0, -90);
|
||||
|
||||
/*
|
||||
* Create a transformation matrix describing where the camera is on the robot.
|
||||
|
@ -1,310 +0,0 @@
|
||||
/* Copyright (c) 2020 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 android.graphics.Bitmap;
|
||||
import android.graphics.ImageFormat;
|
||||
import android.os.Handler;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
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.util.RobotLog;
|
||||
|
||||
import org.firstinspires.ftc.robotcore.external.ClassFactory;
|
||||
import org.firstinspires.ftc.robotcore.external.android.util.Size;
|
||||
import org.firstinspires.ftc.robotcore.external.function.Consumer;
|
||||
import org.firstinspires.ftc.robotcore.external.function.Continuation;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.Camera;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraCaptureRequest;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraCaptureSequenceId;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraCaptureSession;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraCharacteristics;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraException;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraFrame;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.CameraManager;
|
||||
import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
|
||||
import org.firstinspires.ftc.robotcore.internal.collections.EvictingBlockingQueue;
|
||||
import org.firstinspires.ftc.robotcore.internal.network.CallbackLooper;
|
||||
import org.firstinspires.ftc.robotcore.internal.system.AppUtil;
|
||||
import org.firstinspires.ftc.robotcore.internal.system.ContinuationSynchronizer;
|
||||
import org.firstinspires.ftc.robotcore.internal.system.Deadline;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* This OpMode illustrates how to open a webcam and retrieve images from it. It requires a configuration
|
||||
* containing a webcam with the default name ("Webcam 1"). When the opmode runs, pressing the 'A' button
|
||||
* will cause a frame from the camera to be written to a file on the device, which can then be retrieved
|
||||
* by various means (e.g.: Device File Explorer in Android Studio; plugging the device into a PC and
|
||||
* using Media Transfer; ADB; etc)
|
||||
*/
|
||||
@TeleOp(name="Concept: Webcam", group ="Concept")
|
||||
@Disabled
|
||||
public class ConceptWebcam extends LinearOpMode {
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// State
|
||||
//----------------------------------------------------------------------------------------------
|
||||
|
||||
private static final String TAG = "Webcam Sample";
|
||||
|
||||
/** How long we are to wait to be granted permission to use the camera before giving up. Here,
|
||||
* we wait indefinitely */
|
||||
private static final int secondsPermissionTimeout = Integer.MAX_VALUE;
|
||||
|
||||
/** State regarding our interaction with the camera */
|
||||
private CameraManager cameraManager;
|
||||
private WebcamName cameraName;
|
||||
private Camera camera;
|
||||
private CameraCaptureSession cameraCaptureSession;
|
||||
|
||||
/** The queue into which all frames from the camera are placed as they become available.
|
||||
* Frames which are not processed by the OpMode are automatically discarded. */
|
||||
private EvictingBlockingQueue<Bitmap> frameQueue;
|
||||
|
||||
/** State regarding where and how to save frames when the 'A' button is pressed. */
|
||||
private int captureCounter = 0;
|
||||
private File captureDirectory = AppUtil.ROBOT_DATA_DIR;
|
||||
|
||||
/** A utility object that indicates where the asynchronous callbacks from the camera
|
||||
* infrastructure are to run. In this OpMode, that's all hidden from you (but see {@link #startCamera}
|
||||
* if you're curious): no knowledge of multi-threading is needed here. */
|
||||
private Handler callbackHandler;
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// Main OpMode entry
|
||||
//----------------------------------------------------------------------------------------------
|
||||
|
||||
@Override public void runOpMode() {
|
||||
|
||||
callbackHandler = CallbackLooper.getDefault().getHandler();
|
||||
|
||||
cameraManager = ClassFactory.getInstance().getCameraManager();
|
||||
cameraName = hardwareMap.get(WebcamName.class, "Webcam 1");
|
||||
|
||||
initializeFrameQueue(2);
|
||||
AppUtil.getInstance().ensureDirectoryExists(captureDirectory);
|
||||
|
||||
try {
|
||||
openCamera();
|
||||
if (camera == null) return;
|
||||
|
||||
startCamera();
|
||||
if (cameraCaptureSession == null) return;
|
||||
|
||||
telemetry.addData(">", "Press Play to start");
|
||||
telemetry.update();
|
||||
waitForStart();
|
||||
telemetry.clear();
|
||||
telemetry.addData(">", "Started...Press 'A' to capture frame");
|
||||
|
||||
boolean buttonPressSeen = false;
|
||||
boolean captureWhenAvailable = false;
|
||||
while (opModeIsActive()) {
|
||||
|
||||
boolean buttonIsPressed = gamepad1.a;
|
||||
if (buttonIsPressed && !buttonPressSeen) {
|
||||
captureWhenAvailable = true;
|
||||
}
|
||||
buttonPressSeen = buttonIsPressed;
|
||||
|
||||
if (captureWhenAvailable) {
|
||||
Bitmap bmp = frameQueue.poll();
|
||||
if (bmp != null) {
|
||||
captureWhenAvailable = false;
|
||||
onNewFrame(bmp);
|
||||
}
|
||||
}
|
||||
|
||||
telemetry.update();
|
||||
}
|
||||
} finally {
|
||||
closeCamera();
|
||||
}
|
||||
}
|
||||
|
||||
/** Do something with the frame */
|
||||
private void onNewFrame(Bitmap frame) {
|
||||
saveBitmap(frame);
|
||||
frame.recycle(); // not strictly necessary, but helpful
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// Camera operations
|
||||
//----------------------------------------------------------------------------------------------
|
||||
|
||||
private void initializeFrameQueue(int capacity) {
|
||||
/** The frame queue will automatically throw away bitmap frames if they are not processed
|
||||
* quickly by the OpMode. This avoids a buildup of frames in memory */
|
||||
frameQueue = new EvictingBlockingQueue<Bitmap>(new ArrayBlockingQueue<Bitmap>(capacity));
|
||||
frameQueue.setEvictAction(new Consumer<Bitmap>() {
|
||||
@Override public void accept(Bitmap frame) {
|
||||
// RobotLog.ii(TAG, "frame recycled w/o processing");
|
||||
frame.recycle(); // not strictly necessary, but helpful
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void openCamera() {
|
||||
if (camera != null) return; // be idempotent
|
||||
|
||||
Deadline deadline = new Deadline(secondsPermissionTimeout, TimeUnit.SECONDS);
|
||||
camera = cameraManager.requestPermissionAndOpenCamera(deadline, cameraName, null);
|
||||
if (camera == null) {
|
||||
error("camera not found or permission to use not granted: %s", cameraName);
|
||||
}
|
||||
}
|
||||
|
||||
private void startCamera() {
|
||||
if (cameraCaptureSession != null) return; // be idempotent
|
||||
|
||||
/** YUY2 is supported by all Webcams, per the USB Webcam standard: See "USB Device Class Definition
|
||||
* for Video Devices: Uncompressed Payload, Table 2-1". Further, often this is the *only*
|
||||
* image format supported by a camera */
|
||||
final int imageFormat = ImageFormat.YUY2;
|
||||
|
||||
/** Verify that the image is supported, and fetch size and desired frame rate if so */
|
||||
CameraCharacteristics cameraCharacteristics = cameraName.getCameraCharacteristics();
|
||||
if (!contains(cameraCharacteristics.getAndroidFormats(), imageFormat)) {
|
||||
error("image format not supported");
|
||||
return;
|
||||
}
|
||||
final Size size = cameraCharacteristics.getDefaultSize(imageFormat);
|
||||
final int fps = cameraCharacteristics.getMaxFramesPerSecond(imageFormat, size);
|
||||
|
||||
/** Some of the logic below runs asynchronously on other threads. Use of the synchronizer
|
||||
* here allows us to wait in this method until all that asynchrony completes before returning. */
|
||||
final ContinuationSynchronizer<CameraCaptureSession> synchronizer = new ContinuationSynchronizer<>();
|
||||
try {
|
||||
/** Create a session in which requests to capture frames can be made */
|
||||
camera.createCaptureSession(Continuation.create(callbackHandler, new CameraCaptureSession.StateCallbackDefault() {
|
||||
@Override public void onConfigured(@NonNull CameraCaptureSession session) {
|
||||
try {
|
||||
/** The session is ready to go. Start requesting frames */
|
||||
final CameraCaptureRequest captureRequest = camera.createCaptureRequest(imageFormat, size, fps);
|
||||
session.startCapture(captureRequest,
|
||||
new CameraCaptureSession.CaptureCallback() {
|
||||
@Override public void onNewFrame(@NonNull CameraCaptureSession session, @NonNull CameraCaptureRequest request, @NonNull CameraFrame cameraFrame) {
|
||||
/** A new frame is available. The frame data has <em>not</em> been copied for us, and we can only access it
|
||||
* for the duration of the callback. So we copy here manually. */
|
||||
Bitmap bmp = captureRequest.createEmptyBitmap();
|
||||
cameraFrame.copyToBitmap(bmp);
|
||||
frameQueue.offer(bmp);
|
||||
}
|
||||
},
|
||||
Continuation.create(callbackHandler, new CameraCaptureSession.StatusCallback() {
|
||||
@Override public void onCaptureSequenceCompleted(@NonNull CameraCaptureSession session, CameraCaptureSequenceId cameraCaptureSequenceId, long lastFrameNumber) {
|
||||
RobotLog.ii(TAG, "capture sequence %s reports completed: lastFrame=%d", cameraCaptureSequenceId, lastFrameNumber);
|
||||
}
|
||||
})
|
||||
);
|
||||
synchronizer.finish(session);
|
||||
} catch (CameraException|RuntimeException e) {
|
||||
RobotLog.ee(TAG, e, "exception starting capture");
|
||||
error("exception starting capture");
|
||||
session.close();
|
||||
synchronizer.finish(null);
|
||||
}
|
||||
}
|
||||
}));
|
||||
} catch (CameraException|RuntimeException e) {
|
||||
RobotLog.ee(TAG, e, "exception starting camera");
|
||||
error("exception starting camera");
|
||||
synchronizer.finish(null);
|
||||
}
|
||||
|
||||
/** Wait for all the asynchrony to complete */
|
||||
try {
|
||||
synchronizer.await();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
/** Retrieve the created session. This will be null on error. */
|
||||
cameraCaptureSession = synchronizer.getValue();
|
||||
}
|
||||
|
||||
private void stopCamera() {
|
||||
if (cameraCaptureSession != null) {
|
||||
cameraCaptureSession.stopCapture();
|
||||
cameraCaptureSession.close();
|
||||
cameraCaptureSession = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void closeCamera() {
|
||||
stopCamera();
|
||||
if (camera != null) {
|
||||
camera.close();
|
||||
camera = null;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------
|
||||
// Utilities
|
||||
//----------------------------------------------------------------------------------------------
|
||||
|
||||
private void error(String msg) {
|
||||
telemetry.log().add(msg);
|
||||
telemetry.update();
|
||||
}
|
||||
private void error(String format, Object...args) {
|
||||
telemetry.log().add(format, args);
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
private boolean contains(int[] array, int value) {
|
||||
for (int i : array) {
|
||||
if (i == value) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void saveBitmap(Bitmap bitmap) {
|
||||
File file = new File(captureDirectory, String.format(Locale.getDefault(), "webcam-frame-%d.jpg", captureCounter++));
|
||||
try {
|
||||
try (FileOutputStream outputStream = new FileOutputStream(file)) {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
||||
telemetry.log().add("captured %s", file.getName());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
RobotLog.ee(TAG, e, "exception in saveBitmap()");
|
||||
error("exception saving %s", file.getName());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
/* Copyright (c) 2017 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.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.hardware.HardwareMap;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
/**
|
||||
* This is NOT an opmode.
|
||||
*
|
||||
* This class can be used to define all the specific hardware for a single robot.
|
||||
* In this case that robot is a Pushbot.
|
||||
* See PushbotTeleopTank_Iterative and others classes starting with "Pushbot" for usage examples.
|
||||
*
|
||||
* This hardware class assumes the following device names have been configured on the robot:
|
||||
* Note: All names are lower case and some have single spaces between words.
|
||||
*
|
||||
* Motor channel: Left drive motor: "left_drive"
|
||||
* Motor channel: Right drive motor: "right_drive"
|
||||
* Motor channel: Manipulator drive motor: "left_arm"
|
||||
* Servo channel: Servo to open left claw: "left_hand"
|
||||
* Servo channel: Servo to open right claw: "right_hand"
|
||||
*/
|
||||
public class HardwarePushbot
|
||||
{
|
||||
/* Public OpMode members. */
|
||||
public DcMotor leftDrive = null;
|
||||
public DcMotor rightDrive = null;
|
||||
public DcMotor leftArm = null;
|
||||
public Servo leftClaw = null;
|
||||
public Servo rightClaw = null;
|
||||
|
||||
public static final double MID_SERVO = 0.5 ;
|
||||
public static final double ARM_UP_POWER = 0.45 ;
|
||||
public static final double ARM_DOWN_POWER = -0.45 ;
|
||||
|
||||
/* local OpMode members. */
|
||||
HardwareMap hwMap = null;
|
||||
private ElapsedTime period = new ElapsedTime();
|
||||
|
||||
/* Constructor */
|
||||
public HardwarePushbot(){
|
||||
|
||||
}
|
||||
|
||||
/* Initialize standard Hardware interfaces */
|
||||
public void init(HardwareMap ahwMap) {
|
||||
// Save reference to Hardware map
|
||||
hwMap = ahwMap;
|
||||
|
||||
// Define and Initialize Motors
|
||||
leftDrive = hwMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hwMap.get(DcMotor.class, "right_drive");
|
||||
leftArm = hwMap.get(DcMotor.class, "left_arm");
|
||||
leftDrive.setDirection(DcMotor.Direction.FORWARD); // Set to REVERSE if using AndyMark motors
|
||||
rightDrive.setDirection(DcMotor.Direction.REVERSE);// Set to FORWARD if using AndyMark motors
|
||||
|
||||
// Set all motors to zero power
|
||||
leftDrive.setPower(0);
|
||||
rightDrive.setPower(0);
|
||||
leftArm.setPower(0);
|
||||
|
||||
// Set all motors to run without encoders.
|
||||
// May want to use RUN_USING_ENCODERS if encoders are installed.
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
|
||||
leftArm.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
|
||||
|
||||
// Define and initialize ALL installed servos.
|
||||
leftClaw = hwMap.get(Servo.class, "left_hand");
|
||||
rightClaw = hwMap.get(Servo.class, "right_hand");
|
||||
leftClaw.setPosition(MID_SERVO);
|
||||
rightClaw.setPosition(MID_SERVO);
|
||||
}
|
||||
}
|
||||
|
@ -1,363 +0,0 @@
|
||||
/* Copyright (c) 2017 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.hardware.modernrobotics.ModernRoboticsI2cGyro;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
import com.qualcomm.robotcore.util.Range;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of driving a path based on Gyro heading and encoder counts.
|
||||
* It uses the common Pushbot hardware class to define the drive on the robot.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* The code REQUIRES that you DO have encoders on the wheels,
|
||||
* otherwise you would use: PushbotAutoDriveByTime;
|
||||
*
|
||||
* This code ALSO requires that you have a Modern Robotics I2C gyro with the name "gyro"
|
||||
* otherwise you would use: PushbotAutoDriveByEncoder;
|
||||
*
|
||||
* This code requires that the drive Motors have been configured such that a positive
|
||||
* power command moves them forward, and causes the encoders to count UP.
|
||||
*
|
||||
* This code uses the RUN_TO_POSITION mode to enable the Motor controllers to generate the run profile
|
||||
*
|
||||
* In order to calibrate the Gyro correctly, the robot must remain stationary during calibration.
|
||||
* This is performed when the INIT button is pressed on the Driver Station.
|
||||
* This code assumes that the robot is stationary when the INIT button is pressed.
|
||||
* If this is not the case, then the INIT should be performed again.
|
||||
*
|
||||
* Note: in this example, all angles are referenced to the initial coordinate frame set during the
|
||||
* the Gyro Calibration process, or whenever the program issues a resetZAxisIntegrator() call on the Gyro.
|
||||
*
|
||||
* The angle of movement/rotation is assumed to be a standardized rotation around the robot Z axis,
|
||||
* which means that a Positive rotation is Counter Clock Wise, looking down on the field.
|
||||
* This is consistent with the FTC field coordinate conventions set out in the document:
|
||||
* ftc_app\doc\tutorial\FTC_FieldCoordinateSystemDefinition.pdf
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@Autonomous(name="Pushbot: Auto Drive By Gyro", group="Pushbot")
|
||||
@Disabled
|
||||
public class PushbotAutoDriveByGyro_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // Use a Pushbot's hardware
|
||||
ModernRoboticsI2cGyro gyro = null; // Additional Gyro device
|
||||
|
||||
static final double COUNTS_PER_MOTOR_REV = 1440 ; // eg: TETRIX Motor Encoder
|
||||
static final double DRIVE_GEAR_REDUCTION = 2.0 ; // This is < 1.0 if geared UP
|
||||
static final double WHEEL_DIAMETER_INCHES = 4.0 ; // For figuring circumference
|
||||
static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) /
|
||||
(WHEEL_DIAMETER_INCHES * 3.1415);
|
||||
|
||||
// These constants define the desired driving/control characteristics
|
||||
// The can/should be tweaked to suite the specific robot drive train.
|
||||
static final double DRIVE_SPEED = 0.7; // Nominal speed for better accuracy.
|
||||
static final double TURN_SPEED = 0.5; // Nominal half speed for better accuracy.
|
||||
|
||||
static final double HEADING_THRESHOLD = 1 ; // As tight as we can make it with an integer gyro
|
||||
static final double P_TURN_COEFF = 0.1; // Larger is more responsive, but also less stable
|
||||
static final double P_DRIVE_COEFF = 0.15; // Larger is more responsive, but also less stable
|
||||
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
/*
|
||||
* Initialize the standard drive system variables.
|
||||
* The init() method of the hardware class does most of the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
gyro = (ModernRoboticsI2cGyro)hardwareMap.gyroSensor.get("gyro");
|
||||
|
||||
// Ensure the robot it stationary, then reset the encoders and calibrate the gyro.
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
|
||||
// Send telemetry message to alert driver that we are calibrating;
|
||||
telemetry.addData(">", "Calibrating Gyro"); //
|
||||
telemetry.update();
|
||||
|
||||
gyro.calibrate();
|
||||
|
||||
// make sure the gyro is calibrated before continuing
|
||||
while (!isStopRequested() && gyro.isCalibrating()) {
|
||||
sleep(50);
|
||||
idle();
|
||||
}
|
||||
|
||||
telemetry.addData(">", "Robot Ready."); //
|
||||
telemetry.update();
|
||||
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// Wait for the game to start (Display Gyro value), and reset gyro before we move..
|
||||
while (!isStarted()) {
|
||||
telemetry.addData(">", "Robot Heading = %d", gyro.getIntegratedZValue());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
gyro.resetZAxisIntegrator();
|
||||
|
||||
// Step through each leg of the path,
|
||||
// Note: Reverse movement is obtained by setting a negative distance (not speed)
|
||||
// Put a hold after each turn
|
||||
gyroDrive(DRIVE_SPEED, 48.0, 0.0); // Drive FWD 48 inches
|
||||
gyroTurn( TURN_SPEED, -45.0); // Turn CCW to -45 Degrees
|
||||
gyroHold( TURN_SPEED, -45.0, 0.5); // Hold -45 Deg heading for a 1/2 second
|
||||
gyroDrive(DRIVE_SPEED, 12.0, -45.0); // Drive FWD 12 inches at 45 degrees
|
||||
gyroTurn( TURN_SPEED, 45.0); // Turn CW to 45 Degrees
|
||||
gyroHold( TURN_SPEED, 45.0, 0.5); // Hold 45 Deg heading for a 1/2 second
|
||||
gyroTurn( TURN_SPEED, 0.0); // Turn CW to 0 Degrees
|
||||
gyroHold( TURN_SPEED, 0.0, 1.0); // Hold 0 Deg heading for a 1 second
|
||||
gyroDrive(DRIVE_SPEED,-48.0, 0.0); // Drive REV 48 inches
|
||||
|
||||
telemetry.addData("Path", "Complete");
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to drive on a fixed compass bearing (angle), based on encoder counts.
|
||||
* Move will stop if either of these conditions occur:
|
||||
* 1) Move gets to the desired position
|
||||
* 2) Driver stops the opmode running.
|
||||
*
|
||||
* @param speed Target speed for forward motion. Should allow for _/- variance for adjusting heading
|
||||
* @param distance Distance (in inches) to move from current position. Negative distance means move backwards.
|
||||
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from current heading.
|
||||
*/
|
||||
public void gyroDrive ( double speed,
|
||||
double distance,
|
||||
double angle) {
|
||||
|
||||
int newLeftTarget;
|
||||
int newRightTarget;
|
||||
int moveCounts;
|
||||
double max;
|
||||
double error;
|
||||
double steer;
|
||||
double leftSpeed;
|
||||
double rightSpeed;
|
||||
|
||||
// Ensure that the opmode is still active
|
||||
if (opModeIsActive()) {
|
||||
|
||||
// Determine new target position, and pass to motor controller
|
||||
moveCounts = (int)(distance * COUNTS_PER_INCH);
|
||||
newLeftTarget = robot.leftDrive.getCurrentPosition() + moveCounts;
|
||||
newRightTarget = robot.rightDrive.getCurrentPosition() + moveCounts;
|
||||
|
||||
// Set Target and Turn On RUN_TO_POSITION
|
||||
robot.leftDrive.setTargetPosition(newLeftTarget);
|
||||
robot.rightDrive.setTargetPosition(newRightTarget);
|
||||
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
|
||||
// start motion.
|
||||
speed = Range.clip(Math.abs(speed), 0.0, 1.0);
|
||||
robot.leftDrive.setPower(speed);
|
||||
robot.rightDrive.setPower(speed);
|
||||
|
||||
// keep looping while we are still active, and BOTH motors are running.
|
||||
while (opModeIsActive() &&
|
||||
(robot.leftDrive.isBusy() && robot.rightDrive.isBusy())) {
|
||||
|
||||
// adjust relative speed based on heading error.
|
||||
error = getError(angle);
|
||||
steer = getSteer(error, P_DRIVE_COEFF);
|
||||
|
||||
// if driving in reverse, the motor correction also needs to be reversed
|
||||
if (distance < 0)
|
||||
steer *= -1.0;
|
||||
|
||||
leftSpeed = speed - steer;
|
||||
rightSpeed = speed + steer;
|
||||
|
||||
// Normalize speeds if either one exceeds +/- 1.0;
|
||||
max = Math.max(Math.abs(leftSpeed), Math.abs(rightSpeed));
|
||||
if (max > 1.0)
|
||||
{
|
||||
leftSpeed /= max;
|
||||
rightSpeed /= max;
|
||||
}
|
||||
|
||||
robot.leftDrive.setPower(leftSpeed);
|
||||
robot.rightDrive.setPower(rightSpeed);
|
||||
|
||||
// Display drive status for the driver.
|
||||
telemetry.addData("Err/St", "%5.1f/%5.1f", error, steer);
|
||||
telemetry.addData("Target", "%7d:%7d", newLeftTarget, newRightTarget);
|
||||
telemetry.addData("Actual", "%7d:%7d", robot.leftDrive.getCurrentPosition(),
|
||||
robot.rightDrive.getCurrentPosition());
|
||||
telemetry.addData("Speed", "%5.2f:%5.2f", leftSpeed, rightSpeed);
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Stop all motion;
|
||||
robot.leftDrive.setPower(0);
|
||||
robot.rightDrive.setPower(0);
|
||||
|
||||
// Turn off RUN_TO_POSITION
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to spin on central axis to point in a new direction.
|
||||
* Move will stop if either of these conditions occur:
|
||||
* 1) Move gets to the heading (angle)
|
||||
* 2) Driver stops the opmode running.
|
||||
*
|
||||
* @param speed Desired speed of turn.
|
||||
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from current heading.
|
||||
*/
|
||||
public void gyroTurn ( double speed, double angle) {
|
||||
|
||||
// keep looping while we are still active, and not on heading.
|
||||
while (opModeIsActive() && !onHeading(speed, angle, P_TURN_COEFF)) {
|
||||
// Update telemetry & Allow time for other processes to run.
|
||||
telemetry.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to obtain & hold a heading for a finite amount of time
|
||||
* Move will stop once the requested time has elapsed
|
||||
*
|
||||
* @param speed Desired speed of turn.
|
||||
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from current heading.
|
||||
* @param holdTime Length of time (in seconds) to hold the specified heading.
|
||||
*/
|
||||
public void gyroHold( double speed, double angle, double holdTime) {
|
||||
|
||||
ElapsedTime holdTimer = new ElapsedTime();
|
||||
|
||||
// keep looping while we have time remaining.
|
||||
holdTimer.reset();
|
||||
while (opModeIsActive() && (holdTimer.time() < holdTime)) {
|
||||
// Update telemetry & Allow time for other processes to run.
|
||||
onHeading(speed, angle, P_TURN_COEFF);
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Stop all motion;
|
||||
robot.leftDrive.setPower(0);
|
||||
robot.rightDrive.setPower(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform one cycle of closed loop heading control.
|
||||
*
|
||||
* @param speed Desired speed of turn.
|
||||
* @param angle Absolute Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from current heading.
|
||||
* @param PCoeff Proportional Gain coefficient
|
||||
* @return
|
||||
*/
|
||||
boolean onHeading(double speed, double angle, double PCoeff) {
|
||||
double error ;
|
||||
double steer ;
|
||||
boolean onTarget = false ;
|
||||
double leftSpeed;
|
||||
double rightSpeed;
|
||||
|
||||
// determine turn power based on +/- error
|
||||
error = getError(angle);
|
||||
|
||||
if (Math.abs(error) <= HEADING_THRESHOLD) {
|
||||
steer = 0.0;
|
||||
leftSpeed = 0.0;
|
||||
rightSpeed = 0.0;
|
||||
onTarget = true;
|
||||
}
|
||||
else {
|
||||
steer = getSteer(error, PCoeff);
|
||||
rightSpeed = speed * steer;
|
||||
leftSpeed = -rightSpeed;
|
||||
}
|
||||
|
||||
// Send desired speeds to motors.
|
||||
robot.leftDrive.setPower(leftSpeed);
|
||||
robot.rightDrive.setPower(rightSpeed);
|
||||
|
||||
// Display it for the driver.
|
||||
telemetry.addData("Target", "%5.2f", angle);
|
||||
telemetry.addData("Err/St", "%5.2f/%5.2f", error, steer);
|
||||
telemetry.addData("Speed.", "%5.2f:%5.2f", leftSpeed, rightSpeed);
|
||||
|
||||
return onTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* getError determines the error between the target angle and the robot's current heading
|
||||
* @param targetAngle Desired angle (relative to global reference established at last Gyro Reset).
|
||||
* @return error angle: Degrees in the range +/- 180. Centered on the robot's frame of reference
|
||||
* +ve error means the robot should turn LEFT (CCW) to reduce error.
|
||||
*/
|
||||
public double getError(double targetAngle) {
|
||||
|
||||
double robotError;
|
||||
|
||||
// calculate error in -179 to +180 range (
|
||||
robotError = targetAngle - gyro.getIntegratedZValue();
|
||||
while (robotError > 180) robotError -= 360;
|
||||
while (robotError <= -180) robotError += 360;
|
||||
return robotError;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns desired steering force. +/- 1 range. +ve = steer left
|
||||
* @param error Error angle in robot relative degrees
|
||||
* @param PCoeff Proportional Gain Coefficient
|
||||
* @return
|
||||
*/
|
||||
public double getSteer(double error, double PCoeff) {
|
||||
return Range.clip(error * PCoeff, -1, 1);
|
||||
}
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/* Copyright (c) 2017 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.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.LightSensor;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of driving up to a line and then stopping.
|
||||
* It uses the common Pushbot hardware class to define the drive on the robot.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* The code shows using two different light sensors:
|
||||
* The Primary sensor shown in this code is a legacy NXT Light sensor (called "sensor_light")
|
||||
* Alternative "commented out" code uses a MR Optical Distance Sensor (called "sensor_ods")
|
||||
* instead of the LEGO sensor. Chose to use one sensor or the other.
|
||||
*
|
||||
* Setting the correct WHITE_THRESHOLD value is key to stopping correctly.
|
||||
* This should be set half way between the light and dark values.
|
||||
* These values can be read on the screen once the OpMode has been INIT, but before it is STARTED.
|
||||
* Move the senso on asnd off the white line and not the min and max readings.
|
||||
* Edit this code to make WHITE_THRESHOLD half way between the min and max.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@Autonomous(name="Pushbot: Auto Drive To Line", group="Pushbot")
|
||||
@Disabled
|
||||
public class PushbotAutoDriveToLine_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // Use a Pushbot's hardware
|
||||
LightSensor lightSensor; // Primary LEGO Light sensor,
|
||||
// OpticalDistanceSensor lightSensor; // Alternative MR ODS sensor
|
||||
|
||||
static final double WHITE_THRESHOLD = 0.2; // spans between 0.1 - 0.5 from dark to light
|
||||
static final double APPROACH_SPEED = 0.5;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
/* Initialize the drive system variables.
|
||||
* The init() method of the hardware class does all the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
|
||||
// If there are encoders connected, switch to RUN_USING_ENCODER mode for greater accuracy
|
||||
// robot.leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
// robot.rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// get a reference to our Light Sensor object.
|
||||
lightSensor = hardwareMap.lightSensor.get("sensor_light"); // Primary LEGO Light Sensor
|
||||
// lightSensor = hardwareMap.opticalDistanceSensor.get("sensor_ods"); // Alternative MR ODS sensor.
|
||||
|
||||
// turn on LED of light sensor.
|
||||
lightSensor.enableLed(true);
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
telemetry.addData("Status", "Ready to run"); //
|
||||
telemetry.update();
|
||||
|
||||
// Wait for the game to start (driver presses PLAY)
|
||||
// Abort this loop is started or stopped.
|
||||
while (!(isStarted() || isStopRequested())) {
|
||||
|
||||
// Display the light level while we are waiting to start
|
||||
telemetry.addData("Light Level", lightSensor.getLightDetected());
|
||||
telemetry.update();
|
||||
idle();
|
||||
}
|
||||
|
||||
// Start the robot moving forward, and then begin looking for a white line.
|
||||
robot.leftDrive.setPower(APPROACH_SPEED);
|
||||
robot.rightDrive.setPower(APPROACH_SPEED);
|
||||
|
||||
// run until the white line is seen OR the driver presses STOP;
|
||||
while (opModeIsActive() && (lightSensor.getLightDetected() < WHITE_THRESHOLD)) {
|
||||
|
||||
// Display the light level while we are looking for the line
|
||||
telemetry.addData("Light Level", lightSensor.getLightDetected());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Stop all motors
|
||||
robot.leftDrive.setPower(0);
|
||||
robot.rightDrive.setPower(0);
|
||||
}
|
||||
}
|
@ -33,45 +33,53 @@ import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of driving a path based on encoder counts.
|
||||
* It uses the common Pushbot hardware class to define the drive on the robot.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* The code REQUIRES that you DO have encoders on the wheels,
|
||||
* otherwise you would use: PushbotAutoDriveByTime;
|
||||
* otherwise you would use: RobotAutoDriveByTime;
|
||||
*
|
||||
* This code ALSO requires that the drive Motors have been configured such that a positive
|
||||
* power command moves them forwards, and causes the encoders to count UP.
|
||||
* power command moves them forward, and causes the encoders to count UP.
|
||||
*
|
||||
* The desired path in this example is:
|
||||
* - Drive forward for 48 inches
|
||||
* - Spin right for 12 Inches
|
||||
* - Drive Backwards for 24 inches
|
||||
* - Drive Backward for 24 inches
|
||||
* - Stop and close the claw.
|
||||
*
|
||||
* The code is written using a method called: encoderDrive(speed, leftInches, rightInches, timeoutS)
|
||||
* that performs the actual movement.
|
||||
* This methods assumes that each movement is relative to the last stopping place.
|
||||
* This method assumes that each movement is relative to the last stopping place.
|
||||
* There are other ways to perform encoder based moves, but this method is probably the simplest.
|
||||
* This code uses the RUN_TO_POSITION mode to enable the Motor controllers to generate the run profile
|
||||
*
|
||||
* Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@Autonomous(name="Pushbot: Auto Drive By Encoder", group="Pushbot")
|
||||
@Autonomous(name="Robot: Auto Drive By Encoder", group="Robot")
|
||||
@Disabled
|
||||
public class PushbotAutoDriveByEncoder_Linear extends LinearOpMode {
|
||||
public class RobotAutoDriveByEncoder_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // Use a Pushbot's hardware
|
||||
private DcMotor leftDrive = null;
|
||||
private DcMotor rightDrive = null;
|
||||
|
||||
private ElapsedTime runtime = new ElapsedTime();
|
||||
|
||||
// Calculate the COUNTS_PER_INCH for your specific drive train.
|
||||
// Go to your motor vendor website to determine your motor's COUNTS_PER_MOTOR_REV
|
||||
// For external drive gearing, set DRIVE_GEAR_REDUCTION as needed.
|
||||
// For example, use a value of 2.0 for a 12-tooth spur gear driving a 24-tooth spur gear.
|
||||
// This is gearing DOWN for less speed and more torque.
|
||||
// For gearing UP, use a gear ratio less than 1.0. Note this will affect the direction of wheel rotation.
|
||||
static final double COUNTS_PER_MOTOR_REV = 1440 ; // eg: TETRIX Motor Encoder
|
||||
static final double DRIVE_GEAR_REDUCTION = 2.0 ; // This is < 1.0 if geared UP
|
||||
static final double DRIVE_GEAR_REDUCTION = 1.0 ; // No External Gearing.
|
||||
static final double WHEEL_DIAMETER_INCHES = 4.0 ; // For figuring circumference
|
||||
static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) /
|
||||
(WHEEL_DIAMETER_INCHES * 3.1415);
|
||||
@ -81,26 +89,26 @@ public class PushbotAutoDriveByEncoder_Linear extends LinearOpMode {
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
/*
|
||||
* Initialize the drive system variables.
|
||||
* The init() method of the hardware class does all the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
// Initialize the drive system variables.
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
telemetry.addData("Status", "Resetting Encoders"); //
|
||||
telemetry.update();
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// When run, this OpMode should start both motors driving forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
leftDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// Send telemetry message to indicate successful Encoder reset
|
||||
telemetry.addData("Path0", "Starting at %7d :%7d",
|
||||
robot.leftDrive.getCurrentPosition(),
|
||||
robot.rightDrive.getCurrentPosition());
|
||||
telemetry.addData("Starting at", "%7d :%7d",
|
||||
leftDrive.getCurrentPosition(),
|
||||
rightDrive.getCurrentPosition());
|
||||
telemetry.update();
|
||||
|
||||
// Wait for the game to start (driver presses PLAY)
|
||||
@ -112,12 +120,9 @@ public class PushbotAutoDriveByEncoder_Linear extends LinearOpMode {
|
||||
encoderDrive(TURN_SPEED, 12, -12, 4.0); // S2: Turn Right 12 Inches with 4 Sec timeout
|
||||
encoderDrive(DRIVE_SPEED, -24, -24, 4.0); // S3: Reverse 24 Inches with 4 Sec timeout
|
||||
|
||||
robot.leftClaw.setPosition(1.0); // S4: Stop and close the claw.
|
||||
robot.rightClaw.setPosition(0.0);
|
||||
sleep(1000); // pause for servos to move
|
||||
|
||||
telemetry.addData("Path", "Complete");
|
||||
telemetry.update();
|
||||
sleep(1000); // pause to display final telemetry message.
|
||||
}
|
||||
|
||||
/*
|
||||
@ -138,19 +143,19 @@ public class PushbotAutoDriveByEncoder_Linear extends LinearOpMode {
|
||||
if (opModeIsActive()) {
|
||||
|
||||
// Determine new target position, and pass to motor controller
|
||||
newLeftTarget = robot.leftDrive.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
|
||||
newRightTarget = robot.rightDrive.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
|
||||
robot.leftDrive.setTargetPosition(newLeftTarget);
|
||||
robot.rightDrive.setTargetPosition(newRightTarget);
|
||||
newLeftTarget = leftDrive.getCurrentPosition() + (int)(leftInches * COUNTS_PER_INCH);
|
||||
newRightTarget = rightDrive.getCurrentPosition() + (int)(rightInches * COUNTS_PER_INCH);
|
||||
leftDrive.setTargetPosition(newLeftTarget);
|
||||
rightDrive.setTargetPosition(newRightTarget);
|
||||
|
||||
// Turn On RUN_TO_POSITION
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
|
||||
// reset the timeout time and start motion.
|
||||
runtime.reset();
|
||||
robot.leftDrive.setPower(Math.abs(speed));
|
||||
robot.rightDrive.setPower(Math.abs(speed));
|
||||
leftDrive.setPower(Math.abs(speed));
|
||||
rightDrive.setPower(Math.abs(speed));
|
||||
|
||||
// keep looping while we are still active, and there is time left, and both motors are running.
|
||||
// Note: We use (isBusy() && isBusy()) in the loop test, which means that when EITHER motor hits
|
||||
@ -160,25 +165,24 @@ public class PushbotAutoDriveByEncoder_Linear extends LinearOpMode {
|
||||
// onto the next step, use (isBusy() || isBusy()) in the loop test.
|
||||
while (opModeIsActive() &&
|
||||
(runtime.seconds() < timeoutS) &&
|
||||
(robot.leftDrive.isBusy() && robot.rightDrive.isBusy())) {
|
||||
(leftDrive.isBusy() && rightDrive.isBusy())) {
|
||||
|
||||
// Display it for the driver.
|
||||
telemetry.addData("Path1", "Running to %7d :%7d", newLeftTarget, newRightTarget);
|
||||
telemetry.addData("Path2", "Running at %7d :%7d",
|
||||
robot.leftDrive.getCurrentPosition(),
|
||||
robot.rightDrive.getCurrentPosition());
|
||||
telemetry.addData("Running to", " %7d :%7d", newLeftTarget, newRightTarget);
|
||||
telemetry.addData("Currently at", " at %7d :%7d",
|
||||
leftDrive.getCurrentPosition(), rightDrive.getCurrentPosition());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Stop all motion;
|
||||
robot.leftDrive.setPower(0);
|
||||
robot.rightDrive.setPower(0);
|
||||
leftDrive.setPower(0);
|
||||
rightDrive.setPower(0);
|
||||
|
||||
// Turn off RUN_TO_POSITION
|
||||
robot.leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
robot.rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// sleep(250); // optional pause after each move
|
||||
sleep(250); // optional pause after each move.
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,431 @@
|
||||
/* Copyright (c) 2022 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.hardware.bosch.BNO055IMU;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
import com.qualcomm.robotcore.util.Range;
|
||||
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of driving an autonomous path based on Gyro heading and encoder counts.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* The path to be followed by the robot is built from a series of drive, turn or pause steps.
|
||||
* Each step on the path is defined by a single function call, and these can be strung together in any order.
|
||||
*
|
||||
* The code REQUIRES that you have encoders on the drive motors, otherwise you should use: RobotAutoDriveByTime;
|
||||
*
|
||||
* This code ALSO requires that you have a BOSCH BNO055 IMU, otherwise you would use: RobotAutoDriveByEncoder;
|
||||
* This IMU is found in REV Control/Expansion Hubs shipped prior to July 2022, and possibly also on later models.
|
||||
* To run as written, the Control/Expansion hub should be mounted horizontally on a flat part of the robot chassis.
|
||||
*
|
||||
* This sample requires that the drive Motors have been configured with names : left_drive and right_drive.
|
||||
* It also requires that a positive power command moves both motors forward, and causes the encoders to count UP.
|
||||
* So please verify that both of your motors move the robot forward on the first move. If not, make the required correction.
|
||||
* See the beginning of runOpMode() to set the FORWARD/REVERSE option for each motor.
|
||||
*
|
||||
* This code uses RUN_TO_POSITION mode for driving straight, and RUN_USING_ENCODER mode for turning and holding.
|
||||
* Note: You must call setTargetPosition() at least once before switching to RUN_TO_POSITION mode.
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* All angles are referenced to the coordinate-frame that is set whenever resetHeading() is called.
|
||||
* In this sample, the heading is reset when the Start button is touched on the Driver station.
|
||||
* Note: It would be possible to reset the heading after each move, but this would accumulate steering errors.
|
||||
*
|
||||
* The angle of movement/rotation is assumed to be a standardized rotation around the robot Z axis,
|
||||
* which means that a Positive rotation is Counter Clockwise, looking down on the field.
|
||||
* This is consistent with the FTC field coordinate conventions set out in the document:
|
||||
* ftc_app\doc\tutorial\FTC_FieldCoordinateSystemDefinition.pdf
|
||||
*
|
||||
* Control Approach.
|
||||
*
|
||||
* To reach, or maintain a required heading, this code implements a basic Proportional Controller where:
|
||||
*
|
||||
* Steering power = Heading Error * Proportional Gain.
|
||||
*
|
||||
* "Heading Error" is calculated by taking the difference between the desired heading and the actual heading,
|
||||
* and then "normalizing" it by converting it to a value in the +/- 180 degree range.
|
||||
*
|
||||
* "Proportional Gain" is a constant that YOU choose to set the "strength" of the steering response.
|
||||
*
|
||||
* Use Android Studio to Copy this Class, and Paste it into your "TeamCode" folder with a new name.
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list
|
||||
*/
|
||||
|
||||
@Autonomous(name="Robot: Auto Drive By Gyro", group="Robot")
|
||||
@Disabled
|
||||
public class RobotAutoDriveByGyro_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
private DcMotor leftDrive = null;
|
||||
private DcMotor rightDrive = null;
|
||||
private BNO055IMU imu = null; // Control/Expansion Hub IMU
|
||||
|
||||
private double robotHeading = 0;
|
||||
private double headingOffset = 0;
|
||||
private double headingError = 0;
|
||||
|
||||
// These variable are declared here (as class members) so they can be updated in various methods,
|
||||
// but still be displayed by sendTelemetry()
|
||||
private double targetHeading = 0;
|
||||
private double driveSpeed = 0;
|
||||
private double turnSpeed = 0;
|
||||
private double leftSpeed = 0;
|
||||
private double rightSpeed = 0;
|
||||
private int leftTarget = 0;
|
||||
private int rightTarget = 0;
|
||||
|
||||
// Calculate the COUNTS_PER_INCH for your specific drive train.
|
||||
// Go to your motor vendor website to determine your motor's COUNTS_PER_MOTOR_REV
|
||||
// For external drive gearing, set DRIVE_GEAR_REDUCTION as needed.
|
||||
// For example, use a value of 2.0 for a 12-tooth spur gear driving a 24-tooth spur gear.
|
||||
// This is gearing DOWN for less speed and more torque.
|
||||
// For gearing UP, use a gear ratio less than 1.0. Note this will affect the direction of wheel rotation.
|
||||
static final double COUNTS_PER_MOTOR_REV = 537.7 ; // eg: GoBILDA 312 RPM Yellow Jacket
|
||||
static final double DRIVE_GEAR_REDUCTION = 1.0 ; // No External Gearing.
|
||||
static final double WHEEL_DIAMETER_INCHES = 4.0 ; // For figuring circumference
|
||||
static final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) /
|
||||
(WHEEL_DIAMETER_INCHES * 3.1415);
|
||||
|
||||
// These constants define the desired driving/control characteristics
|
||||
// They can/should be tweaked to suit the specific robot drive train.
|
||||
static final double DRIVE_SPEED = 0.4; // Max driving speed for better distance accuracy.
|
||||
static final double TURN_SPEED = 0.2; // Max Turn speed to limit turn rate
|
||||
static final double HEADING_THRESHOLD = 1.0 ; // How close must the heading get to the target before moving to next step.
|
||||
// Requiring more accuracy (a smaller number) will often make the turn take longer to get into the final position.
|
||||
// Define the Proportional control coefficient (or GAIN) for "heading control".
|
||||
// We define one value when Turning (larger errors), and the other is used when Driving straight (smaller errors).
|
||||
// Increase these numbers if the heading does not corrects strongly enough (eg: a heavy robot or using tracks)
|
||||
// Decrease these numbers if the heading does not settle on the correct value (eg: very agile robot with omni wheels)
|
||||
static final double P_TURN_GAIN = 0.02; // Larger is more responsive, but also less stable
|
||||
static final double P_DRIVE_GAIN = 0.03; // Larger is more responsive, but also less stable
|
||||
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// Initialize the drive system variables.
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// When run, this OpMode should start both motors driving forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// define initialization values for IMU, and then initialize it.
|
||||
BNO055IMU.Parameters parameters = new BNO055IMU.Parameters();
|
||||
parameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
|
||||
imu = hardwareMap.get(BNO055IMU.class, "imu");
|
||||
imu.initialize(parameters);
|
||||
|
||||
// Ensure the robot is stationary. Reset the encoders and set the motors to BRAKE mode
|
||||
leftDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
leftDrive.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
||||
rightDrive.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
|
||||
|
||||
// Wait for the game to start (Display Gyro value while waiting)
|
||||
while (opModeInInit()) {
|
||||
telemetry.addData(">", "Robot Heading = %4.0f", getRawHeading());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Set the encoders for closed loop speed control, and reset the heading.
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
resetHeading();
|
||||
|
||||
// Step through each leg of the path,
|
||||
// Notes: Reverse movement is obtained by setting a negative distance (not speed)
|
||||
// holdHeading() is used after turns to let the heading stabilize
|
||||
// Add a sleep(2000) after any step to keep the telemetry data visible for review
|
||||
|
||||
driveStraight(DRIVE_SPEED, 24.0, 0.0); // Drive Forward 24"
|
||||
turnToHeading( TURN_SPEED, -45.0); // Turn CW to -45 Degrees
|
||||
holdHeading( TURN_SPEED, -45.0, 0.5); // Hold -45 Deg heading for a 1/2 second
|
||||
|
||||
driveStraight(DRIVE_SPEED, 17.0, -45.0); // Drive Forward 17" at -45 degrees (12"x and 12"y)
|
||||
turnToHeading( TURN_SPEED, 45.0); // Turn CCW to 45 Degrees
|
||||
holdHeading( TURN_SPEED, 45.0, 0.5); // Hold 45 Deg heading for a 1/2 second
|
||||
|
||||
driveStraight(DRIVE_SPEED, 17.0, 45.0); // Drive Forward 17" at 45 degrees (-12"x and 12"y)
|
||||
turnToHeading( TURN_SPEED, 0.0); // Turn CW to 0 Degrees
|
||||
holdHeading( TURN_SPEED, 0.0, 1.0); // Hold 0 Deg heading for 1 second
|
||||
|
||||
driveStraight(DRIVE_SPEED,-48.0, 0.0); // Drive in Reverse 48" (should return to approx. staring position)
|
||||
|
||||
telemetry.addData("Path", "Complete");
|
||||
telemetry.update();
|
||||
sleep(1000); // Pause to display last telemetry message.
|
||||
}
|
||||
|
||||
/*
|
||||
* ====================================================================================================
|
||||
* Driving "Helper" functions are below this line.
|
||||
* These provide the high and low level methods that handle driving straight and turning.
|
||||
* ====================================================================================================
|
||||
*/
|
||||
|
||||
// ********** HIGH Level driving functions. ********************
|
||||
|
||||
/**
|
||||
* Method to drive in a straight line, on a fixed compass heading (angle), based on encoder counts.
|
||||
* Move will stop if either of these conditions occur:
|
||||
* 1) Move gets to the desired position
|
||||
* 2) Driver stops the opmode running.
|
||||
*
|
||||
* @param maxDriveSpeed MAX Speed for forward/rev motion (range 0 to +1.0) .
|
||||
* @param distance Distance (in inches) to move from current position. Negative distance means move backward.
|
||||
* @param heading Absolute Heading Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from the current robotHeading.
|
||||
*/
|
||||
public void driveStraight(double maxDriveSpeed,
|
||||
double distance,
|
||||
double heading) {
|
||||
|
||||
// Ensure that the opmode is still active
|
||||
if (opModeIsActive()) {
|
||||
|
||||
// Determine new target position, and pass to motor controller
|
||||
int moveCounts = (int)(distance * COUNTS_PER_INCH);
|
||||
leftTarget = leftDrive.getCurrentPosition() + moveCounts;
|
||||
rightTarget = rightDrive.getCurrentPosition() + moveCounts;
|
||||
|
||||
// Set Target FIRST, then turn on RUN_TO_POSITION
|
||||
leftDrive.setTargetPosition(leftTarget);
|
||||
rightDrive.setTargetPosition(rightTarget);
|
||||
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_TO_POSITION);
|
||||
|
||||
// Set the required driving speed (must be positive for RUN_TO_POSITION)
|
||||
// Start driving straight, and then enter the control loop
|
||||
maxDriveSpeed = Math.abs(maxDriveSpeed);
|
||||
moveRobot(maxDriveSpeed, 0);
|
||||
|
||||
// keep looping while we are still active, and BOTH motors are running.
|
||||
while (opModeIsActive() &&
|
||||
(leftDrive.isBusy() && rightDrive.isBusy())) {
|
||||
|
||||
// Determine required steering to keep on heading
|
||||
turnSpeed = getSteeringCorrection(heading, P_DRIVE_GAIN);
|
||||
|
||||
// if driving in reverse, the motor correction also needs to be reversed
|
||||
if (distance < 0)
|
||||
turnSpeed *= -1.0;
|
||||
|
||||
// Apply the turning correction to the current driving speed.
|
||||
moveRobot(driveSpeed, turnSpeed);
|
||||
|
||||
// Display drive status for the driver.
|
||||
sendTelemetry(true);
|
||||
}
|
||||
|
||||
// Stop all motion & Turn off RUN_TO_POSITION
|
||||
moveRobot(0, 0);
|
||||
leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to spin on central axis to point in a new direction.
|
||||
* Move will stop if either of these conditions occur:
|
||||
* 1) Move gets to the heading (angle)
|
||||
* 2) Driver stops the opmode running.
|
||||
*
|
||||
* @param maxTurnSpeed Desired MAX speed of turn. (range 0 to +1.0)
|
||||
* @param heading Absolute Heading Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from current heading.
|
||||
*/
|
||||
public void turnToHeading(double maxTurnSpeed, double heading) {
|
||||
|
||||
// Run getSteeringCorrection() once to pre-calculate the current error
|
||||
getSteeringCorrection(heading, P_DRIVE_GAIN);
|
||||
|
||||
// keep looping while we are still active, and not on heading.
|
||||
while (opModeIsActive() && (Math.abs(headingError) > HEADING_THRESHOLD)) {
|
||||
|
||||
// Determine required steering to keep on heading
|
||||
turnSpeed = getSteeringCorrection(heading, P_TURN_GAIN);
|
||||
|
||||
// Clip the speed to the maximum permitted value.
|
||||
turnSpeed = Range.clip(turnSpeed, -maxTurnSpeed, maxTurnSpeed);
|
||||
|
||||
// Pivot in place by applying the turning correction
|
||||
moveRobot(0, turnSpeed);
|
||||
|
||||
// Display drive status for the driver.
|
||||
sendTelemetry(false);
|
||||
}
|
||||
|
||||
// Stop all motion;
|
||||
moveRobot(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to obtain & hold a heading for a finite amount of time
|
||||
* Move will stop once the requested time has elapsed
|
||||
* This function is useful for giving the robot a moment to stabilize it's heading between movements.
|
||||
*
|
||||
* @param maxTurnSpeed Maximum differential turn speed (range 0 to +1.0)
|
||||
* @param heading Absolute Heading Angle (in Degrees) relative to last gyro reset.
|
||||
* 0 = fwd. +ve is CCW from fwd. -ve is CW from forward.
|
||||
* If a relative angle is required, add/subtract from current heading.
|
||||
* @param holdTime Length of time (in seconds) to hold the specified heading.
|
||||
*/
|
||||
public void holdHeading(double maxTurnSpeed, double heading, double holdTime) {
|
||||
|
||||
ElapsedTime holdTimer = new ElapsedTime();
|
||||
holdTimer.reset();
|
||||
|
||||
// keep looping while we have time remaining.
|
||||
while (opModeIsActive() && (holdTimer.time() < holdTime)) {
|
||||
// Determine required steering to keep on heading
|
||||
turnSpeed = getSteeringCorrection(heading, P_TURN_GAIN);
|
||||
|
||||
// Clip the speed to the maximum permitted value.
|
||||
turnSpeed = Range.clip(turnSpeed, -maxTurnSpeed, maxTurnSpeed);
|
||||
|
||||
// Pivot in place by applying the turning correction
|
||||
moveRobot(0, turnSpeed);
|
||||
|
||||
// Display drive status for the driver.
|
||||
sendTelemetry(false);
|
||||
}
|
||||
|
||||
// Stop all motion;
|
||||
moveRobot(0, 0);
|
||||
}
|
||||
|
||||
// ********** LOW Level driving functions. ********************
|
||||
|
||||
/**
|
||||
* This method uses a Proportional Controller to determine how much steering correction is required.
|
||||
*
|
||||
* @param desiredHeading The desired absolute heading (relative to last heading reset)
|
||||
* @param proportionalGain Gain factor applied to heading error to obtain turning power.
|
||||
* @return Turning power needed to get to required heading.
|
||||
*/
|
||||
public double getSteeringCorrection(double desiredHeading, double proportionalGain) {
|
||||
targetHeading = desiredHeading; // Save for telemetry
|
||||
|
||||
// Get the robot heading by applying an offset to the IMU heading
|
||||
robotHeading = getRawHeading() - headingOffset;
|
||||
|
||||
// Determine the heading current error
|
||||
headingError = targetHeading - robotHeading;
|
||||
|
||||
// Normalize the error to be within +/- 180 degrees
|
||||
while (headingError > 180) headingError -= 360;
|
||||
while (headingError <= -180) headingError += 360;
|
||||
|
||||
// Multiply the error by the gain to determine the required steering correction/ Limit the result to +/- 1.0
|
||||
return Range.clip(headingError * proportionalGain, -1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes separate drive (fwd/rev) and turn (right/left) requests,
|
||||
* combines them, and applies the appropriate speed commands to the left and right wheel motors.
|
||||
* @param drive forward motor speed
|
||||
* @param turn clockwise turning motor speed.
|
||||
*/
|
||||
public void moveRobot(double drive, double turn) {
|
||||
driveSpeed = drive; // save this value as a class member so it can be used by telemetry.
|
||||
turnSpeed = turn; // save this value as a class member so it can be used by telemetry.
|
||||
|
||||
leftSpeed = drive - turn;
|
||||
rightSpeed = drive + turn;
|
||||
|
||||
// Scale speeds down if either one exceeds +/- 1.0;
|
||||
double max = Math.max(Math.abs(leftSpeed), Math.abs(rightSpeed));
|
||||
if (max > 1.0)
|
||||
{
|
||||
leftSpeed /= max;
|
||||
rightSpeed /= max;
|
||||
}
|
||||
|
||||
leftDrive.setPower(leftSpeed);
|
||||
rightDrive.setPower(rightSpeed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the various control parameters while driving
|
||||
*
|
||||
* @param straight Set to true if we are driving straight, and the encoder positions should be included in the telemetry.
|
||||
*/
|
||||
private void sendTelemetry(boolean straight) {
|
||||
|
||||
if (straight) {
|
||||
telemetry.addData("Motion", "Drive Straight");
|
||||
telemetry.addData("Target Pos L:R", "%7d:%7d", leftTarget, rightTarget);
|
||||
telemetry.addData("Actual Pos L:R", "%7d:%7d", leftDrive.getCurrentPosition(),
|
||||
rightDrive.getCurrentPosition());
|
||||
} else {
|
||||
telemetry.addData("Motion", "Turning");
|
||||
}
|
||||
|
||||
telemetry.addData("Angle Target:Current", "%5.2f:%5.0f", targetHeading, robotHeading);
|
||||
telemetry.addData("Error:Steer", "%5.1f:%5.1f", headingError, turnSpeed);
|
||||
telemetry.addData("Wheel Speeds L:R.", "%5.2f : %5.2f", leftSpeed, rightSpeed);
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* read the raw (un-offset Gyro heading) directly from the IMU
|
||||
*/
|
||||
public double getRawHeading() {
|
||||
Orientation angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
|
||||
return angles.firstAngle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the "offset" heading back to zero
|
||||
*/
|
||||
public void resetHeading() {
|
||||
// Save a new heading offset equal to the current raw heading.
|
||||
headingOffset = getRawHeading();
|
||||
robotHeading = 0;
|
||||
}
|
||||
}
|
@ -32,35 +32,36 @@ package org.firstinspires.ftc.robotcontroller.external.samples;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of driving a path based on time.
|
||||
* It uses the common Pushbot hardware class to define the drive on the robot.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* The code assumes that you do NOT have encoders on the wheels,
|
||||
* otherwise you would use: PushbotAutoDriveByEncoder;
|
||||
* otherwise you would use: RobotAutoDriveByEncoder;
|
||||
*
|
||||
* The desired path in this example is:
|
||||
* - Drive forward for 3 seconds
|
||||
* - Spin right for 1.3 seconds
|
||||
* - Drive Backwards for 1 Second
|
||||
* - Stop and close the claw.
|
||||
* - Drive Backward for 1 Second
|
||||
*
|
||||
* The code is written in a simple form with no optimizations.
|
||||
* However, there are several ways that this type of sequence could be streamlined,
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
*/
|
||||
|
||||
@Autonomous(name="Pushbot: Auto Drive By Time", group="Pushbot")
|
||||
@Autonomous(name="Robot: Auto Drive By Time", group="Robot")
|
||||
@Disabled
|
||||
public class PushbotAutoDriveByTime_Linear extends LinearOpMode {
|
||||
public class RobotAutoDriveByTime_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // Use a Pushbot's hardware
|
||||
private DcMotor leftDrive = null;
|
||||
private DcMotor rightDrive = null;
|
||||
|
||||
private ElapsedTime runtime = new ElapsedTime();
|
||||
|
||||
|
||||
@ -70,11 +71,15 @@ public class PushbotAutoDriveByTime_Linear extends LinearOpMode {
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
/*
|
||||
* Initialize the drive system variables.
|
||||
* The init() method of the hardware class does all the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
// Initialize the drive system variables.
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// When run, this OpMode should start both motors driving forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
telemetry.addData("Status", "Ready to run"); //
|
||||
@ -86,37 +91,35 @@ public class PushbotAutoDriveByTime_Linear extends LinearOpMode {
|
||||
// Step through each leg of the path, ensuring that the Auto mode has not been stopped along the way
|
||||
|
||||
// Step 1: Drive forward for 3 seconds
|
||||
robot.leftDrive.setPower(FORWARD_SPEED);
|
||||
robot.rightDrive.setPower(FORWARD_SPEED);
|
||||
leftDrive.setPower(FORWARD_SPEED);
|
||||
rightDrive.setPower(FORWARD_SPEED);
|
||||
runtime.reset();
|
||||
while (opModeIsActive() && (runtime.seconds() < 3.0)) {
|
||||
telemetry.addData("Path", "Leg 1: %2.5f S Elapsed", runtime.seconds());
|
||||
telemetry.addData("Path", "Leg 1: %4.1f S Elapsed", runtime.seconds());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Step 2: Spin right for 1.3 seconds
|
||||
robot.leftDrive.setPower(TURN_SPEED);
|
||||
robot.rightDrive.setPower(-TURN_SPEED);
|
||||
leftDrive.setPower(TURN_SPEED);
|
||||
rightDrive.setPower(-TURN_SPEED);
|
||||
runtime.reset();
|
||||
while (opModeIsActive() && (runtime.seconds() < 1.3)) {
|
||||
telemetry.addData("Path", "Leg 2: %2.5f S Elapsed", runtime.seconds());
|
||||
telemetry.addData("Path", "Leg 2: %4.1f S Elapsed", runtime.seconds());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Step 3: Drive Backwards for 1 Second
|
||||
robot.leftDrive.setPower(-FORWARD_SPEED);
|
||||
robot.rightDrive.setPower(-FORWARD_SPEED);
|
||||
// Step 3: Drive Backward for 1 Second
|
||||
leftDrive.setPower(-FORWARD_SPEED);
|
||||
rightDrive.setPower(-FORWARD_SPEED);
|
||||
runtime.reset();
|
||||
while (opModeIsActive() && (runtime.seconds() < 1.0)) {
|
||||
telemetry.addData("Path", "Leg 3: %2.5f S Elapsed", runtime.seconds());
|
||||
telemetry.addData("Path", "Leg 3: %4.1f S Elapsed", runtime.seconds());
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Step 4: Stop and close the claw.
|
||||
robot.leftDrive.setPower(0);
|
||||
robot.rightDrive.setPower(0);
|
||||
robot.leftClaw.setPosition(1.0);
|
||||
robot.rightClaw.setPosition(0.0);
|
||||
// Step 4: Stop
|
||||
leftDrive.setPower(0);
|
||||
rightDrive.setPower(0);
|
||||
|
||||
telemetry.addData("Path", "Complete");
|
||||
telemetry.update();
|
@ -0,0 +1,144 @@
|
||||
/* Copyright (c) 2017 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.Autonomous;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.ColorSensor;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.hardware.LightSensor;
|
||||
import com.qualcomm.robotcore.hardware.NormalizedColorSensor;
|
||||
import com.qualcomm.robotcore.hardware.NormalizedRGBA;
|
||||
import com.qualcomm.robotcore.hardware.SwitchableLight;
|
||||
|
||||
/**
|
||||
* This file illustrates the concept of driving up to a line and then stopping.
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* The Sensor used here can be a REV Color Sensor V2 or V3. Make sure the white LED is turned on.
|
||||
* The sensor can be plugged into any I2C port, and must be named "sensor_color" in the active configuration.
|
||||
*
|
||||
* Depending on the height of your color sensor, you may want to set the sensor "gain".
|
||||
* The higher the gain, the greater the reflected light reading will be.
|
||||
* Use the SensorColor sample in this folder to determine the minimum gain value that provides an
|
||||
* "Alpha" reading of 1.0 when you are on top of the white line. In this sample, we use a gain of 15
|
||||
* which works well with a Rev V2 color sensor
|
||||
*
|
||||
* Setting the correct WHITE_THRESHOLD value is key to stopping correctly.
|
||||
* This should be set halfway between the bare-tile, and white-line "Alpha" values.
|
||||
* The reflected light value can be read on the screen once the OpMode has been INIT, but before it is STARTED.
|
||||
* Move the sensor on and off the white line and note the min and max readings.
|
||||
* Edit this code to make WHITE_THRESHOLD halfway between the min and max.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@Autonomous(name="Robot: Auto Drive To Line", group="Robot")
|
||||
@Disabled
|
||||
public class RobotAutoDriveToLine_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
private DcMotor leftDrive = null;
|
||||
private DcMotor rightDrive = null;
|
||||
|
||||
/** The colorSensor field will contain a reference to our color sensor hardware object */
|
||||
NormalizedColorSensor colorSensor;
|
||||
|
||||
static final double WHITE_THRESHOLD = 0.5; // spans between 0.0 - 1.0 from dark to light
|
||||
static final double APPROACH_SPEED = 0.25;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// Initialize the drive system variables.
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// When run, this OpMode should start both motors driving forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// If there are encoders connected, switch to RUN_USING_ENCODER mode for greater accuracy
|
||||
// leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
// rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// Get a reference to our sensor object. It's recommended to use NormalizedColorSensor over
|
||||
// ColorSensor, because NormalizedColorSensor consistently gives values between 0 and 1, while
|
||||
// the values you get from ColorSensor are dependent on the specific sensor you're using.
|
||||
colorSensor = hardwareMap.get(NormalizedColorSensor.class, "sensor_color");
|
||||
|
||||
// If necessary, turn ON the white LED (if there is no LED switch on the sensor)
|
||||
if (colorSensor instanceof SwitchableLight) {
|
||||
((SwitchableLight)colorSensor).enableLight(true);
|
||||
}
|
||||
|
||||
// Some sensors allow you to set your light sensor gain for optimal sensitivity...
|
||||
// See the SensorColor sample in this folder for how to determine the optimal gain.
|
||||
// A gain of 15 causes a Rev Color Sensor V2 to produce an Alpha value of 1.0 at about 1.5" above the floor.
|
||||
colorSensor.setGain(15);
|
||||
|
||||
// Wait for driver to press PLAY)
|
||||
// Abort this loop is started or stopped.
|
||||
while (opModeInInit()) {
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
telemetry.addData("Status", "Ready to drive to white line."); //
|
||||
|
||||
// Display the light level while we are waiting to start
|
||||
getBrightness();
|
||||
}
|
||||
|
||||
// Start the robot moving forward, and then begin looking for a white line.
|
||||
leftDrive.setPower(APPROACH_SPEED);
|
||||
rightDrive.setPower(APPROACH_SPEED);
|
||||
|
||||
// run until the white line is seen OR the driver presses STOP;
|
||||
while (opModeIsActive() && (getBrightness() < WHITE_THRESHOLD)) {
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
// Stop all motors
|
||||
leftDrive.setPower(0);
|
||||
rightDrive.setPower(0);
|
||||
}
|
||||
|
||||
// to obtain reflected light, read the normalized values from the color sensor. Return the Alpha channel.
|
||||
double getBrightness() {
|
||||
NormalizedRGBA colors = colorSensor.getNormalizedColors();
|
||||
telemetry.addData("Light Level (0 to 1)", "%4.2f", colors.alpha);
|
||||
telemetry.update();
|
||||
|
||||
return colors.alpha;
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
/* Copyright (c) 2022 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.LinearOpMode;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
import com.qualcomm.robotcore.util.Range;
|
||||
|
||||
/**
|
||||
* This file works in conjunction with the External Hardware Class sample called: ConceptExternalHardwareClass.java
|
||||
* Please read the explanations in that Sample about how to use this class definition.
|
||||
*
|
||||
* This file defines a Java Class that performs all the setup and configuration for a sample robot's hardware (motors and sensors).
|
||||
* It assumes three motors (left_drive, right_drive and arm) and two servos (left_hand and right_hand)
|
||||
*
|
||||
* This one file/class can be used by ALL of your OpModes without having to cut & paste the code each time.
|
||||
*
|
||||
* Where possible, the actual hardware objects are "abstracted" (or hidden) so the OpMode code just makes calls into the class,
|
||||
* rather than accessing the internal hardware directly. This is why the objects are declared "private".
|
||||
*
|
||||
* Use Android Studio to Copy this Class, and Paste it into your team's code folder with *exactly the same name*.
|
||||
*
|
||||
* Or.. In OnBot Java, add a new file named RobotHardware.java, drawing from this Sample; select Not an OpMode.
|
||||
* Also add a new OpMode, drawing from the Sample ConceptExternalHardwareClass.java; select TeleOp.
|
||||
*
|
||||
*/
|
||||
|
||||
public class RobotHardware {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
private LinearOpMode myOpMode = null; // gain access to methods in the calling OpMode.
|
||||
|
||||
// Define Motor and Servo objects (Make them private so they can't be accessed externally)
|
||||
private DcMotor leftDrive = null;
|
||||
private DcMotor rightDrive = null;
|
||||
private DcMotor armMotor = null;
|
||||
private Servo leftHand = null;
|
||||
private Servo rightHand = null;
|
||||
|
||||
// Define Drive constants. Make them public so they CAN be used by the calling OpMode
|
||||
public static final double MID_SERVO = 0.5 ;
|
||||
public static final double HAND_SPEED = 0.02 ; // sets rate to move servo
|
||||
public static final double ARM_UP_POWER = 0.45 ;
|
||||
public static final double ARM_DOWN_POWER = -0.45 ;
|
||||
|
||||
// Define a constructor that allows the OpMode to pass a reference to itself.
|
||||
public RobotHardware (LinearOpMode opmode) {
|
||||
myOpMode = opmode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize all the robot's hardware.
|
||||
* This method must be called ONCE when the OpMode is initialized.
|
||||
*
|
||||
* All of the hardware devices are accessed via the hardware map, and initialized.
|
||||
*/
|
||||
public void init() {
|
||||
// Define and Initialize Motors (note: need to use reference to actual OpMode).
|
||||
leftDrive = myOpMode.hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = myOpMode.hardwareMap.get(DcMotor.class, "right_drive");
|
||||
armMotor = myOpMode.hardwareMap.get(DcMotor.class, "arm");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// If there are encoders connected, switch to RUN_USING_ENCODER mode for greater accuracy
|
||||
// leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
// rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// Define and initialize ALL installed servos.
|
||||
leftHand = myOpMode.hardwareMap.get(Servo.class, "left_hand");
|
||||
rightHand = myOpMode.hardwareMap.get(Servo.class, "right_hand");
|
||||
leftHand.setPosition(MID_SERVO);
|
||||
rightHand.setPosition(MID_SERVO);
|
||||
|
||||
myOpMode.telemetry.addData(">", "Hardware Initialized");
|
||||
myOpMode.telemetry.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the left/right motor powers required to achieve the requested
|
||||
* robot motions: Drive (Axial motion) and Turn (Yaw motion).
|
||||
* Then sends these power levels to the motors.
|
||||
*
|
||||
* @param Drive Fwd/Rev driving power (-1.0 to 1.0) +ve is forward
|
||||
* @param Turn Right/Left turning power (-1.0 to 1.0) +ve is CW
|
||||
*/
|
||||
public void driveRobot(double Drive, double Turn) {
|
||||
// Combine drive and turn for blended motion.
|
||||
double left = Drive + Turn;
|
||||
double right = Drive - Turn;
|
||||
|
||||
// Scale the values so neither exceed +/- 1.0
|
||||
double max = Math.max(Math.abs(left), Math.abs(right));
|
||||
if (max > 1.0)
|
||||
{
|
||||
left /= max;
|
||||
right /= max;
|
||||
}
|
||||
|
||||
// Use existing function to drive both wheels.
|
||||
setDrivePower(left, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass the requested wheel motor powers to the appropriate hardware drive motors.
|
||||
*
|
||||
* @param leftWheel Fwd/Rev driving power (-1.0 to 1.0) +ve is forward
|
||||
* @param rightWheel Fwd/Rev driving power (-1.0 to 1.0) +ve is forward
|
||||
*/
|
||||
public void setDrivePower(double leftWheel, double rightWheel) {
|
||||
// Output the values to the motor drives.
|
||||
leftDrive.setPower(leftWheel);
|
||||
rightDrive.setPower(rightWheel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass the requested arm power to the appropriate hardware drive motor
|
||||
*
|
||||
* @param power driving power (-1.0 to 1.0)
|
||||
*/
|
||||
public void setArmPower(double power) {
|
||||
armMotor.setPower(power);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the two hand-servos to opposing (mirrored) positions, based on the passed offset.
|
||||
*
|
||||
* @param offset
|
||||
*/
|
||||
public void setHandPositions(double offset) {
|
||||
offset = Range.clip(offset, -0.5, 0.5);
|
||||
leftHand.setPosition(MID_SERVO + offset);
|
||||
rightHand.setPosition(MID_SERVO - offset);
|
||||
}
|
||||
}
|
@ -32,30 +32,39 @@ 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.DcMotor;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
import com.qualcomm.robotcore.util.Range;
|
||||
|
||||
/**
|
||||
* This OpMode uses the common Pushbot hardware class to define the devices on the robot.
|
||||
* All device access is managed through the HardwarePushbot class.
|
||||
* This particular OpMode executes a POV Game style Teleop for a direct drive robot
|
||||
* The code is structured as a LinearOpMode
|
||||
*
|
||||
* This particular OpMode executes a POV Game style Teleop for a PushBot
|
||||
* In this mode the left stick moves the robot FWD and back, the Right stick turns left and right.
|
||||
* It raises and lowers the claw using the Gampad Y and A buttons respectively.
|
||||
* It raises and lowers the arm using the Gamepad Y and A buttons respectively.
|
||||
* It also opens and closes the claws slowly using the left and right Bumper buttons.
|
||||
*
|
||||
* Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
|
||||
* 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
|
||||
*/
|
||||
|
||||
@TeleOp(name="Pushbot: Teleop POV", group="Pushbot")
|
||||
@TeleOp(name="Robot: Teleop POV", group="Robot")
|
||||
@Disabled
|
||||
public class PushbotTeleopPOV_Linear extends LinearOpMode {
|
||||
public class RobotTeleopPOV_Linear extends LinearOpMode {
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // Use a Pushbot's hardware
|
||||
double clawOffset = 0; // Servo mid position
|
||||
final double CLAW_SPEED = 0.02 ; // sets rate to move servo
|
||||
public DcMotor leftDrive = null;
|
||||
public DcMotor rightDrive = null;
|
||||
public DcMotor leftArm = null;
|
||||
public Servo leftClaw = null;
|
||||
public Servo rightClaw = null;
|
||||
|
||||
double clawOffset = 0;
|
||||
|
||||
public static final double MID_SERVO = 0.5 ;
|
||||
public static final double CLAW_SPEED = 0.02 ; // sets rate to move servo
|
||||
public static final double ARM_UP_POWER = 0.45 ;
|
||||
public static final double ARM_DOWN_POWER = -0.45 ;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
@ -65,13 +74,29 @@ public class PushbotTeleopPOV_Linear extends LinearOpMode {
|
||||
double turn;
|
||||
double max;
|
||||
|
||||
/* Initialize the hardware variables.
|
||||
* The init() method of the hardware class does all the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
// Define and Initialize Motors
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
leftArm = hardwareMap.get(DcMotor.class, "left_arm");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left stick forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// If there are encoders connected, switch to RUN_USING_ENCODER mode for greater accuracy
|
||||
// leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
// rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// Define and initialize ALL installed servos.
|
||||
leftClaw = hardwareMap.get(Servo.class, "left_hand");
|
||||
rightClaw = hardwareMap.get(Servo.class, "right_hand");
|
||||
leftClaw.setPosition(MID_SERVO);
|
||||
rightClaw.setPosition(MID_SERVO);
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
telemetry.addData("Say", "Hello Driver"); //
|
||||
telemetry.addData(">", "Robot Ready. Press Play."); //
|
||||
telemetry.update();
|
||||
|
||||
// Wait for the game to start (driver presses PLAY)
|
||||
@ -80,7 +105,7 @@ public class PushbotTeleopPOV_Linear extends LinearOpMode {
|
||||
// run until the end of the match (driver presses STOP)
|
||||
while (opModeIsActive()) {
|
||||
|
||||
// Run wheels in POV mode (note: The joystick goes negative when pushed forwards, so negate it)
|
||||
// Run wheels in POV mode (note: The joystick goes negative when pushed forward, so negate it)
|
||||
// In this mode the Left stick moves the robot fwd and back, the Right stick turns left and right.
|
||||
// This way it's also easy to just drive straight, or just turn.
|
||||
drive = -gamepad1.left_stick_y;
|
||||
@ -99,8 +124,8 @@ public class PushbotTeleopPOV_Linear extends LinearOpMode {
|
||||
}
|
||||
|
||||
// Output the safe vales to the motor drives.
|
||||
robot.leftDrive.setPower(left);
|
||||
robot.rightDrive.setPower(right);
|
||||
leftDrive.setPower(left);
|
||||
rightDrive.setPower(right);
|
||||
|
||||
// Use gamepad left & right Bumpers to open and close the claw
|
||||
if (gamepad1.right_bumper)
|
||||
@ -110,16 +135,16 @@ public class PushbotTeleopPOV_Linear extends LinearOpMode {
|
||||
|
||||
// Move both servos to new position. Assume servos are mirror image of each other.
|
||||
clawOffset = Range.clip(clawOffset, -0.5, 0.5);
|
||||
robot.leftClaw.setPosition(robot.MID_SERVO + clawOffset);
|
||||
robot.rightClaw.setPosition(robot.MID_SERVO - clawOffset);
|
||||
leftClaw.setPosition(MID_SERVO + clawOffset);
|
||||
rightClaw.setPosition(MID_SERVO - clawOffset);
|
||||
|
||||
// Use gamepad buttons to move arm up (Y) and down (A)
|
||||
if (gamepad1.y)
|
||||
robot.leftArm.setPower(robot.ARM_UP_POWER);
|
||||
leftArm.setPower(ARM_UP_POWER);
|
||||
else if (gamepad1.a)
|
||||
robot.leftArm.setPower(robot.ARM_DOWN_POWER);
|
||||
leftArm.setPower(ARM_DOWN_POWER);
|
||||
else
|
||||
robot.leftArm.setPower(0.0);
|
||||
leftArm.setPower(0.0);
|
||||
|
||||
// Send telemetry message to signify robot running;
|
||||
telemetry.addData("claw", "Offset = %.2f", clawOffset);
|
@ -32,44 +32,69 @@ package org.firstinspires.ftc.robotcontroller.external.samples;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
import com.qualcomm.robotcore.util.Range;
|
||||
|
||||
/**
|
||||
* This file provides basic Telop driving for a Pushbot robot.
|
||||
* This particular OpMode executes a Tank Drive control TeleOp a direct drive robot
|
||||
* The code is structured as an Iterative OpMode
|
||||
*
|
||||
* This OpMode uses the common Pushbot hardware class to define the devices on the robot.
|
||||
* All device access is managed through the HardwarePushbot class.
|
||||
*
|
||||
* This particular OpMode executes a basic Tank Drive Teleop for a PushBot
|
||||
* It raises and lowers the claw using the Gampad Y and A buttons respectively.
|
||||
* In this mode, the left and right joysticks control the left and right motors respectively.
|
||||
* Pushing a joystick forward will make the attached motor drive forward.
|
||||
* It raises and lowers the claw using the Gamepad Y and A buttons respectively.
|
||||
* It also opens and closes the claws slowly using the left and right Bumper buttons.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
*/
|
||||
|
||||
@TeleOp(name="Pushbot: Teleop Tank", group="Pushbot")
|
||||
@TeleOp(name="Robot: Teleop Tank", group="Robot")
|
||||
@Disabled
|
||||
public class PushbotTeleopTank_Iterative extends OpMode{
|
||||
public class RobotTeleopTank_Iterative extends OpMode{
|
||||
|
||||
/* Declare OpMode members. */
|
||||
HardwarePushbot robot = new HardwarePushbot(); // use the class created to define a Pushbot's hardware
|
||||
double clawOffset = 0.0 ; // Servo mid position
|
||||
final double CLAW_SPEED = 0.02 ; // sets rate to move servo
|
||||
public DcMotor leftDrive = null;
|
||||
public DcMotor rightDrive = null;
|
||||
public DcMotor leftArm = null;
|
||||
public Servo leftClaw = null;
|
||||
public Servo rightClaw = null;
|
||||
|
||||
double clawOffset = 0;
|
||||
|
||||
public static final double MID_SERVO = 0.5 ;
|
||||
public static final double CLAW_SPEED = 0.02 ; // sets rate to move servo
|
||||
public static final double ARM_UP_POWER = 0.50 ; // Run arm motor up at 50% power
|
||||
public static final double ARM_DOWN_POWER = -0.25 ; // Run arm motor down at -25% power
|
||||
|
||||
/*
|
||||
* Code to run ONCE when the driver hits INIT
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
/* Initialize the hardware variables.
|
||||
* The init() method of the hardware class does all the work here
|
||||
*/
|
||||
robot.init(hardwareMap);
|
||||
// Define and Initialize Motors
|
||||
leftDrive = hardwareMap.get(DcMotor.class, "left_drive");
|
||||
rightDrive = hardwareMap.get(DcMotor.class, "right_drive");
|
||||
leftArm = hardwareMap.get(DcMotor.class, "left_arm");
|
||||
|
||||
// To drive forward, most robots need the motor on one side to be reversed, because the axles point in opposite directions.
|
||||
// Pushing the left and right sticks forward MUST make robot go forward. So adjust these two lines based on your first test drive.
|
||||
// Note: The settings here assume direct drive on left and right wheels. Gear Reduction or 90 Deg drives may require direction flips
|
||||
leftDrive.setDirection(DcMotor.Direction.REVERSE);
|
||||
rightDrive.setDirection(DcMotor.Direction.FORWARD);
|
||||
|
||||
// If there are encoders connected, switch to RUN_USING_ENCODER mode for greater accuracy
|
||||
// leftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
// rightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||
|
||||
// Define and initialize ALL installed servos.
|
||||
leftClaw = hardwareMap.get(Servo.class, "left_hand");
|
||||
rightClaw = hardwareMap.get(Servo.class, "right_hand");
|
||||
leftClaw.setPosition(MID_SERVO);
|
||||
rightClaw.setPosition(MID_SERVO);
|
||||
|
||||
// Send telemetry message to signify robot waiting;
|
||||
telemetry.addData("Say", "Hello Driver"); //
|
||||
telemetry.addData(">", "Robot Ready. Press Play."); //
|
||||
}
|
||||
|
||||
/*
|
||||
@ -94,12 +119,12 @@ public class PushbotTeleopTank_Iterative extends OpMode{
|
||||
double left;
|
||||
double right;
|
||||
|
||||
// Run wheels in tank mode (note: The joystick goes negative when pushed forwards, so negate it)
|
||||
// Run wheels in tank mode (note: The joystick goes negative when pushed forward, so negate it)
|
||||
left = -gamepad1.left_stick_y;
|
||||
right = -gamepad1.right_stick_y;
|
||||
|
||||
robot.leftDrive.setPower(left);
|
||||
robot.rightDrive.setPower(right);
|
||||
leftDrive.setPower(left);
|
||||
rightDrive.setPower(right);
|
||||
|
||||
// Use gamepad left & right Bumpers to open and close the claw
|
||||
if (gamepad1.right_bumper)
|
||||
@ -109,16 +134,16 @@ public class PushbotTeleopTank_Iterative extends OpMode{
|
||||
|
||||
// Move both servos to new position. Assume servos are mirror image of each other.
|
||||
clawOffset = Range.clip(clawOffset, -0.5, 0.5);
|
||||
robot.leftClaw.setPosition(robot.MID_SERVO + clawOffset);
|
||||
robot.rightClaw.setPosition(robot.MID_SERVO - clawOffset);
|
||||
leftClaw.setPosition(MID_SERVO + clawOffset);
|
||||
rightClaw.setPosition(MID_SERVO - clawOffset);
|
||||
|
||||
// Use gamepad buttons to move the arm up (Y) and down (A)
|
||||
if (gamepad1.y)
|
||||
robot.leftArm.setPower(robot.ARM_UP_POWER);
|
||||
leftArm.setPower(ARM_UP_POWER);
|
||||
else if (gamepad1.a)
|
||||
robot.leftArm.setPower(robot.ARM_DOWN_POWER);
|
||||
leftArm.setPower(ARM_DOWN_POWER);
|
||||
else
|
||||
robot.leftArm.setPower(0.0);
|
||||
leftArm.setPower(0.0);
|
||||
|
||||
// Send telemetry message to signify robot running;
|
||||
telemetry.addData("claw", "Offset = %.2f", clawOffset);
|
@ -1,167 +0,0 @@
|
||||
/* Copyright (c) 2017 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 android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.view.View;
|
||||
|
||||
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.ColorSensor;
|
||||
import com.qualcomm.robotcore.hardware.DeviceInterfaceModule;
|
||||
import com.qualcomm.robotcore.hardware.DigitalChannel;
|
||||
|
||||
/*
|
||||
*
|
||||
* This is an example LinearOpMode that shows how to use
|
||||
* the Adafruit RGB Sensor. It assumes that the I2C
|
||||
* cable for the sensor is connected to an I2C port on the
|
||||
* Core Device Interface Module.
|
||||
*
|
||||
* It also assuems that the LED pin of the sensor is connected
|
||||
* to the digital signal pin of a digital port on the
|
||||
* Core Device Interface Module.
|
||||
*
|
||||
* You can use the digital port to turn the sensor's onboard
|
||||
* LED on or off.
|
||||
*
|
||||
* The op mode assumes that the Core Device Interface Module
|
||||
* is configured with a name of "dim" and that the Adafruit color sensor
|
||||
* is configured as an I2C device with a name of "sensor_color".
|
||||
*
|
||||
* It also assumes that the LED pin of the RGB sensor
|
||||
* is connected to the signal pin of digital port #5 (zero indexed)
|
||||
* of the Core Device Interface Module.
|
||||
*
|
||||
* You can use the X button on gamepad1 to toggle the LED on and off.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
@TeleOp(name = "Sensor: AdafruitRGB", group = "Sensor")
|
||||
@Disabled // Comment this out to add to the opmode list
|
||||
public class SensorAdafruitRGB extends LinearOpMode {
|
||||
|
||||
ColorSensor sensorRGB;
|
||||
DeviceInterfaceModule cdim;
|
||||
|
||||
// we assume that the LED pin of the RGB sensor is connected to
|
||||
// digital port 5 (zero indexed).
|
||||
static final int LED_CHANNEL = 5;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
// hsvValues is an array that will hold the hue, saturation, and value information.
|
||||
float hsvValues[] = {0F,0F,0F};
|
||||
|
||||
// values is a reference to the hsvValues array.
|
||||
final float values[] = hsvValues;
|
||||
|
||||
// get a reference to the RelativeLayout so we can change the background
|
||||
// color of the Robot Controller app to match the hue detected by the RGB sensor.
|
||||
int relativeLayoutId = hardwareMap.appContext.getResources().getIdentifier("RelativeLayout", "id", hardwareMap.appContext.getPackageName());
|
||||
final View relativeLayout = ((Activity) hardwareMap.appContext).findViewById(relativeLayoutId);
|
||||
|
||||
// bPrevState and bCurrState represent the previous and current state of the button.
|
||||
boolean bPrevState = false;
|
||||
boolean bCurrState = false;
|
||||
|
||||
// bLedOn represents the state of the LED.
|
||||
boolean bLedOn = true;
|
||||
|
||||
// get a reference to our DeviceInterfaceModule object.
|
||||
cdim = hardwareMap.deviceInterfaceModule.get("dim");
|
||||
|
||||
// set the digital channel to output mode.
|
||||
// remember, the Adafruit sensor is actually two devices.
|
||||
// It's an I2C sensor and it's also an LED that can be turned on or off.
|
||||
cdim.setDigitalChannelMode(LED_CHANNEL, DigitalChannel.Mode.OUTPUT);
|
||||
|
||||
// get a reference to our ColorSensor object.
|
||||
sensorRGB = hardwareMap.colorSensor.get("sensor_color");
|
||||
|
||||
// turn the LED on in the beginning, just so user will know that the sensor is active.
|
||||
cdim.setDigitalChannelState(LED_CHANNEL, bLedOn);
|
||||
|
||||
// wait for the start button to be pressed.
|
||||
waitForStart();
|
||||
|
||||
// loop and read the RGB data.
|
||||
// Note we use opModeIsActive() as our loop condition because it is an interruptible method.
|
||||
while (opModeIsActive()) {
|
||||
|
||||
// check the status of the x button on gamepad.
|
||||
bCurrState = gamepad1.x;
|
||||
|
||||
// check for button-press state transitions.
|
||||
if ((bCurrState == true) && (bCurrState != bPrevState)) {
|
||||
|
||||
// button is transitioning to a pressed state. Toggle the LED.
|
||||
bLedOn = !bLedOn;
|
||||
cdim.setDigitalChannelState(LED_CHANNEL, bLedOn);
|
||||
}
|
||||
|
||||
// update previous state variable.
|
||||
bPrevState = bCurrState;
|
||||
|
||||
// convert the RGB values to HSV values.
|
||||
Color.RGBToHSV((sensorRGB.red() * 255) / 800, (sensorRGB.green() * 255) / 800, (sensorRGB.blue() * 255) / 800, hsvValues);
|
||||
|
||||
// send the info back to driver station using telemetry function.
|
||||
telemetry.addData("LED", bLedOn ? "On" : "Off");
|
||||
telemetry.addData("Clear", sensorRGB.alpha());
|
||||
telemetry.addData("Red ", sensorRGB.red());
|
||||
telemetry.addData("Green", sensorRGB.green());
|
||||
telemetry.addData("Blue ", sensorRGB.blue());
|
||||
telemetry.addData("Hue", hsvValues[0]);
|
||||
|
||||
// change the background color to match the color detected by the RGB sensor.
|
||||
// pass a reference to the hue, saturation, and value array as an argument
|
||||
// to the HSVToColor method.
|
||||
relativeLayout.post(new Runnable() {
|
||||
public void run() {
|
||||
relativeLayout.setBackgroundColor(Color.HSVToColor(0xff, values));
|
||||
}
|
||||
});
|
||||
|
||||
telemetry.update();
|
||||
}
|
||||
|
||||
// Set the panel back to the default color
|
||||
relativeLayout.post(new Runnable() {
|
||||
public void run() {
|
||||
relativeLayout.setBackgroundColor(Color.WHITE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/* Copyright (c) 2017 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.DeviceInterfaceModule;
|
||||
import com.qualcomm.robotcore.hardware.DigitalChannel;
|
||||
|
||||
/*
|
||||
* This is an example LinearOpMode that shows how to use the digital inputs and outputs on the
|
||||
* the Modern Robotics Device Interface Module. In addition, it shows how to use the Red and Blue LED
|
||||
*
|
||||
* This op mode assumes that there is a Device Interface Module attached, named 'dim'.
|
||||
* On this DIM there is a digital input named 'digin' and an output named 'digout'
|
||||
*
|
||||
* To fully exercise this sample, connect pin 3 of the digin connector to pin 3 of the digout.
|
||||
* Note: Pin 1 is indicated by the black stripe, so pin 3 is at the opposite end.
|
||||
*
|
||||
* The X button on the gamepad will be used to activate the digital output pin.
|
||||
* The Red/Blue LED will be used to indicate the state of the digital input pin.
|
||||
* Blue = false (0V), Red = true (5V)
|
||||
* If the two pins are linked, the gamepad will change the LED color.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
@TeleOp(name = "Sensor: DIM DIO", group = "Sensor")
|
||||
@Disabled
|
||||
public class SensorDIO extends LinearOpMode {
|
||||
|
||||
final int BLUE_LED_CHANNEL = 0;
|
||||
final int RED_LED_CHANNEL = 1;
|
||||
|
||||
@Override
|
||||
public void runOpMode() {
|
||||
|
||||
boolean inputPin; // Input State
|
||||
boolean outputPin; // Output State
|
||||
DeviceInterfaceModule dim; // Device Object
|
||||
DigitalChannel digIn; // Device Object
|
||||
DigitalChannel digOut; // Device Object
|
||||
|
||||
// get a reference to a Modern Robotics DIM, and IO channels.
|
||||
dim = hardwareMap.get(DeviceInterfaceModule.class, "dim"); // Use generic form of device mapping
|
||||
digIn = hardwareMap.get(DigitalChannel.class, "digin"); // Use generic form of device mapping
|
||||
digOut = hardwareMap.get(DigitalChannel.class, "digout"); // Use generic form of device mapping
|
||||
|
||||
digIn.setMode(DigitalChannel.Mode.INPUT); // Set the direction of each channel
|
||||
digOut.setMode(DigitalChannel.Mode.OUTPUT);
|
||||
|
||||
// wait for the start button to be pressed.
|
||||
telemetry.addData(">", "Press play, and then user X button to set DigOut");
|
||||
telemetry.update();
|
||||
waitForStart();
|
||||
|
||||
while (opModeIsActive()) {
|
||||
|
||||
outputPin = gamepad1.x ; // Set the output pin based on x button
|
||||
digOut.setState(outputPin);
|
||||
inputPin = digIn.getState(); // Read the input pin
|
||||
|
||||
// Display input pin state on LEDs
|
||||
if (inputPin) {
|
||||
dim.setLED(RED_LED_CHANNEL, true);
|
||||
dim.setLED(BLUE_LED_CHANNEL, false);
|
||||
}
|
||||
else {
|
||||
dim.setLED(RED_LED_CHANNEL, false);
|
||||
dim.setLED(BLUE_LED_CHANNEL, true);
|
||||
}
|
||||
|
||||
telemetry.addData("Output", outputPin );
|
||||
telemetry.addData("Input", inputPin );
|
||||
telemetry.addData("LED", inputPin ? "Red" : "Blue" );
|
||||
telemetry.update();
|
||||
}
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ import com.qualcomm.robotcore.hardware.ColorSensor;
|
||||
* You can use the X button on gamepad1 to toggle the LED on and off.
|
||||
*
|
||||
* 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
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list
|
||||
*/
|
||||
@TeleOp(name = "Sensor: MR Color", group = "Sensor")
|
||||
@Disabled
|
||||
|
@ -49,7 +49,7 @@ import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
|
||||
* I2C channel and is configured with a name of "gyro".
|
||||
*
|
||||
* 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
|
||||
* Remove or comment out the @Disabled line to add this OpMode to the Driver Station OpMode list
|
||||
*/
|
||||
@TeleOp(name = "Sensor: MR Gyro", group = "Sensor")
|
||||
@Disabled
|
||||
@ -83,7 +83,7 @@ public class SensorMRGyro extends LinearOpMode {
|
||||
// A similar approach will work for the Gyroscope interface, if that's all you need.
|
||||
|
||||
// Start calibrating the gyro. This takes a few seconds and is worth performing
|
||||
// during the initialization phase at the start of each opMode.
|
||||
// during the initialization phase at the start of each OpMode.
|
||||
telemetry.log().add("Gyro Calibrating. Do Not Move!");
|
||||
modernRoboticsI2cGyro.calibrate();
|
||||
|
||||
|
@ -27,15 +27,9 @@ Sensor: This is a Sample OpMode that shows how to use a specific sensor.
|
||||
It is not intended to drive a functioning robot, it is simply showing the minimal code
|
||||
required to read and display the sensor values.
|
||||
|
||||
Hardware: This is NOT an OpMode, but a helper class that is used to describe
|
||||
one particular robot's hardware configuration: eg: For the K9 or Pushbot.
|
||||
Look at any Pushbot sample to see how this can be used in an OpMode.
|
||||
Teams can copy one of these to their team folder to create their own robot definition.
|
||||
|
||||
Pushbot: This is a Sample OpMode that uses the Pushbot robot hardware as a base.
|
||||
It may be used to provide some standard baseline Pushbot OpModes, or
|
||||
to demonstrate how a particular sensor or concept can be used directly on the
|
||||
Pushbot chassis.
|
||||
Robot: This is a Sample OpMode that assumes a simple two-motor (differential) drive base.
|
||||
It may be used to provide a common baseline driving OpMode, or
|
||||
to demonstrate how a particular sensor or concept can be used to navigate.
|
||||
|
||||
Concept: This is a sample OpMode that illustrates performing a specific function or concept.
|
||||
These may be complex, but their operation should be explained clearly in the comments,
|
||||
@ -43,15 +37,9 @@ Concept: This is a sample OpMode that illustrates performing a specific function
|
||||
Each OpMode should try to only demonstrate a single concept so they are easy to
|
||||
locate based on their name. These OpModes may not produce a drivable robot.
|
||||
|
||||
Library: This is a class, or set of classes used to implement some strategy.
|
||||
These will typically NOT implement a full OpMode. Instead they will be included
|
||||
by an OpMode to provide some stand-alone capability.
|
||||
|
||||
After the prefix, other conventions will apply:
|
||||
|
||||
* Sensor class names are constructed as: Sensor - Company - Type
|
||||
* Hardware class names are constructed as: Hardware - Robot type
|
||||
* Pushbot class names are constructed as: Pushbot - Mode - Action - OpModetype
|
||||
* Robot class names are constructed as: Robot - Mode - Action - OpModetype
|
||||
* Concept class names are constructed as: Concept - Topic - OpModetype
|
||||
* Library class names are constructed as: Library - Topic - OpModetype
|
||||
|
||||
|
@ -5,45 +5,35 @@ This document defines the FTC Sample OpMode and Class conventions.
|
||||
|
||||
### OpMode Name
|
||||
|
||||
A range of different samples classes will reside in the java/external/samples folder.
|
||||
To gain a better understanding of how the samples are organized, and how to interpret the
|
||||
naming system, it will help to understand the conventions that were used during their creation.
|
||||
|
||||
For ease of understanding, the class names will follow a naming convention which indicates
|
||||
the purpose of each class. The prefix of the name will be one of the following:
|
||||
To summarize: A range of different samples classes will reside in the java/external/samples.
|
||||
The class names will follow a naming convention which indicates the purpose of each class.
|
||||
The prefix of the name will be one of the following:
|
||||
|
||||
Basic: This is a minimally functional OpMode used to illustrate the skeleton/structure
|
||||
of a particular style of OpMode. These are bare bones Tank Drive examples.
|
||||
Basic: This is a minimally functional OpMode used to illustrate the skeleton/structure
|
||||
of a particular style of OpMode. These are bare bones examples.
|
||||
|
||||
Sensor: This is a Sample OpMode that shows how to use a specific sensor.
|
||||
It is not intended to drive a functioning robot, it is simply showing the minimal code
|
||||
required to read and display the sensor values.
|
||||
|
||||
Hardware: This is not an actual OpMode, but a helper class that is used to describe
|
||||
one particular robot's hardware configuration: eg: For the K9 or Pushbot.
|
||||
Look at any Pushbot sample to see how this can be used in an OpMode.
|
||||
Teams can copy one of these to create their own robot definition.
|
||||
|
||||
Pushbot: This is a Sample OpMode that uses the Pushbot robot hardware as a base.
|
||||
It may be used to provide some standard baseline Pushbot opmodes, or
|
||||
to demonstrate how a particular sensor or concept can be used directly on the
|
||||
Pushbot chassis.
|
||||
Robot: This is a Sample OpMode that assumes a simple two-motor (differential) drive base.
|
||||
It may be used to provide a common baseline driving OpMode, or
|
||||
to demonstrate how a particular sensor or concept can be used to navigate.
|
||||
|
||||
Concept: This is a sample OpMode that illustrates performing a specific function or concept.
|
||||
These may be complex, but their operation should be explained clearly in the comments,
|
||||
or the comments should reference an external doc, guide or tutorial.
|
||||
Each OpMode should try to only demonstrate a single concept so they are easy to
|
||||
locate based on their name.
|
||||
|
||||
Library: This is a class, or set of classes used to implement some strategy.
|
||||
These will typically NOT implement a full opmode. Instead they will be included
|
||||
by an OpMode to provide some stand-alone capability.
|
||||
locate based on their name. These OpModes may not produce a drivable robot.
|
||||
|
||||
After the prefix, other conventions will apply:
|
||||
|
||||
* Sensor class names should constructed as: Sensor - Company - Type
|
||||
* Hardware class names should be constructed as: Hardware - Robot type
|
||||
* Pushbot class names should be constructed as: Pushbot - Mode - Action - OpModetype
|
||||
* Robot class names should be constructed as: Robot - Mode - Action - OpModetype
|
||||
* Concept class names should be constructed as: Concept - Topic - OpModetype
|
||||
* Library class names should be constructed as: Library - Topic - OpModetype
|
||||
|
||||
### Sample OpMode Content/Style
|
||||
|
||||
|
@ -306,9 +306,9 @@ public class FtcRobotControllerActivity extends Activity
|
||||
preferencesHelper.writeBooleanPrefIfDifferent(context.getString(R.string.pref_rc_connected), true);
|
||||
preferencesHelper.getSharedPreferences().registerOnSharedPreferenceChangeListener(sharedPreferencesListener);
|
||||
|
||||
// Check if this RC app is from a later FTC season that what was installed previously
|
||||
// Check if this RC app is from a later FTC season than what was installed previously
|
||||
int ftcSeasonYearOfPreviouslyInstalledRc = preferencesHelper.readInt(getString(R.string.pref_ftc_season_year_of_current_rc), 0);
|
||||
int ftcSeasonYearOfCurrentlyInstalledRc = AppUtil.getInstance().getFtcSeasonYear(YearMonth.now()).getValue();
|
||||
int ftcSeasonYearOfCurrentlyInstalledRc = AppUtil.getInstance().getFtcSeasonYear(AppUtil.getInstance().getLocalSdkBuildMonth()).getValue();
|
||||
if (ftcSeasonYearOfCurrentlyInstalledRc > ftcSeasonYearOfPreviouslyInstalledRc) {
|
||||
preferencesHelper.writeIntPrefIfDifferent(getString(R.string.pref_ftc_season_year_of_current_rc), ftcSeasonYearOfCurrentlyInstalledRc);
|
||||
// Since it's a new FTC season, we should reset certain settings back to their default values.
|
||||
@ -395,10 +395,9 @@ public class FtcRobotControllerActivity extends Activity
|
||||
readNetworkType();
|
||||
ServiceController.startService(FtcRobotControllerWatchdogService.class);
|
||||
bindToService();
|
||||
logPackageVersions();
|
||||
logDeviceSerialNumber();
|
||||
AndroidBoard.getInstance().logAndroidBoardInfo();
|
||||
RobotLog.logAppInfo();
|
||||
RobotLog.logDeviceInfo();
|
||||
AndroidBoard.getInstance().logAndroidBoardInfo();
|
||||
|
||||
if (preferencesHelper.readBoolean(getString(R.string.pref_wifi_automute), false)) {
|
||||
initWifiMute(true);
|
||||
@ -499,19 +498,6 @@ public class FtcRobotControllerActivity extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
protected void logPackageVersions() {
|
||||
RobotLog.logBuildConfig(com.qualcomm.ftcrobotcontroller.BuildConfig.class);
|
||||
RobotLog.logBuildConfig(com.qualcomm.robotcore.BuildConfig.class);
|
||||
RobotLog.logBuildConfig(com.qualcomm.hardware.BuildConfig.class);
|
||||
RobotLog.logBuildConfig(com.qualcomm.ftccommon.BuildConfig.class);
|
||||
RobotLog.logBuildConfig(com.google.blocks.BuildConfig.class);
|
||||
RobotLog.logBuildConfig(org.firstinspires.inspection.BuildConfig.class);
|
||||
}
|
||||
|
||||
protected void logDeviceSerialNumber() {
|
||||
RobotLog.ii(TAG, "Android device serial number: " + Device.getSerialNumberOrUnknown());
|
||||
}
|
||||
|
||||
protected void readNetworkType() {
|
||||
// Control hubs are always running the access point model. Everything else, for the time
|
||||
// being always runs the Wi-Fi Direct model.
|
||||
|
@ -31,36 +31,37 @@ 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.
|
||||
-->
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:showAsAction="never"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/settings_menu_item"/>
|
||||
<item
|
||||
android:id="@+id/action_restart_robot"
|
||||
android:orderInCategory="200"
|
||||
android:showAsAction="never"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/restart_robot_menu_item"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_configure_robot"
|
||||
android:orderInCategory="300"
|
||||
android:showAsAction="never"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/configure_robot_menu_item"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_program_and_manage"
|
||||
android:orderInCategory="550"
|
||||
android:showAsAction="never"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/program_and_manage_menu_item"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_inspection_mode"
|
||||
android:orderInCategory="600"
|
||||
android:showAsAction="never"
|
||||
android:title="@string/inspection_mode_menu_item"/>
|
||||
android:id="@+id/action_inspection_mode"
|
||||
android:orderInCategory="600"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/inspection_mode_menu_item"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_about"
|
||||
|
@ -65,7 +65,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
<item>@style/AppThemeTealRC</item>
|
||||
</integer-array>
|
||||
|
||||
<string name="pref_ftc_season_year_of_current_rc">pref_ftc_season_year_of_current_rc</string>
|
||||
<string translatable="false" name="pref_ftc_season_year_of_current_rc">pref_ftc_season_year_of_current_rc_new</string>
|
||||
|
||||
<string name="packageName">@string/packageNameRobotController</string>
|
||||
|
||||
|
@ -37,7 +37,6 @@ https://developer.android.com/guide/topics/connectivity/usb/host
|
||||
|
||||
<!-- see also RobotUsbDevice.getUsbIdentifiers() -->
|
||||
<resources>
|
||||
<usb-device vendor-id="1027" product-id="24577" /> <!-- FT232 Modern Robotics: 0x0403/0x6001 -->
|
||||
<usb-device vendor-id="1027" product-id="24597" /> <!-- FT232 Lynx: 0x0403/0x6015 -->
|
||||
|
||||
<!-- cameras -->
|
||||
|
29
LICENSE
Normal file
29
LICENSE
Normal file
@ -0,0 +1,29 @@
|
||||
Copyright (c) 2014-2022 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.
|
||||
|
182
README.md
182
README.md
@ -38,7 +38,7 @@ Note that the online documentation is an "evergreen" document that is constantly
|
||||
### Javadoc Reference Material
|
||||
The Javadoc reference documentation for the FTC SDK is now available online. Click on the following link to view the FTC SDK Javadoc documentation as a live website:
|
||||
|
||||
[FTC Javadoc Documentation](https://javadoc.io/org.firstinspires.ftc)
|
||||
[FTC Javadoc Documentation](https://javadoc.io/doc/org.firstinspires.ftc)
|
||||
|
||||
### Online User Forum
|
||||
For technical questions regarding the Control System or the FTC SDK, please visit the FTC Technology forum:
|
||||
@ -54,6 +54,120 @@ The readme.md file located in the [/TeamCode/src/main/java/org/firstinspires/ftc
|
||||
|
||||
# Release Information
|
||||
|
||||
## Version 8.0 (20220907-131644)
|
||||
|
||||
### Breaking Changes
|
||||
* Increases the Robocol version.
|
||||
* This means an 8.0 or later Robot Controller or Driver Station will not be able to communicate with a 7.2 or earlier Driver Station or Robot Controller.
|
||||
* If you forget to update both apps at the same time, an error message will be shown explaining which app is older and should be updated.
|
||||
* Initializing I2C devices now happens when you retrieve them from the `HardwareMap` for the first time.
|
||||
* Previously, all I2C devices would be initialized before the Op Mode even began executing,
|
||||
whether you were actually going to use them or not. This could result in reduced performance and
|
||||
unnecessary warnings.
|
||||
* With this change, it is very important for Java users to retrieve all needed devices from the
|
||||
`HardwareMap` **during the Init phase of the Op Mode**. Namely, declare a variable for each hardware
|
||||
device the Op Mode will use, and assign a value to each. Do not do this during the Run phase, or your
|
||||
Op Mode may briefly hang while the devices you are retrieving get initialized.
|
||||
* Op Modes that do not use all of the I2C devices specified in the configuration file should take
|
||||
less time to initialize. Op Modes that do use all of the specified I2C devices should take the
|
||||
same amount of time as previously.
|
||||
* Fixes [issue #251](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/251) by changing the order in which axis rotation rates are read from the angular velocity vector in the BNO055 IMU driver.
|
||||
* Deprecates `pitchMode` in `BNO055IMU.Parameters`.
|
||||
* Setting `pitchMode` to `PitchMode.WINDOWS` would break the coordinate conventions used by the driver.
|
||||
* Moves `OpModeManagerImpl` to the `com.qualcomm.robotcore.eventloop.opmode` package.
|
||||
* This breaks third party libraries EasyOpenCV (version 1.5.1 and earlier) and FTC Dashboard (version 0.4.4 and earlier).
|
||||
* Deletes the deprecated `OpMode` method `resetStartTime()` (use `resetRuntime()` instead).
|
||||
* Deletes the protected `LinearOpMode.LinearOpModeHelper` class (which was not meant for use by Op Modes).
|
||||
* Removes I2C Device (Synchronous) config type (deprecated since 2018)
|
||||
|
||||
### Enhancements
|
||||
* Uncaught exceptions in Op Modes no longer require a Restart Robot
|
||||
* A blue screen popping up with a stacktrace is not an SDK error; this replaces the red text in the telemetry area.
|
||||
* Since the very first SDK release, Op Mode crashes have put the robot into "EMERGENCY STOP" state, only showing the first line of the exception, and requiring the user to press "Restart Robot" to continue
|
||||
* Exceptions during an Op Mode now open a popup window with the same color scheme as the log viewer, containing 15 lines of the exception stacktrace to allow easily tracing down the offending line without needing to connect to view logs over ADB or scroll through large amounts of logs in the log viewer.
|
||||
* The exception text in the popup window is both zoomable and scrollable just like a webpage.
|
||||
* Pressing the "OK" button in the popup window will return to the main screen of the Driver Station and allow an Op Mode to be run again immediately, without the need to perform a "Restart Robot"
|
||||
* Adds new Java sample to demonstrate using a hardware class to abstract robot actuators, and share them across multiple Op Modes.
|
||||
* Sample Op Mode is [/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/ConceptExternalHardwareClass.java](ConceptExternalHardwareClass.java)
|
||||
* Abstracted hardware class is [/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples/RobotHardware.java](RobotHardware.java))
|
||||
* Updates RobotAutoDriveByGyro_Linear Java sample to use REV Control/Expansion hub IMU.
|
||||
* Updates Vuforia samples to reference PowerPlay assets and have correct names and field locations of image targets.
|
||||
* Updates TensorFlow samples to reference PowerPlay assets.
|
||||
* Adds opt-in support for Java 8 language features to the OnBotJava editor.
|
||||
* To opt in, open the OnBotJava Settings, and check `Enable beta Java 8 support`.
|
||||
* Note that Java 8 code will only compile when the Robot Controller runs Android 7.0 Nougat or later.
|
||||
* Please report issues [here](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues).
|
||||
* In OnBotJava, clicking on build errors now correctly jumps to the correct location.
|
||||
* Improves OnBotJava autocomplete behavior, to provide better completion options in most cases.
|
||||
* Adds a QR code to the Robot Controller Inspection Report when viewed from the Driver Station for scanning by inspectors at competition.
|
||||
* Improves I2C performance and reliability in some scenarios.
|
||||
|
||||
## Version 7.2 (20220723-130006)
|
||||
|
||||
### Breaking Changes
|
||||
* Updates the build tooling. For Android Studio users, this change requires Android Studio Chipmunk 2021.2.1.
|
||||
* Removes support for devices that are not competition legal, including Modern Robotics Core Control Modules, the Matrix Controller, and HiTechnic/NXT controllers and sensors. Support remains for Modern Robotics I2C sensors.
|
||||
|
||||
### Enhancements
|
||||
* Increases the height of the 3-dots Landscape menu touch area on the Driver Station, making it much easier to select.
|
||||
* Adds `terminateOpModeNow()` method to allow OpModes to cleanly self-exit immediately.
|
||||
* Adds `opModeInInit()` method to `LinearOpMode` to facilitate init-loops. Similar to `opModeIsActive()` but for the init phase.
|
||||
* Warns user if they have a Logitech F310 gamepad connected that is set to DirectInput mode.
|
||||
* Allows SPARKmini motor controllers to react more quickly to speed changes.
|
||||
* Hides the version number of incorrectly installed sister app (i.e. DS installed on RC device or vice-versa) on inspection screen.
|
||||
* Adds support for allowing the user to edit the comment for the runOpMode block.
|
||||
* Adds parameterDefaultValues field to @ExportToBlocks. This provides the ability for a java method with an @ExportToBlocks annotation to specify default values for method parameters when it is shown in the block editor.
|
||||
* Make LinearOpMode blocks more readable. The opmode name is displayed on the runOpMode block, but not on the other LinearOpMode blocks.
|
||||
* Added support to TensorFlow Object Detection for using a different frame generator, instead of Vuforia.
|
||||
Using Vuforia to pass the camera frame to TFOD is still supported.
|
||||
* Removes usage of Renderscript.
|
||||
* Fixes logspam on app startup of repeated stacktraces relating to `"Failed resolution of: Landroid/net/wifi/p2p/WifiP2pManager$DeviceInfoListener"`
|
||||
* Allows disabling bluetooth radio from inspection screen
|
||||
* Improves warning messages when I2C devices are not responding
|
||||
* Adds support for controlling the RGB LED present on PS4/Etpark gamepads from OpModes
|
||||
* Removes legacy Pushbot references from OpMode samples. Renames "Pushbot" samples to "Robot". Motor directions reversed to be compatible with "direct Drive" drive train.
|
||||
|
||||
|
||||
### Bug fixes
|
||||
* Fixes [issue #316](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/316) (MatrixF.inverted() returned an incorrectly-sized matrix for 1x1 and 2x2 matrixes).
|
||||
* Self inspect now allows for Driver Station and Robot Controller compatibility between point releases.
|
||||
* Fixes bug where if the same `RumbleEffect` object instance was queued for multiple gamepads, it
|
||||
could happen that both rumble commands would be sent to just one gamepad.
|
||||
* Fixes bug in Driver Station where on the Driver Hub, if Advanced Gamepad Features was disabled and
|
||||
an officially supported gamepad was connected, then opening the Advanced Gamepad Features or
|
||||
Gamepad Type Overrides screens would cause the gamepad to be rebound by the custom USB driver even
|
||||
though advanced gamepad features was disabled.
|
||||
* Protects against (unlikely) null pointer exception in Vuforia Localizer.
|
||||
* Harden OnBotJava and Blocks saves to protect against save issues when disconnecting from Program and Manage
|
||||
* Fixes issue where the RC app would hang if a REV Hub I2C write failed because the previous I2C
|
||||
operation was still in progress. This hang most commonly occurred during REV 2M Distance Sensor initialization
|
||||
* Removes ConceptWebcam.java sample program. This sample is not compatible with OnBotJava.
|
||||
* Fixes bug where using html tags in an @ExportToBlocks comment field prevented the blocks editor from loading.
|
||||
* Fixes blocks editor so it doesn't ask you to save when you haven't modified anything.
|
||||
* Fixes uploading a very large blocks project to offline blocks editor.
|
||||
* Fixes bug that caused blocks for DcMotorEx to be omitted from the blocks editor toolbox.
|
||||
* Fixes [Blocks Programs Stripped of Blocks (due to using TensorFlow Label block)](https://ftcforum.firstinspires.org/forum/ftc-technology/blocks-programming/87035-blocks-programs-stripped-of-blocks)
|
||||
|
||||
## Version 7.1 (20211223-120805)
|
||||
|
||||
* Fixes crash when calling `isPwmEnabled()` ([issue #223](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/233)).
|
||||
* Fixes lint error ([issue #4](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/4)).
|
||||
* Fixes Driver Station crash when attempting to use DualShock4 v1 gamepad with Advanced Gamepad Features enabled ([issue #173](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/173)).
|
||||
* Fixes possible (but unlikely) Driver Station crash when connecting gamepads of any type.
|
||||
* Fixes bug where Driver Station would use generic 20% deadzone for Xbox360 and Logitech F310 gamepads when Advanced Gamepad Features was disabled.
|
||||
* Added SimpleOmniDrive sample OpMode.
|
||||
* Adds UVC white balance control API.
|
||||
* Fixes [issue #259](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/259) Most blocks samples for TensorFlow can't be used for a different model.
|
||||
* The blocks previously labeled TensorFlowObjectDetectionFreightFrenzy (from the subcategory named "Optimized for Freight Frenzy") and TensorFlowObjectDetectionCustomModel (from the subcategory named "Custom Model") have been replaced with blocks labeled TensorFlowObjectDetection. Blocks in existing opmodes will be automatically updated to the new blocks when opened in the blocks editor.
|
||||
* Fixes [issue #260](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/260) Blocks can't call java method that has a VuforiaLocalizer parameter.
|
||||
* Blocks now has a block labeled VuforiaFreightFrenzy.getVuforiaLocalizer for this.
|
||||
* Added a page to manage the TensorFlow Lite models in /sdcard/FIRST/tflitemodels. To get to the TFLite Models page:
|
||||
* You can click on the link at the bottom of the the Manage page.
|
||||
* You can click on the link at the upper-right the Blocks project page.
|
||||
* Fixes logspam when `isBusy()` is called on a motor not in RTP mode.
|
||||
* Hides the "RC Password" item on the inspection screen for phone-based Robot Controllers. (It is only applicable for Control Hubs).
|
||||
* Adds channel 165 to Wi-Fi Direct channel selection menu in the settings screen. (165 was previously available through the web UI, but not locally in the app).
|
||||
|
||||
## Version 7.0 (20210915-141025)
|
||||
|
||||
### Enhancements and New Features
|
||||
@ -81,50 +195,50 @@ The readme.md file located in the [/TeamCode/src/main/java/org/firstinspires/ftc
|
||||
* org.firstinspires.ftc.ftccommon.external.OnCreateMenu
|
||||
* org.firstinspires.ftc.ftccommon.external.OnDestroy
|
||||
* org.firstinspires.ftc.ftccommon.external.WebHandlerRegistrar
|
||||
* Adds support for REV Robotics Driver Hub
|
||||
* Adds fully custom userspace USB gamepad driver to Driver Station (see "Advanced Gamepad Features" menu in DS settings)
|
||||
* Allows gamepads to work on devices without native Linux kernel support (e.g. some Romanian Motorola devices)
|
||||
* Allows the DS to read the unique serial number of each gamepad, enabling auto-recovery of dropped gamepads even if two gamepads of the same model drop. *(NOTE: unfortunately this does not apply to Etpark gamepads, because they do not have a unique serial)*
|
||||
* Reading the unique serial number also provides the ability to configure the DS to assign gamepads to a certain position by default (so no need to do start+a/b at all)
|
||||
* The LED ring on the Xbox360 gamepad and the RGB LED bar on the PS4 gamepad is used to indicate the driver position the gamepad is bound to
|
||||
* The rumble motors on the Xbox360, PS4, and Etpark gamepads can be controlled from OpModes
|
||||
* The 2-point touchpad on the PS4 gamepad can be read from OpModes
|
||||
* The "back" and "guide" buttons on the gamepad can now be safely bound to robot controls (Previously, on many devices, Android would intercept these buttons as home button presses and close the app)
|
||||
* Advanced Gamepad features are enabled by default, but may be disabled through the settings menu in order to revert to gamepad support provided natively by Android
|
||||
* Improves accuracy of ping measurement
|
||||
* Fixes issue where the ping time showed as being higher than reality when initially connecting to or restarting the robot
|
||||
* To see the full improvement, you must update both the Robot Controller and Driver Station apps
|
||||
* Updates samples located at [/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples](FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples)
|
||||
* Added ConceptGamepadRumble and ConceptGamepadTouchpad samples to illustrtate the use of these new gampad capabilities.
|
||||
* Condensed existing Vuforia samples into just 2 samples (ConceptVuforiaFieldNavigation & ConceptVuforiaFieldNavigationWebcam) showing how to determine the robot's location on the field using Vuforia. These both use the current season's Target images.
|
||||
* Adds support for REV Robotics Driver Hub.
|
||||
* Adds fully custom userspace USB gamepad driver to Driver Station (see "Advanced Gamepad Features" menu in DS settings).
|
||||
* Allows gamepads to work on devices without native Linux kernel support (e.g. some Romanian Motorola devices).
|
||||
* Allows the DS to read the unique serial number of each gamepad, enabling auto-recovery of dropped gamepads even if two gamepads of the same model drop. *(NOTE: unfortunately this does not apply to Etpark gamepads, because they do not have a unique serial)*.
|
||||
* Reading the unique serial number also provides the ability to configure the DS to assign gamepads to a certain position by default (so no need to do start+a/b at all).
|
||||
* The LED ring on the Xbox360 gamepad and the RGB LED bar on the PS4 gamepad is used to indicate the driver position the gamepad is bound to.
|
||||
* The rumble motors on the Xbox360, PS4, and Etpark gamepads can be controlled from OpModes.
|
||||
* The 2-point touchpad on the PS4 gamepad can be read from OpModes.
|
||||
* The "back" and "guide" buttons on the gamepad can now be safely bound to robot controls (Previously, on many devices, Android would intercept these buttons as home button presses and close the app).
|
||||
* Advanced Gamepad features are enabled by default, but may be disabled through the settings menu in order to revert to gamepad support provided natively by Android.
|
||||
* Improves accuracy of ping measurement.
|
||||
* Fixes issue where the ping time showed as being higher than reality when initially connecting to or restarting the robot.
|
||||
* To see the full improvement, you must update both the Robot Controller and Driver Station apps.
|
||||
* Updates samples located at [/FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples](FtcRobotController/src/main/java/org/firstinspires/ftc/robotcontroller/external/samples).
|
||||
* Added ConceptGamepadRumble and ConceptGamepadTouchpad samples to illustrate the use of these new gampad capabilities.
|
||||
* Condensed existing Vuforia samples into just 2 samples (ConceptVuforiaFieldNavigation & ConceptVuforiaFieldNavigationWebcam) showing how to determine the robot's location on the field using Vuforia. These both use the current season's Target images.
|
||||
* Added ConceptVuforiaDriveToTargetWebcam to illustrate an easy way to drive directly to any visible Vuforia target.
|
||||
* Makes many improvements to the warning system and individual warnings
|
||||
* Warnings are now much more spaced out, so that they are easier to read
|
||||
* New warnings were added for conditions that should be resolved before competing
|
||||
* The mismatched apps warning now uses the major and minor app versions, not the version code
|
||||
* The warnings are automatically re-enabled when a Robot Controller app from a new FTC season is installed
|
||||
* Adds support for I2C transactions on the Expansion Hub / Control Hub without specifying a register address
|
||||
* See section 3 of the [TI I2C spec](https://www.ti.com/lit/an/slva704/slva704.pdf)
|
||||
* Calling these new methods when using Modern Robotics hardware will result in an UnsupportedOperationException
|
||||
* Changes VuforiaLocalizer `close()` method to be public
|
||||
* Makes many improvements to the warning system and individual warnings.
|
||||
* Warnings are now much more spaced out, so that they are easier to read.
|
||||
* New warnings were added for conditions that should be resolved before competing.
|
||||
* The mismatched apps warning now uses the major and minor app versions, not the version code.
|
||||
* The warnings are automatically re-enabled when a Robot Controller app from a new FTC season is installed.
|
||||
* Adds support for I2C transactions on the Expansion Hub / Control Hub without specifying a register address.
|
||||
* See section 3 of the [TI I2C spec](https://www.ti.com/lit/an/slva704/slva704.pdf).
|
||||
* Calling these new methods when using Modern Robotics hardware will result in an UnsupportedOperationException.
|
||||
* Changes VuforiaLocalizer `close()` method to be public.
|
||||
* Adds support for TensorFlow v2 object detection models.
|
||||
* Reduces ambiguity of the Self Inspect language and graphics.
|
||||
* OnBotJava now warns about potentially unintended file overwrites
|
||||
* OnBotJava now warns about potentially unintended file overwrites.
|
||||
* Improves behavior of the Wi-Fi band and channel selector on the Manage webpage.
|
||||
|
||||
### Bug fixes
|
||||
* Fixes Robot Controller app crash on Android 9+ when a Driver Station connects
|
||||
* Fixes Robot Controller app crash on Android 9+ when a Driver Station connects.
|
||||
* Fixes issue where an Op Mode was responsible for calling shutdown on the
|
||||
TensorFlow TFObjectDetector. Now this is done automatically.
|
||||
* Fixes Vuforia initialization blocks to allow user to chose AxesOrder. Updated
|
||||
relevant blocks sample opmodes.
|
||||
* Fixes [FtcRobotController issue #114](https://github.com/FIRST-Tech-Challenge/FtcRobotController/issues/114)
|
||||
LED blocks and Java class do not work
|
||||
* Fixes match logging for Op Modes that contain special characters in their names
|
||||
* Fixes Driver Station OpMode controls becoming unresponsive if the Driver Station was set to the landscape layout and an OnBotJava build was triggered while an OpMode was running
|
||||
* Fixes the Driver Station app closing itself when it is switched away from, or the screen is turned off
|
||||
* Fixes "black swirl of doom" (Infinite "configuring Wi-Fi Direct" message) on older devices
|
||||
* Updates the wiki comment on the OnBotJava intro page
|
||||
LED blocks and Java class do not work.
|
||||
* Fixes match logging for Op Modes that contain special characters in their names.
|
||||
* Fixes Driver Station OpMode controls becoming unresponsive if the Driver Station was set to the landscape layout and an OnBotJava build was triggered while an OpMode was running.
|
||||
* Fixes the Driver Station app closing itself when it is switched away from, or the screen is turned off.
|
||||
* Fixes "black swirl of doom" (Infinite "configuring Wi-Fi Direct" message) on older devices.
|
||||
* Updates the wiki comment on the OnBotJava intro page.
|
||||
|
||||
## Version 6.2 (20210218-074821)
|
||||
|
||||
|
@ -15,6 +15,10 @@
|
||||
apply from: '../build.common.gradle'
|
||||
apply from: '../build.dependencies.gradle'
|
||||
|
||||
android {
|
||||
namespace = 'org.firstinspires.ftc.teamcode'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(':FtcRobotController')
|
||||
annotationProcessor files('lib/OpModeAnnotationProcessor.jar')
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
<!-- The package name here determines the package for your R class and your BuildConfig class -->
|
||||
<manifest
|
||||
package="org.firstinspires.ftc.teamcode"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<application/>
|
||||
</manifest>
|
||||
|
@ -14,31 +14,41 @@ Sample opmodes exist in the FtcRobotController module.
|
||||
To locate these samples, find the FtcRobotController module in the "Project/Android" tab.
|
||||
|
||||
Expand the following tree elements:
|
||||
FtcRobotController / java / org.firstinspires.ftc.robotcontroller / external / samples
|
||||
FtcRobotController/java/org.firstinspires.ftc.robotcontroller/external/samples
|
||||
|
||||
A range of different samples classes can be seen in this folder.
|
||||
The class names follow a naming convention which indicates the purpose of each class.
|
||||
The full description of this convention is found in the samples/sample_convention.md file.
|
||||
### Naming of Samples
|
||||
|
||||
A brief synopsis of the naming convention is given here:
|
||||
To gain a better understanding of how the samples are organized, and how to interpret the
|
||||
naming system, it will help to understand the conventions that were used during their creation.
|
||||
|
||||
These conventions are described (in detail) in the sample_conventions.md file in this folder.
|
||||
|
||||
To summarize: A range of different samples classes will reside in the java/external/samples.
|
||||
The class names will follow a naming convention which indicates the purpose of each class.
|
||||
The prefix of the name will be one of the following:
|
||||
|
||||
* Basic: This is a minimally functional OpMode used to illustrate the skeleton/structure
|
||||
Basic: This is a minimally functional OpMode used to illustrate the skeleton/structure
|
||||
of a particular style of OpMode. These are bare bones examples.
|
||||
* Sensor: This is a Sample OpMode that shows how to use a specific sensor.
|
||||
It is not intended as a functioning robot, it is simply showing the minimal code
|
||||
|
||||
Sensor: This is a Sample OpMode that shows how to use a specific sensor.
|
||||
It is not intended to drive a functioning robot, it is simply showing the minimal code
|
||||
required to read and display the sensor values.
|
||||
* Hardware: This is not an actual OpMode, but a helper class that is used to describe
|
||||
one particular robot's hardware devices: eg: for a Pushbot. Look at any
|
||||
Pushbot sample to see how this can be used in an OpMode.
|
||||
Teams can copy one of these to create their own robot definition.
|
||||
* Pushbot: This is a Sample OpMode that uses the Pushbot robot structure as a base.
|
||||
* Concept: This is a sample OpMode that illustrates performing a specific function or concept.
|
||||
|
||||
Robot: This is a Sample OpMode that assumes a simple two-motor (differential) drive base.
|
||||
It may be used to provide a common baseline driving OpMode, or
|
||||
to demonstrate how a particular sensor or concept can be used to navigate.
|
||||
|
||||
Concept: This is a sample OpMode that illustrates performing a specific function or concept.
|
||||
These may be complex, but their operation should be explained clearly in the comments,
|
||||
or the header should reference an external doc, guide or tutorial.
|
||||
* Library: This is a class, or set of classes used to implement some strategy.
|
||||
These will typically NOT implement a full OpMode. Instead they will be included
|
||||
by an OpMode to provide some stand-alone capability.
|
||||
or the comments should reference an external doc, guide or tutorial.
|
||||
Each OpMode should try to only demonstrate a single concept so they are easy to
|
||||
locate based on their name. These OpModes may not produce a drivable robot.
|
||||
|
||||
After the prefix, other conventions will apply:
|
||||
|
||||
* Sensor class names are constructed as: Sensor - Company - Type
|
||||
* Robot class names are constructed as: Robot - Mode - Action - OpModetype
|
||||
* Concept class names are constructed as: Concept - Topic - OpModetype
|
||||
|
||||
Once you are familiar with the range of samples available, you can choose one to be the
|
||||
basis for your own robot. In all cases, the desired sample(s) needs to be copied into
|
||||
@ -50,7 +60,7 @@ This is done inside Android Studio directly, using the following steps:
|
||||
|
||||
2) Right click on the sample class and select "Copy"
|
||||
|
||||
3) Expand the TeamCode / java folder
|
||||
3) Expand the TeamCode/java folder
|
||||
|
||||
4) Right click on the org.firstinspires.ftc.teamcode folder and select "Paste"
|
||||
|
||||
|
@ -100,7 +100,6 @@ android {
|
||||
debug {
|
||||
debuggable true
|
||||
jniDebuggable true
|
||||
renderscriptDebuggable true
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "arm64-v8a"
|
||||
}
|
||||
|
@ -1,23 +1,22 @@
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google() // Needed for androidx
|
||||
jcenter() // Needed for tensorflow-lite
|
||||
flatDir {
|
||||
dirs rootProject.file('libs')
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.firstinspires.ftc:Inspection:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:Blocks:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:Tfod:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:RobotCore:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:RobotServer:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:OnBotJava:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:Hardware:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:FtcCommon:7.0.0'
|
||||
implementation 'org.firstinspires.ftc:Inspection:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:Blocks:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:Tfod:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:RobotCore:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:RobotServer:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:OnBotJava:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:Hardware:8.0.0'
|
||||
implementation 'org.firstinspires.ftc:FtcCommon:8.0.0'
|
||||
implementation 'org.tensorflow:tensorflow-lite-task-vision:0.2.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'org.firstinspires.ftc:gameAssets-FreightFrenzy:1.0.0'
|
||||
implementation 'org.firstinspires.ftc:gameAssets-PowerPlay:1.0.0'
|
||||
}
|
||||
|
||||
|
39
build.gradle
39
build.gradle
@ -4,18 +4,13 @@
|
||||
* It is extraordinarily rare that you will ever need to edit this file.
|
||||
*/
|
||||
|
||||
configurations {
|
||||
doc { transitive false }
|
||||
}
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +20,6 @@ allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,34 +30,3 @@ repositories {
|
||||
dirs '../libs'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
doc 'org.firstinspires.ftc:Hardware:6.2.0'
|
||||
doc 'org.firstinspires.ftc:RobotCore:6.2.0'
|
||||
doc 'org.firstinspires.ftc:FtcCommon:6.2.0'
|
||||
doc 'org.firstinspires.ftc:OnBotJava:6.2.0'
|
||||
doc 'org.firstinspires.ftc:Inspection:6.2.0'
|
||||
}
|
||||
|
||||
task extractJavadoc {
|
||||
doLast {
|
||||
def componentIds = configurations.doc.incoming.resolutionResult.allDependencies.collect { it.selected.id }
|
||||
|
||||
def result = dependencies.createArtifactResolutionQuery()
|
||||
.forComponents(componentIds)
|
||||
.withArtifacts(JvmLibrary, SourcesArtifact, JavadocArtifact)
|
||||
.execute()
|
||||
|
||||
for (component in result.resolvedComponents) {
|
||||
component.getArtifacts(JavadocArtifact).each { artifact ->
|
||||
def version = artifact.identifier.componentIdentifier.version
|
||||
def libName = artifact.identifier.componentIdentifier.moduleIdentifier.name
|
||||
copy {
|
||||
from zipTree(artifact.file)
|
||||
into "docs/$version/$libName/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,5 @@
|
||||
#Fri Jul 24 14:30:03 PDT 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
|
Reference in New Issue
Block a user