Swerve Module Velocity

The drive motor on the swerve modules are constantly going forward and backwards. We narrowed down the problem down to the getVelocity() function and we were wondering how it calculates the velocity. driveEncoder is a RevRobotics RelativeEncoder that is in the drive motor.

    // Calculate the drive output from the drive PID controller.
    final double driveOutput =
        drivePIDController.calculate(driveEncoder.getVelocity(), state.speedMetersPerSecond);

Is it possible that the issue is caused by the PID and not the velocity function? sometimes if our PID loops are acting funny flipping the P constant to a negative will get it to behave.

1 Like

I don’t know the specifics of how the sensor measures the velocity but if you are trying to get to a certain velocity I would recommend using feedforward. Essentially you have to do a characterization routine which basically measures at what velocity do I need this much voltage over the distance. You then plug in the values such as kA, kV, and kS it gives into it’s class and then you utilize it by inputting in the desired velocity. It returns a voltage which you use to control the motor.

When we print the velocity it constantly changes. Without changing the speed. Also when we replace the velocity with a constant it works.

getVelocity() returns rpm by default you might be able to get a more consistent output by using the setVelocityConversionFactor() method

How would I get the conversion factor to put into the method?

Try experimenting with different values and see what works

The NEO drive motors return RPM, so the rotations of the shaft per minute. To convert this to meters per second, you need to figure out wheel rotations per motor rotations, and then multiply that by the wheel circumference in meters. Then, divide by 60 to get meters per second. (Recommend that someone else confirms this math, this is off of the top of my head and I’m not 100% sure.)

YAGSL has a documentation page where they define some default conversion factors, although I’m not sure if they’re unique to YAGSL or generally applicable.

Theyre generally applicable

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