Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for vision branch - working note detection and new drive method. #62

Merged
merged 28 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c3e3518
added the drive to note position code back
SJJCoding Feb 6, 2024
d38721f
Implemented limelight get to distance command, should be able to run …
SJJCoding Feb 7, 2024
3112274
forgor to commit all the files in the last push
SJJCoding Feb 7, 2024
66ddf50
fixed limelight subsystem from gunga selling
SJJCoding Feb 10, 2024
e7f48bd
Merge remote-tracking branch 'upstream/main'
SJJCoding Feb 10, 2024
f7ffce4
implemented jonah rotation method
SJJCoding Feb 10, 2024
686d8dd
fixed command stuff and hopefully better turning methods
SJJCoding Feb 14, 2024
e75a199
Merge remote-tracking branch 'upstream/main'
SJJCoding Feb 21, 2024
42f8b9f
Cleaned up simpleDrive
SJJCoding Feb 22, 2024
0f9e8bc
Merge branch 'robototes:main' into main
SJJCoding Feb 22, 2024
f8ad4b8
Fixed the majority of PR comments
SJJCoding Feb 23, 2024
3c77ece
Merge branch 'main' of https://github.com/SJJCoding/Crescendo2024
SJJCoding Feb 23, 2024
8673859
Update src/main/java/frc/team2412/robot/subsystems/LimelightSubsystem…
SJJCoding Feb 23, 2024
ae0af8f
oscillation issue probably fixed
SJJCoding Feb 23, 2024
fa4def3
working turning method, fixed drivepower
SJJCoding Feb 24, 2024
456417f
Cleaned up a bunch of logic, removed the need for a DriveCommand or s…
SJJCoding Feb 25, 2024
5384c13
Some more PR related changes
SJJCoding Feb 25, 2024
189f119
Removed the old drive and turn power curves due to redundancy and re …
SJJCoding Feb 25, 2024
f781926
Majority of PR comments fixed
SJJCoding Feb 29, 2024
1d88e45
Merge branch 'main' into main
SJJCoding Mar 12, 2024
f57e583
spotlessapply
SJJCoding Mar 12, 2024
d68609d
Merge branch 'main' of https://github.com/SJJCoding/Crescendo2024
SJJCoding Mar 12, 2024
f34c970
fixed pr comments (again)
SJJCoding Mar 19, 2024
6dc22cc
Merge branch 'main' into main
SJJCoding Mar 19, 2024
e30a7bf
spotlessapply maybe
SJJCoding Mar 20, 2024
cfc6016
Merge branch 'main' of https://github.com/SJJCoding/Crescendo2024
SJJCoding Mar 20, 2024
1e6874b
removed redundant methods from limelightsubsystem
SJJCoding Mar 20, 2024
73b94f7
more cleanup
SJJCoding Mar 20, 2024
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
15 changes: 13 additions & 2 deletions src/main/java/frc/team2412/robot/Controls.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static frc.team2412.robot.Subsystems.SubsystemConstants.DRIVEBASE_ENABLED;
import static frc.team2412.robot.Subsystems.SubsystemConstants.INTAKE_ENABLED;
import static frc.team2412.robot.Subsystems.SubsystemConstants.LAUNCHER_ENABLED;
import static frc.team2412.robot.Subsystems.SubsystemConstants.LIMELIGHT_ENABLED;

import edu.wpi.first.math.MathUtil;
import edu.wpi.first.math.geometry.Rotation2d;
Expand All @@ -29,6 +30,7 @@ public static class ControlConstants {

private final CommandXboxController driveController;
private final CommandXboxController codriveController;
private final Trigger getWithinDistanceTrigger;

// Intake
private final Trigger driveIntakeInButton;
Expand All @@ -49,6 +51,7 @@ public static class ControlConstants {
public Controls(Subsystems s) {
driveController = new CommandXboxController(CONTROLLER_PORT);
codriveController = new CommandXboxController(CODRIVER_CONTROLLER_PORT);
getWithinDistanceTrigger = driveController.start();
this.s = s;

// launcherAmpPresetButton = codriveController.povDown();
Expand All @@ -66,6 +69,13 @@ public Controls(Subsystems s) {
if (DRIVEBASE_ENABLED) {
bindDrivebaseControls();
}
if (LIMELIGHT_ENABLED) {
bindLimelightControls();
}
// if (LAUNCHER_ENABLED) {
// bindLauncherControls();
// }
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved

if (LAUNCHER_ENABLED) {
bindLauncherControls();
}
Expand Down Expand Up @@ -95,10 +105,12 @@ private void bindDrivebaseControls() {
driveController::getLeftY,
driveController::getLeftX,
() -> Rotation2d.fromRotations(driveController.getRightX())));
driveController.start().onTrue(new InstantCommand(s.drivebaseSubsystem::resetGyro));
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
driveController.rightStick().onTrue(new InstantCommand(s.drivebaseSubsystem::toggleXWheels));
}

public void bindLimelightControls() {
getWithinDistanceTrigger.onTrue(s.limelightSubsystem.getWithinDistance(s.drivebaseSubsystem));
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
}
// intake controls
private void bindIntakeControls() {
// CommandScheduler.getInstance()
Expand Down Expand Up @@ -131,7 +143,6 @@ private void bindLauncherControls() {
// s.launcherSubsystem,
// LauncherSubsystem.SPEAKER_SHOOT_SPEED_RPM,
// LauncherSubsystem.SUBWOOFER_AIM_ANGLE));

}

public void vibrateDriveController(double vibration) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/frc/team2412/robot/Subsystems.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import frc.team2412.robot.subsystems.DrivebaseSubsystem;
import frc.team2412.robot.subsystems.IntakeSubsystem;
import frc.team2412.robot.subsystems.LauncherSubsystem;
import frc.team2412.robot.subsystems.LimelightSubsystem;
import frc.team2412.robot.util.DrivebaseWrapper;

public class Subsystems {
Expand All @@ -14,7 +15,7 @@ public static class SubsystemConstants {
private static final boolean IS_COMP = Robot.getInstance().isCompetition();

public static final boolean APRILTAGS_ENABLED = false;
public static final boolean LIMELIGHT_ENABLED = false;
public static final boolean LIMELIGHT_ENABLED = true;
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
public static final boolean CLIMB_ENABLED = false;
public static final boolean LAUNCHER_ENABLED = false;
public static final boolean INTAKE_ENABLED = false;
Expand All @@ -24,6 +25,7 @@ public static class SubsystemConstants {
public final DrivebaseWrapper drivebaseWrapper;
public final DrivebaseSubsystem drivebaseSubsystem;
public final LauncherSubsystem launcherSubsystem;
public LimelightSubsystem limelightSubsystem;
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
public final IntakeSubsystem intakeSubsystem;
public final AprilTagsProcessor apriltagsProcessor;

Expand All @@ -46,6 +48,9 @@ public Subsystems() {
} else {
launcherSubsystem = null;
}
if (LIMELIGHT_ENABLED) {
limelightSubsystem = new LimelightSubsystem();
}
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
if (INTAKE_ENABLED) {
intakeSubsystem = new IntakeSubsystem();
} else {
Expand Down
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package frc.team2412.robot.commands.drivebase;

import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.networktables.GenericEntry;
import edu.wpi.first.wpilibj.shuffleboard.BuiltInWidgets;
import edu.wpi.first.wpilibj.shuffleboard.Shuffleboard;
import edu.wpi.first.wpilibj2.command.Command;
import frc.team2412.robot.subsystems.DrivebaseSubsystem;
import java.util.Map;
import java.util.function.DoubleSupplier;

public class DriveCommand extends Command {
private static final double TURBO_ROTATION_DEFAULT = 1.5;

private final DrivebaseSubsystem drivebaseSubsystem;
private final DoubleSupplier forward;
private final DoubleSupplier strafe;
private final DoubleSupplier rotation;
private final DoubleSupplier turboRotation;
// temporary because code is kinda messy
Rotation2d MAX_ROTATIONS_PER_SEC = Rotation2d.fromRotations(0.8574);

// shuffleboard
private static GenericEntry driveSpeedEntry =
Shuffleboard.getTab("Drivebase")
.addPersistent("Drive Speed 1", 1)
.withSize(2, 1)
.withWidget(BuiltInWidgets.kNumberSlider)
.withProperties(Map.of("Min", 0, "Max", 1))
.getEntry();
private static GenericEntry rotationSpeedEntry =
Shuffleboard.getTab("Drivebase")
.addPersistent("Rotation Speed 1", 1)
.withSize(2, 1)
.withWidget(BuiltInWidgets.kNumberSlider)
.withProperties(Map.of("Min", 0, "Max", 1))
.getEntry();
private static GenericEntry fieldOrientedEntry =
Shuffleboard.getTab("Drivebase")
.addPersistent("Field Oriented 1", true)
.withWidget(BuiltInWidgets.kToggleSwitch)
.getEntry();
private static GenericEntry turboRotationEntry =
Shuffleboard.getTab("Drivebase")
.addPersistent("Turbo Rotation Modifier 1", TURBO_ROTATION_DEFAULT)
.withWidget(BuiltInWidgets.kNumberSlider)
.withProperties(Map.of("Min", 0.5, "Max", 2.5))
.getEntry();

public DriveCommand(
DrivebaseSubsystem drivebaseSubsystem,
DoubleSupplier forward,
DoubleSupplier strafe,
DoubleSupplier rotation,
DoubleSupplier turboRotation) {
this.drivebaseSubsystem = drivebaseSubsystem;
this.forward = forward;
this.strafe = strafe;
this.rotation = rotation;
// this variable give the right trigger input
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
this.turboRotation = turboRotation;

addRequirements(drivebaseSubsystem);
}

@Override
public void execute() {
double rotationSpeedModifier =
rotationSpeedEntry.getDouble(1.0)
* (1
- (turboRotation.getAsDouble()
* (1 - turboRotationEntry.getDouble(TURBO_ROTATION_DEFAULT))));

double x = deadbandCorrection(-forward.getAsDouble());
double y = deadbandCorrection(strafe.getAsDouble());
double rot = deadbandCorrection(-rotation.getAsDouble());

// math for normalizing and cubing inputs
double magnitude = Math.pow(Math.min(Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)), 1), 3);
double angle = Math.atan2(y, x);
double cubed_x = magnitude * Math.cos(angle);
double cubed_y = magnitude * Math.sin(angle);

drivebaseSubsystem.simpleDrive(
cubed_x * driveSpeedEntry.getDouble(1.0) * 4.4196, // convert from percent to m/s
cubed_y * driveSpeedEntry.getDouble(1.0) * 4.4196,
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
Rotation2d.fromRotations(
rot
* rotationSpeedModifier
* MAX_ROTATIONS_PER_SEC
.getRotations())); // convert from percent to rotations per second);
}

public double deadbandCorrection(double input) {
return Math.abs(input) < 0.05 ? 0 : (input - Math.signum(input) * 0.05) / 0.95;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*package frc.team2412.robot.commands.limelight;


public class GetWithinDistanceCommand extends Command {

SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
private LimelightSubsystem limelightSubsystem;
private DrivebaseSubsystem drivebaseSubsystem;
private Pose2d currentPose;

private Command getToPositionCommand;

public GetWithinDistanceCommand(
LimelightSubsystem limelightSubsystem, DrivebaseSubsystem drivebaseSubsystem) {
this.limelightSubsystem = limelightSubsystem;
this.drivebaseSubsystem = drivebaseSubsystem;

// find target -> get current pose -> use current pose and target to calculate target pose ->
// move towards target pose

SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public void initialize() {
currentPose = drivebaseSubsystem.getPose();
getToPositionCommand = limelightSubsystem.getWithinDistance(currentPose, drivebaseSubsystem);
// limelightSubsystem.getWithinDistance(currentPose, drivebaseSubsystem);
getToPositionCommand.initialize();
}

@Override
public void execute() {
getToPositionCommand.execute();
limelightSubsystem.getTargetPose(currentPose);
}

@Override
public void end(boolean interrupted) {}

@Override
public boolean isFinished() {
System.out.println("within distance");
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
return limelightSubsystem.isWithinDistance();
}*/
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,20 @@ public void drive(Translation2d translation, Rotation2d rotation, boolean fieldO
}
}

public void driveWithDoubleSupplierTurn(
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
Translation2d translation, Supplier<Double> rotation, boolean fieldOriented) {
// if we're requesting the robot to stay still, lock wheels in X formation
if (translation.getNorm() == 0 && rotation.get() == 0.0 && xWheelsEnabled) {
swerveDrive.lockPose();
}
if (rotationSetpoint != null) {
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
swerveDrive.drive(
translation.unaryMinus(), rotationSetpoint.getRadians(), fieldOriented, false);
} else {
swerveDrive.drive(translation.unaryMinus(), rotation.get(), fieldOriented, false);
}
}

/**
* Drives the robot using joystick inputs
*
Expand Down Expand Up @@ -193,6 +207,14 @@ public Command driveJoystick(
});
}

public void simpleDrive(double forward, double strafe, Rotation2d rotation) {
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved

ChassisSpeeds chassisSpeeds = new ChassisSpeeds(0, 0, 0);
SJJCoding marked this conversation as resolved.
Show resolved Hide resolved
chassisSpeeds = new ChassisSpeeds(forward, -strafe, rotation.getRadians());

drive(chassisSpeeds);
}

// this might need to be put in its own file due to complexity
public Command rotateToAngle(Supplier<Rotation2d> angle, boolean endWhenAligned) {
Command alignCommand =
Expand Down
Loading
Loading