it was originally -1,1 but it would not run at all but when i reversed it it started spinning just not stopping, looking at the number on the smart dashboard i can see it start at 0 and go up and just keep going past the give position here is the full subsystem the method is question is public void adjust(int position)
/----------------------------------------------------------------------------/
/* Copyright © 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/----------------------------------------------------------------------------/
package frc.robot.subsystems;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;
import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
import com.ctre.phoenix.motorcontrol.can.*;
import com.revrobotics.*;
import com.revrobotics.CANSparkMaxLowLevel.MotorType;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
public class ShooterSubsystem extends SubsystemBase {
// motor controllers
WPI_TalonFX fxShooter = new WPI_TalonFX(Constants.fxShooter);
CANSparkMax maxAdjuster = new CANSparkMax(Constants.maxAdjuster, MotorType.kBrushless);
public CANPIDController maxAdjusterPID = new CANPIDController(maxAdjuster);
public CANEncoder maxAdjusterEncoder = new CANEncoder(maxAdjuster);
// variables TODO tune via instrustions at:
int timeOutMs = 30;
int loopIDX = 0;
double f = .053;
double p = .097 ;
double i = 0;
double d = 0;
double sparkP = .1;
double sparkI = 0;
double sparkD = 0;
public ShooterSubsystem() {
//adjuster pid
maxAdjusterPID.setFeedbackDevice(maxAdjusterEncoder);
maxAdjusterPID.setP(sparkP);
maxAdjusterPID.setI(sparkI);
maxAdjusterPID.setD(sparkD);
maxAdjusterPID.setOutputRange(1, -1);
maxAdjusterEncoder.setPosition(0);
// reset to factory default
fxShooter.configFactoryDefault();
// config feedback sensor for PID
fxShooter.configSelectedFeedbackSensor(FeedbackDevice.IntegratedSensor, loopIDX, timeOutMs);
// Config peak and nominal outputs
fxShooter.configNominalOutputForward(0, timeOutMs);
fxShooter.configNominalOutputReverse(0, timeOutMs);
fxShooter.configPeakOutputForward(1, timeOutMs);
fxShooter.configPeakOutputReverse(-1, timeOutMs);
fxShooter.setInverted(true);
fxShooter.setSensorPhase(true);
// config P,I,D,F values
fxShooter.config_kF(loopIDX, f, timeOutMs);
fxShooter.config_kP(loopIDX, p, timeOutMs);
fxShooter.config_kI(loopIDX, i, timeOutMs);
fxShooter.config_kD(loopIDX, d, timeOutMs);
}
public void spinToRPM(int targetRPM) {
// sets shooter to target rpm
fxShooter.set(ControlMode.Velocity, targetRPM / .292);
}
public void setSpeed(double speed) {
fxShooter.set(ControlMode.PercentOutput, speed);
}
public double currentRPM() {
// current rpm = rpm of motor x gear ratio
double motorRPM = fxShooter.getSelectedSensorVelocity() * .292;
double gearRatio = 1;
return motorRPM * gearRatio;
}
public void adjust(int position) {
SmartDashboard.putNumber("enc pos", getAdjusterPosition());
maxAdjusterPID.setReference(position, ControlType.kPosition);
}
public double getAdjusterPosition() {
return maxAdjusterEncoder.getPosition();
}
@Override
public void periodic() {
// This method will be called once per scheduler run
}
}