Skip to content

Commit

Permalink
stopping after shooting and coasting
Browse files Browse the repository at this point in the history
  • Loading branch information
ori-coval committed Feb 5, 2024
1 parent 00e4188 commit 0899d8f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 14 deletions.
1 change: 1 addition & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public static class FeederConstants {
public static final int feederNoteSensorID = 0;
public static final double FeederMotorSpeed = 0.8;
public static final double getNoteSpeed = 0;
public static final double TimeToFeed = 0.7;

}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/aRobotOperations/PrepareForShoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import frc.robot.basicCommands.ShooterArmCommands.ShooterArmSpeakerAngle;
import frc.robot.basicCommands.ShooterCommands.ShooterSpeakerSetSpeed;
import frc.robot.basicCommands.ShooterCommands.ShooterSpeaker;

public class PrepareForShoot extends ParallelCommandGroup {
/** Creates a new PrepareForShoot. */
public PrepareForShoot() {

addCommands(
new ShooterArmSpeakerAngle(),
new ShooterSpeakerSetSpeed()
new ShooterSpeaker()
);
}
}
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/aRobotOperations/ShootSpeaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

package frc.robot.aRobotOperations;

import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import edu.wpi.first.wpilibj2.command.ParallelRaceGroup;
import frc.robot.basicCommands.feederCommands.FeedToShooter;

public class ShootSpeaker extends ParallelCommandGroup {
public class ShootSpeaker extends ParallelRaceGroup {
/** Creates a new ShootSpeaker. */
public ShootSpeaker() {
addCommands(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
package frc.robot.basicCommands.ShooterArmCommands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.Utils.vision.Vision;
import frc.robot.subsystems.ShooterArmSubsystem;
import frc.robot.subsystems.SwerveSubsystem;

public class ShooterArmSpeakerAngle extends Command {
private final ShooterArmSubsystem shooterArmSubsystem = ShooterArmSubsystem.getInstance();
private final Vision vision = Vision.getInstance();
private final SwerveSubsystem swerve = SwerveSubsystem.getInstance();

/** Creates a new ShooterAngleFromDistanceInterpolation. */
public ShooterArmSpeakerAngle() {
Expand All @@ -25,7 +25,7 @@ public void initialize() {
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
shooterArmSubsystem.moveArmTo(shooterArmSubsystem.angleFromDistance(vision.DistanceFromTarget()));
shooterArmSubsystem.moveArmTo(shooterArmSubsystem.angleFromDistance(swerve.getPose()));
}

// Called once the command ends or is interrupted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import frc.robot.subsystems.ShooterSubsysem;
import frc.robot.subsystems.SwerveSubsystem;

public class ShooterSpeakerSetSpeed extends Command {
public class ShooterSpeaker extends Command {
private final ShooterSubsysem shooterSubsystem = ShooterSubsysem.getInstance();
private final SwerveSubsystem swerve = SwerveSubsystem.getInstance();

/** Creates a new ShooterSetSpeedInterpolation. */
public ShooterSpeakerSetSpeed() {
public ShooterSpeaker() {
this.addRequirements(shooterSubsystem);
}

Expand All @@ -31,6 +31,7 @@ public void execute() {
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
shooterSubsystem.coast();
}

// Returns true when the command should end.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

package frc.robot.basicCommands.feederCommands;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants.FeederConstants;
import frc.robot.subsystems.FeederSubsystem;
import frc.robot.subsystems.ShooterArmSubsystem;
import frc.robot.subsystems.ShooterSubsysem;
import static frc.robot.Constants.FeederConstants.*;

public class FeedToShooter extends Command {
private final ShooterSubsysem shooterSubsysem = ShooterSubsysem.getInstance();
private final ShooterSubsysem shooterSubsystem = ShooterSubsysem.getInstance();
private final ShooterArmSubsystem shooterArmSubsystem = ShooterArmSubsystem.getInstance();
private final FeederSubsystem feederSubsystem = FeederSubsystem.getInstance();
Timer timer = new Timer();
boolean startedShooting = false;

/** Creates a new StartFeeder. */
public FeedToShooter() {
Expand All @@ -29,8 +33,10 @@ public void initialize() {
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
if (shooterSubsysem.checkIfShooterAtSpeed() && shooterArmSubsystem.isArmReady()) {
if (!startedShooting && shooterSubsystem.checkIfShooterAtSpeed() && shooterArmSubsystem.isArmReady()) {
feederSubsystem.setSpeed(FeederShootSpeed);
startedShooting = true;
timer.restart();
}
}

Expand All @@ -43,6 +49,6 @@ public void end(boolean interrupted) {
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
return timer.hasElapsed(FeederConstants.TimeToFeed);
}
}
8 changes: 6 additions & 2 deletions src/main/java/frc/robot/subsystems/ShooterArmSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.MotionMagicVoltage;
import com.ctre.phoenix6.hardware.TalonFX;

import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.Utils.interpolation.InterpolateUtil;
import frc.Utils.vision.Vision;
import frc.robot.Constants;

import static frc.robot.Constants.ShooterArmConstants.*;
Expand All @@ -25,6 +28,7 @@ public class ShooterArmSubsystem extends SubsystemBase {
private TalonFX m_shooterArmMotor;
private final MotionMagicVoltage motionMagic = new MotionMagicVoltage(shooterArmStartPose);
DigitalInput limitSwitch;
private final Vision vision = Vision.getInstance();

// the instance
private static ShooterArmSubsystem instance;
Expand Down Expand Up @@ -109,8 +113,8 @@ public void moveArmBySpeed(DoubleSupplier speed) {
m_shooterArmMotor.set(speed.getAsDouble());
}

public double angleFromDistance(double distance) {
return InterpolateUtil.interpolate(SHOOTER_ANGLE_INTERPOLATION_MAP, distance);
public double angleFromDistance(Pose2d pose) {
return InterpolateUtil.interpolate(SHOOTER_ANGLE_INTERPOLATION_MAP, vision.DistanceFromTarget(pose));
}

@Override
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/frc/robot/subsystems/ShooterSubsysem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
import com.ctre.phoenix6.configs.MotionMagicConfigs;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.controls.MotionMagicVelocityVoltage;
import com.ctre.phoenix6.controls.NeutralOut;
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.NeutralModeValue;

import static frc.robot.Constants.ShooterConstants.*;

import edu.wpi.first.math.geometry.Pose2d;
Expand All @@ -25,6 +28,8 @@ public class ShooterSubsysem extends SubsystemBase {

private static ShooterSubsysem instance;

NeutralOut neutralOut = new NeutralOut();

public static ShooterSubsysem getInstance() {
if (instance == null) {
instance = new ShooterSubsysem();
Expand Down Expand Up @@ -58,6 +63,8 @@ private ShooterSubsysem() {
configs.Voltage.PeakReverseVoltage = PeakReverseVoltage;

configs.Feedback.SensorToMechanismRatio = SensorToMechanismRatio;

m_shooterMotor.setNeutralMode(NeutralModeValue.Coast);

// Checking if m_shooterMotor apply configs
StatusCode status = StatusCode.StatusCodeNotInitialized;
Expand Down Expand Up @@ -88,6 +95,10 @@ public double speakerInterpolate(Pose2d pose2d) {
return InterpolateUtil.interpolate(ShooterInterpolation, vision.DistanceFromTarget(pose2d));
}

public void coast() {
m_shooterMotor.setControl(neutralOut);
}

@Override
public void periodic() {
// This method will be called once per scheduler run
Expand Down

0 comments on commit 0899d8f

Please sign in to comment.