So i have a command with the SparkMax inbuilt encoder to moveToSetPoint but it doesnt go in reverse. It wouldnt be too much of an issue but it need it to reverse for auton.
public class MoveToPosition extends CommandBase {
// Create an object for the Manipulator
private final Manipulator m_manipulator;
// Create DoubleSuppliers for the setpoint and power
private final DoubleSupplier m_setpoint, m_power;
/** Creates a new MoveToPosition. */
public MoveToPosition(Manipulator manipulator, DoubleSupplier setpoint, DoubleSupplier power) {
// Use the Manipulator subsystem to gain access to its commands
m_manipulator = manipulator;
// Set the setpoint and power
m_setpoint = setpoint;
m_power = power;
// Use addRequirements() here to declare subsystem dependencies.
addRequirements(manipulator);
}
// Called when the command is initially scheduled.
@Override
public void initialize() {
// Reset the encoder
m_manipulator.resetliftEncoder();
}
// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
// Call the moveToSetpoint method
m_manipulator.moveToSetpoint(m_setpoint.getAsDouble(), m_power.getAsDouble());
}
// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {
m_manipulator.stopArm();
}
// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
PID is untuned since its just a basic wench mechanism that doesnt need to be too accurate. and the m_power is unused right now but it will be basically speed so like
ok, but why are you specifying both setpoint and power together? Setting a speed and using PID are generally two exclusive actions. You can switch between PID and speeds, but you can’t use them together. The whole point of PID is that it controls the speed of your output automatically using your PID(F) Constants.
Also, what about your max and min outputs? Basically could you post at least your entire subsystem class. Preferably you’d post your entire code to like a GitHub Repo so we could view the code in it entirety to try and track down issues.
and i dont really know much about the PID so someone who know more about that helped with that (basically did it all because time limits) so I basically just implemented it as needed and the power is the speed of which it goes to setpoint so at the moment unless if i removed it there was a button on Operator that used the lift full speed but before the match we needed to set the lift to a certain height for autonomous and I did that as a spare button on operator but half speed for safety
So your moveToSetpoint method isn’t using PID at all. Just moving at the given speed until it is greater than or equal to your setpoint, then stopping.
You’d use the setReference method of your PID Controller object liftPID to tell the SparkMAX to go to a setpoint.
Provided your PID output range is set to allow reversed outputs (which it was according to the Git Repo) it should. Of course your results will depend on your PID tuning.
Yep, as it is you don’t have any gain set for any of the PIDF Components.
You generally start with increasing the Proportional gain (kP) until you are either happy with the result or you start getting oscillations, then you add Derivative (kD) to smooth out the Oscillations to get to a quick steady state, and finally you add Integral (kI) to help deal with if the steady state isn’t quite at your setpoint.
Both of our Position PIDs this year worked well enough with only Proportional control, so we didn’t bother adding any Integral or Derivative gain (leaving them at zero).