Advertisement
Guest User

cod autonom

a guest
Feb 24th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.91 KB | None | 0 0
  1. /* Copyright (c) 2017 FIRST. All rights reserved.
  2.  *
  3.  * Redistribution and use in source and binary forms, with or without modification,
  4.  * are permitted (subject to the limitations in the disclaimer below) provided that
  5.  * the following conditions are met:
  6.  *
  7.  * Redistributions of source code must retain the above copyright notice, this list
  8.  * of conditions and the following disclaimer.
  9.  *
  10.  * Redistributions in binary form must reproduce the above copyright notice, this
  11.  * list of conditions and the following disclaimer in the documentation and/or
  12.  * other materials provided with the distribution.
  13.  *
  14.  * Neither the name of FIRST nor the names of its contributors may be used to endorse or
  15.  * promote products derived from this software without specific prior written permission.
  16.  *
  17.  * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
  18.  * LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  24.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  25.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  */
  29.  
  30. package org.firstinspires.ftc.teamcode;
  31.  
  32. import com.qualcomm.robotcore.eventloop.opmode.Disabled;
  33. import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
  34. import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
  35. import com.qualcomm.robotcore.hardware.DcMotor;
  36. import com.qualcomm.robotcore.hardware.NormalizedRGBA;
  37. import com.qualcomm.robotcore.util.ElapsedTime;
  38. import com.qualcomm.robotcore.util.Range;
  39.  
  40.  
  41. /**
  42.  * This file contains an minimal example of a Linear "OpMode". An OpMode is a 'program' that runs in either
  43.  * the autonomous or the teleop period of an FTC match. The names of OpModes appear on the menu
  44.  * of the FTC Driver Station. When an selection is made from the menu, the corresponding OpMode
  45.  * class is instantiated on the Robot Controller and executed.
  46.  *
  47.  * This particular OpMode just executes a basic Tank Drive Teleop for a two wheeled robot
  48.  * It includes all the skeletal structure that all linear OpModes contain.
  49.  *
  50.  * Use Android Studios to Copy this Class, and Paste it into your team's code folder with a new name.
  51.  * Remove or comment out the @Disabled line to add this opmode to the Driver Station OpMode list
  52.  */
  53.  
  54. @TeleOp(name="Test Color", group="Linear Opmode")
  55. //@Disabled
  56. public class autonom extends LinearOpMode {
  57.  
  58.     // Declare OpMode members.
  59.     private ElapsedTime runtime = new ElapsedTime();
  60.  
  61.     HardwarePushbot robot = new HardwarePushbot();
  62.  
  63.     @Override
  64.     public void runOpMode() {
  65.  
  66.         robot.init(hardwareMap);
  67.  
  68.         waitForStart();
  69.  
  70.         NormalizedRGBA colors = robot.colorSensor.getNormalizedColors();
  71.  
  72.         if(colors.red > colors.blue)
  73.         {
  74.  
  75.             runtime.reset();
  76.  
  77.             while(runtime.seconds()< 0.25) {
  78.                 robot.leftDrive.setPower(-0.6);
  79.                 robot.rightDrive.setPower(-0.6);
  80.             }
  81.  
  82.             robot.leftDrive.setPower(0);
  83.             robot.rightDrive.setPower(0);
  84.         } else if(colors.red < colors.blue)
  85.         {
  86.             runtime.reset();
  87.  
  88.             while(runtime.seconds()< 0.25) {
  89.                 robot.leftDrive.setPower(0.6);
  90.                 robot.rightDrive.setPower(0.6);
  91.             }
  92.  
  93.             robot.leftDrive.setPower(0);
  94.             robot.rightDrive.setPower(0);
  95.         }
  96.  
  97.  
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement