Sunteți pe pagina 1din 20

Embedded Control Project

-Iterative learning control for

Author : Axel Andersson


Hariprasad Govindharajan
Shahrzad Khodayari
Project Guide : Alexander Medvedev
Program : “Embedded Systems” and
“Engineering Physics”
Course : Embedded Control System
Date : 2012-04-25

1
Contents
1 Introduction ......................................................................................................................... 3
2 Theory Description .............................................................................................................. 3
2.1 PID Controller .............................................................................................................. 3
2.2 ILC controller ............................................................................................................... 3
2.3 Architecture [1] ............................................................................................................ 4
3 Implementation .................................................................................................................... 5
3.1 PID Controller .............................................................................................................. 5
3.2 ILC controller ............................................................................................................... 5
3.3 Communication between LEGO and PC ....................................................................... 6
4 Modeling and simulation ..................................................................................................... 7
4.1 Purpose and goal........................................................................................................... 7
4.2 Modeling the robot [2] .................................................................................................. 8
4.2.1 GR(s) ..................................................................................................................... 9
4.2.2 Gx,y(s) ................................................................................................................ 10
4.3 Modeling the ILC ....................................................................................................... 11
4.4 Simulation results ....................................................................................................... 12
5 Discussion and conclusions ................................................................................................ 14
Appendix: Codes ...................................................................................................................... 16
References ................................................................................................................................ 20

2
1 Introduction
An autonomous racing car runs laps on a track using a simple controller. Both the lap time and
the mean deviation from the track are taken into account in evaluating the racer performance.
Find a way of improving the car control from one lap to another by utilizing so-called iterative
learning control, ILC, a method typically exploited in control of repetitive movements [1].

2 Theory Description
In order to control a car tracking the line, a simple PID controller is the first solution. As the goal
is to improve the tracking by taking the advantage of the repetitive nature of close-loop track,
ILC is one way of compensating the repetitive part of the error.

2.1 PID Controller

PID stands for Proportional Integral Derivative controller. It is the most common feedback
controller used in industrial systems. As the name suggests, there are three constant parameters
need to be calculated for the PID controller. The final form of the PID controller is

u(t)=Kpe(t)+Ki∫ ( )dt+Kd *de(t)/dt

Where u(t) is the final output of the system, Kp is the proportional gain, Ki is the integral gain

Kd is the derivative gain, e is the error = SP-PV and t is the time.

2.2 ILC controller

The concept of ILC is inspired by human learning and has its origin in industrial robot
applications where the same task is performed repeatedly. It is then a sound idea to try to
improve the performance, using information of how the task was performed in previous
repetitions by adding a correction signal to the system. The key problem in ILC is what type of
algorithm to use for generation of the correction input signal, which should result in a smaller
error in some norm.

The simplest formulation of ILC may be:

( , )= ( , − 1) + ( , − 1)

The inputs in the current batch are determined by the inputs of the previous batch plus the
proportional contribution of tracking error in the previous batch, where is the learning gain
matrix.

3
2.3 Architecture [1]

ILC can be combined with a feedback loop in serial, figure 1. It means the ILC control input is
applied to the reference before the feedback loop for the situation that it is not allowed to modify
directly the control signal. However, in the case that the individual control contributions from the
ILC and feedback controller should be easily separable, ILC can be parallel with PID. The
feedback controller modifies the input/output dynamics with regard to the ILC depending on the
particular arrangement, figure 2.

Figure 1. Serial architecture

Figure 2. Parallel architecture

where j is the iteration index, yj is the output, uj is the control input, yd the desired system
output.

4
3 Implementation
ILC uses open-loop control action only, which cannot compensate for non repeating
disturbances. Thus, in most physical implementations, a well-designed feedback controller must
be used in combination with ILC. In many cases, a feedback controller already exists on the
system, and ILC can be implemented without modifying the feedback controller.

The architecture implemented in our project is parallel architecture where the ILC directly alters
the control signal, which is made by a PID controller, to the plant.

There are three main components in order to have a complete system, PID controller, ILC
controller and communication modules.

3.1.1 PID Controller


In our project we have implmented the PID controller along with a LEGO Mindstorms kit which
will follow the middle of the predefined track. To set the PID controller we start with the P
pararmeter. The light sensor reading from the middle of the track is measured first. We
determine the value of Kp by trial and error method. The proportional gain, which is a constant
Kp is multiplied with the error value e(t).

Care must be taken while tuning the initial Kp value. Because, if the Kp is too high then the
system becomes unstable. Also the controller becomes less sensitive when Kp is very low.

Once, the Kp is tund next our focus is on the Ki, the integral gain which is also a constant. In a
PID controller, the integral denotes the sum of instantaneous error over the time t, and gives the
accumulated offset which should have been corrected previously. The accumulated error is then
multiplied with the Ki.

And once again when tuning the Ki, if Ki is set very high then the stability of the system is
affected along with increase in steady state error and a decrease in stability.

The third parameter, Kd the derivative gain is multiplied with the slope of the error over time.
This term will slow the rate of change of contorller output. Also, the magnitude of the overshoot
produced by the integral component is reduced and the process stability is improved

3.1.2 ILC controller


For practical implementation of ILC algorithms, it involves computer-based controllers operating
in discrete time together with digital storage of the information. Thus, it is natural to consider
discrete-time ILC algorithms applied to systems operating in finite time.

The first issue was how to keep track of one lap. It is handled by marking the start point on the
track. In the first lap, only PID works and all the errors of sampling points are stored in the
memory. Then on the later laps, the ILC changes the control signal based on the value of the

5
same point (approximately) in the previous lap. ILC module contains three elements, memory, L-
function, and Q-filter function.

Figure 3. ILC block diagram

L function is a PD controller and Q filter is a linear-phase low-pass filter. There are two gains, a0
and a1, for Q-filter which are tuned in the lab based on the rule 2a1+a0 = 1.

While ILC alters the input control signal, the error is calculated and then it is saved in the
memory in order to measure the derivation for the next point of the same lap by PID and next lap
by ILC.

3.1.3 Communication between LEGO and PC


In our ILC project, we have three parameters of our concern. The deviation of the robot from
middle of the track, speed of the robot and time it takes to complete each lap. For measuring the
deviation from the middle of the track, and send the measurement to the PC, three different ways
are possible in RobotC.

First is using Bluetooth communication, second is through creating a file inside the LEGO and
writing the deviation values in the file and sending the file through BT or reading the file through
file management utility provided by RobotC. The third option is to use Datalogs.BT
communication is very slow and hence it is not tried here. In the second method, creating the
files were successful but writing to te files was not successful. So, we decided to settle with thr
Datalogs.

The RobotC provides the neccessary APIs for Datalogs. The protocol is to first

Save the desired value using the API AddToDatalog(); and then call the API savenxtdatalog(); .
In our PID code, we need to store the deviation from the middle of the track, ie the variable ’e‘ in
the datalog. The API savenxtdatalog() will save the existing datalog from RAM memory into a
NXT file named DATAnnnn.rdt.

The datalogs can be uploaded in to the PC through the file management utility feature provided
in the RobotC IDE. We can upload the files as a spreadsheet which can be later opened through a
openoffice calc tool. In the sample file provided along with the report, the column “I“ has to be
verified for the deviation from the middle of the track.

6
When tried with ILC, the datalogs were not completely successful. Since the in built delays in
the robotc APIs are unknown, the line follower did not run on the track after 2 or 3 laps and the
datalogs were also not created. The code for the PID controller along with the datalog and the
datalog values stored in the spreadsheet are attached along with this project report.

3.2 Result of implementation


The result of implementation was good and showed in table 1. We had 53% progress after 28
iterations. We tried ILC with and without Q filtering and it is observed that filtering had around
6% better result

Max error(mm) RMS error(mm)


Without ILC only PID 12.5 6.9
With ILC without filter 10.0 3.7
With ILC with Q filter 10.8 3.2
Reduction ~20% ~53%
Table 1. Implementation result

The parameters of the PID controller were:

P = 1 I = 0.002 D = 0.001

In addition, the L function parameters were:

P = 0.05 I=0 D = 0.001

The sampling time for both ILC and PID was 20 Millisecond. Filtering gains were:

a0 = 0.9 a1 = 0.05

4 Modeling and simulation


4.1 Purpose and goal

Simulations of control systems can provide good insight in how the real life system behaves.
Models of real life systems can be used for example when it is too time consuming to do real test
runs, or too costly. In our case, the goal of the simulation was to give us some kind of pointer in
what to expect from the real runs. Since no records were found of anyone trying to implement
ILC on a Lego robot, we had no idea what to expect.

In order to do this, a model representing our robot had to be derived and implemented in
Simulink along with the other components that make up the complete control loop. Furthermore,
the actual ILC had to be implemented as well.

7
4.2 Modeling the robot [2]

Figure 4. The robot

Figure 4 shows a simplified drawing of the robot. The wheels are connected to two motors.
These motors can act independently of each other. The movement of the car is decided by the
voltage applied to these motors. In our robot, the voltages to each motor is given by

= +∆u/2 (1)

= −∆u/2 (2)

where is a constant offset voltage that gives the car its forward motion and ∆u is a differential
voltage that controls the steering. ∆u is the input to the system. The output of the system is the x
and y position of the car.

Figure 5. Block diagram of the robot model.

Figure 5 shows how the block diagram of the model. From the input ∆u to the output x and y.

8
4.2.1 GR(s)

The following equations are given by the laws of mechanics.


= φ̈ (3)

=( − ) (4)
,
, = (5)

φ= (6)

where

- torque

, - torque on right and left wheel

, - force on right and left wheel

, - rotation angle of right and left wheel


– moment of inertia for the robot around center of rotation
Equation 3, 4 and 5 gives

( − ) = φ̈ (7)

A model that takes care of the effects caused by the DC motor is needed. The total torque exerted
by the motor is proportional to the input voltage, = ( − ) . This torque contains 3
parts. One part is needed to accelerate the wheel, = ̈ − ̈ . The second part is to
compensate for the emf of the motor, this is proportional to the angular velocity of the wheel,
= ̇ − ̇ . The rest of the torque will act on the load, rotating the robot. This gives the
equation

= + + (8)

<=> = ( − )− ̈ − ̈ − ̇ − ̇ (9)

Inserting 9 into 7, this gives the equation

φ̈ = ( − )− ̇ − ̇ − ̈ − ̈ (9)

which can be rearranged, using equation 6 and − = ∆u to give

φ̈ = ∆ − φ̇ − φ̈ (10)

9
<=> + φ̈ = − φ̇ + ∆ (11)

This is a second order differential equation that shows the relationship between input ∆ and
output φ(t). From now on, the input will simply be called u. Using the Laplace transform on
equation 11 gives the equation

Ф( ) = ( )
( ) (12)

Where

∆ 1
= , = ( + )
2 2

It's clear from equation 12 that the transfer function from u to phi is

( )= (13)
( )

K and T need to be identified using system identification techniques. A MATLAB-file was


provided for exactly this problem in a lab in a prior course. Using this, the values of K and T
were found to be:

K = 0.0255

T = 0.225

4.2.2 Gx,y(s)

Now that a model from u to the angle around the center of rotation has been derived, a model
that deals with the movement in the x-,y-plane with regard to the rotation needs to be derived.
Two equations that do just that are

= ∫ cos ( ) (14)

and

= ∫ sin ( ) (15)

However, these equations do not fully relate to the control problem at hand. Since the robot does
not measure its position at the center of rotation, these equations need to be expanded. The
position of the sensor is at a distance L from the center of rotation in the direction of the angle.
This adds a second term to equations 14 and 15, making the complete expressions from φ to x
and y:

10
= ∫ cos ( ) + ( ) (16)

= ∫ sin ( ) + ( ) (17)

The simulation of the robot will take place in a discrete time environment. Because of this, there
is no reason to derive a transfer function. Equations like 16 and 17 are easily implemented in
discrete time.

The only thing left is to find v and L. L is simply a set value, this is the length from the center of
rotation to the sensor. This was measured with a ruler to be 0.15 m. The velocity is proportional
to the offset voltage . This needs to be variable in order to test different settings, so no value
was set.

4.3 Modeling the ILC

Figure 6. Overview of the Simulink-model

Figure 6 shows an overview of all the different blocks making up the entire model with the ILC
within the gray box. The System block contains the discrete model of the robot as derived in the
previous section, taking a voltage u as input and gives the x- and y-coordinates of the robot as
output. The Controller block is a simple PID-controller.

Track is a function that calculates the deviation from the track. The track itself is specified as a
vector containing x- and y-coordinates of several points. The function compares the coordinates
of the car and scans the vector for the closest point of the track. The distance between these
coordinates is the deviation e. Using these coordinates and comparing to the origin, one can find
whether the car is to the left or the right of the track. This does not work for all tracks, but it

11
works for our oval-shaped track and tracks with similar symmetry. The downside to using this
type of comparison and using a track made up of points is that e gets noisy.

Counter is a counter that resets each time the robot passes a certain point on the track. This is
needed to define the iterations. Passing a certain point of the track means a new iteration has
started. Because of the symmetry of the track, it was simple to use the x-coordinate as reference.
When the car passes the y-axis, from either side, a new iteration starts. This actually splits the lap
up in two iterations. This is not a problem because the track is symmetrical; the two halves are
exactly the same. Instead it brings a big benefit, the ILC will converge (or blow up) twice as fast.

Memory stores all the values from the previous iteration. In this case, it is the robot’s deviation
from the track and the output of the ILC. It uses the output from Counter to keep track which
sample to use for the ILC

L-function is a simple PID controller with I = 0

Q-filter is a linear-phase low-pass filter.

4.4 Simulation results

In all simulations, the parameters of the PID controller were:

P = 2000 I = 100 D = 800

These settings provide reasonably good tracking abilities without being too aggressive. The Q-
filter coefficients used for all simulations were

= 0.1 = 0.8 = 0.1

The velocity v was set to 0.1366. It made the car finish a lap in about 18 seconds, a speed that
seemed realistic that the robot would use. Using different sample times didn’t seem to make any
difference, as long as the system was stable. For these runs, a sample time of 0.01s was used.

12
Figure 7. RMS-error for different values of the ILC parameters

Figure 7 shows how the RMS error changes over the iterations. It can be seen that the error is
greatly reduced when using ILC, compared to the case with no ILC. With ILC values of P =
1000 and D = 500, the error is reduced from 4.2 mm to 0.19 mm, a decrease of about 95%. It
also converges quickly; it takes about 8 iterations for it to settle. As expected, if the ILC values
are set too high, the error will increase instead of decrease. This will eventually lead to the car
running off-track.

13
Figure 8. Maximum error for different values of the ILC

Figure 8 shows how the maximum error changes over time. As expected, this is fairly similar to
the RMS-error case. Using ILC values of P = 1000 and D = 500 reduces the max error from 7.2
mm to 0.59 mm, a decrease of about 92%.

5 Discussion and conclusions


The goal of this simulation was to figure out whether our implementation will have any chance
of working at all. Judging by these results it seems like it has. Keep in mind that this is a very
simplified model of the robot; it doesn’t contain any noise or constraints (other than the noise
produced by the resolution of the track).

The biggest problem we ran into was that using the MATLAB function c2d on the transfer
function GR(s) did not seem to work. The system went unstable using the discrete function this
function produced. Instead, the continuous transfer function G(s) was inserted in the discrete
Simulink model and it worked without any problems

Other than providing concrete results, these simulations have provided a deeper knowledge in
MATLAB Simulink and modeling in general.

14
In the implementation, it is observed that as the ILC converges, the feedback controller applies
less effort.

Although the real word result was not the same as simulation’s, which was expected, it shows
that using the ILC could improve the performance in the real environment.

The problems we had during implementation were how to determine the next lap, tuning the PID
and ILC controller parameters in such a way that they both worked and the biggest one was how
to store the data from Lego to pc for analyzing the performance.

15
Appendix: Codes
ILC code

16
17
18
Datalog for PID controller

19
References
[1] A Survey of Iterative Learning Control, Douglas A. Bristow, Marina Tharayil,

and Andrew G. Alleyne, IEEE Control Systems Magazine 2006.

[2] Introduction to computer based control systems, Process lab 2 Department of Systems and
control, Uppsala University

20

S-ar putea să vă placă și