Flywheel velocity control

That sounds like a bad encoder, but that would result in a constant velocity of 0, rather than the divide by zero issue. Also, you don’t need to use RPM, so you don’t need to convert from ticks to revolutions. We just use ticks/second at 50 ms intervals.
By delaying the task, you also stabilize your velocity calculation. I saw a few nice graphs of filtered and unfiltered encoder velocities at different intervals. My team uses a 50 ms interval in ours, and there’s no reason to go under 20 ms, which is how frequently the motors update.

At this point I am completely stumped. The divide by zero exception just randomly stopped, it had nothing to do with my ticks so it was delta_ms but it just stopped. Then, adjusting the target value simply doesn’t modify anything, motor_drive isn’t being set.

Here’s my complete code to peruse, any help would be greatly appreciated!

EDIT: Fixed it, literally what I said it was, me not setting motor_drive. Just love it when you miss lines? Thanks for all the help guys!

One more problem now, basically the flywheel ramps up, spins perfectly fine for a bit and then the values just drop and the motors begin to jiggle, making clicking noises. Before that the flywheel ramps up fine, I tried replacing a motor that was making a copious amount of this clicking noise when the flywheel stopped and then the entire system just began to run slower altogether.

Does the flywheel run at 127, and then after it reaches the RPM, the values drop and the calculated motor speed keeps on changing drastically?