PID Position Control Tuning With a Robot

A while back when I was working on tuning the control loops for the expressive degrees of freedom of our robot I thought I’d make a video showing a more fun example of classical controls tuning when you don’t know your system than what I typically see in classrooms.

For this, I’m using a DC motor as an actuator, hall effect quadrature encoder for position sensing, ROS with rqt_plot to visualize the position input and output, dynamic reconfigure to change the control gains, and have a few python scripts to generate and publish reference trajectories.

Step Response

I begin by just publishing a reference step function between 0 and 600 encoder ticks and start twiddling control gains! I’m doing this as quickly as I can to illustrate that you can tune things without actually looking at time domain step response parameters like rise time, settling time, etc.

PID Tuning Via Step Response

Note: at 3:27 I mispoke and say “proportional term” when I actually meant “integral term”.

Frequency Response

After first tuning my gains via visual inspection from a step response, I move on to a frequency response to illustrate what tracking of a varying frequency sinusoidal position input looks like.

The basic thing that I’m trying to convey to students is that the rise time and overshoot from our step response can in a way be translated to our frequency response. When the inverse of the frequency is faster than our rise time, we begin to see that the magnitude of our frequency response decreases. When the inverse of the frequency is at about the time that we see an overshoot in step response we begin to see the beginning of a resonant peak in our frequency response.

Frequency Response

Putting It All Together

I’m just kidding, this is me goofing off, but system dynamics and controls don’t need be dry and boring! Ignore the commentary, we were delirious from working long hours.

Permanent Magnet Encoder Disc Magnetic Field Strength Analysis

OK. This one was SUPER annoying to debug, but basically what was happening is the controls for some D.O.F.s of a previous product looked really bad, almost like we were missing encoder ticks. Looking at the position control loop, it certainly looked like we were missing ticks, but where did they go?

Since we were using ROS for trajectory generation I basically worked my way from that level down, figuring that computational burden was just causing us to not be able to keep up with things in real time. After working ALL THE WAY THROUGH the software side and concluding everything looked fine, I had to turn to the motors and encoders themselves. Now, unbeknownst to me, we had just changed the model of the magnetic disc we were using as an encoder (paired with a hall effect sensor). With almost everything else tested, I resolved to test the magnetic (B) field strength of the magnetic discs.

Experimental Setup

Magnetic field strength of the permanent magnet encoder discs were characterized as a function of angular position using a quadrature encoder and digital Gaussmeter. Discs were mounted via very small 3D printed couplers to a Koyo TRD-MX1024BD quadrature encoder to measure angular position, while B field strength was measured with an F.W. Bell 5180 Gauss meter. The disc was then rotated by hand while the Gauss meter probe was fixtured so that it was in contact with the disc surface. Data was collected with a Saleae pro 16 logic analyzer. The encoder was powered with 12 v from a benchtop power supply, and outputs of the A, B, and Z channels were pulled up to 5v via a 1.5k ohm pullup resistor.

After data collection, data sets were analyzed by python scripts that extracted one full revolution of B-field strength and angular position, matched the angular position in 0.1 degree intervals using a binary search tree, filtered the data, extracted local extrema, and carried out statistical analysis on the identified positive and negative magnetic poles. The test apparatus is shown below, without the rigid fixture between encoder and Gauss meter. Data collect showing A, B, Z channels of the encoder and B field strength from the Gauss meter are shown on the screen.

Output Plots and Analysis

Let’s begin by looking at some of the magnetic discs that we used in the past that have not given us any trouble.

Good Magnetic Disc

POSITIVE POLES:
Angular differences between positive magnetic poles (degrees): 
[ 29.1796875   29.35546875  30.9375      31.81640625  30.76171875
 30.5859375   29.53125     31.81640625  31.55273438  26.015625
 27.59765625]

Magnitude differences between positive magnetic poles (Gauss): 
[ -31.06543128  -37.91607879   48.9585365   -13.01091485   55.52667332
 -25.77534475  139.50712186 -107.25554613    1.97638668   73.26621106
 -42.15276701]

Magnitudes of positive magnetic poles (Gauss): 
[ 803.04389588  771.97846459  734.0623858   783.0209223   770.01000745
 825.53668077  799.76133602  939.26845788  832.01291175  833.98929843
 907.2555095   865.10274249]

Standard deviation of difference in angular position of positive magnetic poles (degrees): 1.75035138526

Standard deviation of difference in positive magnetic field strength (Gauss): 65.0042394818

Standard deviation of positive pole magnetic field strength (Gauss): 56.6024562212

Mean magnetic field strength of positive poles (Gauss): 822.086884405

Mean angular displacement between positive magnetic poles (degrees): 29.9227627841


NEGATIVE POLES:
Angular differences between negative magnetic poles (degrees): 
[ 29.70703125  30.05859375  31.20117188  31.55273438  30.76171875
 29.8828125   30.14648438  30.84960938  30.76171875  26.3671875
 27.24609375]

Magnitude differences between negative magnetic poles (Gauss): 
[ 56.61348071 -26.47935011 -17.37341869 -51.85460574  46.539964
 -1.21482977 -78.56630343  45.94343868 -91.39098625  40.87246128
 18.49249138]

Magnitudes of negative magnetic poles (Gauss): 
[-808.25615348 -751.64267277 -778.12202288 -795.49544157 -847.35004731
-800.81008331 -802.02491308 -880.59121651 -834.64777783 -926.03876408
-885.1663028  -866.67381142]

Standard deviation of difference in angular position of negative magnetic poles (degrees): 1.55056517428

Standard deviation of difference in negative magnetic field strength (Gauss): 49.9112757447

Standard deviation of negative pole magnetic field strength (Gauss): 48.8189412974

Mean magnetic field strength of negative poles (Gauss): -831.401600587

Mean angular displacement between negative magnetic poles (degrees): 29.8668323864T

Bad Magnetic Disc

And now, let’s take a look at a representative “bad” magnetic disc.

Woah, it looks like there’s a big difference in B-field strength here…

POSITIVE POLES:
Angular differences between positive magnetic poles (degrees): 
[ 22.41210938  23.37890625  23.203125    22.32421875  22.06054688
 24.08203125  21.62109375  23.37890625  21.88476562  22.93945312
 25.6640625   18.80859375  22.93945312  22.8515625   21.62109375]

Magnitude differences between positive magnetic poles (Gauss): 
[ -47.8981468   -29.24181437  -56.77963869 -104.24687756   16.93935508
 -48.46134758  -28.67192289   81.30195449   22.73229587   80.86085334
  69.16778126   -1.74263368   87.44192205   -1.72612453    5.0340433 ]

Magnitudes of positive magnetic poles (Gauss): 
[ 480.6194911   432.7213443   403.47952994  346.69989124  242.45301368
 259.39236876  210.93102118  182.25909829  263.56105278  286.29334864
 367.15420199  436.32198325  434.57934957  522.02127162  520.29514709
 525.32919039]

Standard deviation of difference in angular position of positive magnetic poles (degrees): 1.42966348597

Standard deviation of difference in positive magnetic field strength (Gauss): 55.7923451036

Standard deviation of positive pole magnetic field strength (Gauss): 112.811684507

Mean magnetic field strength of positive poles (Gauss): 369.631956489

Mean angular displacement between positive magnetic poles (degrees): 22.611328125


NEGATIVE POLES:
Angular differences between negative magnetic poles (degrees): 
[ 23.203125    23.11523438  23.29101562  22.93945312  21.4453125
 23.5546875   23.02734375  22.58789062  22.06054688  22.32421875
 23.11523438  23.29101562  21.26953125  20.7421875   24.43359375]

Magnitude differences between negative magnetic poles (Gauss): 
[ -31.87032808   61.11857653   16.26178864  122.02554834    2.7446541
  80.43354251  -28.80379618   72.50021235  -75.90017174  -51.9568724
 -61.59044252  -43.34832509  -25.8054608   -36.74159058  -54.81136214]

Magnitudes of negative magnetic poles (Gauss): 
[-521.8299272  -553.70025528 -492.58167875 -476.31989011 -354.29434177
-351.54968767 -271.11614517 -299.91994134 -227.41972899 -303.31990073
-355.27677313 -416.86721565 -460.21554074 -486.02100154 -522.76259212
-577.57395426]

Standard deviation of difference in angular position of negative magnetic poles (degrees): 0.938524830477

Standard deviation of difference in negative magnetic field strength (Gauss): 58.5461130337

Standard deviation of negative pole magnetic field strength (Gauss): 105.59001526

Mean magnetic field strength of negative poles (Gauss): -416.923035904

Mean angular displacement between negative magnetic poles (degrees): 22.693359375

Indeed, upon further verification we were missing that low B-field magnitude tick.

Conclusions

After repeating the tests on 15 magnetic wheels from each class, it was determined that all of the new, supposedly better, magnetic wheels were causing us to miss ticks due to their very non-uniform B-field strength.

The amount of time that it took to debug this was a VERY annoying setback for the control systems, one that I have not had to deal with before. With this discovery there was quite a bit of back and forth with the vendor, to say the least. Ultimately, due to timeline compression, we had to proceed using the same vendor, but used the “old” discs as they appeared to have better quality control.