4.3. Simulation
We can execute the experiment similar to experiments from the previous section in a purely simulated form.
We invoke the USB_TCrane_first_model window. Notice two differences. The TCrane real-time driver block has been replaced by the Tower Crane model simulation model block. The External mode of operation has been replaced by the Normal mode of operation (see Fig. 4.38).
The interior of Tower Crane model includes the complete non-linear model described in section 6. After clicking on Tower Crane model the mask given in Fig. 4.39 opens. You can set the initial values of eight variables. The length of the lift line is constant. In our example all initial conditions are set to zero. The Z position set to 0.6 and the last variable t set to -1. Setting t to –1 denotes that the source of time is the RT-CON clock.
If you look under the Tower Crane model mask you can see its interior (Fig. 4.40). modeltcsimple is the executable dll file. The scale factors are set to 1. These parameters relate to identification parameters like friction and tension of the belts.
In opposite to the real-time model it is not necessary to rebuild the model before running. Open Simulation parameters from the menu bar. Notice the solver options:Fixed step and Fixed-step size set to 0.001 in the editable text box. You can start a simulation from the menu bar. When the simulation is running you can watch the results in the scope (see Fig. 4.41). Similarly as in the real time experiment, the data are saved in the scope in the EX structural variable.
Plotting four curves as functions of time (Fig. 4.41) is produced by:
>> plot(EX.time, EX.signals.values)
We perform simulations related to the previous experiments . The parameters of the xw pos PID regulator are set to: P=3, I=0.3. The results are visible in Fig. 4.41. They are similar to the results of the real-time experiments. The model reflects characteristic features of the laboratory crane. The model compatibility to the real crane strongly depends on such parameters as the payload lift-line length, the static cart friction, the belt tension, etc. These and other parameters are written into the C source code of the modeltowecrane.c file attached in the DevDriv directory. If you wish to modify this file please make a copy and introduce the new parameters in the copy. Remember to produce an executable .dll file afterwards.
Let us turn on the controller PID X ag -responsible for dumping the X angle oscillation. To do this, we change the value of the gain vector ( “C” block ) from the [0 1] value to the [1 0.3], see Fig. 4.42.
The calculations of the dumping oscillations controller X ag are taken now with the weight equal 1 while the xw pos PID controller acts with the weight 0.3. This causes, the the control algorithm mainly dumps the oscillation. The result of the experiment with the working X ag controller presents Fig. 4.43.
One may observe, that the oscillations are minimized by the controller, but a desired position of the cart (square wave) is tracking in a worse way then in the previous experiment.
4.4. PID simulation control of load position
In our experiment the cart is following the desired trajectory similar to Lissajous curves. We invoke the TCrane_impres model from MATLAB Command Window (see Fig. 4.44). We put the cart into motion in two directions. The desired cart positions are generated as two sinusoidal signals. There are two generators identical in amplitudes equal to 0.2 m and different in frequencies. The X motion frequency is 0.05 rad/s (Fig. 4.45) and the T angle motion frequency is 0.1 rad/s.
We perform the experiment twice, for first time without two angle controllers (X ag and Y ag). For the second time the angle controllers are included. The weights of each controller are set in the C and C1 Simulink blocks. For the first experiment we set the gains to the [0 1] values (see Fig. 4.45 and Fig. 4.46). For the second experiment we set the gains of the C and C1 block to the [0.3 1] values.
0.5 5
T ang
0 .5
0.4 5
0 .4
0.3 5
0 .3
0.2 5
0 .2
0.1 5
0 .1
X pos
0.0 5
0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55
Fig. 4.47 The desired cart positions – thin line and the cart positions – thick line (in meters)
0.2 5 0 .2 5
0 .2 0 .2
0.1 5 0 .1 5
0 .1 0 .1
X contr. vs. T contr X contr. vs. T contr
0.0 5
0 .0 5 0 0.0 5
0 .0 5 0 .1
0 .1
X ang. vs. Y ang.
X ang. vs. Y ang.
0.1 5
0 .1 5 0 .2
0 .2 0.2 5
0 .2 5
0.2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 0 .2 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
Fig. 4.48 The controls (normalised units) and Fig. 4.49 The controls (normalised units) and the payload angles [rad] on the X Y plane; the the payload angles [rad] on the X Y plane; the angles without control angles with control
Notice that the control curve in the XT plane for the case of uncontrolled deviations of the payload is smoother than that for the controlled deviations case. The payload deviations are zoomed in Fig. 4.50 and Fig. 4.51 (please notice the scales of deviations).
3
x 10
0.0 1
6
4
0.00 5
2
0
0
2
0.00 5
4
0 .0 1
6
0.01 5
8 0 .02 0.015 0.01 0 .005 0 0.005 0.01 0.015 0.02 0.02 0.015 0.01 0.005 0 0.005 0.01 0.015
Fig. 4.50 Unstabilised deviations of Fig. 4.51 Stabilised deviations of the payload the payload in the X Y plane (in radians) in the X Y plane (in radians)
The controls in the X and T directions are shown in Fig. 4.52 and Fig. 4.53. Two cases of control: with and without stabilisation of angles are compared. The magnifications of the chosen areas are present in Fig. 4.54 and Fig. 4.55
1 .8 0 .2 5
with stbilization with stbilization
0 .2
-
1 .6
0 .1 5
-
1 .4
-
0 .1
-
0 .0 5
-
1 .2
0
1
0 .0 5
0 .1 0 .8
without stbilization
0 .1 5
0 .6
without stbilization
0 .2
0 .4
0 .2 5 0 5 10 15 20 25 30 0 5 10 15 20 25 30
Fig. 4.52 The controls (normalised units) Fig. 4.53 The controls (normalised units) in in the X direction vs. time (seconds) the T angle direction vs. time (seconds)
Notice that the controls related to the case of angles stabilisation share their actions between two tasks: tracking a desired position of the cart and stabilising the payload in its down position.
-
0 .2 2
-
0 .2
-
0 .1 8
-
0 .1 6
-
0 .1 4
-
0 .1 2
5. Prototyping your own controller in the real-time environment
In this section the process of building your own control system is described. The RTW toolbox of MathWorks and RT-CON toolbox of INTECO are used. In this section we give indications how to proceed in the real-time environment.
Before starting, test your MATLAB configuration and compiler installation by building and running an example of a real-time application. TCrane toolbox includes the real-time model of PC speaker.
The model pc_speaker_xxx.mdl does not have any I/O blocks so that you can run this model regardless of the I/O boards in your computer. Running this model will test the installation by running Real-Time Workshop, and your third-party C compiler.
In the MATLAB command window, type
pc_speaker_vc
|
(if you are using Visual C++ compiler)
|
or
|
|
pc_speaker_watc
|
(if you are using OpenWatcom 1.3 compiler)
|
Build and run this real-time model as follows:
• From the Tools menu, point to Real-Time Workshop, and then click Build Model.
The MATLAB command window displays the following messages.
### Starting Real-Time Workshop build procedure for model: pc_speaker_vc
☞ ### Generating code into build directory: C:\apps\MATLAB\R2006a\work\
pc_speaker_vc_RTCON ### Invoking Target Language Compiler on pc_speaker_vc.rtw. . . . .. . . ### Created RT-CON executable: pc_speaker_vc.dll ### Successful completion of Real-Time Workshop build procedure for model:
pc_speaker_vc
• From the Simulation menu, click External, and then click Connect to target.
The MATLAB command window displays the following message. Model pc_speaker_vc loaded
• From Simulation menu, click Start real-time code.
The Dual scope window displays the output signals and you hear the speaker sound.
Only correct configuration of the MATLAB, Simulink, RTW and C compiler guaranties the proper operation of the Tower Crane system.
To build the system that operates in the real-time mode the user has to:
-
create a Simulink model of the control system which consists of the Tower Crane Driver and other blocks chosen from the Simulink library,
-
build the executable file under RTW and RT-CON (see the Tools menu in )
-
start the real-time code using menu of the model window.
6.1. Equations
The schematic diagram related to the tower crane matheamtical model is shown in Fig.
There are five measured quantities:
x
-
w denotes the distance of the cart along the arm from the center of the construction frame;
-
θ denotes the angular position of the arm
-
L denotes the length of the lift-line;
-
denotes the angle between the z axis and the projection of the lift-line onto xz plane;
-
denotes the angle between the projection of the lift-line onto the xz plane and the lift-line;
-
xc, yc, zc define coordinates of the payload.
An important element in the construction of the mathematical model is the appropriate choice of the coordinates. The center point (x=0, y=0, z=0) of the Cartesian system is in the center of the crane tower at the level equal to the suspension point of the load. The position of the payload is described by two angles, α and β , shown in Fig. 6.63. The Cartesian system rotates according to the tower movement, described by the θ angle.
It is assumed that the lift-line is permanently stretched. The position of the payload according to Fig. 6.63 is described by the formulas:
xc =xw−L cos sin (1)
y= L sin (2)
c
z=−L cos cos (3)
c
The first derivatives of the equations (1-3) and the kinetic and potential energy of the payload are calculated. Based on the Lagrange equations, Amjed A. Al-Mousa1 gives the following equations that describes the dynamics of the tower crane.
x˙1 = x5 x˙2 = x6 x˙3 = x7 x˙4 =x8
x˙5=− 1 2 g cos x2 sin x 14 x7 x8 cos x1 −L x82sin 2 x1 cos2 x2 − 2 x3 x28sin x1sin x2
2 L − 4 Lx6 x8cos x2 cos2 x1 Lx62sin 2 x1 2 sin x1 sin x2 u12 x3 cos x1 u2 − 2 L sin x2 u2
x˙6 =− 1 g sin x 2x3 x28 cos x2 −Lx82 sin x2 cos x1 cos x22 Lx5 x8 cos x1 cos x2
L cos x1
− 2 Lx5 x6sin x1 −cos x2 u1 Lsin x1cos x2 u2 x˙7 =u1 x˙8 =u2
where: x1= , x2= , x3 = xw , x4 = , x5 =˙, x6 =˙, x7 = x˙w , x8 =˙, u1 =x¨w , u2 =¨.
It is assumed that the length of the lift line L is constant.
6.2. Comparison between the mathematical model and laboratory system.
Figures 6.64 and 6.65 presents variables and directions used in the model and system.
The basic differences between the model and system are as follows:
-
the control signal – it is the acceleration inside the model it is the velocity inside the system,
-
the angles of the payload – see the completely different notification in the above figures.
1 Amjed A. Al-Mousa, Control of Rotary Cranes Using Fuzzy Logic and Time-Delayed Position Feedback Control, Virginia Polytechnic Institute and State University, 27-th November 2000
• the tower rotate clockwise in the model and counterclockwise in the system.
The Tower Crane system is supplied with a Simulink block Tower Crane model that is based on the mathematical model see Fig. 6.66.
The model is equipped in two control inputs: X control and T control that correspond to the appropriate accelerations. The third input feeds a constant as the lift line length. The state variables are collected as the outputs.
Double clicking the Tower Crane model block to introduce the initial values of the ststes Fig. 6.67.
To adopt the mathematical model to the system a number of modifications of the Simulink model have been introduced (see Fig. 6.68).
To assure a control signal compatibility (velocity – acceleration) two Simulink block Derrivative are added and two gains: Scale rate x and Scale rate T.
A conversion between the angles , and X,Y describes two formulas: X =arcsin −cos⋅sin sin
Y =arcsin −
.,
cos X
The clockwise rotation in the system and counterclockwise rotation in the model have been equalized. The gain = – 1 in the n2 block was introduced and the Scale rate T factor was multiplied by – 1 as well.
7. Description of the Tower Crane class properties
The towercrane is a MATLAB class, which gives the access to all the features of the RTDAC/USB board equipped with the logic for the Tower Crane model. The RT-DAC/USB board is an interface between the control software executed by a PC computer and the power-interface electronic of the Tower Crane model. The logic on the board contains the following blocks:
-
incremental encoder registers – five 16-bit registers to measure the position of the incremental encoders. There are five encoders measuring five state quantities: two cart positions at the cylindrical plane, the lift-line-length and two deviation angles of the payload;
-
incremental encoder resets logic. The incremental encoders are able to generate different output waves when the encoder rotates clockwise and the counter clockwise. The encoders are not able to detect the reference (“zero”) position. To determine the “zero” position the incremental encoder registers can be set to zero from the computer program or an encoder register is reset when the corresponding limit switch to the encoder is reached;
-
PWM generation block – generates three sets of signals. Each set contains the PWM output signal, the direction signal and the brake signal. The PWM prescaler determines the frequency of all the PWM waves. The PWM block logic can prevent the cart from motion outside the rail limits and the lift-line angles from lying outside the operating range. The operating ranges are detected twofold – by the limit switches and by three limit registers;
-
power interface thermal flags – when the temperature of the power interface for the DC motors is too high the thermal flags can be used to disable the operation of the corresponding overheated DC motor.
All the parameters and measured variables from the RT-DAC/USB board are accessible by appropriate methods of the towercrane class.
The object of the towercrane class is created by the command:
object_name = towercrane;
The get method is called to read a value of the property of the object:
property_value = get( object_name, ‘property_name’ );
The set method is called to set new value of the given property:
set( object_name, ‘property_name’, new_property_value );
The display method is applied to display the property values when the object_name is entered in the MATLAB command window.
This section describes all the properties of the towercrane class. The description consists of the following fields:
Purpose
|
Provides short description of the property
|
Synopsis
|
Shows the format of the method calls
|
Description
|
Describes what the property does and the restrictions of is
|
|
subjected to
|
Arguments
|
Describes arguments of the set method
|
See
|
Refers to other related properties
|
Examples
|
Provides examples how the property can be used
|
7.1. BaseAddress
Purpose: Read the base address of the RT-DAC/USB board.
Synopsis: BaseAddress = get( tcrane, ‘BaseAddress’ );
Description: The base address of RT-DAC/USB board is determined by OS. Each towercrane object has to know the base address of the board. When the towercrane object is created the base address is detected automatically. The detection procedure detects the base address of the first RT-DAC/USB board plugged into the USB slots.
Example: Create the towercrane object: tcrane = towercrane;
Display its properties by typing the command:
tcrane
>>Type: towercrane Object >>BaseAddress: 528 >>Bitstream ver.: x33 >>Encoder: [ 65479 7661 20032 65533 65534 ][bit] >> [ -0.0022207[m] 0.29847[m] 0.38411[m] -0.004602[rad] -0.003068[rad] ] >>Z displacement: 0.32[m] >>PWM: [ -0.062561 0.031281 -1 ] >>PWMPrescaler: 60 >>RailLimit: [ 361 381 815 ]*64[bit] <--> [23104 24384 52160 ][bit] >> [ 0.90013 0.95 1.0002 ][m] >>RailLimitFlag: [ 1 1 1 ] >>RailLimitSwitch: [ 0 1 1 ] >>ResetSwitchFlag: [ 0 0 0 ] >>Therm: [ 1 1 1 ]>>ThermFlag: [ 1 1 1 ] >>Time: 1.041 [sec]
Read the base address:
BA = get( tcrane, ‘BaseAddress’ );
7.2. BitstreamVersion
Purpose: Read the version of the logic design for the RT-DAC/USB board.
Synopsis: Version = get( tcrane, ‘BitstreamVersion’ );
Description: This property determines the version of the logic design of the RTDAC/USB board. The Tower Crane models may vary and the detection of the logic design version makes it possible to check if the logic design is compatible with the physical model.
7.3. Encoder
Purpose: Read the incremental encoder registers.
Synopsis: enc = get( tcrane, ‘Encoder’ );
Description: The property returns five digits. The first two measure the position of the cart – linear and angle. The third digit is used to measure the length of the lift-line and the last two measure the angles of the lift-line. The returned values can vary from 0 to 65535 (16-bit counters). When a register is reset the value is set to zero. When a rail limit flag is set it disables the movement outside the defined working range (rail limit). When a reset switch flag is set the encoder register is reset automatically when the appropriate switch is pressed.
The incremental encoders generate 4096 or 2048 pulses per rotation. The values of the Encoder property should be converted into physical units.
See: ResetEncoder, RailLimit, RailLimitFlag, ResetSwitchFlag
7.4. PWM
Purpose: Set the parameters of the PWM waves.
Synopsis: PWM = get( tcrane, ‘PWM’ ); set( tcrane, ‘PWM’, NewPWM );
Description: The property determines the duty cycle and direction of the PWM waves for three DC motors. The first two DC motors control the position of the cart and the last motor controls the length of the lift-line. The PWM and NewPWM variables are 1x3 vectors. Each element of these vectors determines the parameters of the PWM wave for one DC motor. The values of the elements of these vectors can vary from –1.0 to 1.0. The value –1.0 means the maximum control in one direction, the value 0.0 means zero control and the value 1.0 means the maximum control in the opposite direction.
The PWM wave is not generated if:
-
a rail limit flag is set and the cart or lift-line are going to operate outside the working range,
-
a therm flag is set and the power amplifier is overheated.
See: RailLimit, RailLimitFlag, Therm, ThermFlag
Example: set( tcrane, ‘PWM’, [ -0.3 0.0 1.0 ] );
7.5. PWMPrescaler
Purpose: Determine the frequency of the PWM waves.
Synopsis: Prescaler = get( tcrane, ‘PWMPrescaler’ ); set( tcrane, ‘PWMPrescaler’, NewPrescaler );
Description: The prescaler value can vary from 0 to 63. The 0 value generates the maximum PWM frequency. The value 63 generates the minimum frequency.
See: PWM
7.6. ResetEncoder
Purpose: Reset the encoder counters.
Synopsis: set( tcrane, ‘ResetEncoder’, ResetFlags );
Description: The property is used to reset the encoder registers. The ResetFlags is a 1x5 vector. Each element of this vector is responsible for one encoder register. If the element is equal to 1 the appropriate register is set to zero. If the element is equal to 0 the appropriate register remains unchanged.
See: Encoder
Example: To reset the first and fourth encoder registers execute the command: set( tcrane, ‘ResetEncoder’, [ 1 0 0 1 0 ] );
7.7. RailLimit
Purpose: Control the operating range of the tower crane system.
Synopsis: Limit = get( tcrane, ‘RailLimit’ ); set( tr3, ‘RailLimit’, NewLimit );
Description: The Limit and NewLimit variables are 1x3 vectors. The elements of these vectors define the operating range of the cart and the maximum length of the lift-line. If a flag defined by the RailLimitFlag property is set the corresponding to it PWM wave stops when the corresponding to it encoder register exceeds the limit.
See: RailLimitFlag
7.8. RailLimitFlag
Purpose: Set range of limit flags.
Synopsis: LimitFlag = get( tcrane, ‘RailLimitFlag’ ); set( tr3, ‘RailLimitFlag’, NewLimitFlag );
Description: The RailLimitFlags is a 1x3 vector. The first two elements control the operating range of the cart (a length of the rail and an angle position of the tower). The last element controls the maximum length of the lift-line. If the flag is set to 1 and the encoder register exceeds the range the DC motorcorresponding to it stops. If the flag is set to 0 the motion continues in spite of the range limit exceeded in the encoder register.
See: RailLimit, RailLimitSwitch
7.9. RailLimitSwitch
Purpose: Read the state of limit switches. Synopsis: LimitSwitch = get( tcrane, ‘RailLimitSwitch’ ); Description: Reads the state of three limit switches. Returns a 1x3 vector. If an element of
this vector is equal to 0 it means that the switch has been pressed.
See: RailLimit, RailLimitFlag
7.10. ResetSwitchFlag
Purpose: Control the auto-reset of the encoder registers.
Synopsis: ResetSwitchFlag = get( tcrane, ‘ResetSwitchtFlag’ ); set( tcrane, ‘ResetSwitchFlag’, ResetSwitchFlag );
Description: The ResetSwitchFlag and NewResetSwitchFlag are 1x3 vectors. If an element of these vectors is equal to 1 the corresponding to it encoder register is automatically reset in the case when the corresponding to it limit switch is pressed.
See: ResetEncoder, RailLimitSwitch
7.11. Therm
Purpose: Read thermal flags of the power amplifiers. Synopsis: Therm = get( tcrane, ‘Therm’ ); Description: Returns three thermal flags of three power amplifiers. When the temperature
of a power amplifier is too high the appropriate flag is set to x.
See: ThermFlag
7.12. ThermFlag
Purpose: Control an automatic power down of the power amplifiers.
Synopsis: ThermFlag = get( tcrane, ‘ThermFlag’ ); set( tcrane, ‘ThermFlag’, NewThermFlag );
Description: The ThermFlag and NewThermFlag are 1x3 vectors. If an element of these vectors is equal to 1 the DC motor corresponding to it is not excited by the PWM wave when it is overheated.
See: Therm
7.13. Time
Purpose: Return time information.
Synopsis: T = get( tcrane, ‘Time’ );
Description: The towercrane object contains the time counter. When a towercrane object is created the time counter is set to zero. Each reference to the Timeproperty updates its value. The value is equal to the number of milliseconds past since the object was created.
7.14. Quick reference table
Property Name
|
Description
|
BitstreamVersion
|
Read the version of the logic design for the RT-DAC/USB board
|
Encoder
|
Read the incremental encoder registers
|
PWM
|
Set the parameters of the PWM waves
|
PWMPrescaler
|
Determine the frequency of the PWM waves
|
ResetEncoder
|
Reset the encoder counters
|
RailLimit
|
Control the operating range of the Tower Crane system
|
RailLimitFlag
|
Set the range limit flags
|
RailLimitSwitch
|
Read the state of the limit switches
|
ResetSwitchFlag
|
Control the auto-reset of the encoder registers
|
Therm
|
Read the thermal flags of the power amplifiers
|
ThermFlag
|
Control the automatic power down of the power amplifiers
|
Time
|
Return time information
|
8. How to fill in the compilation settings page
In Fig. 8.69 and Błąd: Nie znaleziono źródła odwołania the Configuration Parameters pages for different MATLAB versions are shown.
Notice that system target file towercrane.tlc (rtcon.tlc) is chosen. Also note that template makefile, responsible for compilation and linking process, istowercrane_vc.tmf (rtcon_vc_usb.tmf). It means the MS VC++ compiler is used in this case.
Interface page, responsible for connection with external target system, is shown in Fig.
8.70. To fulfil it properly a user must select External mode in Interface edit window. After that the user have to set RT-CON tcpip in the Transport layer edit window.
If this checkbox is marked the message on loading real-time code is displayed (Fig. 8.72) after connecting to target in the model window.