Velocity Control For Easy C

`Currently my team is seeking help in generating some kind of velocity control for our flywheels. We have looked through out the forum but all that we see is only for Robot C and hardly anything for easy C. We are currently using IMEs on the flywheels motors but we can also use The Shaft encoders. Or if anybody knows how to get the speed of the motors to print to a LCD. all help is appreciated thanks

Sadly I don’t have a copy of easy-c on this computer to show you an example in easy-c so I’m just going to have to tell you at least until tomorrow when I will have a computer that has easy-c to make some sample code, but what you need to do is set the encoder to 0, then get the value of the encoder and assign it to a variable then wait a few hundred ms then subtract the current value of the encoder and divide the time waited and assign it to a variable called velocity of something and finally if you are trying to find rpm multiply by 60,000 to get it to rpm. Hope this helped it may be a little confusing, but on a side note I would switch to RobotC as soon as you can it allows you to do things like this much more easily.

One i calculate RPM, what next? How fo i make it adjust?

I personally would recommend TBH, since it is easier to tune and works just as well, at least in my experience.
To use it, first you set a target velocity. This is whatever speed your flywheel needs to spin at to score from the position you want. Then you subtract the current velocity from the target velocity, and assign this to a variable, called error. Add error to a variable called integral (it is the total error accumulated by the system since the loop began, incremented in each iteration, and so is the area under the velocity curve, which is an integral in calculus). Multiply the integral by an experimentally determined decimal coefficient (usually very, very small), and set the motor power to that.
Once this is done, you need to add in the “TBH” part. Detect a zero crossing (the sign of the current error and last error won’t match, I don’t know an efficient way to do it in EasyC), and when there is a zero crossing, divide the sum of the current motor power and a TBH variable by 2. Assign that value to both the motor power and TBH variables, and assign the value of the current error to a lastError variable.

Attached is the code for a TBH loop. The detection of a zero crossing can be significantly streamlined, but I am not familiar enough with EasyC to do so.