Merge branch 'master' into danielv5
This commit is contained in:
@@ -6,6 +6,11 @@ import com.acmerobotics.dashboard.config.Config;
|
||||
public class Color {
|
||||
public static boolean redAlliance = true;
|
||||
public static double Light0 = 0.28, Light1 = 0.67, Light2 = 0.36, Light3 = 0.5;
|
||||
public static double LightGreen = 0.5;
|
||||
public static double LightPurple = 0.715;
|
||||
public static double LightOrange = 0.33;
|
||||
public static double LightRed = 0.28;
|
||||
public static double LightBlue = 0.6;
|
||||
|
||||
public static double colorFilterAlpha = 1;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
package org.firstinspires.ftc.teamcode.constants;
|
||||
|
||||
public class Types {
|
||||
public class StateEnums {
|
||||
public enum Motif {
|
||||
NONE,
|
||||
GPP, // Green, Purple, Purple
|
||||
PGP, // Purple, Green, Purple
|
||||
PPG // Purple, Purple, Green
|
||||
}
|
||||
|
||||
public enum LightState {
|
||||
BALL_COUNT,
|
||||
BALL_COLOR,
|
||||
GOAL_LOCK,
|
||||
MANUAL,
|
||||
DISABLED,
|
||||
OFF
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,12 @@ import com.qualcomm.hardware.lynx.LynxModule;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||
|
||||
import org.firstinspires.ftc.teamcode.constants.Color;
|
||||
import org.firstinspires.ftc.teamcode.constants.StateEnums;
|
||||
import org.firstinspires.ftc.teamcode.libs.RR.MecanumDrive;
|
||||
import org.firstinspires.ftc.teamcode.utils.Drivetrain;
|
||||
import org.firstinspires.ftc.teamcode.utils.Flywheel;
|
||||
import org.firstinspires.ftc.teamcode.utils.Light;
|
||||
import org.firstinspires.ftc.teamcode.utils.MeasuringLoopTimes;
|
||||
import org.firstinspires.ftc.teamcode.utils.Robot;
|
||||
import org.firstinspires.ftc.teamcode.utils.Servos;
|
||||
@@ -48,6 +51,7 @@ public class TeleopV3 extends LinearOpMode {
|
||||
boolean fixedTurret = false;
|
||||
Robot robot;
|
||||
MultipleTelemetry TELE;
|
||||
Light light;
|
||||
Servos servo;
|
||||
Flywheel flywheel;
|
||||
MecanumDrive drive;
|
||||
@@ -65,7 +69,6 @@ public class TeleopV3 extends LinearOpMode {
|
||||
double headingOffset = 0.0;
|
||||
int ticker = 0;
|
||||
|
||||
|
||||
boolean autoSpintake = false;
|
||||
boolean enableSpindexerManager = true;
|
||||
|
||||
@@ -102,6 +105,11 @@ public class TeleopV3 extends LinearOpMode {
|
||||
tController.setTolerance(0.001);
|
||||
|
||||
Turret turret = new Turret(robot, TELE, robot.limelight);
|
||||
|
||||
light = Light.getInstance();
|
||||
light.init(robot.light, spindexer, turret);
|
||||
|
||||
light.setState(StateEnums.LightState.MANUAL);
|
||||
limelightUsed = true;
|
||||
|
||||
robot.light.setPosition(1);
|
||||
@@ -109,11 +117,18 @@ public class TeleopV3 extends LinearOpMode {
|
||||
robot.limelight.start();
|
||||
if (redAlliance) {
|
||||
robot.limelight.pipelineSwitch(4);
|
||||
light.setManualLightColor(Color.LightRed);
|
||||
} else {
|
||||
robot.limelight.pipelineSwitch(2);
|
||||
light.setManualLightColor(Color.LightBlue);
|
||||
|
||||
}
|
||||
|
||||
light.update();
|
||||
}
|
||||
|
||||
limelightUsed = true;
|
||||
|
||||
waitForStart();
|
||||
if (isStopRequested()) return;
|
||||
|
||||
@@ -124,9 +139,6 @@ public class TeleopV3 extends LinearOpMode {
|
||||
|
||||
//TELE.addData("Is limelight on?", robot.limelight.getStatus());
|
||||
|
||||
// LIGHT COLORS
|
||||
spindexer.ballCounterLight();
|
||||
|
||||
//DRIVETRAIN:
|
||||
|
||||
drivetrain.drive(
|
||||
@@ -137,9 +149,17 @@ public class TeleopV3 extends LinearOpMode {
|
||||
);
|
||||
|
||||
if (gamepad1.right_bumper) {
|
||||
|
||||
shootAll = false;
|
||||
servo.setTransferPos(transferServo_out);
|
||||
|
||||
light.setState(StateEnums.LightState.BALL_COUNT);
|
||||
|
||||
} else if (gamepad2.triangle){
|
||||
light.setState(StateEnums.LightState.BALL_COLOR);
|
||||
|
||||
} else {
|
||||
light.setState(StateEnums.LightState.GOAL_LOCK);
|
||||
}
|
||||
|
||||
//TURRET TRACKING
|
||||
@@ -230,6 +250,8 @@ public class TeleopV3 extends LinearOpMode {
|
||||
drive = new MecanumDrive(hardwareMap, new Pose2d(0, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (enableSpindexerManager) {
|
||||
//if (!shootAll) {
|
||||
spindexer.processIntake();
|
||||
@@ -321,16 +343,16 @@ public class TeleopV3 extends LinearOpMode {
|
||||
//
|
||||
// TELE.addData("shootall commanded", shootAll);
|
||||
// Targeting Debug
|
||||
// TELE.addData("robotX", robotX);
|
||||
// TELE.addData("robotY", robotY);
|
||||
// TELE.addData("robotInchesX", targeting.robotInchesX);
|
||||
// TELE.addData( "robotInchesY", targeting.robotInchesY);
|
||||
// TELE.addData("Targeting Interpolate", turretInterpolate);
|
||||
// TELE.addData("Targeting GridX", targeting.robotGridX);
|
||||
// TELE.addData("Targeting GridY", targeting.robotGridY);
|
||||
// TELE.addData("Targeting FlyWheel", targetingSettings.flywheelRPM);
|
||||
// TELE.addData("Targeting HoodAngle", targetingSettings.hoodAngle);
|
||||
// TELE.addData("timeSinceStamp", getRuntime() - shootStamp);
|
||||
TELE.addData("robotX", robotX);
|
||||
TELE.addData("robotY", robotY);
|
||||
TELE.addData("robotInchesX", targeting.robotInchesX);
|
||||
TELE.addData("robotInchesY", targeting.robotInchesY);
|
||||
TELE.addData("Targeting Interpolate", turretInterpolate);
|
||||
TELE.addData("Targeting GridX", targeting.robotGridX);
|
||||
TELE.addData("Targeting GridY", targeting.robotGridY);
|
||||
TELE.addData("Targeting FlyWheel", targetingSettings.flywheelRPM);
|
||||
TELE.addData("Targeting HoodAngle", targetingSettings.hoodAngle);
|
||||
TELE.addData("timeSinceStamp", getRuntime() - shootStamp);
|
||||
TELE.addData("Voltage", voltage); // returns alleged recorded voltage (not same as driver hub)
|
||||
TELE.addData("Avg Loop Time", loopTimes.getAvgLoopTime());
|
||||
TELE.addData("Min Loop Time", loopTimes.getMinLoopTimeOneMin());
|
||||
@@ -338,6 +360,8 @@ public class TeleopV3 extends LinearOpMode {
|
||||
|
||||
TELE.update();
|
||||
|
||||
light.update();
|
||||
|
||||
ticker++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package org.firstinspires.ftc.teamcode.utils;
|
||||
|
||||
import com.acmerobotics.dashboard.config.Config;
|
||||
import com.qualcomm.robotcore.hardware.Servo;
|
||||
|
||||
import org.firstinspires.ftc.teamcode.constants.Color;
|
||||
import org.firstinspires.ftc.teamcode.constants.StateEnums.LightState;
|
||||
|
||||
|
||||
@Config
|
||||
public final class Light {
|
||||
|
||||
private static Light instance;
|
||||
public static double ballColorCycleTime = 1000; //in ms
|
||||
public static double restingTime = 150; //in ms
|
||||
|
||||
private Servo lightServo;
|
||||
private LightState state = LightState.DISABLED;
|
||||
|
||||
// References to other systems (NOT static)
|
||||
private Spindexer spindexer;
|
||||
private Turret turret;
|
||||
private double manualLightColor = Color.Light0;
|
||||
|
||||
private double lightColor = Color.Light0;
|
||||
private double previousLightColor = lightColor;
|
||||
|
||||
private Light() {
|
||||
}
|
||||
|
||||
public static synchronized Light getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Light();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Call once in OpMode init()
|
||||
public void init(
|
||||
Servo servo,
|
||||
Spindexer spin,
|
||||
Turret turr
|
||||
) {
|
||||
this.lightServo = servo;
|
||||
this.spindexer = spin;
|
||||
this.turret = turr;
|
||||
}
|
||||
|
||||
public void setManualLightColor(double value) {
|
||||
this.manualLightColor = value;
|
||||
}
|
||||
|
||||
public void setState(LightState newState) {
|
||||
state = newState;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if (lightServo == null) return;
|
||||
|
||||
switch (state) {
|
||||
|
||||
case BALL_COUNT:
|
||||
lightColor = spindexer.ballCounterLight();
|
||||
break;
|
||||
|
||||
case BALL_COLOR:
|
||||
|
||||
if ((System.currentTimeMillis() % ballColorCycleTime) < ((ballColorCycleTime / 3) - restingTime)) {
|
||||
lightColor = spindexer.getRearCenterLight();
|
||||
} else if ((System.currentTimeMillis() % ballColorCycleTime) < (ballColorCycleTime / 3)) {
|
||||
lightColor = 0;
|
||||
} else if ((System.currentTimeMillis() % ballColorCycleTime) < ((2 * ballColorCycleTime / 3) - restingTime)) {
|
||||
lightColor = spindexer.getDriverLight();
|
||||
|
||||
} else if ((System.currentTimeMillis() % ballColorCycleTime) < (2 * ballColorCycleTime / 3)) {
|
||||
lightColor = 0;
|
||||
} else if ((System.currentTimeMillis() % ballColorCycleTime) < (ballColorCycleTime - restingTime)) {
|
||||
lightColor = spindexer.getPassengerLight();
|
||||
|
||||
} else {
|
||||
lightColor = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case GOAL_LOCK:
|
||||
lightColor = turret.getLightColor();
|
||||
break;
|
||||
|
||||
case MANUAL:
|
||||
lightColor = manualLightColor;
|
||||
break;
|
||||
|
||||
case DISABLED:
|
||||
break;
|
||||
|
||||
case OFF:
|
||||
lightColor = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (lightColor != previousLightColor) {
|
||||
lightServo.setPosition(lightColor);
|
||||
}
|
||||
|
||||
previousLightColor = lightColor;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,11 @@ import static org.firstinspires.ftc.teamcode.utils.Servos.spinI;
|
||||
import static org.firstinspires.ftc.teamcode.utils.Servos.spinP;
|
||||
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.DistanceUnit;
|
||||
import org.firstinspires.ftc.teamcode.constants.Types;
|
||||
import org.firstinspires.ftc.teamcode.constants.StateEnums;
|
||||
import org.firstinspires.ftc.teamcode.libs.RR.MecanumDrive;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Spindexer {
|
||||
|
||||
Robot robot;
|
||||
@@ -50,7 +52,7 @@ public class Spindexer {
|
||||
private double prevPos = 0.0;
|
||||
public double spindexerPosOffset = 0.00;
|
||||
public static int shootWaitMax = 4;
|
||||
public Types.Motif desiredMotif = Types.Motif.NONE;
|
||||
public StateEnums.Motif desiredMotif = StateEnums.Motif.NONE;
|
||||
// For Use
|
||||
enum RotatedBallPositionNames {
|
||||
REARCENTER,
|
||||
@@ -284,35 +286,65 @@ public class Spindexer {
|
||||
|
||||
}
|
||||
|
||||
private double prevLight = 0.0;
|
||||
public void ballCounterLight(){
|
||||
public double getRearCenterLight() {
|
||||
BallColor color = GetRearCenterColor();
|
||||
if (Objects.equals(color, BallColor.GREEN)) {
|
||||
return LightGreen;
|
||||
} else if (Objects.equals(color, BallColor.PURPLE)) {
|
||||
return LightPurple;
|
||||
} else {
|
||||
return LightOrange;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public double getDriverLight() {
|
||||
BallColor color = GetFrontDriverColor();
|
||||
if (Objects.equals(color, BallColor.GREEN)) {
|
||||
return LightGreen;
|
||||
} else if (Objects.equals(color, BallColor.PURPLE)) {
|
||||
return LightPurple;
|
||||
} else {
|
||||
return LightOrange;
|
||||
}
|
||||
}
|
||||
|
||||
public double getPassengerLight() {
|
||||
BallColor color = GetFrontPassengerColor();
|
||||
if (Objects.equals(color, BallColor.GREEN)) {
|
||||
return LightGreen;
|
||||
} else if (Objects.equals(color, BallColor.PURPLE)) {
|
||||
return LightPurple;
|
||||
} else {
|
||||
return LightOrange;
|
||||
}
|
||||
}
|
||||
public double ballCounterLight() {
|
||||
int counter = 0;
|
||||
if (!ballPositions[0].isEmpty){
|
||||
if (!ballPositions[0].isEmpty) {
|
||||
counter++;
|
||||
}
|
||||
if (!ballPositions[1].isEmpty){
|
||||
if (!ballPositions[1].isEmpty) {
|
||||
counter++;
|
||||
}
|
||||
if (!ballPositions[2].isEmpty){
|
||||
if (!ballPositions[2].isEmpty) {
|
||||
counter++;
|
||||
}
|
||||
|
||||
double light;
|
||||
if (counter == 3){
|
||||
light = Light3;
|
||||
} else if (counter == 2){
|
||||
light = Light2;
|
||||
} else if (counter == 1){
|
||||
light = Light1;
|
||||
if (counter == 3) {
|
||||
return Light3;
|
||||
} else if (counter == 2) {
|
||||
return Light2;
|
||||
} else if (counter == 1) {
|
||||
return Light1;
|
||||
} else {
|
||||
light = Light0;
|
||||
return Light0;
|
||||
}
|
||||
if (light != prevLight){
|
||||
robot.light.setPosition(light);
|
||||
}
|
||||
prevLight = light;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean slotIsEmpty(int slot){
|
||||
return !ballPositions[slot].isEmpty;
|
||||
}
|
||||
@@ -531,7 +563,7 @@ public class Spindexer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setDesiredMotif (Types.Motif newMotif) {
|
||||
public void setDesiredMotif (StateEnums.Motif newMotif) {
|
||||
desiredMotif = newMotif;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ import com.arcrobotics.ftclib.controller.PIDController;
|
||||
import com.qualcomm.hardware.limelightvision.LLResult;
|
||||
import com.qualcomm.hardware.limelightvision.LLResultTypes;
|
||||
import com.qualcomm.hardware.limelightvision.Limelight3A;
|
||||
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
|
||||
import com.qualcomm.robotcore.hardware.DcMotor;
|
||||
import com.qualcomm.robotcore.util.ElapsedTime;
|
||||
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.Pose3D;
|
||||
import org.firstinspires.ftc.teamcode.constants.Color;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -53,6 +53,7 @@ public class Turret {
|
||||
private int obeliskID = 0;
|
||||
private double offset = 0.0;
|
||||
private double currentTrackOffset = 0.0;
|
||||
private double lightColor = Color.LightRed;
|
||||
private int currentTrackCount = 0;
|
||||
private double permanentOffset = 0.0;
|
||||
private PIDController bearingPID;
|
||||
@@ -67,6 +68,10 @@ public class Turret {
|
||||
bearingPID = new PIDController(B_PID_P, B_PID_I, B_PID_D);
|
||||
}
|
||||
|
||||
public double getLightColor() {
|
||||
return lightColor;
|
||||
}
|
||||
|
||||
public void zeroTurretEncoder() {
|
||||
robot.intake.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
|
||||
robot.intake.setMode(DcMotor.RunMode.RUN_WITHOUT_ENCODER);
|
||||
@@ -161,11 +166,17 @@ public class Turret {
|
||||
// LL has 54.5 degree total Horizontal FOV; very edges are not useful.
|
||||
final double HORIZONTAL_FOV_RANGE = 26.0; // Total usable horizontal degrees from center +/-
|
||||
final double DRIVE_POWER_REDUCTION = 2.0;
|
||||
final double COLOR_OK_TOLERANCE = 2.5;
|
||||
|
||||
if (abs(targetTx) < TARGET_POSITION_TOLERANCE) {
|
||||
bearingAligned = true;
|
||||
} else {
|
||||
lightColor = Color.LightBlue;
|
||||
} else if (abs(targetTx) < COLOR_OK_TOLERANCE) {
|
||||
bearingAligned = false;
|
||||
lightColor = Color.LightPurple;
|
||||
} else {
|
||||
bearingAligned = false;
|
||||
lightColor = Color.LightOrange;
|
||||
}
|
||||
|
||||
// Only with valid data and if too far off target
|
||||
@@ -254,6 +265,7 @@ public class Turret {
|
||||
// if (currentTrackCount > 20) {
|
||||
// offset = currentTrackOffset;
|
||||
// }
|
||||
lightColor = Color.LightRed;
|
||||
currentTrackOffset = 0.0;
|
||||
currentTrackCount = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user