Application Center - Maplesoft

# Fuzzy controler for reversed pendulum

You can switch back to the summary page by clicking here.

fuzzy.mws

Fuzzy Controler for Reversed Pendulum

Dr.Laczik Blint laczik@goliat.eik.bme.hu

>

```Warning, the name changecoords has been redefined
```

```Warning, the name arrow has been redefined
```

Introduction

Given an initial state for an unstable nonlinear mechanical system of the reversed pendulum. Our purpose is to find a sequence of forces to adjust the system to be in a stable state by inference rules of fuzzy logic .

The differential equation system of the reversed pendulum are derived from Lagrange's formula. From a given non-equilibrical original state by N step we calculate the first linear/angular position and linear/angular velocity of cart and pole. By method of fuzzy logic we first estimate the desired force Q to approximate stabile position of pole.In the following step we observe the movement of the system from the calculated initial conditions and by the force Q.

In fuzzy logic, a fuzzy set A on universe X is defined by the ordered pair (x, ), where x is the object on X, is called the membership function of A.The membership function can be any value in the range of [0,1].

The expression of and rules in the fuzzy logic are the following: Assume the form x is A and y is B. This rule can be defined as a fuzzy set R on the product space X x Y with the associated membership function being

By the all-used symetrical triangular membership functions are for the given value "k" section

and

In different case we must calculate the value of locus of center gravity.

In order to get the value of the objects simultane rules, we need to defuzzify theis membership function. The most frequently used method is the "center of gravity".

The flow-charte of the control system is shown in the next figure.

The input is the state variables of the cart-pole system are y(t), , , , and the output is the desired force Q to be applied. We define 7-7 fuzzy sets for , and Q which are negative/positive large (NL/PL), negative/positive middle (NM/PM), negative/positive small (NS,PS) and zero (Z). Rows of the table of rules "rulm" represent the angular velocity, columns the angular position of pole.

Basics of fuzzy system

For example: if the angular velocity of pole is NS (row index = 3) and the angular position is Z (column index = 4) then the force Q is PS.

>

>

The membership functions of fuzzy controler are the follows:

>

>

>

>

>

>

>

Displaying the membership functions:

>

Mechanical princips

Let the kinetical energy of the system be E, the potential energy U, and the dissipation (D) in the system 0. The generalized variables and their derivates are

y(t) position of the cart

y||1= velocity of the cart

angle between the pole and vertical position

= angular velocity of the pole.

The differential equation of system by the general Lagrange`s formula is

where is the i'th generalized variable of system, is the i'th generalized force applied to the system. The basic equations by M = mass of cart, m = mass of pole, l = length of pole and g = constant of gravity are

>

Expand the derivations by Lagrange's formula

>

>

>

The number of cicles ("ciklusmax"), the initial conditions (xe, xv, , ), mechanical parameters ("parameter") and the number "N" of stpes by RKF45 method:

>

The actual formula of the differential equation system of the reversed pendulum is:

>

Work of the controller

By the working of the controller the program writes the number of observations step, the values of calculated force, the angular position, the angular velociy, the linear position and linear velocity by fuzzy logic calculation.

>

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

```Warning, the 'value' option is deprecated, use 'output' instead
```

Animation of the motion of the reversed pendulum

The animation displayed the controled system.

>

Displaying of the control process

Remark: between values of 0 <= nn < ne <= q - 1 can be displaying any part of control process.

> nn:=0:ne:=q-1:

>

>

>