SparkMAX Java encoder.getVelocity() returning position value

We’re trying to get the velocity of our NEO-driven shooter, but the Java API call for getVelocity is returning the same value as a call to getPosition.

We have the latest API and firmware. We also tried doing a factory reset on the Spark. Still getting position.

We’re reading the velocity from the leader of a pair of MAXs.

If we take the position value every cycle and do the math, we do get the correct velocity, but it’s noisy and seems to bounce to a 2x value frequently. We’d rather just get the correct velocity from the API.

Is there something we did wrong in the configuration? Or is there a regression in the API?

Thanks

Can you please post your code to github or somewhere similar?

Will have to push the latest to github later tonight.

But in the meantime, the relevant parts of the code are basically the sample Java code:

class shooterSubsystem extends SubsystemBase {
CANSparkMAX shooter = new CANSparkMAX(14, kBrushless);
CANEncoder encoder = shooter.getEncoder();

[ other methods using setReference in kVelocity mode to run shooter ]

void periodic() {
SmartDashboard.putNumber(“shooter velocity”, encoder.getVelocity());
}

It would be best to see how else the MAX is configured. However, generally speaking this is correct. Just make sure that no other code is updating “shooter velocity” on SmartDashboard.

Here is the latest code. This is part of a pending PR, so I’ll update the link if it gets merged anytime soon. There are open comments against the PR, so there will be changes before the merge can happen.

The bug looks to be in your SimmableCANSparkMax.java. it’s returning the same value for getPosition and getVelocity.

7 Likes

Yep, that looks like a classic paste-o. Thanks for spotting that.

1 Like

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