mirror of
https://github.com/TimeCrafters/FTC_2022
synced 2025-12-16 13:32:36 +00:00
Tank drive w/ bumper strafe, playing with LEDS and sensors.
This commit is contained in:
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@@ -1,5 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<list size="1">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="com.qualcomm.robotcore.eventloop.opmode.TeleOp" />
|
||||||
|
</list>
|
||||||
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.timecrafters.minibots.cyberarm;
|
||||||
|
|
||||||
|
import org.cyberarm.engine.V2.CyberarmEngine;
|
||||||
|
|
||||||
|
public class PortsCheckGeneric {
|
||||||
|
|
||||||
|
private CyberarmEngine engine;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
package org.timecrafters.minibots.cyberarm.states;
|
|
||||||
|
|
||||||
import com.qualcomm.hardware.rev.RevBlinkinLedDriver;
|
|
||||||
import com.qualcomm.robotcore.hardware.CRServo;
|
|
||||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
|
||||||
import com.qualcomm.robotcore.hardware.Servo;
|
|
||||||
|
|
||||||
import org.cyberarm.engine.V2.CyberarmState;
|
|
||||||
|
|
||||||
public class AssignmentOmniKinetic extends CyberarmState {
|
|
||||||
CRServo Wheel, Rack;
|
|
||||||
DcMotor Three, Zero, Two, One;
|
|
||||||
Servo Zygo;
|
|
||||||
@Override
|
|
||||||
public void init() {
|
|
||||||
super.init();
|
|
||||||
|
|
||||||
Wheel=engine.hardwareMap.crservo.get("Wheel");
|
|
||||||
Rack=engine.hardwareMap.crservo.get("Rack");
|
|
||||||
Three=engine.hardwareMap.dcMotor.get("Three");
|
|
||||||
Zero=engine.hardwareMap.dcMotor.get("Zero");
|
|
||||||
Two=engine.hardwareMap.dcMotor.get("Two");
|
|
||||||
One=engine.hardwareMap.dcMotor.get("One");
|
|
||||||
Zygo=engine.hardwareMap.servo.get("Zygo");
|
|
||||||
}
|
|
||||||
MecanumRobot robot;
|
|
||||||
public AssignmentOmniKinetic (MecanumRobot robot) {this.robot = robot;}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void exec() {
|
|
||||||
|
|
||||||
if (engine.gamepad1.left_bumper) {
|
|
||||||
|
|
||||||
robot.frontLeftDrive.setPower(1);
|
|
||||||
robot.frontRightDrive.setPower(-1);
|
|
||||||
robot.backLeftDrive.setPower(-1);
|
|
||||||
robot.backRightDrive.setPower(1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engine.gamepad1.right_bumper) {
|
|
||||||
|
|
||||||
robot.frontLeftDrive.setPower(-1);
|
|
||||||
robot.frontRightDrive.setPower(1);
|
|
||||||
robot.backLeftDrive.setPower(1);
|
|
||||||
robot.backRightDrive.setPower(-1);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
if (engine.gamepad1.dpad_up) {
|
|
||||||
|
|
||||||
Zygo.setPosition(1.0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engine.gamepad1.dpad_down) {
|
|
||||||
Zygo.setPosition(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engine.gamepad1.a) {
|
|
||||||
|
|
||||||
engine.hardwareMap.led.get(String.valueOf(RevBlinkinLedDriver.BlinkinPattern.GREEN));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engine.gamepad1.b) {
|
|
||||||
|
|
||||||
engine.hardwareMap.led.get(String.valueOf(RevBlinkinLedDriver.BlinkinPattern.RED));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engine.gamepad1.x) {
|
|
||||||
|
|
||||||
engine.hardwareMap.led.get(String.valueOf(RevBlinkinLedDriver.BlinkinPattern.BLUE));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (engine.gamepad1.y) {
|
|
||||||
|
|
||||||
engine.hardwareMap.led.get(String.valueOf(RevBlinkinLedDriver.BlinkinPattern.YELLOW));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Three.setPower(engine.gamepad1.left_stick_y * 1);
|
|
||||||
Two.setPower(engine.gamepad1.left_stick_y * 1);
|
|
||||||
One.setPower(engine.gamepad1.right_stick_y * 1);
|
|
||||||
Zero.setPower(engine.gamepad1.right_stick_y * 1);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package org.timecrafters.minibots.cyberarm.states;
|
||||||
|
|
||||||
|
public class BlitzkriegState {
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.timecrafters.testing.engine;
|
||||||
|
|
||||||
|
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||||
|
|
||||||
|
import org.cyberarm.engine.V2.CyberarmEngine;
|
||||||
|
import org.timecrafters.testing.states.PrototypeBot1;
|
||||||
|
import org.timecrafters.testing.states.PrototypeTeleOPState;
|
||||||
|
|
||||||
|
@TeleOp (name = "PrototypeTeleOP")
|
||||||
|
|
||||||
|
public class PrototypeTeleOP extends CyberarmEngine {
|
||||||
|
|
||||||
|
PrototypeBot1 robot;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setup() {
|
||||||
|
|
||||||
|
robot = new PrototypeBot1(this);
|
||||||
|
|
||||||
|
addState(new PrototypeTeleOPState(robot));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package org.timecrafters.testing.states;
|
||||||
|
|
||||||
|
import com.qualcomm.robotcore.hardware.CRServo;
|
||||||
|
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||||
|
import com.qualcomm.robotcore.hardware.DcMotorSimple;
|
||||||
|
|
||||||
|
import org.cyberarm.engine.V2.CyberarmEngine;
|
||||||
|
|
||||||
|
public class PrototypeBot1 {
|
||||||
|
|
||||||
|
private CyberarmEngine engine;
|
||||||
|
|
||||||
|
public DcMotor frontLeftDrive, frontRightDrive, backLeftDrive, backRightDrive, armMotor;
|
||||||
|
|
||||||
|
public CRServo collectorLeft, collectorRight;
|
||||||
|
|
||||||
|
public PrototypeBot1(CyberarmEngine engine) {
|
||||||
|
this.engine = engine;
|
||||||
|
|
||||||
|
setupRobot();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupRobot () {
|
||||||
|
|
||||||
|
//motors configuration
|
||||||
|
frontLeftDrive = engine.hardwareMap.dcMotor.get("front left");
|
||||||
|
frontRightDrive = engine.hardwareMap.dcMotor.get("front right");
|
||||||
|
backRightDrive = engine.hardwareMap.dcMotor.get("back left");
|
||||||
|
backLeftDrive = engine.hardwareMap.dcMotor.get("back right");
|
||||||
|
armMotor = engine.hardwareMap.dcMotor.get("arm motor");
|
||||||
|
|
||||||
|
// servo configuration
|
||||||
|
collectorLeft = engine.hardwareMap.crservo.get("collector left");
|
||||||
|
collectorRight = engine.hardwareMap.crservo.get("collector right");
|
||||||
|
|
||||||
|
//motors direction and encoders
|
||||||
|
frontLeftDrive.setDirection(DcMotorSimple.Direction.FORWARD);
|
||||||
|
frontLeftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
|
||||||
|
frontRightDrive.setDirection(DcMotorSimple.Direction.REVERSE);
|
||||||
|
frontRightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
|
||||||
|
backLeftDrive.setDirection(DcMotorSimple.Direction.FORWARD);
|
||||||
|
backLeftDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
|
||||||
|
backRightDrive.setDirection(DcMotorSimple.Direction.REVERSE);
|
||||||
|
backRightDrive.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package org.timecrafters.testing.states;
|
||||||
|
|
||||||
|
import org.cyberarm.engine.V2.CyberarmState;
|
||||||
|
|
||||||
|
public class PrototypeTeleOPState extends CyberarmState {
|
||||||
|
|
||||||
|
private final PrototypeBot1 robot;
|
||||||
|
public boolean A;
|
||||||
|
public boolean X;
|
||||||
|
public boolean Y;
|
||||||
|
private boolean bprev;
|
||||||
|
private double drivePower = 1;
|
||||||
|
|
||||||
|
public PrototypeTeleOPState(PrototypeBot1 robot) {
|
||||||
|
this.robot = robot;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void exec() {
|
||||||
|
|
||||||
|
//Gamepad Read
|
||||||
|
|
||||||
|
A = engine.gamepad1.a;
|
||||||
|
X = engine.gamepad1.x;
|
||||||
|
Y = engine.gamepad1.y;
|
||||||
|
|
||||||
|
|
||||||
|
//drive speed toggle
|
||||||
|
|
||||||
|
boolean b = engine.gamepad1.b;
|
||||||
|
|
||||||
|
if (b && !bprev) {
|
||||||
|
|
||||||
|
if (drivePower == 1) {
|
||||||
|
drivePower = 0.5;
|
||||||
|
} else {
|
||||||
|
drivePower = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Drivetrain Variables
|
||||||
|
double y = -engine.gamepad1.left_stick_y; // Remember, this is reversed! because of the negative
|
||||||
|
double x = engine.gamepad1.right_stick_x * 1.1; // Counteract imperfect strafing
|
||||||
|
double rx = engine.gamepad1.left_stick_x;
|
||||||
|
|
||||||
|
// Denominator is the largest motor power (absolute value) or 1
|
||||||
|
// This ensures all the powers maintain the same ratio, but only when
|
||||||
|
// at least one is out of the range [-1, 1]
|
||||||
|
|
||||||
|
double denominator = Math.max(Math.abs(y) + Math.abs(x) + Math.abs(rx), 1);
|
||||||
|
double frontLeftPower = (y + x + rx) / denominator;
|
||||||
|
double backLeftPower = (y - x + rx) / denominator;
|
||||||
|
double frontRightPower = (y - x - rx) / denominator;
|
||||||
|
double backRightPower = (y + x - rx) / denominator;
|
||||||
|
|
||||||
|
// As I programed this and ran it, I realized everything was backwards
|
||||||
|
// in direction so to fix that i either went in the robot object state and reversed
|
||||||
|
// directions on drive motors or put a negative in behind the joystick power to reverse it.
|
||||||
|
// I put negatives in to reverse it because it was the easiest at the moment.
|
||||||
|
|
||||||
|
robot.frontLeftDrive.setPower(-frontLeftPower);
|
||||||
|
robot.backLeftDrive.setPower(backLeftPower);
|
||||||
|
robot.frontRightDrive.setPower(-frontRightPower);
|
||||||
|
robot.backRightDrive.setPower(backRightPower);
|
||||||
|
robot.armMotor.setPower(engine.gamepad1.left_stick_y * 0.5);
|
||||||
|
|
||||||
|
if (engine.gamepad1.y) {
|
||||||
|
|
||||||
|
robot.collectorLeft.setPower(0);
|
||||||
|
robot.collectorRight.setPower(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (engine.gamepad1.a) {
|
||||||
|
|
||||||
|
robot.collectorLeft.setPower(1);
|
||||||
|
robot.collectorRight.setPower(-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (engine.gamepad1.x) {
|
||||||
|
|
||||||
|
robot.collectorLeft.setPower(-1);
|
||||||
|
robot.collectorRight.setPower(1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user