Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Copyright (c) 2019 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 com.team16488.opmodes.auto;
- import android.app.Activity;
- import android.graphics.Color;
- import android.view.View;
- 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.eventloop.opmode.TeleOp;
- import com.qualcomm.robotcore.hardware.ColorSensor;
- import com.qualcomm.robotcore.hardware.DistanceSensor;
- import com.qualcomm.robotcore.util.ElapsedTime;
- import com.team16488.library.subsystems.MecanumDrive;
- import com.team16488.skystone.Robot;
- import org.firstinspires.ftc.robotcore.external.ClassFactory;
- import org.firstinspires.ftc.robotcore.external.matrices.OpenGLMatrix;
- import org.firstinspires.ftc.robotcore.external.matrices.VectorF;
- import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
- import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
- import org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer;
- import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackable;
- import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackableDefaultListener;
- import org.firstinspires.ftc.robotcore.external.navigation.VuforiaTrackables;
- import org.firstinspires.ftc.robotcore.external.hardware.camera.WebcamName;
- import java.util.ArrayList;
- import java.util.List;
- import java.lang.Math;
- import java.util.Locale;
- import static org.firstinspires.ftc.robotcore.external.navigation.AngleUnit.DEGREES;
- import static org.firstinspires.ftc.robotcore.external.navigation.AxesOrder.XYZ;
- import static org.firstinspires.ftc.robotcore.external.navigation.AxesOrder.YZX;
- import static org.firstinspires.ftc.robotcore.external.navigation.AxesReference.EXTRINSIC;
- import static org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer.CameraDirection.BACK;
- /**
- * This 2019-2020 OpMode illustrates the basics of using the Vuforia localizer to determine
- * positioning and orientation of robot on the SKYSTONE FTC field.
- * The code is structured as a LinearOpMode
- *
- * When images are located, Vuforia is able to determine the position and orientation of the
- * image relative to the camera. This sample code then combines that information with a
- * knowledge of where the target images are on the field, to determine the location of the camera.
- *
- * From the Audience perspective, the Red Alliance station is on the right and the
- * Blue Alliance Station is on the left.
- * Eight perimeter targets are distributed evenly around the four perimeter walls
- * Four Bridge targets are located on the bridge uprights.
- * Refer to the Field Setup manual for more specific location details
- *
- * A final calculation then uses the location of the camera on the robot to determine the
- * robot's location and orientation on the field.
- *
- * @see VuforiaLocalizer
- * @see VuforiaTrackableDefaultListener
- * see skystone/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.
- *
- * IMPORTANT: In order to use this OpMode, you need to obtain your own Vuforia license key as
- * is explained below.
- */
- @Autonomous(name="TestAuto", group="Linear Opmode")
- public class redVision extends LinearOpMode {
- // IMPORTANT: For Phone Camera, set 1) the camera source and 2) the orientation, based on how your phone is mounted:
- // 1) Camera Source. Valid choices are: BACK (behind screen) or FRONT (selfie side)
- // 2) Phone Orientation. Choices are: PHONE_IS_PORTRAIT = true (portrait) or PHONE_IS_PORTRAIT = false (landscape)
- //
- // NOTE: If you are running on a CONTROL HUB, with only one USB WebCam, you must select CAMERA_CHOICE = BACK; and PHONE_IS_PORTRAIT = false;
- //
- ColorSensor sensorColor;
- DistanceSensor sensorDistance;
- private static final VuforiaLocalizer.CameraDirection CAMERA_CHOICE = BACK;
- private static final boolean PHONE_IS_PORTRAIT = false;
- private boolean align = false;
- private boolean close = false;
- private boolean backedUp = false;
- private boolean otherSide = false;
- private boolean praked = false;
- /*
- * IMPORTANT: You need to obtain your own license key to use Vuforia. The string below with which
- * 'parameters.vuforiaLicenseKey' is initialized is for illustration only, and will not function.
- * A Vuforia 'Development' license key, can be obtained free of charge from the Vuforia developer
- * web site at https://developer.vuforia.com/license-manager.
- *
- * Vuforia license keys are always 380 characters long, and look as if they contain mostly
- * random data. As an example, here is a example of a fragment of a valid key:
- * ... yIgIzTqZ4mWjk9wd3cZO9T1axEqzuhxoGlfOOI2dRzKS4T0hQ8kT ...
- * Once you've obtained a license key, copy the string from the Vuforia web site
- * and paste it in to your code on the next line, between the double quotes.
- */
- private static final String VUFORIA_KEY =
- "AQLgl7n/////AAABme+dNMPhrUUJjKAoNuY8bohUPjuCocER5Fpn94nlG5wvrLJZsJabuSihGcb5US+gHaLRCt20n4q2opXCriEaa+vi2pb3kIMMLuFioUVynCEJrTa9Y/9wPELJUwvpTfq55v6pSWfU/LIFnkTVIqm5OuG6X/KDeA3nTg6ykBYErTSd1zOYUabMdTR+DBKBevHF9NsmHo3/Le3XgCfopFYw049yYAVmRYy+dx84wlLhgF1JBNtDqx4rjQgICRzKQmKuh4EBe39ygQDnFd85uxD6Lbo6VZ3IuQeIrb0nu9eaD4H8oE+jRIvho8d3WJWR8smec0ddud1UFTRdXt69njtluVDe9zSU5vMGOnDn/cw8lQAb";
- // 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
- 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
- // Constant for Stone Target
- private static final float stoneZ = 2.00f * mmPerInch;
- // Constants for the center support targets
- private static final float bridgeZ = 6.42f * mmPerInch;
- private static final float bridgeY = 23 * mmPerInch;
- private static final float bridgeX = 5.18f * mmPerInch;
- private static final float bridgeRotY = 59; // Units are degrees
- private static final float bridgeRotZ = 180;
- // Constants for perimeter targets
- private static final float halfField = 72 * mmPerInch;
- private static final float quadField = 36 * mmPerInch;
- // Class Members
- private OpenGLMatrix lastLocation = null;
- private VuforiaLocalizer vuforia = null;
- WebcamName webcamName = null;
- private boolean targetVisible = false;
- private float phoneXRotate = 0;
- private float phoneYRotate = 0;
- private float phoneZRotate = 0;
- private int asd = 0;
- private ElapsedTime runtime = new ElapsedTime();
- @Override
- public void runOpMode() {
- /*
- * Configure Vuforia by creating a Parameter object, and passing it to the Vuforia engine.
- * We can pass Vuforia the handle to a camera preview resource (on the RC phone);
- * If no camera monitor is desired, use the parameter-less constructor instead (commented out below).
- */
- Robot robot = new Robot(this, telemetry);
- webcamName = hardwareMap.get(WebcamName.class, "Webcam 1");
- int cameraMonitorViewId = hardwareMap.appContext.getResources().getIdentifier("cameraMonitorViewId", "id", hardwareMap.appContext.getPackageName());
- VuforiaLocalizer.Parameters parameters = new VuforiaLocalizer.Parameters(cameraMonitorViewId);
- // TAKE THIS OUT IF NO SCREEN WANTED VuforiaLocalizer.Parameters parameters = new VuforiaLocalizer.Parameters();
- parameters.vuforiaLicenseKey = VUFORIA_KEY;
- parameters.cameraDirection = CAMERA_CHOICE;
- // do not use extended tracking; too messy
- parameters.useExtendedTracking = false;
- parameters.cameraName = webcamName;
- // Instantiate the Vuforia engine
- vuforia = ClassFactory.getInstance().createVuforia(parameters);
- MecanumDrive mecanum = new MecanumDrive(hardwareMap);
- // Load the data sets for the trackable objects. These particular data
- // sets are stored in the 'assets' part of our application.
- VuforiaTrackables targetsSkyStone = this.vuforia.loadTrackablesFromAsset("Skystone");
- sensorColor = hardwareMap.get(ColorSensor.class, "colour");
- // get a reference to the distance sensor that shares the same name.
- sensorDistance = hardwareMap.get(DistanceSensor.class, "colour");
- // 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;
- // sometimes it helps to multiply the raw RGB values with a scale factor
- // to amplify/attentuate the measured values.
- final double SCALE_FACTOR = 255;
- // 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);
- VuforiaTrackable stoneTarget = targetsSkyStone.get(0);
- stoneTarget.setName("Stone Target");
- // VuforiaTrackable blueRearBridge = targetsSkyStone.get(1);
- // blueRearBridge.setName("Blue Rear Bridge");
- // VuforiaTrackable redRearBridge = targetsSkyStone.get(2);
- // redRearBridge.setName("Red Rear Bridge");
- // VuforiaTrackable redFrontBridge = targetsSkyStone.get(3);
- // redFrontBridge.setName("Red Front Bridge");
- // VuforiaTrackable blueFrontBridge = targetsSkyStone.get(4);
- // blueFrontBridge.setName("Blue Front Bridge");
- // VuforiaTrackable red1 = targetsSkyStone.get(5);
- // red1.setName("Red Perimeter 1");
- // VuforiaTrackable red2 = targetsSkyStone.get(6);
- // red2.setName("Red Perimeter 2");
- // VuforiaTrackable front1 = targetsSkyStone.get(7);
- // front1.setName("Front Perimeter 1");
- // VuforiaTrackable front2 = targetsSkyStone.get(8);
- // front2.setName("Front Perimeter 2");
- // VuforiaTrackable blue1 = targetsSkyStone.get(9);
- // blue1.setName("Blue Perimeter 1");
- // VuforiaTrackable blue2 = targetsSkyStone.get(10);
- // blue2.setName("Blue Perimeter 2");
- // VuforiaTrackable rear1 = targetsSkyStone.get(11);
- // rear1.setName("Rear Perimeter 1");
- // VuforiaTrackable rear2 = targetsSkyStone.get(12);
- // rear2.setName("Rear Perimeter 2");
- // For convenience, gather together all the trackable objects in one easily-iterable collection */
- // List<VuforiaTrackable> allTrackables = new ArrayList<VuforiaTrackable>();
- // allTrackables.addAll(targetsSkyStone);
- /**
- * In order for localization to work, we need to tell the system where each target is on the field, and
- * where the phone resides on the . These specifications are in the form of <em>transformation matrices.</em>
- * Transformation matrices are a central, important concept in the math here involved in localization.
- * See <a href="https://en.wikipedia.org/wiki/Transformation_matrix">Transformation Matrix</a>
- * for detailed information. Commonly, you'll encounter transformation matrices as instances
- * of the {@link OpenGLMatrix} class.
- *
- * If you are standing in the Red Alliance Station looking towards the center of the field,
- * - The X axis runs from your left to the right. (positive from the center to the right)
- * - The Y axis runs from the Red Alliance Station towards the other side of the field
- * where the Blue Alliance Station is. (Positive is from the center, towards the BlueAlliance station)
- * - The Z axis runs from the floor, upwards towards the ceiling. (Positive is above the floor)
- *
- * Before being transformed, each target image is conceptually located at the origin of the field's
- * coordinate system (the center of the field), facing up.
- */
- // Set the position of the Stone Target. Since it's not fixed in position, assume it's at the field origin.
- // Rotated it to to face forward, and raised it to sit on the ground correctly.
- // This can be used for generic target-centric approach algorithms
- stoneTarget.setLocation(OpenGLMatrix
- .translation(0, 0, stoneZ)
- .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, -90)));
- // //Set the position of the bridge support targets with relation to origin (center of field)
- // blueFrontBridge.setLocation(OpenGLMatrix
- // .translation(-bridgeX, bridgeY, bridgeZ)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 0, bridgeRotY, bridgeRotZ)));
- //
- // blueRearBridge.setLocation(OpenGLMatrix
- // .translation(-bridgeX, bridgeY, bridgeZ)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 0, -bridgeRotY, bridgeRotZ)));
- //
- // redFrontBridge.setLocation(OpenGLMatrix
- // .translation(-bridgeX, -bridgeY, bridgeZ)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 0, -bridgeRotY, 0)));
- //
- // redRearBridge.setLocation(OpenGLMatrix
- // .translation(bridgeX, -bridgeY, bridgeZ)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 0, bridgeRotY, 0)));
- //
- // //Set the position of the perimeter targets with relation to origin (center of field)
- // red1.setLocation(OpenGLMatrix
- // .translation(quadField, -halfField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 180)));
- //
- // red2.setLocation(OpenGLMatrix
- // .translation(-quadField, -halfField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 180)));
- //
- // front1.setLocation(OpenGLMatrix
- // .translation(-halfField, -quadField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0 , 90)));
- //
- // front2.setLocation(OpenGLMatrix
- // .translation(-halfField, quadField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 90)));
- //
- // blue1.setLocation(OpenGLMatrix
- // .translation(-quadField, halfField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 0)));
- //
- // blue2.setLocation(OpenGLMatrix
- // .translation(quadField, halfField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, 0)));
- //
- // rear1.setLocation(OpenGLMatrix
- // .translation(halfField, quadField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0 , -90)));
- //
- // rear2.setLocation(OpenGLMatrix
- // .translation(halfField, -quadField, mmTargetHeight)
- // .multiplied(Orientation.getRotationMatrix(EXTRINSIC, XYZ, DEGREES, 90, 0, -90)));
- //
- // Create a transformation matrix describing where the phone is on the robot.
- //
- // NOTE !!!! It's very important that you turn OFF your phone's Auto-Screen-Rotation option.
- // Lock it into Portrait for these numbers to work.
- //
- // Info: The coordinate frame for the robot looks the same as the field.
- // The robot's "forward" direction is facing out along X axis, with the LEFT side facing out along the Y axis.
- // Z is UP on the robot. This equates to a bearing angle of Zero degrees.
- //
- // The phone starts out lying flat, with the screen facing Up and with the physical top of the phone
- // pointing to the LEFT side of the Robot.
- // The two examples below assume that the camera is facing forward out the front of the robot.
- // We need to rotate the camera around it's long axis to bring the correct camera forward.
- if (CAMERA_CHOICE == BACK) {
- phoneYRotate = -90;
- } else {
- phoneYRotate = 90;
- }
- // Rotate the phone vertical about the X axis if it's in portrait mode
- if (PHONE_IS_PORTRAIT) {
- phoneXRotate = 90 ;
- }
- // Next, translate the camera lens to where it is on the robot.
- // In this example, it is centered (left to right), but forward of the middle of the robot, and above ground level.
- // final float CAMERA_FORWARD_DISPLACEMENT = 4.0f * mmPerInch; // eg: Camera is 4 Inches in front of robot center
- // final float CAMERA_VERTICAL_DISPLACEMENT = 8.0f * mmPerInch; // eg: Camera is 8 Inches above ground
- final float CAMERA_FORWARD_DISPLACEMENT = 0; // eg: Camera is 4 Inches in front of robot center
- final float CAMERA_VERTICAL_DISPLACEMENT = 0;
- final float CAMERA_LEFT_DISPLACEMENT = 0; // eg: Camera is ON the robot's center line
- OpenGLMatrix robotFromCamera = OpenGLMatrix
- .translation(CAMERA_FORWARD_DISPLACEMENT, CAMERA_LEFT_DISPLACEMENT, CAMERA_VERTICAL_DISPLACEMENT)
- .multiplied(Orientation.getRotationMatrix(EXTRINSIC, YZX, DEGREES, phoneYRotate, phoneZRotate, phoneXRotate));
- /** Let all the trackable listeners know where the phone is. */
- // for (VuforiaTrackable trackable : allTrackables) {
- ((VuforiaTrackableDefaultListener)stoneTarget.getListener()).setPhoneInformation(robotFromCamera, parameters.cameraDirection);
- // WARNING:
- // In this sample, we do not wait for PLAY to be pressed. Target Tracking is started immediately when INIT is pressed.
- // This sequence is used to enable the new remote DS Camera Preview feature to be used with this sample.
- // CONSEQUENTLY do not put any driving commands in this loop.
- // To restore the normal opmode structure, just un-comment the following line:
- waitForStart();
- // Note: To use the remote camera preview:
- // AFTER you hit Init on the Driver Station, use the "options menu" to select "Camera Stream"
- // Tap the preview window to receive a fresh image.
- robot.start();
- runtime.reset();
- targetsSkyStone.activate();
- double a = runtime.seconds();
- while(a<1)
- {
- robot.lift.setPower(0.85);
- }
- robot.alternateIntake.setDown(true);
- while(a<2)
- {
- robot.lift.setPower(-0.85);
- }
- robot.alternateIntake.setDown(false);
- while (!isStopRequested()) {
- // check all the trackable targets to see which one (if any) is visible.
- targetVisible = false;
- // for (VuforiaTrackable trackable : allTrackables) {
- if (((VuforiaTrackableDefaultListener)stoneTarget.getListener()).isVisible()) {
- telemetry.addData("Visible Target", stoneTarget.getName());
- targetVisible = true;
- // getUpdatedRobotLocation() will return null if no new information is available since
- // the last time that call was made, or if the trackable is not currently visible.
- OpenGLMatrix robotLocationTransform = ((VuforiaTrackableDefaultListener) stoneTarget.getListener()).getUpdatedRobotLocation();
- if (robotLocationTransform != null) {
- lastLocation = robotLocationTransform;
- }
- }
- // break;
- // }
- // Provide feedback as to where the robot is located (if we know).
- if (targetVisible) {
- // express position (translation) of robot in inches.
- VectorF translation = lastLocation.getTranslation();
- double delta_x = translation.get(0);
- double delta_y = translation.get(1);
- // not very useful; phone should not move
- double delta_z = translation.get(2);
- telemetry.addData("Pos X", delta_x / mmPerInch);
- telemetry.addData("Pos Y",delta_y / mmPerInch);
- // telemetry.addData("Pos Z", delta_z / mmPerInch);
- // telemetry.addData("Pos (in)", "{X, Y, Z} = %.1f, %.1f, %.1f",
- // translation.get(0) / mmPerInch, translation.get(1) / mmPerInch, translation.get(2) / mmPerInch);
- // get the rotation of the robot
- Orientation rotation = Orientation.getOrientation(lastLocation, EXTRINSIC, XYZ, DEGREES);
- double angleFromPhone = rotation.thirdAngle;
- // output the 'Z' angle rotation, or heading of the robot
- // this angle goes from a line parallel to the x axis and the current camera rotation
- telemetry.addData("Rot (Heading)", angleFromPhone);
- // telemetry.addData("Rot X", rotation.firstAngle);
- // telemetry.addData("Rot Y", rotation.secondAngle);
- // compute distance to target
- double targetRange = (Math.hypot(delta_x, delta_y))/ mmPerInch;
- // compute angle from line parallel to x axis to the block
- // From left to block negative; right to block positive
- double xToBlock1 = Math.toDegrees(Math.atan(delta_y / delta_x));
- // double xToBlock2 = Math.toDegrees(Math.asin(delta_y/targetRange));
- // compute relative angle
- double relativeAngle = xToBlock1 - angleFromPhone;
- // telemetry.addData("ToBlock Angle1", xToBlock1);
- telemetry.addData("Relative Angle", relativeAngle);
- telemetry.addData("Total distance", targetRange);
- // telemetry.addData("To Block Test 2", xToBlock2);
- Color.RGBToHSV((int) (sensorColor.red() * SCALE_FACTOR),
- (int) (sensorColor.green() * SCALE_FACTOR),
- (int) (sensorColor.blue() * SCALE_FACTOR),
- hsvValues);
- // send the info back to driver station using telemetry function.
- telemetry.addData("Distance (cm)",
- String.format(Locale.US, "%.02f", sensorDistance.getDistance(DistanceUnit.CM)));
- telemetry.addData("Alpha", sensorColor.alpha());
- telemetry.addData("Red ", sensorColor.red());
- telemetry.addData("Green", sensorColor.green());
- telemetry.addData("Blue ", sensorColor.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();
- if(89<=angleFromPhone && angleFromPhone<=91)
- {
- align = true;
- }
- if(!align && angleFromPhone>91)
- {
- mecanum.setVelocity(0,-0.4,0);
- }
- if(!align && angleFromPhone<89)
- {
- mecanum.setVelocity(0,0.4,0);
- }
- if(align && !close)
- {
- mecanum.setVelocity(-0.7,0,0);
- }
- if(3.35>=delta_x&& 3.15<=delta_x)
- {
- close = true;
- }
- }
- else {
- telemetry.addData("Visible Target", "none");
- if(!align)
- {
- mecanum.setVelocity(0,-0.3,0);
- }
- }
- double b = 0;
- if(align && close && !backedUp)
- {
- robot.alternateIntake.setDown(true);
- if(b==0)
- {
- b = runtime.seconds();
- }
- }
- double c = 0;
- if(align && close && !backedUp && runtime.seconds()>(b + 0.5))
- {
- mecanum.setVelocity(0.7,0,0);
- if(c==0)
- {
- c = runtime.seconds();
- }
- }
- if(align && close && !backedUp&& runtime.seconds()>(c+1))
- {
- mecanum.setVelocity(0,0,0);
- backedUp = true;
- }
- double d = 0;
- if(align && close && backedUp && !otherSide)
- {
- mecanum.setVelocity((0,0.5,0);
- if(d ==0){
- d = runtime.seconds();
- }
- }
- if(align && close && backedUp && runtime.seconds()>(d+0.5) )
- {
- mecanum.setVelocity(0,0,0);
- otherSide = true;
- robot.alternateIntake.setDown(false);
- }
- if(align && close && backedUp && otherSide && sensorColor.red()<500)
- {
- mecanum.setVelocity(0,-0.3,0);
- }
- if(align && close && backedUp && otherSide && sensorColor.red()>500)
- telemetry.addData("align", align);
- telemetry.addData("close", close);
- telemetry.update();
- mecanum.update();
- }
- // Disable Tracking when we are done;
- targetsSkyStone.deactivate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement