Skip to content

Instantly share code, notes, and snippets.

@mralext20
Created January 30, 2018 23:51
Show Gist options
  • Save mralext20/b395297fcd073bd765969f26964f25d0 to your computer and use it in GitHub Desktop.
Save mralext20/b395297fcd073bd765969f26964f25d0 to your computer and use it in GitHub Desktop.
/*
* turn(625) gives you a turn to the leftby 90 degrees.
* this method can be given negative numbers in order to turn right.
*
* drive()
*
*
*/
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.hardware.ColorSensor;
@Autonomous(name = "GEM ONLY auto", group = "competition")
public class Auto extends LinearOpMode {
// Declare OpMode members.
private DcMotor leftWheel = null;
private DcMotor rightWheel = null;
private DcMotor centerWheel = null;
public void drive(int delta) {
int curLeft = leftWheel.getCurrentPosition();
int curRight = rightWheel.getCurrentPosition();
if (delta > 0) {
leftWheel.setTargetPosition(curLeft + delta);
rightWheel.setTargetPosition(curRight + delta);
} else if (delta < 0) {
leftWheel.setTargetPosition(curLeft - delta);
rightWheel.setTargetPosition(curRight - delta);
}
while (leftWheel.isBusy() || rightWheel.isBusy())
{
sleep(10);
}
}
@Override
public void runOpMode() {
leftWheel = hardwareMap.get(DcMotor.class, "leftwheel");
rightWheel = hardwareMap.get(DcMotor.class, "rightwheel");
centerWheel = hardwareMap.get(DcMotor.class, "centerwheel");
leftWheel.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightWheel.setMode(DcMotor.RunMode.RUN_TO_POSITION);
rightWheel.setDirection(DcMotor.Direction.REVERSE);
centerWheel.setDirection(DcMotor.Direction.REVERSE);
leftWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
rightWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
centerWheel.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
// Wait for the game to start
waitForStart();
drive(200);
print("helo?");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment