Count RPM's with encoders

I’m programming a flywheel for an AP Physics project, the program works fine but for shits and giggles I wanted to know how many RPM’s the final output is. So I put an encoder on the output shaft and realized I have no idea how I would program that. Any ideas/suggestions? I’m programming with PROS but tell me how you would do it with anything else and I can probably figure the rest out.

To measure RPM, you must have a measurement of distance/time. The units can be anything, but it must be a measure of distance (or rotations, degrees, etc.) / time. You already have an encoder, which would give you distance (specifically degrees), so now all you need is a measure of time. As long as you calculate the RPM at a constant rate, you can use that rate to figure out how fast it is going, which would be the time factor. I don’t know what else you’re doing in your code, so I’ll give an example that would run in a different task so it won’t interfere.


int prev = 0;
void calcRPM() {
    
    int enc = encoderGet(encoder); // gets the encoder value
    int change = enc - prev; // determines how much the encoder has moved since the last update
    printf("RPM: %f\n", change * 0.17f); // convert to RPM (assuming a 1000ms update interval) and print
    prev = enc; // update the previous encoder variable for next update
    
}

Then you just have to call


taskRunLoop(calcRPM, 1000);

at some point at the beginning of your program (NOT IN A LOOP) to run the function in the background every 1000ms (1 second). Make sure not to place parenthesis at the end of calcRPM.

You’ll notice I multiply change by 0.17f. This number is the conversion factor of degrees/second to revolutions/minute (RPM). If your gear ratio is different (giving the encoder a different precision) or you want to calculate the RPM more often than once per second, you must figure this factor out yourself. To do this, use this website. Simply divide how many encoder ticks per degree (a 1:1 gear ratio will be 1, a 1:3 speed ratio will be 3, etc.) by the update interval in milliseconds and place than calculation into the “Degrees Per Millisecond” box.

Take a look at this forum post https://vexforum.com/t/calculating-rpms/31506/1