Skip to content
Open
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
@@ -0,0 +1,34 @@
package org.firstinspires.ftc.teamcode;

public class BangBangController {
private double lowValue = 0.0;
private double highValue = 1.0;
private double tolerance = 0.0;

public BangBangController(double tolerance) {
this.tolerance = tolerance;
}

public void setTolerance(double tolerance) {
this.tolerance = tolerance;
}

public void setHighValue(double highValue) {
this.highValue = highValue;
}

public void setLowValue(double lowValue) {
this.lowValue = lowValue;
}

public double calculate(double measurement, double setpoint) {
if (Math.abs(measurement - setpoint) < tolerance) return lowValue;
else if (measurement < setpoint) {
return highValue;
} else return lowValue;
}

public boolean isAtSetpoint(double measurement, double setpoint) {
return Math.abs(measurement - setpoint) < tolerance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
@Autonomous(group = "red far")
public class BlueFarCycles extends ActionOpMode {
DischargeSubsystem dischargeSubsystem;
IntakeSubsystem intakeSubsystem;
CarouselSubsystem carouselSubsystem;
IntakeSubsystem intake;
CarouselSubsystem carousel;
MecanumDrive mecanumDrive;
LimelightSubsystem limelightSubsystem;
double turretStartAngle = 90;
Expand All @@ -42,11 +42,11 @@ public void initialize() {
SavedValues.currentCount = 0;
SavedValues.teamColor = AutoShooter.TeamColor.BLUE;
Set<Subsystem> requirements = new HashSet<>();
intakeSubsystem = new IntakeSubsystem(hardwareMap);
intake = new IntakeSubsystem(hardwareMap);
dischargeSubsystem = new DischargeSubsystem(hardwareMap);
dischargeSubsystem.resetTurret();
carouselSubsystem = new CarouselSubsystem(hardwareMap);
carouselSubsystem.resetEncoders();
carousel = new CarouselSubsystem(hardwareMap);
carousel.resetEncoders();
mecanumDrive = new MecanumDrive(hardwareMap, new Pose2d(61.5, 22, Math.PI / 2));
mecanumDrive.driveMode();
limelightSubsystem = new LimelightSubsystem(hardwareMap, SavedValues.teamColor, mecanumDrive);
Expand All @@ -73,63 +73,63 @@ public void initialize() {

CommandScheduler.getInstance().schedule(
new ParallelCommandGroup(
new DischargeCommands.AutomaticAiming(dischargeSubsystem, limelightSubsystem, mecanumDrive, carouselSubsystem, SavedValues.teamColor),
new DischargeCommands.AutomaticAiming(dischargeSubsystem, limelightSubsystem, mecanumDrive, carousel, SavedValues.teamColor),
new SequentialCommandGroup(
new CommandGroups.Shoot(intakeSubsystem, carouselSubsystem),
new CommandGroups.Shoot(intake, carousel),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoOne.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2500),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2500),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)

),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoTwo.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2000),
new CommandGroups.StartOuttake(intakeSubsystem, carouselSubsystem).withTimeout(300),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2000),
CommandGroups.startOuttake(intake, carousel).withTimeout(300),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)
),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoThree.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2000),
new CommandGroups.StartOuttake(intakeSubsystem, carouselSubsystem).withTimeout(300),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2000),
CommandGroups.startOuttake(intake, carousel).withTimeout(300),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)
),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoTwo.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2000),
new CommandGroups.StartOuttake(intakeSubsystem, carouselSubsystem).withTimeout(300),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2000),
CommandGroups.startOuttake(intake, carousel).withTimeout(300),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)
),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoThree.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2000),
new CommandGroups.StartOuttake(intakeSubsystem, carouselSubsystem).withTimeout(300),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2000),
CommandGroups.startOuttake(intake, carousel).withTimeout(300),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)
),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoTwo.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2000),
new CommandGroups.StartOuttake(intakeSubsystem, carouselSubsystem).withTimeout(300),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2000),
CommandGroups.startOuttake(intake, carousel).withTimeout(300),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)
),
new ParallelCommandGroup(
new ActionCommand(wheatleyAutoThree.build(), requirements),
new SequentialCommandGroup(
new CommandGroups.StartIntake(intakeSubsystem, carouselSubsystem).withTimeout(2000),
new CommandGroups.StartOuttake(intakeSubsystem, carouselSubsystem).withTimeout(300),
new CommandGroups.PrepareShooting(intakeSubsystem, carouselSubsystem, mecanumDrive)
CommandGroups.startIntake(intake, carousel).withTimeout(2000),
CommandGroups.startOuttake(intake, carousel).withTimeout(300),
new CommandGroups.PrepareShooting(intake, carousel, mecanumDrive)
)
),
new ActionCommand(park.build(), requirements)
Expand All @@ -146,12 +146,12 @@ public void initialize_loop() {
if (time.seconds() > 1) {
int current = limelightSubsystem.getMotif();
SavedValues.startMotif = (current != -1) ? current : SavedValues.startMotif;
double power = -(turretStartAngle - dischargeSubsystem.getTurretAngle()) * 0.018;
if (Math.abs(turretStartAngle - dischargeSubsystem.getTurretAngle()) < 5) {
double power = -(turretStartAngle - dischargeSubsystem.turret.getAngle()) * 0.018;
if (Math.abs(turretStartAngle - dischargeSubsystem.turret.getAngle()) < 5) {
power = 0;
}
power = Range.clip(power, -0.3, 0.3);
dischargeSubsystem.setTurretPower(power);
dischargeSubsystem.turret.setPower(power);
multipleTelemetry.addData("used", SavedValues.startMotif);
multipleTelemetry.addData("current", current);
multipleTelemetry.update();
Expand All @@ -168,6 +168,6 @@ public void run() {
multipleTelemetry.addData("y", mecanumDrive.localizer.getPose().position.y);
multipleTelemetry.update();
SavedValues.position = mecanumDrive.localizer.getPose();
SavedValues.turretAngle = dischargeSubsystem.getTurretAngle();
SavedValues.turretAngle = dischargeSubsystem.turret.getAngle();
}
}
Loading