# Programming RPM using IME

I’m a little lost on how i can do this. I want a program to display on the LCD the rpm of the wheel. I know the rpm is 100 but the wheel will be geared. If anyone could help me out? It would really help a lost programmer out…

As you are measuring the RPM of the motor, it is easy to find the RPM of the wheel. You just need to calculate the gear ratio for the flywheel, for example if you have a 60 tooth gear turning a 12 tooth gear you have a ratio of 60:12 or 5:1, and if this is compounded to another 60 tooth gear turning a 12 tooth gear you have also have the ratio of 5:1. 5x5=25, so you have an overall gear ratio of 25:1, now you just need to multiply the measured motor RPM by the ratio (25) to find the speed of the flywheel.

For reference, these are the sizes of VEX gears:
12 tooth (1)
36 tooth (3)
60 tooth (5)
84 tooth (7)

You can measure the encoder_counts/millisecond by taking two encoder measurements with a wait in between them then taking the last measurement and taking away the first then dividing by the wait time.

``````
float FirstMeasurement;
float SecondMeasurement;
float velocity;
int waitTime;

FirstMeasurement = SensorValue YourFlywheelEncoderOrIME ];
wait1Msec(waitTime);
SecondMeasurement = SensorValue YourFlywheelEncoderOrIME ];

ecs = (FirstMeasurement - SecondMeasurement) / waitTime
``````

From this calculated EC/S you can calculate the RPM by
EC/S * 1000 * 60 * GearRatio, you then also ( thanks Jpearman ) divide by the amount of ticks in a rotation for your particular motor config.

( From Jpearmans flywheel velocity controller.
IME Motor: 269 240.448
IME Motor: 393R 261.333
IME Motor: 393S 392
IME Motor: 393T 627.2

``````
float gearRatio = 5;

float calculateRPM(float ecs)
{
return( ecs * 1000 * 60 * gearRatio) /  IMEMotorValue;
}
``````

This will return the RPM, the gear ratio is the

1:gearRatio

so for 1:5 the gear ratio would be 5.

To display on the LCD you will write to the LCD screen using code similar to that found in the robotC sample programs.

``````
bLCDBacklight = true;
string rpm_str;

while(true)
{
// Clear the LCD
clearLCDLine(0);
clearLCDLine(1);

// Calculate the RPM
float RPM = calculateRPM(ecs);

// Display the first part of the screen
displayLCDString(0, 0, "Fly RPM: ");
// Makes the displayed string with your RPM value
sprintf(rpm_str, "%d", RPM);
// Displays the string
displayNextLCDString(rpm_str);

//Dont Hog CPU
wait1Msec(100);
}``````

Good Luck

That will give you encoder_counts/second, you then need to know how many counts per rotation of wherever the encoder is.

(also check the units of velocity below, string or float? )

Yes true, so I adjusted my rpm calculation to divide by the motor ticks per rotation. This should work, right?

Yes, ‘string velocity’ was meant to be ‘string rpm’ which was written to with the RPM value on line 16 of the last code paragraph.

thank you so much! that all makes sense now… Thanks for the help:)