Sunday, August 23, 2015

Paint Flow Control Project, Fuzzy Logic Success, 3.16

Yes, success with the Fuzzy Logic algorithm but no good news on the Project. I expect that the robot equipment is still locked up in a warehouse in southern California. However, I am very pleased that I have been able to get a good solution for the FL algorithm. As I mentioned in my last post, I had three options that I could try:
1) the Li and Lau approach that they outlined in their 1989 IEEE Control System magazine article "Development of Fuzzy Algorithms for Servo Systems" by Y.F. Li and C. C. Lau (Li and Lau),
2) the NeuroFuzzy scheme described in Constantin Von Altrock's book, "NeuroFuzzy Applications Explained" or
3) come up with my own scheme, whatever that might be.

I confess to being a bit skeptical about the NeuroFuzzy idea and figuring that it might take me a long time to get a NeuroFuzzy algorithm to work, I decided to follow Li and Lau's paper. That really paid off, but I have some problems with the details in their paper. Of course, one can't expect perfection in such a paper and after some effort I was able to come up with a solution that should be excellent for the Paint Flow Control Project, providing accurate control of the paint flow or at least a promising approach to the problem. Specifically, my solution is to employ the two stage approach described by Li and Lau, rough control using a Coarse Look-Up-Table (LUT) and finer control with a second LUT, the Fine LUT.

Li and Lau don't provide the FL rules and terms but do provide their Coarse and Fine LUT's along with scaling factors to be used with the LUT's. Li and Lau's scaling is for errors up to 1000 and Error Change up to 100. They use a scale of 200 for the Error values for the Coarse LUT. That is, for an error of 1000, the Quantized Level as input to the Coarse LUT is 5. The scale for the Error Change for the Coarse LUT is 20. For the Fine LUT, they use a scale of 20 for the Error and a scale of 15 for the Error Change. Then after the scale factors are applied to the Error and Error Change values, the output control value is read from the LUT. The Coarse LUT is used for Errors > 100 and then for smaller Errors, they switch to the Fine LUT to home in on the Setpoint. It seemed a bit strange that the full-scale Error value is apparently 1000 but their simulation example uses a Setpoint of only 20. Of course the Error signal would be scaled but Li and Lau's simulation example was for a Setpoint of 20 and they don't provide scaling info for that simulation example. For my simulation tests, I left the full-scale at 1000 and did simulations with Setpoints of 100, 200, 500 and 1000. For the paint flow, I will necessarily adjust the scaling factors to match up with the expected paint flow range.

Li and Lau show terrific results in their simulation but I am skeptical that their Coarse LUT could have been used to get those results as my simulations using their LUT's showed very poor results. Of course, my simulation code could be at fault but their Coarse LUT appears to be inadequate as I'll describe below.

I am continuing to use Python to simulate the FL design. I considerably modified my previous code to more closely conform to Li and Lau's two-stage scheme as previously I was using only a single-stage LUT. However as I said, I found their Coarse LUT to be inadequate. At first I thought I had some problems with my Python code but then a closer look at their Coarse LUT showed the problem. Anyhow, below is a graph from my Python code with Li and Lau's Coarse and Fine LUT's. The simulation shows that the Li and Lau LUTs are completely inadequate, showing and error of 200 to 300 points. That indicated to me that their Coarse LUT was too flat near zero error, resulting in no response until the error reached greater than 200. Note in the chart below that for a Setpoint of 200, the Li and Lau simulation didn't even get off the ground, staying at zero. And for a Setpoint of 500, the simulation value rose to only about 200. For a Setpoint of 1000, the simulation rose to only about 700. The Fine LUT only kicks in when the Error drops below 100 and so with the error from Setpoint of around 300, the Fine LUT was never utilized. The problem with the Li and Lau paper and simulation points clearly to their Coarse LUT.

The chart below is my simulation of the Li and Lau Coarse and Fine LUTs. The green trace in the chart is the Setpoint that I stepped to 200, 500, 1000, back down to 500 and then finally to 200. The control output trace is red and the trace for the resulting output is blue but the red and blue traces are overlapped, resulting in a purplish trace.

Simulation of Li and Lau Fuzzy Logic LUT's.
Below is their Coarse LUT, and I'm pretty sure that the problem with the LUT is the spread of 0's for the Error positions in the center of the LUT. That wide spread of 0's would certainly cause a serious dead spot or deadband in the controller's response as I saw in my simulations.

Li and Lau Coarse LUT
I realized that I would have to revise the Coarse LUT in order to decrease the deadband. However, Li and Lau didn't provide FL rules and terms that would allow me to apply the Octave Fuzzy Logic analysis program, so I decided to use the "seat of the pants" technique to adjust the values in the LUT, sculpting it in order to tighten up the center and also to increase the slope along the Error axis of the LUT chart.

Here is my Coarse LUT, revised from Li and Lau's Coarse LUT. You can see that the center of the LUT is tightened up quite a bit and there's considerably more slope in the Error axis. Also my Coarse LUT is somewhat symmetrical around a line from corner to corner, not necessary of course, but I think more pleasing to the eye than the shape of the Li and Lau LUT.


The resulting simulated response with my Coarse LUT is much better than the response that resulted from using Li and Lau's Coarse LUT. The resulting error is less than 100 as desired with the Coarse LUT only, so the fine LUT can be applied to further reduce the error. Note that this simulation GUI has a few more entries, entries for the Time Constant of the system, the Sample Rate (0.25s) and the various scale factors. I did more simulations not shown in this post that clearly indicate that best results are obtained when the Sample Rate is set close to or faster than the system Time Constant. These values of the system Time Constant and the Sample Rate are those used by Li and Lau, as I was trying to duplicate their results. For the Paint Flow Control System, I would adjust the Sample Rate to be less than the system Time Constant. Li and Lau measured their servo system time constant and set the Sampling Rate accordingly. In my simulations, I found that the Sample Rate must be approximately the same as the system Time Constant or less than the system Time Constant, otherwise oscillation will occur. Anyhow, the chart below shows my simulation of their system using their Coarse and Fine LUT. Note the large discrepancy between the Setpoint and the resulting simulated output.

Simulations Using my Coarse LUT.
Li and Lau's Fine LUT is shown below. It also has a dead spot in the center for the Error Change axis. I didn't like the looks of it, particularly because of the dead spot in the center of the LUT. So I went ahead and revised it as well.

Li and Lau's Fine LUT and Chart

My Fine LUT is shown below. You can see that I tightened up the center of the LUT and also made the LUT more symmetrical.


I then replaced both of Li and Lau's LUTs in my Python simulation code and ran a simulation to produce the following response chart. The chart shows a terrific response and far superior accuracy to the Setpoints, resulting in a worse case error of 4% at the lowest Setpoint in the simulation. Normally in actual operation of the Paint Flow Control System, the Setpoint would be near the high end where the simulations showed less than 1% error to the Setpoint . The inclusion of the Fine LUT greatly reduces the error from the Setpoint as can be seen by comparing this chart and the previous chart above.


In general, I am pretty happy with the results but I believe a little more tweaking is in order since in the Coarse simulations the error from the Setpoint is only slightly less than 100. The error from the Setpoint must be less than 100 in order for the Fine LUT to be activated and then the error will be reduced to the 1% level. So I will be looking to see how I can improve the Coarse LUT or possibly simply change the scale factors. Some of my previous LUTs were much smoother than the Coarse LUT that I used in these simulations and I suspect that I can use one of those previous LUTs in place of the Coarse LUT and reduce the error from Setpoint in the simulations to ensure that the error will be less than 100 to ensure that the Fine LUT will be activated. But at least it looks like the solution to the FL control is to use two LUTs as in Li and Lau's paper, a Coarse and a Fine one, and thereby get very good control for the paint flow.

Even though I whined about some discrepancies in their paper, I am indebted to the work by Y.F. Li and C. C. Lau and their very useful and helpful paper in the IEEE Control System magazine, 1989 IEEE Control System magazine article "Development of Fuzzy Algorithms for Servo Systems/" Their work has enabled me to make satisfying progress in developing my Fuzzy Logic algorithm for the Paint Flow Control Project and I won't have to try to develop a NeuroFuzzy algorithm or try to "roll my own."

No comments:

Post a Comment