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

Automatic Align Player Station #107

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e7d2c7b
changed all occurances of onTrue in robot container to whileTrue.
Feb 22, 2023
32b8e75
changed driverController buttons to use onTrue
Feb 22, 2023
3c7c254
Merge branch 'main' of https://github.com/frc1675/frc1675-2023
jagernet-ops Feb 24, 2023
b353387
Merge branch 'main' of https://github.com/frc1675/frc1675-2023
jagernet-ops Mar 10, 2023
9725cdc
Created AutoAlign command, mapped to DriverDPad Up and added required…
Mar 15, 2023
282f158
redefined x and y values for the human player stations and added rota…
Mar 15, 2023
afb7034
Merge branch 'main' of https://github.com/frc1675/frc1675-2023
jagernet-ops Mar 15, 2023
afe3bc1
merged with main
jagernet-ops Mar 15, 2023
ef17fc1
fixed some merging errors and added alliance checking in the PlayerSt…
jagernet-ops Mar 15, 2023
cce5dc7
Merge branch 'main' of https://github.com/frc1675/frc1675-2023
jagernet-ops Mar 16, 2023
64bdfd1
Merge branch 'main' of https://github.com/frc1675/frc1675-2023
jagernet-ops Mar 17, 2023
98e03c0
merged with main, updated the AprilTag overrides in the command to al…
jagernet-ops Mar 17, 2023
35add96
swapped from using vision.getBotPose() to drivetrainSubsystem.getPose…
jagernet-ops Mar 17, 2023
61f276d
removed comments
jagernet-ops Mar 18, 2023
d5513a6
merged to be up to date with main
Mar 20, 2023
0d69906
Merge branch 'PlayerStationAutoAlign' of https://github.com/frc1675/f…
Mar 20, 2023
34bfeab
Merge branch 'main' of https://github.com/frc1675/frc1675-2023
jagernet-ops Mar 21, 2023
62c9f15
XY Axis are relative to alliance refactor code later
Mar 22, 2023
d28e732
changed to use one Pose2d object
jagernet-ops Mar 22, 2023
396d9d9
merged with main
jagernet-ops Mar 22, 2023
9807381
Commented the XY position code out of the auto align code
jagernet-ops Mar 23, 2023
c8f016c
Merge branch 'main' into PlayerStationAutoAlign
Mar 31, 2023
bb263e5
Merge remote-tracking branch 'origin/main' into PlayerStationAutoAlign
Apr 1, 2023
3620079
Player station auto align updates
Apr 1, 2023
947bbc6
Merge branch 'main' into PlayerStationAutoAlign
Apr 15, 2023
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
6 changes: 6 additions & 0 deletions simgui-ds.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,11 @@
"buttonCount": 0,
"povCount": 0
}
],
"robotJoysticks": [
{
"guid": "78696e70757401000000000000000000",
"useGamepad": true
}
]
}
7 changes: 7 additions & 0 deletions simgui.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"NTProvider": {
"types": {
"/FMSInfo": "FMSInfo",
"/Shuffleboard/Auto/Auto Location": "String Chooser",
"/Shuffleboard/Auto/Auto Path Action": "String Chooser",
"/Shuffleboard/Auto/Auto Start Action": "String Chooser",
"/Shuffleboard/Auto/Current Auto Trajectory (Always appears on blue side)": "Field2d",
"/SmartDashboard/Field Sim": "Field2d"
},
"windows": {
Expand All @@ -22,6 +26,9 @@
"NetworkTables": {
"Persistent Values": {
"open": false
},
"Retained Values": {
"open": false
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package frc.robot;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;

public final class Constants {
//auto constants
public static final double AUTO_MAX_VELOCITY = 3;
Expand All @@ -21,6 +24,10 @@ public final class Constants {

public static final double FIELD_WIDTH_METERS = 16;
public static final double FIELD_HEIGHT_METERS = 7.85;
jdlanning marked this conversation as resolved.
Show resolved Hide resolved

public static final Pose2d HUMAN_STATION_BOUNDARY = new Pose2d(12.6, 2.5, Rotation2d.fromDegrees(0));



//sim constants
public static final double RED_ORIGIN_POS_X_METERS = 16.541748984;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import frc.robot.commands.intake.armIntake.IntakeCone;
import frc.robot.commands.intake.floor.FloorDrop;
import frc.robot.commands.intake.floor.FloorPickup;
import frc.robot.commands.vision.PlayerStationAutoAlign;
import frc.robot.commands.vision.ChangeVisionPipeline;
import frc.robot.commands.vision.ToggleLED;
import frc.robot.subsystems.ArmSubsystem;
Expand Down Expand Up @@ -68,6 +69,11 @@ public class RobotContainer {
private final DPadButton operatorDPadLeft = new DPadButton(operatorController, DPadButton.Direction.LEFT);
private final DPadButton operatorDPadDown = new DPadButton(operatorController, DPadButton.Direction.DOWN);

private final DPadButton driverDPadUp = new DPadButton(driverController, DPadButton.Direction.UP);
private final DPadButton driverDPadRight = new DPadButton(driverController, DPadButton.Direction.RIGHT);
private final DPadButton driverDPadLeft = new DPadButton(driverController, DPadButton.Direction.LEFT);
private final DPadButton driverDPadDown = new DPadButton(driverController, DPadButton.Direction.DOWN);

public RobotContainer() {
configureBindings();
}
Expand Down Expand Up @@ -193,6 +199,7 @@ private void configureBindings() {
);
//vision
operatorControllerStartButton.toggleOnTrue(new ToggleLED(vision));
driverDPadUp.onTrue(new PlayerStationAutoAlign(drivetrainSubsystem, vision));
operatorControllerBackButton.toggleOnTrue(new ChangeVisionPipeline(vision));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands.vision;

import frc.robot.Constants;
import frc.robot.subsystems.DrivetrainSubsystem;
import frc.robot.subsystems.Vision;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj2.command.CommandBase;

public class PlayerStationAutoAlign extends CommandBase {
/** Creates a new PlayerStationAutoAlign. */
private final Vision vision;
private final DrivetrainSubsystem drivetrainSubsystem;
public PlayerStationAutoAlign(DrivetrainSubsystem drivetrainSubsystem, Vision vision) {
// Use addRequirements() here to declare subsystem dependencies.
this.vision = vision;
this.drivetrainSubsystem = drivetrainSubsystem;
addRequirements(this.drivetrainSubsystem);
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
if(vision.getTargetID() == 4){ // Override if Blue Alliance Human Player April Tag is seen
drivetrainSubsystem.resetPose(vision.getBotpose());
drivetrainSubsystem.setRotationTarget(Constants.HUMAN_STATION_BOUNDARY.getRotation());
}else if(vision.getTargetID() == 5){ // Override if RED Alliance Human Player April Tag is seen
drivetrainSubsystem.resetPose(vision.getBotpose());
drivetrainSubsystem.setRotationTarget(Constants.HUMAN_STATION_BOUNDARY.getRotation());
}else if(DriverStation.getAlliance() == Alliance.Red){ // For Red Alliance
jagernet-ops marked this conversation as resolved.
Show resolved Hide resolved
if(drivetrainSubsystem.getPose().getX() > Constants.HUMAN_STATION_BOUNDARY.getX() && drivetrainSubsystem.getPose().getY() < Constants.HUMAN_STATION_BOUNDARY.getY()){
drivetrainSubsystem.setRotationTarget(Constants.HUMAN_STATION_BOUNDARY.getRotation());
}
}else{ // For Blue Alliance
if(drivetrainSubsystem.getPose().getX() > Constants.HUMAN_STATION_BOUNDARY.getX() && drivetrainSubsystem.getPose().getY() > Constants.HUMAN_STATION_BOUNDARY.getY()){
drivetrainSubsystem.setRotationTarget(Constants.HUMAN_STATION_BOUNDARY.getRotation());
}
jagernet-ops marked this conversation as resolved.
Show resolved Hide resolved
}
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return true;
}
}
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/Vision.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// the WPILib BSD license file in the root directory of this project.

package frc.robot.subsystems;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.networktables.NetworkTable;
Expand Down