Encoder RPM

So, I have this task to calculate the RPM of the side of my robot by averaging out 2 quad encoder values then calculating stuff.
(Gonna make lookup tables)
However I think my calculations are incorrect as the RPM don’t really match under load.
Can someone have a look over the code and correct it?

Thanks :slight_smile:

task cMotorRpm(){
  float mRecordedValues[128];
  float curValue;
  float nextValue;
  float curRPM;

  for (int i = 0; i <= 127; i++)

    SensorValue[encLeftF] = 0;
    SensorValue[encLeftB] = 0; 
    motor[port2] = i;
    curValue = (SensorValue[encLeftF] + SensorValue[encLeftB])/2;
    nextValue = (SensorValue[encLeftF] + SensorValue[encLeftB])/2;
    curRPM = ((nextValue - curValue)/90.0)*60.0; 
    mRecordedValues* = curRPM;
	motor[port2] = 0;
  motor[port2] = 0;
  for (int i = 0; i <=127; i++){
    writeDebugStreamLine("%d", mRecordedValues*);


I see a couple of issues.

  1. A quad encoder has 360 counts/revolution. Your encoder change is measured over three seconds, so you need to divide the count by 1080 (assuming the encoder is on the motor shaft) to get revs/second and then multiply by 60 to get revs/minute. Is the encoder after any gearing?

curRPM = ((float)(nextValue - curValue)/1080.0)*60.0;

  1. You probably don’t want to send a speed of 0 to the motor in between each measurement, just send the next speed and wait a little longer for the motor to stabilize.