Repository navigation
Releases
Beta Theta Gamma
package org.firstinspires.ftc.teamcode.Auto;
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.DcMotor.ZeroPowerBehavior;
import org.firstinspires.ftc.teamcode.DriveTrain;
@autonomous(name = "fear", group = "Auto")
public class fear extends LinearOpMode {
@OverRide
public void runOpMode() throws InterruptedException {
DriveTrain Drive = new DriveTrain();
Drive.init(this);
waitForStart();
while (opModeIsActive()) {
Drive.turn(179, 0.3);
Drive.stop();
break;
}
}
}
Java
package org.firstinspires.ftc.teamcode;
import static com.qualcomm.robotcore.hardware.DcMotorSimple.Direction.FORWARD;
import static com.qualcomm.robotcore.hardware.DcMotorSimple.Direction.REVERSE;
import static org.firstinspires.ftc.robotcore.external.BlocksOpModeCompanion.telemetry;
import static org.firstinspires.ftc.teamcode.MotorPulsesCalculator.calculatePulses;
import com.qualcomm.hardware.rev.RevHubOrientationOnRobot;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DcMotorSimple;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.IMU;
import com.qualcomm.robotcore.hardware.Servo;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.YawPitchRollAngles;
public class DriveTrain {
<<<<<<< Updated upstream
private DcMotor FrontLM = null;
private DcMotor FrontRM = null;
private DcMotor BackLM = null;
private DcMotor BackRM = null;
public DcMotor FrontLM = null;
public DcMotor FrontRM = null;
public DcMotor BackLM = null;
public DcMotor BackRM = null;
public IMU imu = null;
Stashed changes
private LinearOpMode opmode = null;
public DriveTrain() {
BackRM = hwMap.dcMotor.get("BackRM");
BackLM = hwMap.dcMotor.get("BackLM");
FrontLM.setDirection(REVERSE);
FrontRM.setDirection(FORWARD);
BackLM.setDirection(FORWARD);
BackRM.setDirection(FORWARD);
FrontLM.setPower(0);
BackRM.setPower(0);
BackLM.setPower(0);
imu = hwMap.get(IMU.class, "imu");
/* Define how the hub is mounted on the robot to get the correct Yaw, Pitch and Roll values.
*
* Two input parameters are required to fully specify the Orientation.
* The first parameter specifies the direction the printed logo on the Hub is pointing.
* The second parameter specifies the direction the USB connector on the Hub is pointing.
* All directions are relative to the robot, and left/right is as-viewed from behind the robot.
/
/ The next two lines define Hub orientation.
* The Default Orientation (shown) is when a hub is mounted horizontally with the printed logo pointing UP and the USB port pointing FORWARD.
*
* To Do: EDIT these two lines to match YOUR mounting configuration.
*/
RevHubOrientationOnRobot.LogoFacingDirection logoDirection = RevHubOrientationOnRobot.LogoFacingDirection.UP;
RevHubOrientationOnRobot.UsbFacingDirection usbDirection = RevHubOrientationOnRobot.UsbFacingDirection.FORWARD;
RevHubOrientationOnRobot orientationOnRobot = new RevHubOrientationOnRobot(logoDirection, usbDirection);
// Now initialize the IMU with this mounting orientation
// Note: if you choose two conflicting directions, this initialization will cause a code exception.
imu.initialize(new IMU.Parameters(orientationOnRobot));
}
public void forward(double speed){
BackLM.setPower(speed);
BackRM.setPower(-speed);
}
// public void turn(double angle, double speed) {
//
// YawPitchRollAngles orientation = imu.getRobotYawPitchRollAngles();
//
// FrontRM.setPower(-speed);
// FrontLM.setPower(speed);
// BackLM.setPower(speed);
// BackRM.setPower(-speed);
//
// opmode.telemetry.addData("Yaw (Z)", "%.2f Deg. (Heading)", orientation.getYaw(AngleUnit.DEGREES));
// opmode.telemetry.update();
//// if(5==5){
//// stop();
//// }
// while(orientation.getYaw(AngleUnit.DEGREES) < angle){
//
// }
// stop();
// }
public void turn(double angle, double speed) {
Boolean isDone = false;
while(!isDone){
// telemetry.addData("Hub Orientation", "Logo=%s USB=%s\n", logoFacingDirections, usbFacingDirections);
YawPitchRollAngles orientation = imu.getRobotYawPitchRollAngles();
opmode.telemetry.addData("Yaw", "%.2f Deg. (Heading)", orientation.getYaw(AngleUnit.DEGREES));
opmode.telemetry.update();
if(orientation.getYaw(AngleUnit.DEGREES)<90){
turnLeft(0.1);
}else{
stop();
isDone=true;
break;
}
}
}
public void strafeRight(double speed) {
FrontRM.setPower(speed);
public void strafeLeft(double speed) {
FrontRM.setPower(-speed);
while (BackLM.isBusy()) {
}
stop();
}
public void strafeRight(double speed, double distance) {
int pulses = calculatePulses(distance);
prepareEncoders();
BackLM.setTargetPosition(pulses);
BackRM.setTargetPosition(pulses);
BackLM.setPower(speed);
BackRM.setPower(-speed);
FrontLM.setPower(speed);
FrontRM.setPower(-speed);
while (BackLM.isBusy()) {
}
stop();
}
public void strafeLeft(double speed, double distance) {
int pulses = calculatePulses(distance);
prepareEncoders();
BackLM.setTargetPosition(pulses);
BackRM.setTargetPosition(pulses);
BackLM.setPower(-speed);
BackRM.setPower(speed);
FrontLM.setPower(-speed);
FrontRM.setPower(speed);
while (BackLM.isBusy()) {
}
stop();
}
public void stop() {
FrontRM.setPower(0);
FrontLM.setPower(0);
BackLM.setPower(0);
BackRM.setPower(0);
}
}
Theta pi.4
Credit to Portapps/ Brave.com.
Code is from a million people and under a million licenses
omega
This is the one that isn't portable. As always, open source monstrosity. Mostly mozzilla maybe?