SHARE
TWEET
teleop
a guest
Nov 22nd, 2016
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- package org.firstinspires.ftc.teamcode;
- 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.util.ElapsedTime;
- import com.qualcomm.robotcore.util.Range;
- @TeleOp
- //@Disabled
- public class Teleop1 extends OpMode
- {
- /* Declare OpMode members. */
- RobotHardware robot = new RobotHardware();
- private ElapsedTime runtime = new ElapsedTime();
- /*
- * Code to run ONCE when the driver hits INIT
- */
- @Override
- public void init() {
- telemetry.addData("Status", "Initialized");
- updateTelemetry(telemetry);
- robot.init(hardwareMap);
- robot.buttonPushPosition = 0;
- }
- /*
- * Code to run REPEATEDLY after the driver hits INIT, but before they hit PLAY
- */
- @Override
- public void init_loop() {
- }
- /*
- * Code to run ONCE when the driver hits PLAY
- */
- @Override
- public void start() {
- runtime.reset();
- }
- {
- /*
- * Gamepad 1
- *
- * Gamepad 1 controls the motors via the left and right sticks
- */
- // tank drive
- // note that if y equal -1 then joystick is pushed all of the way forward.
- float left = -gamepad1.left_stick_y;
- float right = -gamepad1.right_stick_y;
- // clip the right/left values so that the values never exceed +/- 1
- right = Range.clip(right, -1, 1);
- left = Range.clip(left, -1, 1);
- // scale the joystick value to make it easier to control
- // the robot more precisely at slower speeds.
- right = (float) scaleInput(right);
- left = (float) scaleInput(left);
- // write the values to the motors
- robot.driveRight.setPower(right);
- robot.driveLeft.setPower(left);
- if (gamepad1.a) {
- robot.buttonPushPosition += robot.buttonPushDelta;
- }
- if (gamepad1.b) {
- robot.buttonPushPosition -= robot.buttonPushDelta;
- }
- /*
- * Gamepad 2
- *
- * Gamepad 2 controls the linear slide and shooter system
- */
- if (gamepad2.a) {
- robot.shooterIntake.setPower(1);
- } else {
- robot.shooterIntake.setPower(0);
- }
- if (gamepad2.b) {
- robot.shooterIntake.setPower(-1);
- } else {
- robot.shooterIntake.setPower(0);
- }
- if (gamepad2.x) {
- robot.shooterLaunch.setPower(1);
- } else {
- robot.shooterLaunch.setPower(0);
- }
- if (gamepad2.y) {
- robot.shooterLaunch.setPower(-1);
- } else {
- robot.shooterLaunch.setPower(0);
- }
- if (gamepad2.left_bumper) {
- robot.linearSlide.setPower(-1);
- } else {
- robot.linearSlide.setPower(0);
- }
- if (gamepad2.right_bumper) {
- robot.linearSlide.setPower(1);
- } else {
- robot.linearSlide.setPower(0);
- }
- }
- /*
- * Code to run REPEATEDLY after the driver hits PLAY but before they hit STOP
- */
- @Override
- public void loop() {
- telemetry.addData("Status", "Running: " + runtime.toString());
- // eg: Run wheels in tank mode (note: The joystick goes negative when pushed forwards)
- // leftMotor.setPower(-gamepad1.left_stick_y);
- // rightMotor.setPower(-gamepad1.right_stick_y);
- }
- /*
- * Code to run ONCE after the driver hits STOP
- */
- @Override
- public void stop() {
- }
- double scaleInput(double dVal) {
- double[] scaleArray = { 0.0, 0.05, 0.09, 0.10, 0.12, 0.15, 0.18, 0.24,
- 0.30, 0.36, 0.43, 0.50, 0.60, 0.72, 0.85, 1.00, 1.00 };
- // get the corresponding index for the scaleInput array.
- int index = (int) (dVal * 16.0);
- // index should be positive.
- if (index < 0) {
- index = -index;
- }
- // index cannot exceed size of array minus 1.
- if (index > 16) {
- index = 16;
- }
- // get value from the array.
- double dScale = 0.0;
- if (dVal < 0) {
- dScale = -scaleArray[index];
- } else {
- dScale = scaleArray[index];
- }
- // return scaled value.
- return dScale;
- }
- }
RAW Paste Data
