# Using genetic algorithm for tuning controllers

I've read some papers for controlling nonlinear systems (e.g. nonlinear pendulum). There are several approaches for targeting nonlinear systems. The most common ones are feedback linearizaing, backstepping, and sliding mode controllers.

In my case, I've done the theoretical and practical parts of controlling nonlinear model of a simple pendulum plus other manipulators problems in C++. For the pendulum, I've utilized a backstepping controller for solving the tracking task for the angular displacement and velocity. The results are

$$\ddot{\theta} + (k/m) \dot{\theta} + (g/L) \sin\theta= u$$

where $m=0.5, k=0.0001, L=.2$ and $g=9.81$.

The results are good. However, tuning the controller is time consuming. The majority of papers use genetic algorithms for tuning their controllers such as PD, PID, and backstepping controllers. I'm clueless in this field and I hope someone sheds some light on this concept, preferable if there is a MATLAB sample for at least controlling a simple pendulum.

So far I've designed a simple GUI in C++/Qt in order to tune the controller manually. In the below picture, the response of the controller for step function.

## 3 Answers

Using evolutionary methods (GA is one of them) for parameter tuning is indeed a common method [1] in the control domain. Especially for non-linear systems, the analytic solutions for optimal parameters can be difficult to find. Evolutionary methods are one way to efficiently perform a search for near-optimal parameters.

A very successful and universal method that is widely used is CMA-ES. There are a large number of implementations out there, including for MATLAB. I know that pole balancing in its various forms is often used as a benchmark.

Applying the algorithm is usually not that difficult. Rating the performance of your result - this is called the fitness function in EA - is usually the most involved part.

[1] P.J Fleming, R.C Purshouse, Evolutionary algorithms in control systems engineering: a survey, Control Engineering Practice, Volume 10, Issue 11, November 2002, Pages 1223-1241, ISSN 0967-0661, http://dx.doi.org/10.1016/S0967-0661(02)00081-3.

• Have you came across any good book you think it is worth reading about GA? – CroCo Mar 24 '18 at 6:25

Genetic algorithms are a machine learning technique to remove the need for a user to 'fine tune' a system, and instead allow a computer to figure out how to tune the system. The benefits of this approach are that it frees up the researchers/users time and often can lead to a system that is tuned better than what the researcher/user would have been able to achieve themselves.

The general idea of using a genetic algorithm would follow some basic control flow as follow:

Create_X_Number_Of_Random_Controllers()
while (Not_Yet_Satisfied_With_tuning)
Score_Each_Controller_Based_On_Performance()
Remove_Lowest_Performing_Controllers()
Create_New_Controllers_By_Mixing_Best_Performers()
Add_Slight_Randomness_For_Evolution()
Display_Top_Performer()


The best example I can easily show of this principle in practice is this 'game' that uses genetic evolution to design vehicles that are capable of driving over a course. The same idea applies to any system you want to fine tune without having to actual do any tuning yourself. Example: http://rednuht.org/genetic_cars_2/

• If that is what @CroCo meant by using a genetic algorithm, then the Ziegler Nichols method of tuning would be a great candidate for implementing, because it is nicely procedural. – SteveO Feb 15 '16 at 16:31
• I can't see what else @CroCo would have meant, but the problem with Ziegler Nichols is it still requires you to tune one of the components where as with a genetic algo you can change any aspect of the system and it will 'evolve' to match without the developer having to do any brute work – beeedy Feb 15 '16 at 18:10
• This answer still stands as the general process to achieve that. Genetic Algorithms are an entire area of study and far to complex however to really explain in a short response, I recommend reading up on them however if you are interested in using them to tune your models! – beeedy Feb 16 '16 at 0:13
• I'm picturing an ill bounded genetic algorithm that quite happily snaps the string when over tuning. – Ramrod Feb 16 '16 at 5:31
• as @octopus mentioned, this is hard to achieve with actual physics equipment unless you are willing to allow a long period of time to let the computer physically control the device you are trying to tune, even then you need some 'guardian' program that monitors and scores each controller based on performance and verifies that it isn't going to damage the machine. All in all this is relatively complex task that will take a lot of reading on genetic algorithms to implement, this is no small task. – beeedy Feb 17 '16 at 22:50

I am confused by what you are calling a genetic algorithm. The PD, PID, etc., controllers are not heuristic nor stochastic methods, and they are not based on evolutionary algorithms. They are, instead, deterministic algorithms intended to allow placement of poles and zeroes of a system response to provide desired performance (error minimization, speed of response, settling time, stability, and disturbance rejection). A good learning reference, in my opinion, is Kuo's Automatic Control Systems book. You can find a less rigorous treatment in Raven's Automatic Control Engineering book.

• I'm not acquainted with the genetic algorithm (GA). I just saw some papers claim that the tuning part of their controllers done by using GA. No further details in their papers regarding this matter. I don't know what the hell GA is and how can I utilize it. – CroCo Feb 17 '16 at 0:07
• Using evolutionary methods for parameter tuning is a very common technique. I would consider it an alternative method to the analytical approaches you are describing. – Jakob Feb 19 '16 at 8:40