# Setting a motor for a flywheel at constant velocity

I was wondering if there is any way to code a flywheel to remain at a constant velocity. Yes, when it shoots the ball it will lose some speed, but it recovers. However, I find that the motor on the flywheel tends to slightly change velocity, it hovers around the 160-170 range with any number inbetween while it’s just spinning. The code I have written for the flywheel sets the velocity at 167, I just assumed it’s somewhere inbetween the range but at the higher end of the spectrum and I also have it relaying the motor’s current rpm in real time to the controller which is why I can see this happeing. Is there anyway to code such motor to spin at an exact 167 rpm. We use v5 btw. The motors automatically drop voltage if they overheat so I don’t see any reason why I wouldn’t be able to code something like this.

I was thinking something like:

if( flywheel.velocity (velocity: : units, rpm) < 167){
flywheel.setVelocity(167, velocity: : units, rpm)}

This is a very simple example, but I’m not sure if it would work nor have I tested it. Does anyone have any better ideas?

First off, the PID loop running to control the motor should keep the flywheel at the set velocity, so any deviation is either mechanical in nature, such as a bent axle, or intrinsic to the PID loop. If you are confident that the problem isn’t mechanical, then you could mess around with the PID values to try to create a closer oscillation around the target velocity, but I have never done this myself so there might be unexpected consequences. I don’t have much experience with how the new V5 motors work though, so I could be incorrect.

All axels are straight and there is minimal friction but I can try lithium grease to be sure. All axels are running through flat bearings that I made sure were perfectly aligned so the axels have smooth rotations. The gears are making full contact, I haven’t seen any of them skip. When I hand spin the flywheel, it spins for 3-4 seconds. I doubt it’s a friction issue. The axel on the wheel could be slightly bent though because of the force the ball exerts on the wheel but it’s not noticeably bent. I could double check though. I checked on the devices menu of the brain and ran the flywheel through there and for some reason the range of oscillation is much smaller than the range on the flywheel when I run my code. Is there not a way to ensure it remains at an exact velocity though? I rather it not oscillate at all.

When the flywheel is spinning at full speed, does the wheel’s axle look like it is vibrating back and forth, or does it look straight? If it looks like it is vibrating, then the axle is bent slightly. Adding some lube should help a bit. Our flywheel was doing the same thing but getting a straight axle and adding grease decreased the oscillations dramatically.

It looks pretty straight to me. It might be some friction point that I’m not aware of and a slightly bent axle. Regardless, is there not a way to code it to be exact?