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
55 changes: 55 additions & 0 deletions src/main/java/frc/robot/commands/CustomizedExecutionCommands.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package frc.robot.commands;

import java.util.function.BooleanSupplier;

import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.WrapperCommand;


public class CustomizedExecutionCommands {


private static class ConditionalCommandExecution extends WrapperCommand {

protected BooleanSupplier condition;

public ConditionalCommandExecution(Command command, BooleanSupplier condition){
super(command);
this.condition = condition;
}

@Override
public void execute(){
if (condition.getAsBoolean()){
m_command.execute();
}
}
}

private static class InitializedConditionalStartCommand extends WrapperCommand {

protected BooleanSupplier condition;
protected boolean canRun;

public InitializedConditionalStartCommand(Command command, BooleanSupplier condition){
super(command);
this.condition = condition;
}

@Override
public void execute(){
canRun = canRun || condition.getAsBoolean();
if (canRun){
m_command.execute();
}
}
}

public static Command executeIf(Command command, BooleanSupplier condition){
return new ConditionalCommandExecution(command, condition);
}

public static Command initilizedOnlyIf(Command command, BooleanSupplier condition){
return new InitializedConditionalStartCommand(command, condition);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package frc.robot.commands.drive;

import java.util.function.BooleanSupplier;

import com.pathplanner.lib.auto.AutoBuilder;
import com.pathplanner.lib.path.PathConstraints;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.commands.CustomizedExecutionCommands;

public class ConditionalDelayedPathfindingCommand {

public static Command generateCommand(Pose2d pose, PathConstraints constraints, double goalEndVelocity, BooleanSupplier conditionToStart){
return generateCommand(AutoBuilder.pathfindToPose(pose, constraints, goalEndVelocity), conditionToStart);
}

public static Command generateCommand(Command pathFindingCommand, BooleanSupplier conditionToStart){
return CustomizedExecutionCommands.initilizedOnlyIf(pathFindingCommand, conditionToStart);
}

}