I have been trying to use the talon srx Velocity control mode to keep out motor at a given rpm but no matter what a set the rpm to the motor spins up to full speed I’m not sure I fully understand how the velocity control mode works. Here is our current code for driving the motor the method in question is spinToRPM() if anyone knows a solution help would be much appreciated
/----------------------------------------------------------------------------/
/* Copyright © 2018 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.wpilibj.command.Subsystem;
import frc.robot.RobotMap;
import com.ctre.phoenix.motorcontrol.ControlMode;
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
import com.ctre.phoenix.motorcontrol.can.*;
public class ShooterSubsystem extends Subsystem {
// motor controllerS
//WPI_TalonFX fxShooter = new WPI_TalonFX(RobotMap.fxShooter);
WPI_TalonSRX fxShooter = new WPI_TalonSRX(RobotMap.fxShooter);
// variables TODO tune via instrustions at:
int timeOutMs = 30;
int loopIDX = 0;
double f = 1023;
double p = .25;
double i = .001;
double d = 20;
@Override
public void initDefaultCommand() {
}
public ShooterSubsystem() {
// reset to factory default
fxShooter.configFactoryDefault();
// config feedback sensor for PID
// fxShooter.configSelectedFeedbackSensor(FeedbackDevice.IntegratedSensor, loopIDX, timeOutMs);
fxShooter.configSelectedFeedbackSensor(FeedbackDevice.CTRE_MagEncoder_Relative, 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(false);
fxShooter.setSensorPhase(false);
// 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,600);
}
public void setSpeed(double speed) {
fxShooter.set(ControlMode.PercentOutput,speed);
}
public int currentRPM() {
//current rpm = rpm of motor x gear ratio
int motorRPM = fxShooter.getSelectedSensorVelocity();
int gearRatio = 1;
return motorRPM*gearRatio;
}
}