SPARK MAX setRefrence not working

Were using NEO motors and the .setrefrence method to drive them to position and it just spins in circles. Here is the code does anyone know what is going wrong?

	double P = 10;
	double I = 0;
	double D = .5;
	drive1.setP(P);
	drive1.setI(I);
	drive1.setD(D);
	drive1.setIZone(0);
	drive1.setFF(0);
	drive1.setOutputRange(-.25, .25);
	drive2.setP(P);
	drive2.setI(I);
	drive2.setD(D);
	drive2.setIZone(0);
	drive2.setFF(0);
	drive2.setOutputRange(-.25, .25);
	drive3.setP(P);
	drive3.setI(I);
	drive3.setD(D);
	drive3.setIZone(0);
	drive3.setFF(0);
	drive3.setOutputRange(-.25, .25);
	drive4.setP(P);
	drive4.setI(I);
	drive4.setD(D);
	drive4.setIZone(0);
	drive4.setFF(0);
	drive4.setOutputRange(-.25, .25);
	double ticks = 100;
	SmartDashboard.putNumber("ticks", ticks); 
	drive1.setReference(-ticks, ControlType.kPosition);
	drive2.setReference(ticks, ControlType.kPosition);
	drive3.setReference(ticks, ControlType.kPosition);
	drive4.setReference(-ticks, ControlType.kPosition);

Your P gain seems to be huge, especially considering the units… how did you tune your PID loop?

I just tried resetting d to 0 and setting p to 1 to no avail it doesn’t seem to be a PID tuning issue as changing the PID values have little effect on the way it moves.

Well, you are telling the SPARK MAX to have the motor move to 100 revolutions. Are you sure you’re not just waiting for it to get to that position?

is the .setrerence method done in revolutions not encoder ticks?

https://www.revrobotics.com/content/sw/max/sw-docs/java/com/revrobotics/CANPIDController.html#setReference(double,com.revrobotics.ControlType)

… unless you’ve set the conversion factor for the encoder:

https://www.revrobotics.com/content/sw/max/sw-docs/java/com/revrobotics/CANEncoder.html#setPositionConversionFactor(double)

1 Like

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