move basic gamepad controls into seperate class

This commit is contained in:
missing 2022-01-18 12:15:05 -06:00
parent 39ef371aff
commit c017d804f0
3 changed files with 12 additions and 93 deletions

View file

@ -3,12 +3,11 @@ package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@TeleOp(name = "Gamepad 1.0 IMU 1.0 tt")
public class Gamepad extends OpMode {
private final API.Motor intakeMotor = API.Motor.M4;
private final API.Motor liftMotor = API.Motor.M5;
private final API.Motor carouselMotor = API.Motor.M6;
private double speed = 1;
protected final API.Motor intakeMotor = API.Motor.M4;
protected final API.Motor liftMotor = API.Motor.M5;
protected final API.Motor carouselMotor = API.Motor.M6;
protected double speed = 1;
@Override
public void init() {
@ -16,6 +15,7 @@ public class Gamepad extends OpMode {
API.print("Status", "Initializing, please wait");
API.pause(1);
liftMotor.setDirection(API.Direction.REVERSE);
MovementAPI.init(API.Motor.M0, API.Motor.M1, API.Motor.M2, API.Motor.M3);
API.clear();
@ -25,26 +25,13 @@ public class Gamepad extends OpMode {
@Override
public void start() {
API.clear();
API.imu.reset();
liftMotor.setDirection(API.Direction.REVERSE);
}
@Override
public void loop() {
long ms = System.currentTimeMillis() + 15;
double imuOut = API.imu.adjustAngle(API.imu.getHeading());
MovementAPI.move(-gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x, speed, true);
double turn = gamepad1.right_stick_x;
if (gamepad1.y && gamepad1.right_stick_x == 0) turn = imuOut / 180;
else API.imu.reset();
MovementAPI.move(-gamepad1.left_stick_y, gamepad1.left_stick_x, turn, speed, false);
API.print(
"Speed: " + speed + System.lineSeparator() +
"Rotation (degrees, IMU): " + imuOut + System.lineSeparator() +
"IMU Active: " + !gamepad1.y
);
API.print("Speed", speed + ""); // i dont know how to do this better
if (gamepad1.right_bumper) speed = Math.min(speed + 0.01, 1);
else if (gamepad1.left_bumper) speed = Math.max(speed - 0.01, 0.2);
@ -52,12 +39,5 @@ public class Gamepad extends OpMode {
intakeMotor.controlWithTwoButtons(gamepad2.a, gamepad2.b);
liftMotor.controlWithTwoButtons(gamepad2.dpad_up, gamepad2.dpad_down, 0.25);
carouselMotor.controlWithTwoButtons(gamepad2.x, gamepad2.y);
ms -= System.currentTimeMillis();
if (ms > 5) try {
Thread.sleep(ms);
} catch (InterruptedException ie) {
API.print("Why are we here? Just to suffer?");
}
}
}

View file

@ -12,12 +12,7 @@ import org.json.JSONObject;
import java.io.File;
@TeleOp(name="Gamepad Recorder v1.0.1")
public class GamepadRecord extends OpMode {
private double speed = 1;
private final API.Motor intakeMotor = API.Motor.M4;
private final API.Motor liftMotor = API.Motor.M5;
private final API.Motor carouselMotor = API.Motor.M6;
public class GamepadRecord extends Gamepad {
private final String outputFileName = "recording1.json";
private File outputFile;
private JSONObject outputJSON;
@ -26,13 +21,8 @@ public class GamepadRecord extends OpMode {
@Override
public void init() {
API.init(this);
API.print("Status", "Initializing, please wait");
API.pause(1);
super.init();
MovementAPI.init(API.Motor.M0, API.Motor.M1, API.Motor.M2, API.Motor.M3);
liftMotor.setDirection(API.Direction.REVERSE);
outputFile = AppUtil.getInstance().getSettingsFile(outputFileName);
try {
outputJSON = new JSONObject();
@ -45,29 +35,13 @@ public class GamepadRecord extends OpMode {
API.print("Press play to start");
}
@Override
public void start() {
API.clear();
this.resetStartTime();
}
@Override
public void loop() {
long ms = System.currentTimeMillis()+15;
MovementAPI.move(-gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x, speed, false);
super.loop();
API.print(
"Speed: " + speed + System.lineSeparator() +
"Time: " + this.time
);
if (gamepad1.right_bumper && !gamepad1.left_bumper) speed = Math.min(speed+0.01, 1);
if (gamepad1.left_bumper && !gamepad1.right_bumper) speed = Math.max(speed-0.01, 0.2);
intakeMotor.controlWithTwoButtons(gamepad2.a, gamepad2.b);
liftMotor.controlWithTwoButtons(gamepad2.dpad_up, gamepad2.dpad_down, 0.25);
carouselMotor.controlWithTwoButtons(gamepad2.x, gamepad2.y);
API.print("Time", this.time + "");
try {
JSONObject currentData = new JSONObject()

View file

@ -1,41 +1,6 @@
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
@TeleOp(name = "AAAAAAAAA")
public class TotallyGamepaad extends OpMode {
private final API.Motor intakeMotor = API.Motor.M4;
private final API.Motor liftMotor = API.Motor.M5;
private final API.Motor carouselMotor = API.Motor.M6;
private double speed = 1;
@Override
public void init() {
API.init(this);
API.print("Status", "Initializing, please wait");
API.pause(1);
MovementAPI.init(API.Motor.M0, API.Motor.M1, API.Motor.M2, API.Motor.M3);
API.clear();
API.print("Press play to start");
}
@Override
public void start() {
API.clear();
liftMotor.setDirection(API.Direction.REVERSE, false);
}
@Override
public void loop() {
MovementAPI.move(-gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x, gamepad1.y ? 1 : gamepad1.a ? 0.35 : speed, false);
if (gamepad1.right_bumper) speed = Math.min(speed + 0.002, 1);
else if (gamepad1.left_bumper) speed = Math.max(speed - 0.002, 0.2);
intakeMotor.controlWithTwoButtons(gamepad2.a, gamepad2.b);
liftMotor.controlWithTwoButtons(gamepad2.dpad_up, gamepad2.dpad_down, gamepad2.left_bumper ? 0.6 : 0.25);
carouselMotor.controlWithTwoButtons(gamepad2.x, gamepad2.y, 0.75);
}
}
public class TotallyGamepaad extends Gamepad {}