Skip to content

Commit

Permalink
Stator limits, error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekChen1 committed Sep 21, 2023
1 parent 71931a9 commit b53df54
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 23 deletions.
6 changes: 2 additions & 4 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
import edu.wpi.first.math.numbers.N3;
import edu.wpi.first.wpilibj.Filesystem;
import frc.robot.Constants.Drive.Dims;
import frc.util.NodeSelectorUtility;
import frc.util.NodeSelectorUtility.Height;
import frc.util.NodeSelectorUtility.NodeSelection;
import frc.util.NodeSelectorUtility.NodeType;
import frc.robot.commands.ScoreCommand.ScoreStep;
import frc.robot.subsystems.ElevatorSubsystem.ElevatorState;
import frc.robot.subsystems.NetworkWatchdogSubsystem.IPv4;
import frc.robot.subsystems.RGBSubsystem.RGBColor;
import frc.robot.subsystems.VisionSubsystem.TagCountDeviation;
import frc.robot.subsystems.VisionSubsystem.UnitDeviationParams;
import frc.util.CAN;
import frc.util.NodeSelectorUtility.Height;
import frc.util.NodeSelectorUtility.NodeType;
import frc.util.pathing.FieldObstructionMap;
import java.nio.file.Path;
import java.util.List;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import edu.wpi.first.wpilibj2.command.WaitCommand;
import edu.wpi.first.wpilibj2.command.button.CommandXboxController;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.Constants;
import frc.robot.Constants.Config;
import frc.robot.Constants.Drive;
import frc.robot.commands.AlignGamepieceCommand;
Expand Down Expand Up @@ -408,7 +407,7 @@ private void setupAutonomousCommands() {

final List<ScoreStep> drivingCubeOuttake =
List.of(
new ScoreStep(ElevatorState(35, Constants.Elevator.MIN_HEIGHT)).canWaitHere(),
new ScoreStep(ElevatorState(35.0, Constants.Elevator.MIN_HEIGHT)).canWaitHere(),
new ScoreStep(IntakeMode.OUTTAKE));
final boolean[] intakeLow = {false};
final Map<String, Command> eventMap =
Expand Down
21 changes: 9 additions & 12 deletions src/main/java/frc/robot/commands/GroundPickupCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@
// https://docs.wpilib.org/en/stable/docs/software/commandbased/convenience-features.html
public class GroundPickupCommand extends SequentialCommandGroup {
/** Creates a new GroundPickupCommand. */
public GroundPickupCommand(
ElevatorSubsystem elevatorSubsystem,
IntakeSubsystem intakeSubsystem
) {
public GroundPickupCommand(ElevatorSubsystem elevatorSubsystem, IntakeSubsystem intakeSubsystem) {
// Add your commands in the addCommands() call, e.g.
// addCommands(new FooCommand(), new BarCommand());
addCommands(
new IntakeModeCommand(intakeSubsystem, IntakeSubsystem.IntakeMode.INTAKE)
.deadlineWith(
new IntakeModeCommand(intakeSubsystem, IntakeSubsystem.IntakeMode.INTAKE)
.alongWith(new ElevatorPositionCommand(elevatorSubsystem, Elevator.Setpoints.HANDOFF)))
.andThen(
new ElevatorPositionCommand(elevatorSubsystem, Elevator.Setpoints.STOWED)
.alongWith(new IntakeModeCommand(intakeSubsystem, IntakeSubsystem.IntakeMode.HOLD))));
//hold???

.deadlineWith(
new ElevatorPositionCommand(elevatorSubsystem, Elevator.Setpoints.HANDOFF))
.andThen(
new ElevatorPositionCommand(elevatorSubsystem, Elevator.Setpoints.STOWED)
.alongWith(
new IntakeModeCommand(intakeSubsystem, IntakeSubsystem.IntakeMode.HOLD))));
// hold???

}
}
17 changes: 12 additions & 5 deletions src/main/java/frc/robot/subsystems/ElevatorSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ElevatorSubsystem extends SubsystemBase {
private double targetHeight;
private double currentAngle;
private double targetAngle;
private double statorCurrentLimit;

private PIDController heightController;
private PIDController wristController;
Expand Down Expand Up @@ -59,6 +60,7 @@ public ElevatorSubsystem() {
targetHeight = 0.0;
currentAngle = 0.0;
targetAngle = 0.0;
statorCurrentLimit = 10.0;

rightMotor.configFactoryDefault();
leftMotor.configFactoryDefault();
Expand All @@ -72,7 +74,7 @@ public ElevatorSubsystem() {
leftMotor.setNeutralMode(NeutralMode.Brake);
wristMotor.setNeutralMode(NeutralMode.Brake);

filter = LinearFilter.movingAverage(35);
filter = LinearFilter.movingAverage(30);

tab.addDouble("Motor Position", () -> canCoder.getAbsolutePosition());
}
Expand Down Expand Up @@ -117,11 +119,16 @@ public void setTargetAngle(double targetAngle) {
public void periodic() {
currentHeight = getHeight();
currentAngle = getCurrentAngleDegrees();
double motorPower = heightController.calculate(currentHeight, targetHeight);
rightMotor.set(TalonFXControlMode.PercentOutput, motorPower);

if (filter.calculate(rightMotor.getStatorCurrent()) < statorCurrentLimit) {
double motorPower = heightController.calculate(currentHeight, targetHeight);
rightMotor.set(TalonFXControlMode.PercentOutput, motorPower);
} else {
rightMotor.set(TalonFXControlMode.PercentOutput, 0);
}

wristMotor.set(
TalonFXControlMode.PercentOutput,
MathUtil.clamp(
wristController.calculate(currentAngle, targetAngle), -0.25, 0.25));
MathUtil.clamp(wristController.calculate(currentAngle, targetAngle), -0.25, 0.25));
}
}
1 change: 1 addition & 0 deletions src/main/java/frc/robot/subsystems/IntakeSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void intakePeriodic(IntakeMode mode) {
intakeMotor.set(TalonFXControlMode.PercentOutput, -1);
case HOLD:
case OFF:
intakeMotor.set(TalonFXControlMode.PercentOutput, 0);
default:
intakeMotor.set(TalonFXControlMode.PercentOutput, 0);
}
Expand Down

0 comments on commit b53df54

Please sign in to comment.