generated from Yeti-Robotics/yeti-robot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from qwertycloudhub/dev
Dev
- Loading branch information
Showing
17 changed files
with
1,145 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package frc.robot; | ||
|
||
import edu.wpi.first.math.geometry.Translation3d; | ||
import edu.wpi.first.math.util.Units; | ||
|
||
import java.util.Map; | ||
|
||
public class Constants { | ||
|
||
public static final double fieldLength = Units.inchesToMeters(651.223); | ||
public static final class InboundingBox { | ||
public static final Translation3d inboundingBoxPosition = new Translation3d(0, 0, 0); | ||
} | ||
public static final class CenterTank { | ||
public static final Translation3d centerTankPosition = new Translation3d(0,0,0); | ||
} | ||
public static final class DunkTank { | ||
public static final Translation3d dunkTankPosition = new Translation3d(0,0,0); | ||
} | ||
|
||
|
||
public static final Map<Integer, ControllerType> CONTROLLERS = Map.of( | ||
0, ControllerType.CUSTOM, 1, ControllerType.XBOX | ||
); | ||
public static final int CONTROLLER_COUNT = CONTROLLERS.size(); | ||
public enum ControllerType { | ||
CUSTOM, | ||
XBOX | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package frc.robot; | ||
|
||
public class TalonFXConstants { | ||
public static final boolean TALON_FUTURE_PROOF = true; | ||
public static final String CANIVORE_NAME = "canivoreBus"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package frc.robot.commands; | ||
|
||
import com.ctre.phoenix6.StatusCode; | ||
import com.ctre.phoenix6.mechanisms.swerve.SwerveModule; | ||
import com.ctre.phoenix6.mechanisms.swerve.SwerveRequest; | ||
import edu.wpi.first.math.geometry.Rotation2d; | ||
import edu.wpi.first.math.geometry.Translation2d; | ||
|
||
public class AutoAimCommand extends SwerveRequest.FieldCentricFacingAngle { | ||
|
||
private Translation2d pointToFace; | ||
|
||
@Override | ||
public StatusCode apply( | ||
SwerveControlRequestParameters parameters, SwerveModule... modulesToApply) { | ||
this.TargetDirection = pointToFace.minus(parameters.currentPose.getTranslation()).getAngle(); | ||
if (ForwardReference == SwerveRequest.ForwardReference.OperatorPerspective) { | ||
this.TargetDirection = this.TargetDirection.minus(parameters.operatorForwardDirection); | ||
} | ||
return super.apply(parameters, modulesToApply); | ||
} | ||
|
||
@Override | ||
public FieldCentricFacingAngle withTargetDirection(Rotation2d targetDirection) { | ||
return this; | ||
} | ||
|
||
public void setPointToFace(Translation2d point) { | ||
pointToFace = point; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/frc/robot/commands/CenterDunkTankAlignCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package frc.robot.commands; | ||
|
||
import edu.wpi.first.math.geometry.Translation2d; | ||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.Constants; | ||
import frc.robot.subsystems.VisionSubsystem; | ||
import frc.robot.subsystems.drivetrain.CommandSwerveDrivetrain; | ||
import frc.robot.util.AllianceFlipUtil; | ||
import frc.robot.util.LimelightHelpers; | ||
|
||
import java.util.function.DoubleSupplier; | ||
|
||
|
||
public class CenterDunkTankAlignCommand extends Command { | ||
private final CommandSwerveDrivetrain drivetrain; | ||
private final DoubleSupplier xVelSupplier; | ||
private final AutoAimCommand poseAimRequest; | ||
private final DoubleSupplier yVelSupplier; | ||
private double currentTag; | ||
|
||
public CenterDunkTankAlignCommand( | ||
CommandSwerveDrivetrain drivetrain, | ||
DoubleSupplier xVelSupplier, | ||
DoubleSupplier yVelSupplier) { | ||
|
||
this.drivetrain = drivetrain; | ||
this.xVelSupplier = xVelSupplier; | ||
this.yVelSupplier = yVelSupplier; | ||
|
||
addRequirements(drivetrain); | ||
|
||
poseAimRequest = new AutoAimCommand(); | ||
poseAimRequest.HeadingController.setPID(5,0,0); | ||
poseAimRequest.HeadingController.enableContinuousInput(-Math.PI,Math.PI); | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
currentTag = LimelightHelpers.getFiducialID(VisionSubsystem.VisionConstants.LIMELIGHT_NAME); | ||
|
||
Translation2d centerTank = AllianceFlipUtil.apply( | ||
Constants.CenterTank.centerTankPosition.toTranslation2d() | ||
); | ||
|
||
poseAimRequest.setPointToFace(centerTank); | ||
} | ||
|
||
@Override | ||
public void execute() { | ||
if(LimelightHelpers.getFiducialID(VisionSubsystem.VisionConstants.LIMELIGHT_NAME) == currentTag) { | ||
drivetrain.setControl( | ||
poseAimRequest.withVelocityX(xVelSupplier.getAsDouble() * 1.5).withVelocityY(yVelSupplier.getAsDouble() * 1.5) | ||
); | ||
} else { | ||
end(true); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFinished() {return false;} | ||
|
||
} |
Oops, something went wrong.