Unable to change power with spark max

For some reason, I am unable to change the power to our ball shooter which uses a neo with a spark max, code is below.
Right now I have it set to 45, but changing it does not seem to change the rpm

public class Thrower extends Subsystem {

private CANSparkMax throwermotor;
private CANSparkMax feedmotor;
private CANSparkMax stackmotor;
private NetworkTable table;
private double a1;
private double a2;
private double h1;
private double h2;
private double d;
private double power;
private CANEncoder m_encoder;

public void thrown(){
throwermotor = new CANSparkMax(RobotMap.THROWER_MOTOR_ID, MotorType.kBrushless);

table = NetworkTableInstance.getDefault().getTable("limelight");
final NetworkTableEntry ty = table.getEntry("ty");

a1 = 12; // Angle of camera from the horizontal in degrees
a2 = ty.getDouble(0.0); // Angle of tower to camera found with limelight
h1 = 27; // Height of limelight to ground in inches
h2 = 82; // Height of tower's tape to ground in inches

d = 55 / Math.tan(Math.toRadians(a1+a2)); // Calculates the distance between camera and target

m_encoder = throwermotor.getEncoder();
// Set motor power for shooting the turret.
// Over time, the turret occasionally gets less accurate
// use the power nerf to adjust for that.
int power_nerf = 4;
int nerf_test = 20;
//power = 4.06 + 0.346*d + -0.000475*(d*d) - power_nerf;
// power = 25.9*Math.pow(Math.E, 0.00368*d);
power = 45;
SmartDashboard.putNumber("Ball Shooter Speed (RPM)", -m_encoder.getVelocity());
SmartDashboard.putNumber("Distance to Tower", d);
SmartDashboard.putNumber("Power", power);


throwermotor.set(-(int)power); —> -(int) power?

void com.revrobotics.CANSparkMax.set (double speed ) You are passing an int type variable and it should be double with value between -1 and 1. Power is 45 and an int type
Also loose the negative and use: void com.revrobotics.CANSparkMax.setInverted (true)

double power = 1;

If you use set(double) you are putting the motor in percent output mode and the value should be between [-1, 1], so 45 is essentially saying run at 100%.

If you’re intending to set the motor to 45% output, you need to be passing 0.45. As @Beeker pointed out, the value is a double so you should not cast to int.

If you’re intending to set the motor to 45 RPM (which is really slow for a shooter) you need to use the motor’s PID controller:

var throwerPIDController = throwermotor.getPIDController();
throwerPIDController.setReference(rpm, ControlType.kVelocity);

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.