# Calculate RPM for flywheel

I was thinking about how to calculate RPM of the flywheel to better control the flywheel. In have an I2C encoder connected onto one of my shooter motors.

The derivative of position is velocity.

What you have to do is say you have x ticks in y time. Then if you divide x by y you get the ticks per unit of time. Then scale from ticks to revs, and seconds to minutes.

30 ticks in .1 seconds 30/.1=300 ticks/second then scale

as you make y smaller, you would get faster response of velocity, but you could lose accuracy do to a smaller tick count over that time.

Because the encoder count constantly increases, I assume the time used to calculate the rpm has to increase as well.

I am stuck as to how to do that. Any ideas?

It depends upon whether you want noisy data that can swing a bit or something a bit more smoothed out. Instantaneous velocity is good but there is a gap of time you need to worry about where velocity could continue to go up and cause overshoots and potentially miss the target.

You could keep a rolling stack of velocities within a period and average or a simple trend on them to ensure you were within an acceptable range for your distance. You may not want to shoot until the velocity evens out versus being a minimum velocity.

If you don’t wait and you start to shoot at that first trip of minimum velocity, you may overshoot. The ball has some additional time before it gets to the wheels - a few tenths of a second possibly. If the velocity has continued upward beyond what you want, your ball will go further than you would like.

But if you put in some settling time and see that the velocity is no longer on a big upward trajectory, you can fire away and know that the tenths of seconds until the ball reaches the shooter wheel is most likely within the velocity range you want it to be.

Is it better to send multiple balls at the goal target in a time period and hope they go in or wait until you have a stable angular velocity of your flywheel? You could end up waiting too long between shots and if the no wait gets you in more times than the waiting time within the match, then shoot away!

Waiting a few milliseconds for settling seems to be the way I would go…

(see James Pearman’s velocity control thread and graphs. See how there is a bit of overshoot and settling time. Will that velocity overshoot cause you to miss?)