Calculating RPM on FlyWheel

My team is trying to figure out in autonomous when to run our conveyor belt based on if the flywheel is at the top speed, but we are not sure how to calculate the rpm based on the IME’S recordings. Could Someone Please Give me some sample code or a demonstration on how to do so.

9364F- Team Captain

task velocity()
{
	// This task determines the current velocity of the shooter wheels
	float L = 0;


	float circ = 5*3.1415926535;//finds the circumfrence of the wheel
	while(true)
	{


	L = (nMotorEncoder[I2C_2]+ nMotorEncoder[I2C_3])/2; // how would i do this with ime's

		velocityIn =  (circ/12)*(L/392)*50*21; // determines how far the wheels spun in last 20 MS and converts it to FPS
		velocity =  L*50*25;
		clearLCDLine(0);
		clearLCDLine(1);



		SensorValue[I2C_2] = SensorValue[I2C_3] = 0;
		wait1Msec(20);
	}
}




here is a code example for a shooter using 2 IME’s on motors to power a one wheel shooter, the motors are speed motors, and they are geared 25 to one to the shooter wheel

how would i code one for a two wheels shooter with a 87-17 gear ratio?

If your flywheels are mechanically linked, then you only need to calculate the velocity for one side, as they must be the same. Otherwise, use two velocities (and perhaps compare them to make sure they are at least close). Here’s some pseudocode:


task velCalc() {

  infinite loop {

    leftVelocity = leftEncoder - leftEncoderLast
    rightVelocity = rightEncoder - rightEncoderLast

    leftEncoderLast = leftEncoder
    rightEncoderLast = rightEncoder

  }
}

This gives you the rotational velocities of each flywheel. The gear ratio then scales this value by (input/output). the gear ratio must be a decimal, and you might as well declare it as a constant, unless you have a transmission on your flywheel. It looks like this:


leftFlyVelocity = leftVelocity * gearRatio
rightFlyVelocity = rightVelocity * gearRatio

Here are some threads with similar questions that you might be interested in:
https://vexforum.com/t/calculate-rpm-for-flywheel/30292/1
(A simple example of a motor speed calculation)
https://vexforum.com/t/flywheel-velocity-control/29892/1
(jpearmans post, scroll down to post #4 (although its a good read) for some robotc code using the TBH algorithm)

What exactly do all those factors mean? and btw we have an 87-12 gear ratio to get that right. And are those factors for a certain wheel . For details. We have a 87-12 gear ratio a dual flywheel with 5’ wheels with two motors per wheel and two 87 turning a 12 on each wheel and each 87 being turned by a highspeed motor. I am really trying to make this right so if you could provide some reasoning behind the math for an engineering notebook page that would be great.

  • 9364F Head Programmer

Firstly, are you sure your not using 84 tooth gears? That would make your gear ratio 7:1 http://www.vexrobotics.com/media/catalog/product/cache/11/image/5e06319eda06f020e43594a9c230972d/f/i/file_73.jpg *84 tooth gear

Anyway, to calculate the RPM of a flywheel, you first must figure out how fast the motor attached to a flywheel is moving. You can do that by taking an IME reading, waiting, then taking another IME reading. Then to get the ticks per milisecond you take the last IME reading, minus the first IME reading, then divide by the time. You then times by 7 to get the flywheel ticks p/s and finally times by 60 and divide by a motors full rotation (260 - 360) to get the RPM.