Hi,

Last year, in ITZ, there was a head programmer and I didn’t have to do that much coding. This year, I will have to do most of the coding and I was wondering how to measure Kp, Ki and Kd. Last year, the head programmer did all the measuring. Also, how can I make Encoder counts for motors? Is it possible to do it by calculations?

Thank you,

I assume the “encoder counts” you refer to are the number of “counts” (I call them “ticks”) to travel an distance.

Every full turn of the wheel you will move

```
wheel_diameter * PI
```

inches. Depending on whether you use the external red encoder modules or integrated encoder modules, the ticks per revolution of the motor shaft will vary.

The ticks per revolution of each type of encoder are (source):

360 for the red encoders

627.2 for IMEs on a motor with *torque* internal gearing

392 for IMEs on a motor with *speed* internal gearing

261.333 for IMEs on a motor with *turbo* internal gearing

If you are using 4 inch wheels with a high speed motor (with an IME), the number of ticks per inch is

```
392 / ( 4 * PI )
```

.

If you have your drive geared for torque or speed, you will have to multiply the result by the gear ratio (e.g. if the gear ratio is 2:1 speed, the number of ticks per inch is

```
392 / ( 4 * PI ) / 2
```

.

You can do a similar thing to turn the robot on the spot. The number of ticks per degree turned is

```
(wheelBaseDiameter * ticksPerRev) / (360 * wheelSize)
```

where wheelBaseDiameter is the distance between your drive sides.

People say IMEs are unreliable and fail (and/or give incorrect readings) often. In my 3 years using them extensively I have not had any issues and I used them successfully at this year’s Worlds. Using a gyroscope to turn is recommended instead of encoders.

@DarkMatterMatt Thank you so much!

You really don’t “measure” the constants, you just sorta enter them and tune them by looking at a graph of the error over time

This was a helpful resource while I was on a FRC team as a programmer for the last 3 years of highschool. https://www.crossco.com/blog/basics-tuning-pid-loops

Here are 2 articles I wrote that will help with pID coding:

RobotC datalog, so you can see & graph your error & integral values - https://renegaderobotics.org/robotc-datalog/

And here’s one on PID resources. I recommend George Guillard ‘s document - https://renegaderobotics.org/pid-resources/

The very end of George’s document gives some mathematical formulas for setting the 3 K constants, which you can do if you use the RobotC datalog feature.