This commit is contained in:
missing 2022-02-24 16:30:03 -06:00
parent 757d1591fa
commit 5cb433bb19
5 changed files with 140 additions and 28 deletions

View file

@ -3,13 +3,8 @@ package org.firstinspires.ftc.teamcode;
import com.qualcomm.hardware.bosch.BNO055IMU;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ReadWriteFile;
import org.firstinspires.ftc.robotcore.external.navigation.Quaternion;
import org.firstinspires.ftc.robotcore.internal.system.AppUtil;
import java.io.File;
import java.util.UUID;
public class API {
private final OpMode opMode;
@ -102,6 +97,7 @@ public class API {
Motor(String name) {
rawMotor = opMode.hardwareMap.get(DcMotor.class, name);
rawMotor.setPower(0);
this.setBehaviour(MotorBehaviour.BRAKE);
}
/**
@ -197,6 +193,34 @@ public class API {
);
}
/**
* Sets the mode of the motor.
*
* @param mode the mode to use
*/
public void setMode(MotorMode mode) {
switch (mode) {
case RUN_WITHOUT_ENCODER:
rawMotor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
break;
case RUN_WITH_ENCODER:
rawMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
break;
case RUN_TO_POSITION:
rawMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
break;
}
}
/**
* Runs the motor to a position, then holds it in place.
*
* @param pos the position to run to
*/
public void runToPosition(int pos) {
rawMotor.setTargetPosition(pos * direction.i);
}
/**
* Moves the motor forward or backward at the provided speed based on the button inputs
*
@ -243,6 +267,12 @@ public class API {
FLOAT
}
public enum MotorMode {
RUN_WITH_ENCODER,
RUN_WITHOUT_ENCODER,
RUN_TO_POSITION,
}
public enum Direction {
FORWARD(1), REVERSE(-1);
private final int i;
@ -262,13 +292,13 @@ public class API {
}
/**
* Sets the intended position of the servo, in degrees.
* Sets the intended position of the servo, from 0 to 1.
* Note that intended means it will not necessarily get to this position, but that it will constantly attempt to get there.
*
* @param degrees The intended position.
* @param pos The intended position.
*/
public void setPosition(double degrees) {
servo.setPosition(degrees);
public void setPosition(double pos) {
servo.setPosition(pos);
}
/**
@ -283,7 +313,7 @@ public class API {
/**
* Starts the servo
*
* @param power The power to use, from 0 to 1
* @param power The power to use, from -1 to 1
*/
public void start(double power) {
this.power = power;
@ -310,6 +340,46 @@ public class API {
start(power);
}
}
/**
* Moves the servo forward or backward at the provided speed based on the button inputs
*
* @param positiveControl the button used to move the motor forward
* @param negativeControl the button used to move the motor backward
*/
public void controlWithTwoButtons(boolean positiveControl, boolean negativeControl, double speed) {
if (positiveControl && !negativeControl) this.start(speed);
else if (negativeControl && !positiveControl) this.start(-speed);
else this.stop();
}
/**
* Moves the servo forward or backward at maximum speed based on the button inputs
*
* @param positiveControl the button used to move the motor forward
* @param negativeControl the button used to move the motor backward
*/
public void controlWithTwoButtons(boolean positiveControl, boolean negativeControl) {
this.controlWithTwoButtons(positiveControl, negativeControl, 1);
}
/**
* Moves the servo forward at the provided speed if the button is pressed.
*
* @param positiveControl the button used to move forward
*/
public void controlWithOneButton(boolean positiveControl, double speed) {
this.controlWithTwoButtons(positiveControl, false, speed);
}
/**
* Moves the servo forward at maximum speed if the button is pressed.
*
* @param positiveControl the button used to move forward
*/
public void controlWithOneButton(boolean positiveControl) {
this.controlWithOneButton(positiveControl, 1);
}
}
public class HubIMU {

View file

@ -4,12 +4,14 @@ public abstract class AutonFour extends LinearOpModeWithMovement {
public abstract void runOpMode();
public void run(boolean blue) {
if (System.currentTimeMillis() > -1) throw new RuntimeException("Not yet implemented");
this.construct(true);
movement.setFlipped(!blue);
api.print("Status", "Initializing, please wait");
motors.lift.setDirection(API.Direction.REVERSE, false);
// motors.lift.setDirection(API.Direction.REVERSE, false);
api.clear();
api.print("Press play to start");
@ -19,12 +21,12 @@ public abstract class AutonFour extends LinearOpModeWithMovement {
movement.move(-180, 0.4, true);
api.pause(0.7);
movement.stop();
motors.lift.start(0.25);
// motors.lift.start(0.25);
api.pause(3);
motors.lift.stop();
motors.lift.start(-0.25);
// motors.lift.stop();
// motors.lift.start(-0.25);
api.pause(2.5);
motors.lift.stop();
// motors.lift.stop();
movement.move(0, 0.4, true);
api.pause(1);
movement.move(90, 0.4, true);

View file

@ -1,8 +1,10 @@
package org.firstinspires.ftc.teamcode;
public enum GameMotor {
FL("m0"), FR("m1"), BL("m2"), BR("m3"),
INTAKE("m4"), LIFT("m5"), CAROUSEL("m6");
FL("m7"), FR("m1"), BL("m2"), BR("m3"),
CAROUSEL("s11"),
SHOULDER1("m5"), SHOULDER2("m0"), ELBOW("m7"),
HAND("s6");
public final String name;

View file

@ -1,8 +1,8 @@
package org.firstinspires.ftc.teamcode;
public class GameMotors {
public final API.Motor fl, fr, bl, br, intake, lift, carousel;
public final API.Motor fl, fr, bl, br, shoulder1, shoulder2, elbow;
public final API.Servo hand, carousel;
public GameMotors(API api) {
fl = api.new Motor(GameMotor.FL.name);
@ -10,8 +10,12 @@ public class GameMotors {
bl = api.new Motor(GameMotor.BL.name);
br = api.new Motor(GameMotor.BR.name);
intake = api.new Motor(GameMotor.INTAKE.name);
lift = api.new Motor(GameMotor.LIFT.name);
carousel = api.new Motor(GameMotor.CAROUSEL.name);
carousel = api.new Servo(GameMotor.CAROUSEL.name);
shoulder1 = api.new Motor(GameMotor.SHOULDER1.name);
shoulder2 = api.new Motor(GameMotor.SHOULDER2.name);
elbow = api.new Motor(GameMotor.ELBOW.name);
hand = api.new Servo(GameMotor.HAND.name);
}
}

View file

@ -4,6 +4,9 @@ public abstract class Gamepad extends OpModeWithMovement {
protected double speed = 0.7;
protected boolean slowMode = false;
protected boolean prevX = false;
protected boolean armUp = false;
protected boolean prevL3 = false;
protected double armHeight = 0;
@Override
public void init() {
@ -12,7 +15,13 @@ public abstract class Gamepad extends OpModeWithMovement {
api.print("Status", "Initializing, please wait");
api.pause(1);
motors.lift.setDirection(API.Direction.REVERSE);
// motors.shoulder1.runToPosition(0);
// motors.shoulder2.runToPosition(0);
// motors.shoulder1.setMode(API.MotorMode.RUN_TO_POSITION);
// motors.shoulder2.setMode(API.MotorMode.RUN_TO_POSITION);
// motors.shoulder1.start(1);
// motors.shoulder2.start(1);
motors.shoulder2.setDirection(API.Direction.REVERSE);
api.clear();
api.print("Press play to start");
@ -25,24 +34,49 @@ public abstract class Gamepad extends OpModeWithMovement {
@Override
public void loop() {
double ms = getRuntime() / 1000;
// double ms = getRuntime() / 1000;
double currentSpeed = gamepad1.y ? 1 : slowMode ? 0.35 : speed;
movement.move(-gamepad1.left_stick_y, gamepad1.left_stick_x, gamepad1.right_stick_x, currentSpeed, true);
api.print("Speed", Double.toString(speed));
api.print("Slow mode", slowMode ? "true" : "false");
api.print("Arm up", armUp ? "true" : "false");
api.print("Arm height", Double.toString(armHeight));
if (gamepad1.x && !prevX) slowMode = !slowMode;
if (gamepad2.left_stick_button && !prevL3) armUp = !armUp;
if (gamepad1.right_bumper) speed = Math.min(speed + 0.01, 1);
else if (gamepad1.left_bumper) speed = Math.max(speed - 0.01, 0.2);
motors.intake.controlWithTwoButtons(gamepad2.a, gamepad2.b);
motors.lift.controlWithTwoButtons(gamepad2.dpad_up, gamepad2.dpad_down, 0.25);
motors.carousel.controlWithTwoButtons(gamepad2.x, gamepad2.y, 0.9);
prevX = gamepad1.x;
// motors.shoulder1.runToPosition((int)armHeight);
// motors.shoulder2.runToPosition((int)armHeight);
motors.shoulder1.start(gamepad2.left_stick_y);
motors.shoulder2.start(gamepad2.left_stick_y);
motors.elbow.start(gamepad2.right_stick_y);
while (getRuntime() / 1000 - ms < 15) ; // no empty while loop here!
// armHeight += gamepad2.left_stick_y;
// if (gamepad2.a && !gamepad2.b) posThingy += 0.05; //motors.hand.start(1);
// else if (!gamepad2.a && gamepad2.b) posThingy -= 0.05; //motors.hand.start(-1);
// else motors.hand.stop();
// motors.hand.setPosition(posThingy);
// System.out.println(posThingy);
if (armUp) {
motors.hand.start(1);
} else {
motors.hand.start(-1);
}
prevX = gamepad1.x;
prevL3 = gamepad2.left_stick_button;
// while (getRuntime() / 1000 - ms < 15) ; // no empty while loop here!
}
}