Skip to content

Commit c8e1ed6

Browse files
authored
Merge pull request #207 from strykeforce/rkalnins/hatch-place
Rkalnins/hatch place
2 parents f3d7654 + 03e4589 commit c8e1ed6

22 files changed

+280
-100
lines changed

src/main/java/frc/team2767/deepspace/command/TeleOpDriveCommand.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import frc.team2767.deepspace.subsystem.DriveSubsystem;
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
11+
import org.strykeforce.thirdcoast.util.ExpoScale;
1112

1213
public final class TeleOpDriveCommand extends Command {
1314

@@ -16,9 +17,15 @@ public final class TeleOpDriveCommand extends Command {
1617
private static DriverControls controls;
1718

1819
private static final double DEADBAND = 0.05;
20+
private static final double YAW_EXPO = 0.5;
21+
private static final double DRIVE_EXPO = 0.5;
22+
private final ExpoScale yawExpo;
23+
private final ExpoScale driveExpo;
1924

2025
public TeleOpDriveCommand() {
2126
requires(DRIVE);
27+
this.yawExpo = new ExpoScale(DEADBAND, YAW_EXPO);
28+
this.driveExpo = new ExpoScale(DEADBAND, DRIVE_EXPO);
2229
}
2330

2431
@Override
@@ -30,9 +37,9 @@ protected void initialize() {
3037

3138
@Override
3239
protected void execute() {
33-
double forward = deadband(controls.getForward());
34-
double strafe = deadband(controls.getStrafe());
35-
double azimuth = deadband(controls.getYaw());
40+
double forward = driveExpo.apply(controls.getForward());
41+
double strafe = driveExpo.apply(controls.getStrafe());
42+
double azimuth = yawExpo.apply(controls.getYaw());
3643

3744
DRIVE.drive(forward, strafe, azimuth);
3845
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package frc.team2767.deepspace.command.approach;
2+
3+
import edu.wpi.first.wpilibj.command.ConditionalCommand;
4+
import frc.team2767.deepspace.command.states.SetFieldDirectionCommand;
5+
import frc.team2767.deepspace.subsystem.FieldDirection;
6+
7+
public class ChooseTeleopHatchPlaceDirection extends ConditionalCommand {
8+
9+
public ChooseTeleopHatchPlaceDirection() {
10+
super(
11+
new SetFieldDirectionCommand(FieldDirection.LEFT),
12+
new SetFieldDirectionCommand(FieldDirection.RIGHT));
13+
}
14+
15+
@Override
16+
protected boolean condition() {
17+
return true;
18+
}
19+
}

src/main/java/frc/team2767/deepspace/command/approach/OpenLoopDriveUntilCurrentCommand.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,25 @@
77
import frc.team2767.deepspace.subsystem.VacuumSubsystem;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
import org.strykeforce.thirdcoast.swerve.SwerveDrive;
1011

1112
public class OpenLoopDriveUntilCurrentCommand extends Command {
1213

1314
private static final DriveSubsystem DRIVE = Robot.DRIVE;
1415
private static final VacuumSubsystem VACUUM = Robot.VACUUM;
15-
private static final double TRANSITION_CURRENT_DIFFERENCE = 50.0;
16+
private static final double TRANSITION_CURRENT = 20.0;
17+
private static final int CURRENT_STABLE_COUNT = 2;
18+
private static final double CURRENT_IGNORE = 0.5;
1619
private static final double DIRECTION = -0.25;
17-
private static final double OUT_DRIVE_SECONDS = 0.5;
18-
private static final double SOLENOID_DELAY = 0.2;
20+
private static final double OUT_DRIVE_SECONDS = 0.25;
21+
private static final double SOLENOID_DELAY = 0.5;
1922
private final Logger logger = LoggerFactory.getLogger(this.getClass());
2023
private DriveState driveState;
24+
private double initBlankTime;
2125
private double initialCurrent;
2226
private double outDriveInitTime;
2327
private double solenoidDelayInit;
28+
private int currentStableCount;
2429

2530
public OpenLoopDriveUntilCurrentCommand() {
2631
setTimeout(5.0);
@@ -31,6 +36,9 @@ public OpenLoopDriveUntilCurrentCommand() {
3136
protected void initialize() {
3237
driveState = DriveState.FAST;
3338
initialCurrent = DRIVE.getAverageOutputCurrent();
39+
currentStableCount = 0;
40+
DRIVE.setDriveMode(SwerveDrive.DriveMode.CLOSED_LOOP);
41+
initBlankTime = Timer.getFPGATimestamp();
3442
}
3543

3644
@Override
@@ -39,7 +47,14 @@ protected void execute() {
3947
case FAST:
4048
DRIVE.setWheels(DIRECTION, DriveState.FAST.velocity);
4149
double averageCurrent = DRIVE.getAverageOutputCurrent();
42-
if (averageCurrent > initialCurrent + TRANSITION_CURRENT_DIFFERENCE) {
50+
if (Timer.getFPGATimestamp() - initBlankTime > CURRENT_IGNORE
51+
&& averageCurrent > initialCurrent + TRANSITION_CURRENT) {
52+
currentStableCount++;
53+
} else {
54+
currentStableCount = 0;
55+
}
56+
57+
if (currentStableCount > CURRENT_STABLE_COUNT) {
4358
driveState = DriveState.CLOSE_SOLENOID;
4459
logger.debug("set state to {}, current = {}", driveState, averageCurrent);
4560
}
@@ -60,6 +75,7 @@ protected void execute() {
6075
DRIVE.setWheels(DIRECTION, DriveState.OUT.velocity);
6176
if (Timer.getFPGATimestamp() - outDriveInitTime > OUT_DRIVE_SECONDS) {
6277
driveState = DriveState.DONE;
78+
DRIVE.setWheels(0.0, 0.0);
6379
logger.debug("set state to {}", driveState);
6480
}
6581
break;
@@ -70,12 +86,12 @@ protected void execute() {
7086

7187
@Override
7288
protected boolean isFinished() {
73-
return false;
89+
return driveState == DriveState.DONE;
7490
}
7591

7692
private enum DriveState {
77-
FAST(0.5),
78-
CLOSE_SOLENOID(0.06),
93+
FAST(0.25),
94+
CLOSE_SOLENOID(0.08),
7995
WAIT(0.06),
8096
OUT(-0.6),
8197
DONE(0.0);

src/main/java/frc/team2767/deepspace/command/approach/OpenLoopDriveUntilSuctionCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class OpenLoopDriveUntilSuctionCommand extends Command {
1414
private static final DriveSubsystem DRIVE = Robot.DRIVE;
1515
private static final VacuumSubsystem VACUUM = Robot.VACUUM;
1616
private static final double TRANSITION_PRESSURE_DIFFERENCE = 3.0;
17-
private static final double HATCH_SEAL_GOOD_ENOUGH = 10.0;
17+
private static final double HATCH_SEAL_GOOD_ENOUGH = 7.5;
1818
private static final double OUT_DRIVE_SECONDS = 0.25;
1919
private final Logger logger = LoggerFactory.getLogger(this.getClass());
2020
private double direction;
@@ -34,6 +34,7 @@ protected void initialize() {
3434
logger.warn("Transition pressures not set correctly");
3535
}
3636

37+
DRIVE.setDriveMode(SwerveDrive.DriveMode.CLOSED_LOOP);
3738
initialPressure = VACUUM.getPressure();
3839
logger.debug("init pressure = {}", initialPressure);
3940
DRIVE.setDriveMode(SwerveDrive.DriveMode.OPEN_LOOP);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package frc.team2767.deepspace.command.approach;
2+
3+
import edu.wpi.first.wpilibj.command.InstantCommand;
4+
import frc.team2767.deepspace.Robot;
5+
import frc.team2767.deepspace.subsystem.DriveSubsystem;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
public class TalonConfigCommand extends InstantCommand {
10+
private static final DriveSubsystem DRIVE = Robot.DRIVE;
11+
private final DriveSubsystem.DriveTalonConfig config;
12+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
13+
14+
public TalonConfigCommand(DriveSubsystem.DriveTalonConfig config) {
15+
this.config = config;
16+
}
17+
18+
@Override
19+
protected void initialize() {
20+
DRIVE.setSlotConfig(config);
21+
logger.debug("set config to {}", config);
22+
}
23+
}

src/main/java/frc/team2767/deepspace/command/approach/YawToTargetCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public YawToTargetCommand(double setpoint) {
3434
controller = getPIDController();
3535
controller.setContinuous();
3636
controller.setOutputRange(-1.0, 1.0);
37-
controller.setAbsoluteTolerance(1.0);
37+
controller.setAbsoluteTolerance(0.35);
3838
this.setpoint = setpoint;
3939
count = 0;
4040
logger.debug("construct yaw command");

src/main/java/frc/team2767/deepspace/command/approach/sequences/AutoHatchPickupCommandGroup.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ public class AutoHatchPickupCommandGroup extends CommandGroup {
88

99
public AutoHatchPickupCommandGroup() {
1010
addSequential(new LogCommand("BEGIN AUTO HATCH PICKUP"));
11-
// addSequential(new SquareTwistCommandGroup());
1211
addSequential(new ApproachDirectionCommand());
13-
addSequential(new SnapDriveCommandGroup());
12+
addSequential(new HatchPickupCommandGroup());
1413
addSequential(new LogCommand("END AUTO HATCH PICKUP"));
1514
}
1615
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.wpi.first.wpilibj.command.CommandGroup;
44
import frc.team2767.deepspace.command.approach.CalculateRotationCommand;
55
import frc.team2767.deepspace.command.approach.OpenLoopDriveUntilSuctionCommand;
6+
import frc.team2767.deepspace.command.approach.TalonConfigCommand;
67
import frc.team2767.deepspace.command.approach.YawToTargetCommand;
78
import frc.team2767.deepspace.command.biscuit.BiscuitExecutePlanCommand;
89
import frc.team2767.deepspace.command.elevator.ElevatorExecutePlanCommand;
@@ -17,9 +18,9 @@
1718
import frc.team2767.deepspace.command.vision.QueryPyeyeCommand;
1819
import frc.team2767.deepspace.subsystem.*;
1920

20-
public class SnapDriveCommandGroup extends CommandGroup {
21+
public class HatchPickupCommandGroup extends CommandGroup {
2122

22-
public SnapDriveCommandGroup() {
23+
public HatchPickupCommandGroup() {
2324
addSequential(new LogCommand("BEGIN AUTO SNAP DRIVE HATCH PICKUP"));
2425
addSequential(new LightsOnCommand());
2526
addSequential(new SetSolenoidStatesCommand(VacuumSubsystem.SolenoidStates.PRESSURE_ACCUMULATE));
@@ -34,16 +35,18 @@ public SnapDriveCommandGroup() {
3435

3536
addSequential(new PressureSetCommand(VacuumSubsystem.kHatchPressureInHg));
3637
addSequential(new SetSolenoidStatesCommand(VacuumSubsystem.SolenoidStates.GAME_PIECE_PICKUP));
38+
addSequential(new TalonConfigCommand(DriveSubsystem.DriveTalonConfig.YAW_CONFIG));
3739
addSequential(new QueryPyeyeCommand());
3840
addSequential(new CalculateRotationCommand());
39-
addSequential(new YawToTargetCommand());
4041
addSequential(
4142
new CommandGroup() {
4243
{
44+
addParallel(new YawToTargetCommand());
4345
addParallel(new ElevatorExecutePlanCommand());
4446
addParallel(new BiscuitExecutePlanCommand());
4547
}
4648
});
49+
addSequential(new TalonConfigCommand(DriveSubsystem.DriveTalonConfig.DRIVE_CONFIG));
4750
addSequential(new OpenLoopDriveUntilSuctionCommand(), 10);
4851
addParallel(new BlinkLightsCommand(VisionSubsystem.LightPattern.GOT_HATCH), 0.5);
4952
addParallel(new SetActionCommand(Action.PLACE));
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package frc.team2767.deepspace.command.approach.sequences;
2+
3+
import edu.wpi.first.wpilibj.DriverStation;
4+
import edu.wpi.first.wpilibj.command.CommandGroup;
5+
import edu.wpi.first.wpilibj.command.ConditionalCommand;
6+
import frc.team2767.deepspace.command.approach.CalculateRotationCommand;
7+
import frc.team2767.deepspace.command.approach.OpenLoopDriveUntilCurrentCommand;
8+
import frc.team2767.deepspace.command.approach.TalonConfigCommand;
9+
import frc.team2767.deepspace.command.approach.YawToTargetCommand;
10+
import frc.team2767.deepspace.command.biscuit.BiscuitExecutePlanCommand;
11+
import frc.team2767.deepspace.command.elevator.ElevatorExecutePlanCommand;
12+
import frc.team2767.deepspace.command.log.LogCommand;
13+
import frc.team2767.deepspace.command.states.SetFieldDirectionCommand;
14+
import frc.team2767.deepspace.command.vision.LightsOnCommand;
15+
import frc.team2767.deepspace.command.vision.QueryPyeyeCommand;
16+
import frc.team2767.deepspace.subsystem.DriveSubsystem;
17+
import frc.team2767.deepspace.subsystem.FieldDirection;
18+
19+
public class HatchPlaceCommandGroup extends CommandGroup {
20+
21+
public HatchPlaceCommandGroup() {
22+
addSequential(new LogCommand("BEGIN HATCH PLACE"));
23+
24+
addSequential(
25+
new ConditionalCommand(new SetFieldDirectionCommand(FieldDirection.LEFT)) {
26+
@Override
27+
protected boolean condition() {
28+
return DriverStation.getInstance().isAutonomous();
29+
}
30+
});
31+
addSequential(new LightsOnCommand());
32+
addSequential(new QueryPyeyeCommand());
33+
addParallel(new TalonConfigCommand(DriveSubsystem.DriveTalonConfig.YAW_CONFIG));
34+
addSequential(new CalculateRotationCommand());
35+
addSequential(
36+
new ConditionalCommand(
37+
new CommandGroup() {
38+
{
39+
addParallel(new YawToTargetCommand());
40+
addParallel(new ElevatorExecutePlanCommand());
41+
addParallel(new BiscuitExecutePlanCommand());
42+
}
43+
}) {
44+
@Override
45+
protected boolean condition() {
46+
return DriverStation.getInstance().isAutonomous();
47+
}
48+
});
49+
addSequential(new LogCommand("FINISHED MOVING AXIS"));
50+
addSequential(new TalonConfigCommand(DriveSubsystem.DriveTalonConfig.DRIVE_CONFIG));
51+
addSequential(new OpenLoopDriveUntilCurrentCommand(), 5.0);
52+
addSequential(new LogCommand("END HATCH PLACE"));
53+
}
54+
}

src/main/java/frc/team2767/deepspace/command/approach/sequences/SandstormHatchPlaceCommandGroup.java

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)