Initialize motors inside MovementAPI

This commit is contained in:
Yash Karandikar 2022-11-07 21:58:41 -06:00
parent 5ec14a3fc7
commit f26e7ef093
6 changed files with 15 additions and 41 deletions

View file

@ -2,19 +2,13 @@ package org.firstinspires.ftc.teamcode.createdcode.enhancedautos;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
@Autonomous
public class AutoBlueSubstationParkingBehavior extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
DcMotor fl = hardwareMap.get(DcMotor.class, "frontLeft");
DcMotor fr = hardwareMap.get(DcMotor.class, "frontRight");
DcMotor rl = hardwareMap.get(DcMotor.class, "rearLeft");
DcMotor rr = hardwareMap.get(DcMotor.class, "rearRight");
API api = new API(this);
MovementAPI movementAPI = new MovementAPI(api, fl, fr, rl, rr);
MovementAPI movementAPI = new MovementAPI(api);
waitForStart();

View file

@ -2,19 +2,14 @@ package org.firstinspires.ftc.teamcode.createdcode.enhancedautos;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
@Autonomous
public class AutoBlueTerminalParkingBehavior extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
DcMotor fl = hardwareMap.get(DcMotor.class, "frontLeft");
DcMotor fr = hardwareMap.get(DcMotor.class, "frontRight");
DcMotor rl = hardwareMap.get(DcMotor.class, "rearLeft");
DcMotor rr = hardwareMap.get(DcMotor.class, "rearRight");
API api = new API(this);
MovementAPI movementAPI = new MovementAPI(api, fl, fr, rl, rr);
MovementAPI movementAPI = new MovementAPI(api);
waitForStart();

View file

@ -2,19 +2,13 @@ package org.firstinspires.ftc.teamcode.createdcode.enhancedautos;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
@Autonomous
public class AutoRedSubstationParkingBehavior extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
DcMotor fl = hardwareMap.get(DcMotor.class, "frontLeft");
DcMotor fr = hardwareMap.get(DcMotor.class, "frontRight");
DcMotor rl = hardwareMap.get(DcMotor.class, "rearLeft");
DcMotor rr = hardwareMap.get(DcMotor.class, "rearRight");
API api = new API(this);
MovementAPI movementAPI = new MovementAPI(api, fl, fr, rl, rr);
MovementAPI movementAPI = new MovementAPI(api);
waitForStart();

View file

@ -2,20 +2,15 @@ package org.firstinspires.ftc.teamcode.createdcode.enhancedautos;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
@Autonomous
public class AutoRedTerminalParkingBehavior extends LinearOpMode {
@Override
public void runOpMode() throws InterruptedException {
DcMotor fl = hardwareMap.get(DcMotor.class, "frontLeft");
DcMotor fr = hardwareMap.get(DcMotor.class, "frontRight");
DcMotor rl = hardwareMap.get(DcMotor.class, "rearLeft");
DcMotor rr = hardwareMap.get(DcMotor.class, "rearRight");
API api = new API(this);
MovementAPI movementAPI = new MovementAPI(api, fl, fr, rl, rr);
MovementAPI movementAPI = new MovementAPI(api);
waitForStart();

View file

@ -9,12 +9,13 @@ public class ColorSensorTest extends LinearOpMode {
@Override
public void runOpMode() {
ColorSensor sensor = hardwareMap.get(ColorSensor.class, "color");
API api = new API(this);
waitForStart();
while (opModeIsActive()) {
telemetry.addData("r:", sensor.red());
telemetry.addData("g:", sensor.green());
telemetry.addData("b:", sensor.blue());
telemetry.update();
api.print("r:", String.valueOf(sensor.red()));
api.print("g:", String.valueOf(sensor.green()));
api.print("b:", String.valueOf(sensor.blue()));
}
}
}

View file

@ -18,22 +18,17 @@ public class MovementAPI {
public DcMotor getBR() { return br; }
/**
* Initializes the API
*
* @param _fl the front-left wheel
* @param _fr the front-right wheel
* @param _bl the back-left wheel
* @param _br the back-right wheel
* Initializes the MovementAPI
*/
public MovementAPI(API api, DcMotor _fl, DcMotor _fr, DcMotor _bl, DcMotor _br) {
public MovementAPI(API api) {
this.api = api;
api.print("Initializing MovementApi...");
fl = _fl;
fr = _fr;
bl = _bl;
br = _br;
fl = api.opMode.hardwareMap.get(DcMotor.class, "frontLeft");
fr = api.opMode.hardwareMap.get(DcMotor.class, "frontRight");
bl = api.opMode.hardwareMap.get(DcMotor.class, "rearLeft");
br = api.opMode.hardwareMap.get(DcMotor.class, "rearRight");
fl.setDirection(DcMotor.Direction.REVERSE);
bl.setDirection(DcMotor.Direction.REVERSE);