1.1. Product overview
The crane is delivered in partially mounted form. The mounting frame makes a support and a flexible construction of the system. If it is fixed to the walls and the floor then the crane becomes a rigid construction. The construction is available in user-defined sizes. The dimensions are from the range: length from 1 m to 3 m, width from 1 m to 3 m.
SETUP COMPONENTS
-
hardware
-
mechanical unit
-
interface and Power Interface Unit
-
I/O RT-DAC/PCI board (the PWM control logic is stored in a XILINX chip)
-
software
-
• 3D-Crane Control/Simulation Toolbox operating in MATLAB®/Simulink® environment
-
manuals
-
Installation and Commissioning
-
Getting Started Manual
-
1.2. Requirements
-
PC 486 100MHz or higher, RAM 64M,
-
Video card resolution 1024 x 768 pixels
-
MATLAB® 5.3, 6.x /Simulink® 2.x, 3.x,
-
Real Time Workshop and Real Time Windows Target toolboxes
-
Optimisation Toolbox (needed only for one demo experiment),
-
Compiler: Watcom C/C++ 10.6, 11.0 or MS Visual C 5.0, 6.0
The 3DCrane toolbox supports Matlab 5.3 with a Watcom compiler, and Matlab 6.0 with the MS Visual C++ 5.0, 6.0 or the Watcom 11.0 compiler. See
section 10.
2. Installation of the software
The application must be started by the system administrator, who has full
access to all drivers and system settings.
3. Starting, testing and stopping procedures
3.1. Starting procedure
Combine the acquisition board, Control Interface and 3DCrane together. In the MSWINDOWS environment invoke MATLAB by double clicking on the MATLAB icon. The MATLAB command window opens. Then simply type:
cr
MATLAB brings up the window 3DCrane Main Control Window (see Fig. 3.1). Pushbuttons indicate an action that executes callback routines when the user selects a menu item.
The Main Control Window contains testing tools, drivers, models and demo applications. Also a case study is included.
You can see a number of pushbuttons ready to use.
3.2. Testing and troubleshooting
This section explains how to perform the tests. These tests allow checking if mechanical assembling and wiring has been done correctly. The tests have to be performed obligatorily after assembling the system. They are also necessary after an incorrect operation of the system. The tests are helpful to look for causes of errors when the system fails. The tests have been designed to validate the existence and sequence of measurements and controls. They do not relate to accuracy of the signals.
In this manual some terms are used which describe the location of the cart. Fig. 3.2 defines these terms.
First, you have to be aware that all signals are transferred in a proper way. Eleven checking steps are applied.
Before starting the test move the cart and the rail manually to an arbitrary position different from the zero position (Fig. 3.2).
• Double click the Basic Tests button. The following window appears (Fig. 3.3): Fig. 3.3 The Basic Tests window
The first step in testing the crane is to check the proper operation of the limit switches. There are three switches applied to stop the moving parts of the system and to secure the system against destruction if the cart or the rail approaches the limits.
• Double click the Test limit switches button. The window presented in Fig. 3.4 opens:
Then close manually one by one all switches related to x, y and z-axes. After each closing you hear a sound signal. If you switch on the x-axis limit switch then the window presented in Fig. 3.5 appears. This means that the switch works properly. Close the window – click the OK button. When a switch is not detected please check connection of the appropriate cables to the undetected switch.
Next, you can check if the cart, rail and payload move in the right direction and if the system stops at the desired limit position. The system is moved in the chosen direction until it reaches the zero position (at this point the switch limit must be active).
• Double click the Go Home X-axis (Y-axis and Z-axis) button and observe the behaviour of the system. The window (Fig. 3.6) opens. You can interrupt the motion clicking the OK button.
After performing tests along three directions the system is stopped at the zero position. The encoders of X,Y and Z-axes are automatically reset to zero value.
If motion in a given direction is not observed check wires and plugs related to that direction.
The next three steps perform the change of the system position from the initial position to the initial + 0.3 [m] position along a selected direction.
-
Double click the X-axis (Y-axis and Z-axis) Movement button. The window (Fig. 3.7) opens where you can stop the motion clicking the OK button.
-
In the next step double click the Go To Center button. The system moves to position in the center of the physical system workspace. Workspace boundaries are limited by sizes of the laboratory set and fixed in the program. The window presented in Fig. 3.9 opens
-
Double click the Reset Angle Encoders button. The window shown in Fig. 3.11 opens.
-
Now you must set the load motionless and click Yes. The angle encoders are reset and the zero position is memorised by the system.
-
To check if angle measurements are correct double clicks the Check Angles button. The window presented in Fig. 3.12 opens. Then manually move the load to a non-zero position and push it. After that click OKbutton and observe the motion on the screen (Fig. 3.13)
3.3. Stopping procedure
The system is equipped with the hardware stop pushbutton. It cuts off the transfer of control signals to the crane. The pushbutton does not terminate the real-time process running in the background. Therefore to stop the task you have to use Simulation/Stop from the pull-down menus in the model window.
4. Main Control Window
The user has a rapid access to all basic functions of the 3DCrane control system from the Main Control Window. It includes tests, drivers, models and application examples.
The Main Control Window presented in Fig. 3.1 contains four groups of the menu items:
-
Tools
-
Drivers
-
Demo Controllers
-
Experiments
4.1. Tools
The respective buttons in the TOOLS column perform the following tasks:
Basic Tests -checks the measurements and control.
Go Home – moves the crane to the zero position, resets the encoders and sets control signals to zero. This button is frequently used before starting an experiment. When the Go Home procedure is finished we can be sure that the values of all measured signals have been set to zero.
Reset Angles – resets the angle measuring encoders in a fixed position. If you stop the payload manually, perform the Reset Angles operation to be sure that the payload angles measured by the encoders show zeros.
Go to Center -moves the crane to the center of the crane workspace and switches off the control. Remember that the zero position of the crane is in the corner of the XY plane. Most experiments cannot be started from the zero point. Go to Center allows the crane quickly move to the center.
Set Parameters -enables the user to change the default values of Rail limits, Base Address and Z displacement. The default value of the Base Address may cause a conflict with other devices installed in the computer. One has to be ensured that his computer configuration is free from address conflicts.
The user can also need to adjust the crane workspace dimensions to his requirements. Fig.
4.1 presents the window where such changes can be done. The user has to type numerical values into these editable text boxes.
All introduced modifications are written to the configuration file. Please be careful with introducing them. Writing the rail limit values exceeding the real
rail limits may result in damage of the system elements.
Manual Setup – GUI interface enables you to change the 3DCrane MATLAB structure. Double click the Manual Setup button and the screen presented in Fig. 4.2 opens.
There are numerical data in the window read from the XILINX chip placed on the RTDAC/PCI board. These data reflects the MATLAB structure, which includes measurements and constants assumed in the system.
In the first frame there is basic information:
-
Bitstream ver. − the version of the logic design for the RT-DAC/PCI board,
-
Base Address – the base address (autodetected) of the board,
-
PWM prescaler – the frequency of the PWM (pulse wave modulation) waves (see section 8).
The next frame includes the control sliders for the three axes. You can use them to check if the controls activate the cart and rail motions. Note that after opening this window all controls are set to zero. Move any slider and observe the cart and rail motions. To stop the experiment click the Stop Control button. The system will stop and all sliders return to the zero positions.
In the third frame the information is organised as follows:
-
Scale coefficients. These coefficients correspond to the sizes of the cog wheels and the model of the encoders. Each crane during manufacturing is equipped with default values specific to the set.
-
Positions of the cart in three axes expressed in bits and meters.
-
X-angle and Y-angle expressed in bits and radians.
X-angle and Y-angle denote the angle deviations in X and Y direction, respectively. They are denoted by α and β in the mathematical model (see
Fig. 8.1).
-
Reset check boxes. Marking a reset checkbox results in the resetting of the encoder related to the mark.
-
Rail limits in the three axes directions. These limits are pre-set by the producer. However, you can change them using the Set Parameters button in the Main Control Window.
-
Z displacement expressed in bits and meters. The Z displacement is the difference between the measured lift-line length along the Z axis and the length of the mathematical pendulum model of the crane payload.
-
Rail limit flags – checkboxes. When a flag is marked and a numerical value in the encoder register related to this flag exceeds the limit range then the DC motor corresponding to this flag is stopped.
-
States of the rail limit switches. The cross appears when the switch is on. This information is used by the system to stop the cart and the rail.
-
Autoreset flags – checkboxes. If a checkbox is marked and the cart or the rail reaches the limits then the encoder corresponding to the autoreset flag is reset.
-
Thermal states and thermal flags. If a thermal flag is marked and the temperature exceeds the safety level then the power supply is switched off.
Go to the Main Control Window and click the Go Home button. Come back to the Manual Setup window and click the Update button. You should obtain a result similar to that presented in Fig. 4.3. The current stage of the system is updated.
Notice that the X,Y and Z positions are reset and the Rail limit switches are marked. The Autoreset flags are also marked. This is the result of the Go Home action.
Now, click the Go to Center button and you can see other changes in the Manual Setup window (see Fig. 4.4). Note that the X position, Y position and Z position have changed their values and become the center positions in the crane workspace. The Rail limit switch textboxes are empty and the Autoreset flags checkboxes are not marked.
4.2. Drivers
The main driver is located in the RTWT Device Driver column. The driver is a software go-between for the real crane MATLAB environment and the RT-DAC/PCI acquisition board. This driver serves to the control and measurement signals. Click the 3Dcrane Device Drivers button and the driver window opens (Fig. 4.5)
The driver has three PWM inputs (DC motor controls) for the X,Y and Z-axes. There are 10 outputs of the driver: X position, Y position, Z position, two angles (see section 8) and
additionally three safety switches. According to a pre-programmed logic the internal XILINX program of the RT-DAC/PCI board can use the switches to stop the DC motors. When one wants to build his own application one can copy this driver to a new model.
Do not make any changes inside the original driver. They can be made only inside its copy!!!
Simulation Model – the simulation model of the crane is located under this button. Its external is identical as the model given in the 3Dcrane Device Drivers except the lack of the safety switches (see Fig. 4.6). These switches are not used in the simulation mode. The simulation model is used for many purposes: identification, controllers design, etc.
In the mask presented in Fig. 4.7 you can introduce initial conditions for the model state variables. Additionally, by marking the checkbox you can use the model with constant length (see section 8 for details).
The simulation model is running in the normal simulation mode.
Set solver options to: Fixed step and Fixed-step size equal to 0.001 at least. A greater value could result in the errors of solution. The Runge-Kutta solver
is recommended.
The C source code of the model3ddm.c file is attached to the DevDriv directory.
4.3. Demo Controllers
In this column some examples of control systems are given. These demos can be used to familiarise the user with the crane system operation and allow creating the user-defined control systems. The examples must be rebuilt before using.
Due to similarity of the examples we focus our attention on one of them. After clicking on the Relay button the model appears (Fig. 4.8):
Notice that this model looks like a typical Simulink model. The device driver is applied in the same way as other blocks from the Simulink library. The only difference is that the model is used by Real Time Windows Target (RTWT) to create the executable library, which runs in the real-time mode.
The goal of the model is the relay control in the X-axis only. Therefore GainY and GainZ are set to zero.
-
Look at the mask of the Relay block connected to the X PWM input (Fig. 4.9).
-
Note that the control generated by the controller has two values: +0.5 and –0.5. The On/Off limits are 0.2 and 0.6. This means that the crane will move between these limits with the speed corresponding to the control value equal to 0.5.
-
To choose the starting point inside the [−0.5, 0.5] range go to Main Control Window and click the Go to Center button.
-
Then, choose the Tools pull-down menus in the Simulink model window. The pop-up menus provide a choice between predefined items. Choose the RTW Build item. A successful compilation and linking process is finished with the following message:
Model Crane3D_Relay.rtd successfully created
### Successful completion of Real-Time Workshop build procedure for model: Crane3D_Relay
If any error occurs then the message corresponding to the error is displayed in the MATLAB command window.
-
Next, click the Tools/External Mode Control Panel item and next click the Signal Triggering button. The window presented in Fig. 4.10 opens.
-
Select XT Scope , set Source as the manual option, mark Arm when connect to Target option and close the window.
-
Return to the model window and click the Simulation/Connect to Target option. Next, click the Simulation/Start real-time code item.
-
Observe the plots in the scope and click Stop Simulation after some time. Results of the example are presented in Fig. 4.11.
The X position starts from 0.54 and changes between 0.2 and 0.6. The control (red line) is a square wave in the range [−0.5, 0.5]. The control switches when the X position reaches one of the limit values. Note that the X angle in the form of a sinusoidal curve is modulated by the control interacting with friction.
5. Your first real-time control experiment
We propose two experiments. In the first experiment only one control loop in the x direction is defined. In this case stabilisation of the angle of the payload is neglected. In the second experiment the stabilisation of the payload angle is added.
We begin from a simple real-time control experiment. A PID controller for the x position of the cart is built. The Crane3D_first model is illustrated in Fig. 5.1. To invoke it, click Model for control experiment button in the Main Control Window. In this case, the active control corresponding to the x cart position is all you need. The Simulink blocks included in the control are drawn with dropped shadows to distinguish active control loops from disabled loops. In our first experiment we use the X position of the cart PID controller activating only its P control part.
We define a source of a desired x position signal as the X reference/Generator from the Simulink library (see Fig. 5.2)
As usual, after performing the GO HOME and GO TO CENTER actions, we start an experiment from the middle of the x, y rails. Therefore the constant block shift is required.
Next, we define the signals to be used. These are X-reference – the desired x position value, X-position, X-control and X-angle. These signals, among others, are connected to the Scope block.
The properties of this block are defined below (see Fig. 5.3). This window opens after the selection of the Scope/Properties tab. Mark the Save data to workspace checkbox, define the Variable name as EX1 and the data format as structure. This means the collected data within 30 seconds time range are saved to the workspace in the structure EX1. The sampling period set in the Simulation Parameters window (see Fig. 5.3) is equal to 0.01, Sampling Decimation is set to 10. Therefore, the size of EX1 is equal to
30 s / (0.01 s × 10) + 1= 301
Next, return to the Main Control Window and select the Simulation/Parameters item. In the Solver tab select Fixed Step and set Stop time equal to 30. The Real-time Workshop tab must be defined as in Fig. 5.4.
The next step is to set the PID controllers. We set the Proportional part of the X position of the cart PID controller as indicated by the arrow in Fig. 5.5. The X angle of the payload PID controller remains inactive. The other controlling loops are disabled due to the Gain blocks set to zero (see Fig. 5.1).
Next, invoke the Tools/External mode control panel item. The External Mode Control Panel window opens (see Fig. 5.7).
By clicking on the Signal & Triggering button invoke the window shown in Fig. 5.8. In this window we define a triggering mode for marked blocks. In our case only one block exists
– XT Scope. We mark XT Scope , set Source as the manual option, mark Arm when connect to target and close the window.
Now we can build the real-time model. To do it select the Simulation /Parameters item and then the Real-Time Workshop tab in the model window, and click the Build item. Successful compilation and linking process should be finished with the following message:
Model Crane3D_first.rtd successfully created ### Successful completion of Real-Time Workshop build procedure for model: Crane3D_first
5.1. Real-time experiment
Having prepared the controller model you can start the real-time experiment.
Two actions GO HOME and GO TO CENTER must be performed in the Main Control Window first. The crane is ready for the experiment. The cart is in the middle of the x, y plane, the payload is hanging down in its rest position. Open the Scope figure clicking on the Scope block.
Now return to the model window and click the Simulation/Connect to Target item. Next, click the Simulation/Start real-time code item. It activates the experiment lasting 30 seconds. Observe the cart motion in the xdirection. The cart follows the desired square wave signal controlled by the P regulator. The payload oscillates freely, being uncontrolled. After 30 seconds the experiment stops. The history of the EX1 variable is visible in the Scope (see Fig. 5.9). Notice the harmonic (uncontrolled) angle signal of the payload, the square wave generated by Signal Generator followed by the cart x position signal. The static error is due to the inadequate P control action. The control has the highest magnitude among other signals visible in the figure. When an abrupt change in the wave signal occurs then it results in the saturation of the control signal.
5.1.1. Data processing
The results are saved to the workspace as a structure variable EX1. If you write the variable name in the MATLAB command window then you obtain the answer
EX1 = time: [301x1 double] signals: [1x1 struct] blockName: Crane3D_pid_all/Scope
This data can be plotted in many ways. For example use the following command
>> plot(EX1.time,EX1.signals.values(:,1:4))
You can repeat the experiment several times using different P parameter settings and including another P controller for the x angle. The parameters of the controllers for successive five experiments are given in Table 5-1.
Number of experiment
|
P of the cart position
|
P of the payload angle
|
Figure
|
1
|
2.5
|
−
|
Fig. 5.10
|
2
|
5
|
−
|
Fig. 5.10
|
3
|
2.5
|
1
|
Fig. 5.11
|
4
|
5
|
2
|
Fig. 5.11
|
5
|
5
|
4
|
Fig. 5.11
|
Table 5-1 Parameters for the experiments
|
The results of five experiments are presented in Fig. 5.10 and Fig. 5.11. 0 0.5 1 desired x position x position x angle0 0.5 1desired x position x position x angle
|
|
-0.5
|
|
|
|
|
-0.5
|
|
|
|
|
0 -1
|
5
|
10 15 20 control P set to 2.5
|
25
|
30
|
0 -1
|
5
|
10 15 20 control P set to 5
|
25
|
30
|
|
Fig. 5.10 Only one controller is active – desired x position of the cart is tracked
|
|
|
0.5 1
|
desired x position x position
|
0.5 1
|
desired x position x position
|
|
|
0
|
x angle
|
0 x angle
|
|
|
|
-0.5
|
|
-0.5
|
|
|
|
0 -1
|
5
|
10 15 control
|
20
|
25
|
30
|
0 -1
|
5
|
10 15 control
|
20
|
25
|
30
|
|
|
P of the cart position set to 2.5 P of the payload angle set to 1
|
P of the cart position set to 5 P of the payload angle set to 2
|
|
3DCRANE GETTING STARTED
1
desired x position
0.5
x position
x angle 0
-0.5
|
P of the cart position set to 5
|
-1
|
|
control
|
|
|
|
P of the payload angle set to 4
|
0
|
5
|
10
|
15
|
20
|
25
|
30
|
|
Fig. 5.11 Two controllers – desired x position of the cart and x angle of the payload are tracked
The left-hand side of Fig. 5.10 shows that the P value set to 2.5 is too small for a proper x position tracking. The static error of x position is large. A higher gain P equal to 5 (the right-hand side of Fig. 5.10) reduces the static error but results in the saturation of control.
In Fig. 5.11 one can see similar results obtained for two active controllers. We focus our attention on the x angle control. The trade-off between two acting controllers is well visible in the upper left-hand picture of Fig. 5.11. One control signal serves for two control purposes: follow the desired value of the cart x position and simultaneously stabilises the payload in its hanging down position.
5.2. Simulation
We can repeat the real-time experiment from the previous section in a purely simulated form.
We invoke the Crane3D_first_model window. Notice two differences. The Crane3D real-time driver block has been replaced by the Crane3D_model simulation model block. The External mode of operation has been replaced by the Normal mode of operation (see Fig. 5.12). All other parts remain as in the real-time experiment.
The interior of Crane3D_model includes the complete nonlinear model described in section 6.4. After clicking on Crane3D_model the mask given in Fig. 5.13 opens. You can set the initial values of 10 variables. You can mark the constant or varying pendulum length. In our example all initial conditions are set to zero except the X position set to 0.55 and Z position set to 0.5 and the last variable t set to -1. Setting t to –1 denotes that the source of time is the RTWT clock.
If you look under the Crane3D_model mask you can see its interior (Fig. 5.14). model3dddm is the executable dll file. The scale factors are set to 34. These parameters relate to 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. 5.15). Similarly as in the real time experiment, the data are saved in the scope in the EX1 structural variable.
Plotting four curves as functions of time (Fig. 5.15) is produced by:
>> plot(EX1.time, EX1.signals.values)
We perform simulations related to the experiments 2 and 5 from Table 5-1. The results are visible in Fig. 5.16. 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 model3ddm.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.
Fig. 5.15 Simulation data visible in the scope
1
1
desired x position
desired x position
0.5
0.5
x position
x position
0
|
|
0
|
|
x angle
|
|
-0.5
|
|
-0.5
|
x angle
|
control
control
-1
-1
Fig. 5.16 Simulation results
0
|
5
|
10
|
15
|
20
|
25
|
30
|
0
|
5
|
10
|
15
|
20
|
25
|
30
|
P of the cart position set to 5
|
P of the cart position set to 5
|
P of the payload angle set to 0
|
P of the payload angle set to 4
|
Only one controller is active – the desired x
|
Two controllers – the desired x position of
|
position of the cart is tracked
|
the cart is tracked and the
|
x
|
angle of the
|
|
payload is stabilised
|
5.3. PID control of load position
In our experiment the cart is following a Lissajous curve. We invoke the Crane3D_impres model from the MATLAB command window (see Fig. 5.17).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.4 rad/s (Fig. 5.18) and the Y motion frequency is 0.8 0.4 rad/s.
We perform the experiment twice, first time without the P angle controllers and second time, with the P angle controllers set to 20 (see Fig. 5.19).
The cart motion is shown in Fig. 5.20. The thick line represents the cart position in the XY plane (there is no movement in the Z direction). The respective controls and the payload angles are shown in Fig. 5.21 and Fig. 5.22.
0.8
0.6
Y control vs. X control
0.4
0.2
Y angle vs. X angle 0 -0.2 -0.4 -0.6 -0.8 -0.5 0 0.5
Fig. 5.21 The controls (normalised units) and the payload angles [rad] on the XY plane; the angles without control
0.8
0.6
Y control vs. X control
0.4
0.2
Y angle vs. X angle
0 -0.2 -0.4 -0.6 -0.8
-0.4 -0.2 0 0.2 0.4
Fig. 5.22 The controls (normalised units) and the payload angles [rad] on the XY plane; the angles with control
Notice that the control curve in the XY 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. 5.23 and Fig. 5.24 (please notice the scales of deviations).
0.08
0.015 Y angle vs. X angle
0.06
0.01
0.04
0.005
0.02
0 0
Y angle vs. X angle -0.005
-0.02
-0.04
-0.01
-0.06
|
|
-0.015
|
-0.08
|
|
|
-0.06
|
-0.04
|
-0.02
|
0
|
0.02
|
0.04
|
0.06
|
-0.01
|
-0.005
|
0
|
0.005
|
0.01
|
Fig. 5.23 Unstabilised deviations of
|
|
Fig. 5.24 Stabilised deviations of the payload
|
the payload in the X Y plane (in meters)
|
|
in the X Y plane (in meters)
|
The controls in the X and Y directions are shown in Fig. 5.25 and Fig. 5.26. Two cases of control: with and without stabilisation of angles are compared.
0.8
0.5
0.6
0.4
0.3
0.4
0.2
0.2
0.1
0
0 -0.2
-0.1
-0.2
-0.4
-0.3
-0.6 -0.4
-0.8
0 510 15 20 25 0 5 10 15 20 25
Notice that the controls related to the case of angles stabilisation (thick lines in the figures) share their actions between two tasks: tracking a desired position of the cart and stabilising the payload in its down position.
6. CASE STUDY
This section describes nine steps to be performed by the user for collecting data from the real 3DCrane system, identifying a simple crane model and identifying the z displacement. Finally, the optimisation of the 5 DOF PID controller based on the collected data yields an appropriate set of the PID controller’s parameters.
All steps are described in detail below. After clicking on the Simple Model button the following window opens (see Fig. 6.1).
Step 1 and Step 2 have been described in section 4.1. After performing these steps the crane is ready to start an experiment.
Step 3
This step collects the XYZ data. The cart is steered forth and back in the X and Y directions. The payload is lifted up and lowered. These actions run simultaneously due to operating controllers, as illustrated in Fig. 6.2. There are three identical Relay blocks used as controllers. You can see the control ranges by clicking on a block – see Fig. 6.3. The control values change from 0.5 to −0.5 (a half of the maximal excitations). The motion ranges are between 0.3 and 0.5 m.
Before starting the motion set the Base Address first. Click the Set Base Address button in the 3DCrane 3DOF Relay Controller window – see Fig. 6.2. Next, choose Tools from the window menu bar. These pull-down menus execute callback routines when the user selects an individual menu item. Choose the Real_Time Workshop menu and the Build Model submenu. The model is rebuilt. Finally, choose Simulation from the window menu bar and click the Connect to target pull-down menu.
When the system is running observe the real motion of the crane and the plot in the scope – see Fig. 6.4.
The cart velocities in X and Y directions are much alike. The payload moves slower down and up. The angles of the payload are not closed-loop controlled and in consequence the payload oscillates freely.
The Matlab Optimisation Toolbox is required to perform step 4.
Step 4
Click the Identify XYZ Model button. The optimisation procedure starts. The plot illustrated in Fig. 6.5 appears. The following simple linear model of the crane dynamics in the X-axis is assumed K
G (s) = x .xs(Txs +1) The Identify XYZ Model button calls the CaseStudy_XYZIdent m-file. This routine calls the Crane3D_CSPenaltyXY function. The function invokes simulation of theCrane3D_CSModelXY Simulink model (see Fig. 6.6). If you wish to build your own optimisation procedure all source codes are available. The optimisation procedure (called insideCaseStudy_XYZIdent) uses the fmincon procedure from the MATLAB optimisation library, which finds the constrained minimum of the Crane3D_CSPenaltyXY function. The iterative procedure based on fminunc results in matching real system time responses to the simple model responses.
Finally, we obtain Kx and Tx parameters of the simple model. In this example they have the following numerical values
Kx = 0.173511, Tx= 0.074388.
The final plots after optimisation (shown in Fig. 6.7) indicate that the model matching is successful.
After pressing a key again the program starts. The same procedure is repeated in the Y axis. A similar simple linear model of the crane dynamics in Y-axis is assumed K
G (s) = y .
ys(Tys +1)
Results obtained for the unmatched model (before optimisation) and the matched model (after optimisation) are visible in Fig. 6.8 and Fig. 6.9.
The following numerical values of Ky and Ty were obtains: Ky = 0.172034, Ty = 0.129360.
If we press a key again then the model optimisation in the Z direction starts (again the simple model is used). The initial stage before optimisation is visible in Fig. 6.10.
After optimisation the following picture is obtained (see Fig. 6.11)
The model matching in the Z direction results in two models identical in form and different in parameters. We have Kp= 0.103062 and Tsp= 0.019731 when the payload is lifted and Km= 0.091699 and Tsm= 0.012947 when the payload is lowered. The model shown in Fig. 6.12, different from that presented in Fig. 6.6, is used.
Step 5 Perform the Go To Center action. Set the payload motionless. After that it is necessary to reset the angle encoders. Go to the Main Control Window and reset the angle encoders.
Step 6
Click on the Collect X Y Data button. The corresponding controller denoted by 3DCrane Angle Excitation opens – see Fig. 6.13. Click Set Address button and rebuild the model. Next choose successively Connect to Target and Start real-time simulation from the pull-down menu. The cart and the rail start to move and stop afterwards. This short (in time) motion gives an impulse to the payload to swing. The system collects angles data.
Step 7
Having collected data of angles trajectories you can start the identification of Z displacement. Click on the Identify Z Displacement button. The angle data are displayed (see Fig. 6.15)
The mathematical pendulum model is assumed. The period of oscillations T is calculated from the formula
lT = 2π
g where l is the mathematical pendulum length and g is the gravity constant. You obtain the values for the period and the length of the pendulum. They are: 1.826 s and 0.822 m in the presented example.
Step 8
We click on the PID Optimisation button to invoke the iterative procedure. This procedure tunes the parameters of the PI controller for each axis using the model given in Fig. 6.17. The performance index is equal to the sum of squares of the differences between the reference signal and the response of the system. The penalty function is also used (see CaseStudy_penaltyPID.m file for details).
The optimisation runs. The temporary system responses to the iterative parameters Kp and
Ki values are displayed in the consecutive three figures. The final results are visible in Fig. 6.18, Fig. 6.19 and Fig. 6.20, and displayed in the MATLAB command window.
In the presented example the PI optimisation results in:
[ Kpx Kix ]= [ 32.9328 8.82428e-007 ]
[ Kpy Kiy ]= [ 19.0999 4.74215e-006 ]
[ Kpz Kiz ]= [ 267.3002 3.414063e-007 ]
The proportional gains are large. This follows from the fact that the time constants in the previously identified models are very small. The models are thus close to non-dynamical systems. In such a case the closed-loop system requires very large K parameters for PI controllers to track the step reference signals.
Remember that the parameters tuned above relate only to the PI controllers of the desired X, Y and Z cart positions. They do not relate to the PID controllers of the X and Y angles.
When the optimisation is finished click 5DOF Experiment button, invoke the Crane3D_CSPID model (see Fig. 6.21 ) and manually introduce the set of new parameters for the X PID and Y PID controllers.
The PID controllers of the X an Y angles have the default Kp values equal to 20. You may change and enlarge these values up to your requirements. However, do remember that this is a trade-off between tracking the desired cart trajectory and the payload stabilisation. Too high Kp values may result in an unstable behaviour of the crane.
Rebuild the model, then open two scopes and start the real-time experiment. The results of the experiment are visible in the scopes (see Fig. 6.22 and Fig. 6.23).
The cart is tracking the reference signals in the form of square waves. Abrupt changes in the cart movement result in oscillations of the payload. These oscillations are immediately dumped due to the P angle controllers operation.
7. Prototyping your own controller in RTWT environment
In this section the process of building your own control system is described. The Real Time Windows Target (RTWT) toolbox is used. An example how to use the Crane3D software is shown later in section 5.3. In this section we give indications how to proceed in the RTWT environment.
Before start, test your MATLAB configuration and compiler installation by building and running an example of real-time application. Real-time
Windows Target includes the model rtvdp.mdl. In the MATLAB Command Window, type
rtvdp
Next, build and run the real-time model. For details refer to the Real-Time Windows Target help, section Installation and Configuration.
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 3DCrane Device Driver and other blocks chosen from the Simulink library,
-
build the executable file under RTWT (see the pop-up menus in Fig. 5.1)
-
start the real-time code to run from the Simulation/Start real-time code pull-down menus.
7.1. Creating a model
The simplest way to create a Simulink model of the control system is to use one of the models included in the Main Control Window as a template. For example, click on the Pxyz button and save it as MySystem.mdlname. The MySystem Simulink model is shown in Fig.
7.2.
Now, you can modify the model. You have absolute freedom to develop your own controller. Remember to leave the 3DCrane driver model and the Set Base Address button in the window. This is necessary to activate transferring the base address of the I/O card to the model as a MATLAB workspace variable.
Though it is not obligatory, we recommend you to live the multiplexer with the scope and the control saturation blocks. You need a scope to watch how the system runs. You also need the saturation blocks to constraint the controls to match the maximal PWM signals sent to the DC motors. The saturation blocks are built in the Crane 3D driver block. They limit currents to DC motors for safety reasons. However they are not visible for the user who may amaze at the saturation of controls. Other blocks remaining in the window are not necessary for our new project.
Creating your own model on the basis of an old example ensures that all-internal options of the model are set properly. These options are required to proceed with compiling and linking in a proper way. To put the 3DCrane Device Driver into the real-time code a special make-file is required. This file is included to the 3DCrane software.
You can apply most of the blocks from the Simulink library. However, some of them cannot be used (see MathWorks references manual).
The scope block properties are important for appropriate data acquisition and watching how the system runs.
The Scope block properties are defined in the Scope property window (see Fig. 7.3). This window opens after the selection of the Scope/Properties tab. You can gather measurement data to the Matlab Workspacemarking the Save data to workspace checkbox. The data is placed under Variable name. The variable format can be set as structure or matrix. The default Sampling Decimation parameter value is set to 1. This means that each measured point is plotted and saved. Often we choose the Decimation parameter value equal to 5 or 10. This is a good choice to get enough points to describe the signal behaviour and to save the computer memory.
When the Simulink model is ready, click the Tools/External Mode Control Panel option and next click the Signal Triggering button. The window presented in Fig. 7.4 opens. Select XT Scope, set Source as manual, set Duration equal to the number of samples you intend to collect and close the window.
7.2. Code generation and the build process
Once a model of the system has been designed the code for real-time mode can be generated, compiled, linked and downloaded into the processor.
The code is generated by the use of Target Language Compiler (TLC) (see description of the Simulink Target Language). The make-file is used to build and download object files to the target hardware automatically.
First, you have to specify the simulation parameters of your Simulink model in the Simulation parameters dialog box. The RTW page appears when you select the RTW tab (Fig. 7.5). The RTW page allows you to set the real-time build options and then to start the building process of the RTW.DLL executable file.
The system target file name is win_watc.tlc. It manages the code generation process. The crane3d_win_watc.tmf template make-file is devoted to C code generation using the WATCOM 11.0 compiler.
Notice that the crane3d_win_vc.tmf template make-file is also included to the software. It is ready to be used by the Microsoft Visual C++ 6.0 compiler.
Template make-file must correspond to the compiler in use. See section 10 for details.
There are three options which have to be properly marked as shown in Fig. 7.5:
-
Inline parameters -not used when building a real-time program,
-
Retain.rtw file -if marked, auxiliary information is stored in the file (with .rtw extension),
-
Generate code only -if marked, a code is generated but compilation is not performed.
The Solver page appears when you select the Solver tab (Fig. 7.6). The Solver page allows you to set the simulation parameters. Several parameters and options are available in the window. The Fixed-step sizeeditable text box is set to 0.01 (this is the sampling period in seconds).
The Fixed-step solver is obligatory for real-time applications. If you use an arbitrary block from the discrete Simulink library or a block from the driver
library remember that different sampling periods must have a common divider.
The Start time has to be set to 0. The solver has to be selected. In our example the fifth-order integration method − ode5 is chosen.
If all parameters are set properly you can start the DLL executable building process. For this purpose press the Build push button on the RTW page (Fig. 7.5).
Successful compilation and linking processes generate the following message:
Model MyModel.rtd successfully created ### Successful completion of Real-Time Workshop build procedure for model: MyModel
Otherwise, an error massage is displayed in the MATLAB command window.
Before starting the experiment set the initial position of the cart, the rail and the payload in a safe zone. The Go Home and Go To Center buttons are
applied to fulfil these tasks.
8. Mathematical model of the 3DCrane
The schematic diagram of the crane is given in Fig. 8.1.
There are five measured quantities:
-
xw (not marked in Fig. 8.1) denotes the distance of the rail with the cart from the center of the construction frame;
-
yw (not marked in Fig. 8.1) denotes the distance of the cart from the center of the rail;
-
R denotes the length of the lift-line;
-
denotes the angle between the y axis and the lift-line;
-
denotes the angle between the negative direction on the z axis and the projection of the lift-line onto the xz plane.
Denote also:
mc -mass of the payload
mw -mass of the cart
ms -mass of the moving rail
xc,yc,zc -coordinates of the payload
S-reaction force in the lift-line acting on the cart
Fx -force driving the rail with cart
Fy -force driving the cart along the rail
FR -force controlling the length of the lift-line
Tx, Ty, TR -friction forces.
Detailed model is delivered with complete system
9. Description of the Crane3D class properties
The Crane3D is a MATLAB class, which gives the access to all the features of the RTDAC/PCI board equipped with the logic for the 3DCrane model. The RT-DAC/PCI board is an interface between the control software executed by a PC computer and the power-interface electronic of the 3DCrane 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 identical encoders measuring five state quantities: two cart positions at the horizontal 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/PCI board are accessible by appropriate methods of the Crane3D class.
The object of the Crane3D class is created by the command:
object_name = crane3d;
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 Crane3D 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
|
9.1. BaseAddress
Purpose: Read the base address of the RT-DAC/PCI board.
Synopsis: BaseAddress = get( cr3, ‘BaseAddress’ );
Description: The base address of RT-DAC/PCI board is determined by OS. Each Crane3D object has to know the base address of the board. When a Crane3D object is created the base address is detected automatically. The detection procedure detects the base address of the first RT-DAC/PCI board plugged into the PCI slots.
Example: Create the Crane3D object:
cr3 = crane3d;
Display its properties by typing the command:
cr3
>>Type: Crane3D 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( cr3, ‘BaseAddress’ );
9.2. BitstreamVersion
Purpose: Read the version of the logic design for the RT-DAC/PCI board.
Synopsis: Version = get( cr3, ‘BitstreamVersion’ );
Description: This property determines the version of the logic design of the RTDAC/PCI board. The 3DCrane 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.
9.3. Encoder
Purpose: Read the incremental encoder registers.
Synopsis: enc = get( cr3, ‘Encoder’ );
Description: The property returns five digits. The first two measure the position of the cart. 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
9.4. PWM
Purpose: Set the parameters of the PWM waves.
Synopsis: PWM = get( cr3, ‘PWM’ ); set( cr3, ‘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( cr3, ‘PWM’, [ -0.3 0.0 1.0 ] );
9.5. PWMPrescaler
Purpose: Determine the frequency of the PWM waves.
Synopsis: Prescaler = get( cr3, ‘PWMPrescaler’ ); set( cr3, ‘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
9.6. ResetEncoder
Purpose: Reset the encoder counters.
Synopsis: set( cr3, ‘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( cr3, ‘ResetEncoder’, [ 1 0 0 1 0 ] );
9.7. RailLimit
Purpose: Control the operating range of the 3D-crane system.
Synopsis: Limit = get( cr3, ‘RailLimit’ ); set( cr3, ‘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
9.8. RailLimitFlag
Purpose: Set range of limit flags.
Synopsis: LimitFlag = get( cr3, ‘RailLimitFlag’ ); set( cr3, ‘RailLimitFlag’, NewLimitFlag );
Description: The RailLimitFlags is a 1x3 vector. The first two elements control the operating range of the cart. 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 motor corresponding 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
9.9. RailLimitSwitch
Purpose: Read the state of limit switches. Synopsis: LimitSwitch = get( cr3, ‘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
9.10. ResetSwitchFlag
Purpose: Control the auto-reset of the encoder registers.
Synopsis: ResetSwitchFlag = get( cr3, ‘ResetSwitchtFlag’ ); set( cr3, ‘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
9.11. Therm
Purpose: Read thermal flags of the power amplifiers. Synopsis: Therm = get( cr3, ‘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
9.12. ThermFlag
Purpose: Control an automatic power down of the power amplifiers.
Synopsis: ThermFlag = get( cr3, ‘ThermFlag’ ); set( cr3, ‘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
9.13. Time
Purpose: Return time information.
Synopsis: T = get( cr3, ‘Time’ );
Description: The Crane3D object contains the time counter. When a Crane3D object is created the time counter is set to zero. Each reference to the Time property updates its value. The value is equal to the number of milliseconds past since the object was created.
9.14. Quick reference table
Property Name
|
Description
|
BitstreamVersion
|
Read the version of the logic design for the RT-DAC/PCI 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 3DCrane 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
|
10. How to fulfil the compilation settings page
In Fig. 10.1, Fig. 10.2 and Fig. 10.3 the different Simulation Parameters pages are shown. Having the MATLAB version and the compiler version the user has to choose the appropriate Simulation Parameters page version.