Vous êtes sur la page 1sur 5

dSPACE quick manual

Building a Simulink file and connecting the variables in ControlDesk

1.) Download the IO file for the motor from the course home page. DoR_IO.mdl

2.) Start Matlab and open DoR_IO.mdl.

2.b) If you want to see how the PWM block works just open it. In the Enc I/F subsystem the
counters from the encoders are read and scaled to radians. Both of the encoder I/O block has a
second output which is the number of pulses since the last reading, this is used to calculate the
velocity. To get the correct scaling for the velocity we need to set the sampling period of the
model in each scaling block (the Ts parameter). The best is to enter Ts at the matlab prompt and
not as an numeric value in the gain block. A good start can be to set Ts = 0.01 .

3)Choose, Simulation -> Configuration Parameters from the menu in the Simulink file. A few
changes should be done to prepare Simulink for real-time. Se the Matlab output below.

----------------------------------------------------------------------------------------
Some Simulink default parameters are unsuitable for use with RTI.
It is recommended to adapt the Configuration Preferences.

- Solver - current recommended setting


Stop time: '' -> 'Inf'
Solver type: '' -> ´Fixed-step´
Fixed-step-size: '' -> ´must be the sampling period Ts

-Optimization-
Block reduction optimization: '' -> 'off'
Signal storage reuse: '' -> 'off’

- Real-Time Workshop -
RTW system target file: '' -> 'rti1104.tlc'

----------------------------------------------------------------------------------------

4.) IMPORTANT: change to the correct directory in Matlab at the Matlab prompt, i.e. the
same directory that you have saved the Simulink file in. Many files will be created in the cur-
rent Matlab directory.

5.) Choose Tools -> Real-Time Workshop -> Build Model (Ctrl+B). Check that the build pro-
cedure has been performed correctly at the Matlab prompt. The simulink file now runs in real-
time on the real-time hardware in the PC. It should end with the message,
### Successful completion........................

6.)Start the program ControlDesk (ikon on the desktop), it consists of four main windows. Top
left is the Navigator Window, with three pages. Top middle/right is the Working Area for
instrumentations. Bottom is the Tool Window with 2-3 pages. To the right is the Virtual
Instrument. (If any of the windows are not showing they can be opened under the menu,
View -> Controlbars.)

6.b) ControlDesk may give you a few warnings about read only attributes. Just ignore this.

7.) Create a new experiment, an experiment is a container for all necessary files.
i) choose File -> New Experiment from the menu, give an experiment name and the working
directory, press (...) to brows. Important select File -> Save Experiment, even though nothing
have been created since the experiment was created. (it is a bug/feature)....

8.) The Working Area is used to build up instrumentation using layout files, to interact with
the real-time process. With input instruments is it possible to change Simulink parameters on
the fly and with displays and plotters to watch real-time data from the Simulink diagram.
i) Choose File -> New -> Layout, from the menu,
ii) Select File -> Save as, when the layout is active and save it in your home directory.
iii) If the Instrument Selector is on (the right most window) select the following instruments
one by one from the Virtual Instruments and draw them in the Layout. Is it not visible choose,
View -> Controlbars -> Instrument Selector.
One RadioButton, two Numeric Inputs, two Displays, one CheckButton and one OnOffButton.

9.) Chose File -> Open Variable File, from the menu and open the simulinkfile_name.sdf from
your home directory. The variable file maps the names of the individual Simulink blocks to the
correct memory address on the real-time processor.

10.) In the Tool Window, (see 7), of ControlDesk, choose the just opened page
c:\...\homedir\simulinkfile_name.sdf here you will find all the Simulink Block names under
their respective hierarchy. Example, the Signal Generator is directly under the Model Root,
whereas the grouped blocks PWM and Enc I/F are expandable by clicking the + sign. The sig-
nals and parameter of the Simulink blocks are connected to the instruments by simply drag
and drop. Each basic block in Simulink has at least one parameter and one output signal. The
parameters are shown as a P in the list and the output as a Out1.
Connect:
i.) The two Displays to the positions ϕ 1 and ϕ 2 , found on the top level of the Enc I/F block.
ii.) The two Numeric Inputs to the Signal generators Amplitude and Frequency and the Wave-
Form to the Radio Button, configure the Radio Button by double clicking on it set the value of
one of the buttons to 1, and the other to 2. 1 gives a Sine output and 2 a Square output, write an
appropriate Text for each button.
iii.) The OnOffButton is used to reset the encoders. Connect it to the Simulink block Reset
Encoder which is in the group Enc I/F. Configure the Button so that its value is 1 when pushed
and 0 when it is off and remove the second button, write an appropriate text for the button.
iiii.) The CheckButton is used to set power on, connect it to the parameter in the block
pwm_on found in the PWM group.

Observe that when a data connection is valid the red frame around the instruments disappears.

11.) Add files to the experiment, choose File -> Add All Opened Files, from the menu. Check
which files that have been added by choosing the Experiment page in the Navigator Window.
It is possible to delete files from the experiment by right clicking here and to add other files by
right clicking in the files window. Save the experiment.

12.) Start the real-time connection between instruments and the real-time application. Choose
Instrumentation -> Animation Mode in the menu.

13.) Turn on the DC power supply to the OBSERVE.! Connect motor plus cable to 12V and
motor ground to ground on the power supply.

14.) Turn the motor by hand an check if the encoders work correctly, e.g., turn the load one
revolution and check if the displays show the correct values. Generate a signal from the signal
generator and check if the motor starts. Reset the encoders

15.) Close ControlDesk and open it again, open your experiment, start the animation mode and
check that it still works.

16.) The real-time execution can be stopped by selecting Platform -> Application -> Stop
Real-Time Processor and restarted by Platform -> Application -> Reload Application from the
menu. This can be useful if a program reset is needed.

Creating plot windows in ControlDesk


1.) If Animation mode is on enter Edit mode by selecting Instrumentation -> Edit Mode from
the menu in ControlDesk.

2.) Open a new Layout by selecting, File -> New, in the menu. Save the layout with a name
and add it to the experiment, (see 13.).

3.) In the Instrument selector, see 8, highlight the page Data Aqusition and select the Plotter-
Array.

4.) Double click on the PlotterArray to open the Properties Window. At Add Instrument push
the button Plotter twice.

5.) Connect the variables to the plotter by dragging them from the Tools Window. Drop the
variable to the left of the y-axis in the plotter. A second variable can be dragged to the same
plotter, if it is dropped to the left of the y-axis it uses the same y-axis as the first variable, if it
is dropped to the right of the y-axis is a new y-axis created for the second variable.
Connect the time derivated position signals w1 and w2 to respective plot window.

6.) Enter Animation mode and initialize the capture setting window by selecting the host ser-
vice in the top menu of the capture setting window. Turn first the motor load by hand and then
by turning on the power pwm_on. Generate a square wave voltage with 4 V amplitude and 0.3
Hz frequency.

7.) The signal flow in the plotters are controlled by the Edit Capture Settings which is opened
by right clicking in the PlotterArray. If you don’t see the Capture Settings window it probably
hides to the very right in ControlDesk. Rescale the main window so you can bring the Capture
Settings window out in the main window. Right click in the Capture Settings window and
deselect the Allow Docking option. Change the signal length, e.g., 2.0 s. Make the Capture set-
tings Window a bit taller since a few buttons are not showed (bug...). Try the trigger function
found in the Capture Settings Window. Select the signal output of the signal generator as trig-
ger signal.

8.) To manipulate the plots, e.g., zooming, time measuring, grid lines etc. just click on the
PlotterArray to open the Toolbar PlotterArray Instrument. Fast zooming can be done by dou-
ble clicking left of the y-axis in the template.

9.) Check if the motors rotates in correct direction, i.e., when the voltage is positive should the
position increase (positive velocity), and when the voltage is negative should the position
decrease. You can enter zero frequency to the signal generator to create a dc-voltage. Some
motors will do the opposite, this can be corrected in the model, by multiplying the input to the
PWM block with minus one (-1.0).

Saving the signals from a plotter in ControlDesk to Matlab


The ControlDesk plots can be exported to Matlab where they can be manipulated and printed
and/or exported to a word processing program etc.

When a plot exists in the ControlDesk plotter, switch off the Auto Replay or push the Stop but-
ton, push the button Save in the Capture Setting instrument. Save the binary data file,
name.mat in your home directory. Type help load at the Matlab prompt to se how to retrieve
the data file to Matlab workspace. The data is loaded as a Matlab Struct. The individual data
signals can be reached within the struct by point notation and indexing, name.Y(i).Data, where
i = 1..n, where n is the number of saved signals from ControlDesk, the signal mapping to num-
bers can be seen in name.Y.Name. The matching time vector is found in name.X.Data.

-- End of example. Return to the Workshop.

Connecting more than one parameter to one instrument


This may have to be done later depending on how you have designed your Simulink file.

1.) Create an Instrument and connect the parameter of the first Simulink block that you would
like to change to the instrument.

2.) Connect the second parameter from the second Simulink block by dragging it with the right
mouse button instead of the left. You should then get a question of how you would like the
second connection to be configured. Choose Write To Variable.

Online Help
The online help in ControlDesk is called Help Desk and is a Explorer based help browser, it is
simple to use. There is much functionality in ControlDesk which is not described in this docu-
ment, so please use the help if you need some special function of ControlDesk.

TIP
At the different stages in the control design process, e.g., parameter identification, feedback,
feedforward design, etc. try to work with different Experiments and different Simulink files.
When things start going wrong in the later stages is it essential that there exists a functioning
Simulink file with an Experiment for an earlier design stage. This simplifies debugging and
thereby decreases your design effort and time.

Vous aimerez peut-être aussi