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

Tracks how long for the motor to reach setpoint #125

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion src/main/java/frc/robot/commands/shooter/StartShooter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package frc.robot.commands.shooter;

import frc.robot.subsystems.Shooter;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.CommandBase;

/**
Expand All @@ -11,16 +12,37 @@
public class StartShooter extends CommandBase {

private final Shooter shooter;
private double reachSetpointCycleCounter;
private boolean isShooterComingUpToSpeed = true;
private double previousSetpoint;
private double newSetpoint;

public StartShooter(Shooter shooter) {
this.shooter = shooter;

addRequirements(shooter);
}

@Override
public void initialize(){
reachSetpointCycleCounter = 0;
isShooterComingUpToSpeed = true;
}
@Override
public void execute() {
shooter.setSpeed(shooter.shooterSpeedFeetPerSecondWidget.getDouble(0));
double targetSetpoint = shooter.shooterSpeedFeetPerSecondWidget.getDouble(0);
newSetpoint = targetSetpoint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if we're never resetting our reachSetpointCycleCounter or isShooterComingUpToSpeed - do we need to have a previous/next here? Or can we just have the single setpoint?

Doing the zeroing/resetting the way you were doing is fine. You'd only have to move your SmartDashboard.putNumber back in to that if (isShooterComingUpToSpeed block for that to still work.

Either approach is fine here IMO. I don't know if at this point in time we'll be like, holding the button to start the shooter and changing the values on the slider. I think it's more likely we'll set the value in code and then want to see how long the shooter takes to get up to speed between StartShooter calls.

shooter.setSpeed(targetSetpoint);
if (isShooterComingUpToSpeed || (previousSetpoint != newSetpoint)) {
if (!shooter.isShooterToSpeed()) {
reachSetpointCycleCounter ++;
} else {
isShooterComingUpToSpeed = false;
}
}
previousSetpoint = targetSetpoint;
//20 ms in a cycle, so we multiply our cycle time by 50 to get the amount of milliseconds, divide by 1000 to get seconds.
SmartDashboard.putNumber("Time to reach Setpoint in sec", ((reachSetpointCycleCounter * 50) / 1000));
}

@Override
Expand Down