Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Rayne working teleop #82

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.firstinspires.ftc.teamcode.auton;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.CRServo;
import com.qualcomm.robotcore.hardware.DcMotor;
Expand All @@ -11,6 +12,7 @@

import org.firstinspires.ftc.teamcode.subsystems.robotMethods.*;

@Autonomous(name = "Auton Park")
public class autonPark extends OpMode {
byte startingLocationIndex = 0;
double[][] startingLocation = new double[][] {new double[] {0, 0, 0}, new double[] {0, 0, 0},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.firstinspires.ftc.teamcode.auton.tests;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;

import org.firstinspires.ftc.teamcode.subsystems.hardware.Hardware;
import org.firstinspires.ftc.teamcode.subsystems.hardware.HardwareElement;
import org.firstinspires.ftc.teamcode.subsystems.robotMethods.RobotMethods;
import org.firstinspires.ftc.teamcode.subsystems.stateMachineController.Context;

@Autonomous(name = "Auton Wheels Test")
public class AutonWheelsTest extends OpMode {
Hardware robot;
Context context;
double motorRunPower = 0.5;

@Override
public void init() {
telemetry.addData("Status", "Initializing");

robot = new Hardware(hardwareMap, telemetry);
context = new Context();

// Init DcMotors.
robot.introduce(new HardwareElement<>(DcMotor.class, hardwareMap, "leftFront",
"setDirection:REVERSE"));
robot.introduce(new HardwareElement<>(DcMotor.class, hardwareMap, "leftRear",
"setDirection:REVERSE"));
robot.introduce(new HardwareElement<>(DcMotor.class, hardwareMap, "rightFront"));
robot.introduce(new HardwareElement<>(DcMotor.class, hardwareMap, "rightRear"));

telemetry.addData("Status", "Initialized");
}

@Override
public void start() {
RobotMethods.setTargetPosition(robot.<DcMotor>get("leftFront"), 300);
RobotMethods.setTargetPosition(robot.<DcMotor>get("leftRear"), 300);
RobotMethods.setTargetPosition(robot.<DcMotor>get("rightFront"), 300);
RobotMethods.setTargetPosition(robot.<DcMotor>get("rightRear"), 300);
}

@Override
public void loop() {
if (gamepad1.a) {
robot.<DcMotor>get("leftFront").setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
robot.<DcMotor>get("leftRear").setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
robot.<DcMotor>get("rightFront").setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
robot.<DcMotor>get("rightRear").setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
} else {
RobotMethods.updateMotor(telemetry, robot.<DcMotor>get("leftFront"), motorRunPower);
RobotMethods.updateMotor(telemetry, robot.<DcMotor>get("leftRear"), motorRunPower);
RobotMethods.updateMotor(telemetry, robot.<DcMotor>get("rightFront"), motorRunPower);
RobotMethods.updateMotor(telemetry, robot.<DcMotor>get("rightRear"), motorRunPower);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.firstinspires.ftc.teamcode.auton.tests;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;

import org.firstinspires.ftc.teamcode.subsystems.hardware.Hardware;
import org.firstinspires.ftc.teamcode.subsystems.hardware.HardwareElement;

@Autonomous(name = "DcMotor Test")
public class DcMotorTest extends OpMode {
Hardware robot;

@Override
public void init() {
telemetry.addData("Status", "Initializing");

robot = new Hardware(hardwareMap, telemetry);

// Init DcMotors.
robot.introduce(new HardwareElement<>(DcMotor.class, hardwareMap, "testMotor"));
robot.<DcMotor>get("testMotor").setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);

telemetry.addData("Status", "Initialized");
}

@Override
public void start() {
robot.<DcMotor>get("testMotor").setTargetPosition(-300);
robot.<DcMotor>get("testMotor").setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
robot.<DcMotor>get("testMotor").setPower(-0.75);
}

@Override
public void loop() {
if (robot.<DcMotor>get("testMotor").getCurrentPosition() > 100) {
robot.<DcMotor>get("testMotor").setPower(0.75);
} else if (robot.<DcMotor>get("testMotor").getCurrentPosition() <=
robot.<DcMotor>get("testMotor").getTargetPosition()) {
robot.<DcMotor>get("testMotor").setPower(0);
}

telemetry.addData("target pos", robot.<DcMotor>get("testMotor").getTargetPosition());
telemetry.addData("current pos", robot.<DcMotor>get("testMotor").getCurrentPosition());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.firstinspires.ftc.teamcode.auton;
package org.firstinspires.ftc.teamcode.auton.tests;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.firstinspires.ftc.teamcode.auton.tests;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
import com.qualcomm.robotcore.hardware.DcMotor;

import org.firstinspires.ftc.teamcode.subsystems.hardware.Hardware;
import org.firstinspires.ftc.teamcode.subsystems.hardware.HardwareElement;
import org.firstinspires.ftc.teamcode.subsystems.robotMethods.RobotMethods;
import org.firstinspires.ftc.teamcode.subsystems.stateMachineController.Context;

@Autonomous(name = "Robot Methods Test")
public class RobotMethodsTest extends OpMode {
Hardware robot;
Context context;
double motorRunPower = 0.5;

@Override
public void init() {
telemetry.addData("Status", "Initializing");

robot = new Hardware(hardwareMap, telemetry);
context = new Context();

// Init DcMotors.
robot.introduce(new HardwareElement<>(DcMotor.class, hardwareMap, "testMotor"));

telemetry.addData("Status", "Initialized");
}

@Override
public void start() {
RobotMethods.setTargetPosition(robot.<DcMotor>get("testMotor"), 300);
}

@Override
public void loop() {
RobotMethods.updateMotor(telemetry, robot.<DcMotor>get("testMotor"), motorRunPower);

if (gamepad1.a) {
robot.<DcMotor>get("testMotor").setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.firstinspires.ftc.teamcode.auton;
package org.firstinspires.ftc.teamcode.auton.tests;

import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,34 @@ private static void setWheelTargets(Hardware robot, double mm) {
setTargetPosition(robot.<DcMotor>get("rightRear"), mm);
}

private static void setTargetPosition(DcMotor motor, double mm) {
public static void setTargetPosition(DcMotor motor, double mm) {
motor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
motor.setTargetPosition((int) Math.round(mm/mmPerEncoderTick));
motor.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
}

private static void updateMotor(Telemetry telemetry, DcMotor motor, double motorRunPower) {
public static void updateMotor(Telemetry telemetry, DcMotor motor, double motorRunPower) {
showMotorStatus(motor, telemetry);
updateMotorPower(motor, motorRunPower);
}

private static void updateMotorPower(DcMotor motor, double motorRunPower) {
if (motor.getTargetPosition() == motor.getCurrentPosition()) {
// Is motor in position?
if ((motor.getTargetPosition() <= 0 && motor.getCurrentPosition() <= motor.getTargetPosition() ||
motor.getTargetPosition() >= 0 && motor.getCurrentPosition() >= motor.getTargetPosition())) {
motor.setPower(0);
} else {
motor.setPower(motorRunPower);
} else if (motor.getPower() == 0) { // If not in position and power is zero, set power.
if (motor.getTargetPosition() > 0){
motor.setPower(motorRunPower);
} else if (motor.getTargetPosition() > 0) {
motor.setPower(-motorRunPower);
}
}

// Catch any motors running the wrong way.
if (motor.getTargetPosition() < motor.getCurrentPosition() && motor.getCurrentPosition() > 0 ||
motor.getTargetPosition() > motor.getCurrentPosition() && motor.getCurrentPosition() < 0) {
motor.setPower(-motor.getPower());
}
}

Expand Down
Loading