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

added new command, YIPPIE! #37

Merged
merged 1 commit into from
Jan 31, 2024
Merged
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
4 changes: 3 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.pathplanner.lib.util.PathPlannerLogging;
import com.pathplanner.lib.util.ReplanningConfig;

import frc.robot.commands.AimShooter;
import frc.robot.commands.AimRobotMoving;
import frc.robot.commands.IntakeCommand;
import frc.robot.commands.Autos;
Expand Down Expand Up @@ -167,7 +168,8 @@ private void driveTrainInst() {
}
private void shooterInst() {
shooter = new ShooterSubsystem(ShooterConstants.SHOOTER_MOTOR_POWER);
angleShooterSubsystem = new AngleShooterSubsystem(()-> (operatorController.getPOV() == 0));
angleShooterSubsystem = new AngleShooterSubsystem();
angleShooterSubsystem.setDefaultCommand(new AimShooter(angleShooterSubsystem, ()-> (operatorController.getPOV() == 0)));
}
private void intakeInst() {
intake = new IntakeSubsystem();
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/frc/robot/commands/AimShooter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package frc.robot.commands;

import java.util.function.BooleanSupplier;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.settings.Constants.Field;
import frc.robot.settings.Constants.ShooterConstants;
import frc.robot.subsystems.AngleShooterSubsystem;

public class AimShooter extends Command {
AngleShooterSubsystem angleShooterSubsystem;
BooleanSupplier aimAtAmp;

public AimShooter(AngleShooterSubsystem angleShooterSubsystem, BooleanSupplier aimAtAmp) {
this.angleShooterSubsystem = angleShooterSubsystem;
this.aimAtAmp = aimAtAmp;
}

@Override
public void initialize() {

}

@Override
public void execute() {
if (!aimAtAmp.getAsBoolean()) {
double desiredShooterAngleSpeed = angleShooterSubsystem.calculateSpeakerAngle() * ShooterConstants.AUTO_AIM_SHOOTER_kP;
angleShooterSubsystem.pitchShooter(desiredShooterAngleSpeed);
} else {
double differenceAmp = Field.AMPLIFIER_ANGLE - angleShooterSubsystem.getShooterAngle();
double ampSpeed = differenceAmp * ShooterConstants.AUTO_AIM_SHOOTER_kP;
angleShooterSubsystem.pitchShooter(ampSpeed);
}
}

@Override
public boolean isFinished() {
return false;
}

@Override
public void end(boolean interrupted) {
angleShooterSubsystem.pitchShooter(0);
}
}
16 changes: 2 additions & 14 deletions src/main/java/frc/robot/subsystems/AngleShooterSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ public class AngleShooterSubsystem extends SubsystemBase {
CANSparkMax pitchMotor;
SparkPIDController pitchPID;
CANcoder angleEncoder;
BooleanSupplier aimAtAmp;
double shootingSpeed = ShooterConstants.SHOOTING_SPEED_MPS;
public static Pose2d dtvalues;
public static ChassisSpeeds DTChassisSpeeds;

public AngleShooterSubsystem(BooleanSupplier aimAtAmp) {
this.aimAtAmp = aimAtAmp;
public AngleShooterSubsystem() {
pitchMotor = new CANSparkMax(ShooterConstants.PITCH_MOTOR_ID, MotorType.kBrushless);

pitchPID = pitchMotor.getPIDController();
Expand Down Expand Up @@ -105,15 +103,5 @@ public double calculateSpeakerAngle() {
return differenceAngle;
}

@Override
public void periodic() {
if (!aimAtAmp.getAsBoolean()) {
double desiredShooterAngleSpeed = calculateSpeakerAngle() * ShooterConstants.AUTO_AIM_SHOOTER_kP;
pitchShooter(desiredShooterAngleSpeed);
} else {
double differenceAmp = Field.AMPLIFIER_ANGLE - this.getShooterAngle();
double ampSpeed = differenceAmp * ShooterConstants.AUTO_AIM_SHOOTER_kP;
pitchShooter(ampSpeed);
}
}

}
Loading