Convert CPR to RPM

Hi, I read that the getRate from Encoder class returns CPR value and getVelocity returns RPM. I would like to know how can I convert this CPR value to RPM?

Assuming you’re talking about the WPI library Encoder class details can be found here.

getRate: Get the current rate of the encoder. Units are distance per second as scaled by the value from setDistancePerPulse().

setDistancePerPulse: Set the distance per pulse for this encoder. This sets the multiplier used to determine the distance driven based on the count value from the encoder. Do not include the decoding type in this scale. The library already compensates for the decoding type. Set this value based on the encoder’s rated Pulses per Revolution and factor in gearing reductions following the encoder shaft. This distance can be in any units you like, linear or angular.

CPR means cycles per revolution and is not what the getRate method returns.

The encoder class of the WPI library does not have a getVelocity() method.

This thread will be a useful read. Finding RPMs with encoder - Sensors - Chief Delphi

If that doesn’t address your questions then feel free to clarify your question.

2 Likes

Still is not clear to me how can I get the rpm from the class Encoder :grimacing:

Determine CPR of your encoder, this can be found in the manufacturer info. Let’s say it’s 4096 for this example.
Here’s some common ones from CTRE.

Use setDistancePerPulse() to set the number of degrees per pulse. So in this case is would be setDistancePerPulse(360.0/4096).

Now getRate() will give you degrees per second, convert this to RPM. (60 sec/min) (1 rev / 360 deg)
getRate()/6 will be your speed in RPM.

Alternatively you can move this conversion into the setDistancePerPulse() method so getRate just gives you RPM, but this can lead to confusion in time units so I wouldn’t recommend it.

Example code is in the thread I linked.

2 Likes

thanks!! :smiley:

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