How to code RPM/PID?

My team is wanting to program our robot so that the launcher speed is determined by the RPM read by a quad opt encoder. This is our first year with RobotC and are still learning so we don’t really know where to start. Reading other forum threads, it sounds like a PID might do the trick but we are unsure of how to program that. We are using 2 motor ports for the launcher and 1 encoder. Can someone help us start this code or provide a sample code?

I posted a bit on how to use builtin PID to control flywheel speed here
https://vexforum.com/t/robotc-has-pid-to-control-your-flywheel/31108/1

It really needs to be used with an IME, however, that may change later today :slight_smile: (depending on where the quad encoder is mounted).

does this mean we can expect integrated PID control for the optical quad encoders sometime soon?

We use TBH based off of Jpearman’s code

here is a tutorial document I made, it is a pretty good guide for making the code you need, the document contains example code for a PID controller, you will need to make the velocity measuring code.

the document starts with a link to a video tutorial I made, I recommend you watch that first, in the comments of that video is the math you need for the velocity code

Yes, but how well it will work is TBD. Because the quad encoder may not be placed on a motor axle and may, for example, be setup to count the wrong way, it will not work as well as an IME, however, there is some support for this in the next release.

I also enabled velocity for the IMEs.


short getMotorVelocity(tMotor nMotor) 

Will return the velocity (in rpm) for a motor equipped with an IME (no quad encoder for this one).

Our team is using a version of Jpearman’s PID code given in his thread. If I am reading that thread correctly, the value you set your motor at is a divisor of the PID function. Before we were uing the PID, we found that with a fully charged battery, our launcher need to shoot at a “power” of 75 to shoot into the high goal. How would I make the PID’s target 75 in RobotC for VEX V4.5? We saw how to do it in Stiers’ document, but he has the PID set up in the written code so I was unsure if this is how to do it.