Title: Getting Started with xPC Target ME4803C
1Getting Started with xPC TargetME4803C
2System Identification of Structure Dynamics in
Flexible Robotics
RALF (Robotic Arm Large and Flexible)
- RALF
- Hydraulically Actuated
- 20 Reach
- Lightweight and Flexible
- DFT Averaging Analysis
- Structure Dynamics
- Actuator Model
- Computer Interface
- Analog Control with LabVIEW DAQ
- Math Works XPC Target
3PNNL TEST BED
- Spar 2500 Macro Manipulator
- 3.4 Meter Aluminum Beam
- Schilling Titan II
- 2.14 Hz First Natural Frequency
- 0.006 Damping Ratio
4Computer Basics
- Login into host computer as
- Username lab
- Password student (or students)
- There is a directory called C\xPC_Tutorial
that has a number of useful Simulink models and
tutorial files.
- Create a directory on C\ for your lab and make
sure this is selected as the working directory in
Matlab when using xPC Target.
5Intro to xPC target
- Matlabs xPC target takes your Simulink model
from the host computer, compiles it into C-code
and runs it using a real-time operator system on
the target computer. - The target computer repeatedly executes this code
at a defined iteration period.
- The target computer can interface with physical
components through Input / Output cards.
- More information can be found at the Mathworks
websites xPC-target page. There is also the file
xpc_target_gs.pdf in the tutorial directory.
6Useful xPC Target Functions
- Xpctargetping checks if communication is
working
- Xpctest tests to see if target is fully
functional
- xpcrctool remote control tool useful for
general operation
- tg is structure that is generated in the
workspace that has relevant data including
uploaded data.
- tg.start, tg.stop, . Can start, stop, the
program on the target.
7Testing xPC Target Machine Connection
- Make sure the target PC is turned on
- Type xpctest, if everything is ok you should
see the following report in Matlab.
8Opening a Program
- Programming an xPC file is similar to programming
a regular Simulink simulation, but there are
several settings that need to be changed in the
Simulation ? Simulation Parameters menu. - For simplicity start with a Simulink file already
configured for xPC-target such as
C\xPC_tutorial \blank_project.mdl. Save the
file in your directory located on C\
9Things to Know
- You will be making a discrete controller meaning
it will update at a specified sampling rate.
Later labs will discuss selection of sampling
rate, for now use 1 KHz, or a sampling period of
0.001 seconds. - This rate can be set in Simulations menu and all
discrete simulink blocks must match.
- Start, stop time can be set in the main menu or
using xpcrctool.
- inf (infinite) stop time is often useful.
10Setting Controller Sampling Rate
Click on Simulation and select Simulation
Parameters
Enter Stop Time (pick a large number or enter
inf)
Enter Controller Iteration Period (select 0.001
seconds for now)
11Adding Input / Output interface Blocks
- Open simulink library
- view ? library browser
- Place a D/A interface block. In the library
browser go to
- xPC Target ? D/A ? Computer Boards ? CIO-DAS1602
12
- Place a A/D interface block. In the library
browser go to
- xPC Target ? A/D ? Computer Boards ? CIO-DAS1602
12
- Drag the blocks to your Simulink Model
- Double Click on the Simulink Blocks in your model
and modify the settings as illustrated on the
next page.
12Model with Interfaces (settings)
13Adding Additional Components
- Add a Signal Generator to your model and wire
it to the D/A block
- Simulink ? Sources ? Signal Generator
- Add a xPC Target Scope to your model
- xPC Target ? Misc ? Scope (xPC)
- Place a Simulink signal Mux to your model
- Simulink ? Signal Routing ? Mux
- Place an Output Block in the model
- Simulink ? Sinks ? Out1
- Wire the A/D card into the upper Mux input
- Wire the lower Mux input to the signal
Generator
- Wire the Mux output to both the xPC Target
Scope and Out1 block
- Verify your model looks similar to the following
page and then save it to your directory as
xPC_Tutorial.mdl
14xPC Tutorial Block Diagram
Build Model Button
- Build your model by selecting
- Tools? Real -Time Workshop ? Build Model
- (Alternatively the Build Model button on the
Simulink header or the menu options in
xpcrctool may be used to build the model.)
- If you receive an error message try building it
again. If you continue to receive an error
message then something is not correctly set in
your model.
15Running Your Program
- Option A xpcrctool
- Open the xpcrctool
- Hit the play stop buttons to run stop the
target
- Option B command prompt
- Type tg.start to start target
- Type tg.stop to stop target
- Run your program and look at the monitor of the
Target machine. Inspect the wiring of the signal
generator, physical scope, and wiring to the
Target machine (pins 37 18 are A/D and 9 7
D/A). Play with the physical signal generators
frequency setting and see what happens on the
scope and Target Machines monitor.
16Changing Parameters While Program is Running (A)
- Option A xpcrctool
- Open xpcrctool
- Select Tools ? Tune Parameters
- This will open a window that looks like the
Simulink model. Double click on the block you
wish to modify settings. When done entering new
settings select OK or Apply - When done, close the Tune Parameters Window.
- This method does not change the saved Simulink
model file.
- Use this method to change the frequency and
amplitude of the virtual scope being generated by
the program. Watch the results on the Target
Machines monitor and physical scope.
17Changing Parameters While Program is Running (B)
- Option B Using external Mode of the Simlink
File
- In the Simulink file select Simulation ?
External
- In the Simulink file select Simulation ? Connect
to Target
- This will automatically download to the target
all values set in the Simulink file. Any
Parameter change you make while connected to the
target will also be downloaded to the target. - When done, select Simulation ? Disconnect from
Target
- This method is more powerful than using
xpcrctool, but it changes the Simulink model
file and care must be taken to reset all
parameters to initial desired start up values
before rebuilding. - Use this method to change the frequency and
amplitude of the virtual scope being generated by
the program. Watch the results on the Target
Machines monitor and physical scope.
18Saving Data (A)
- Option A Using Output Log
- Any data wired into an output block at the
highest model level (out1 in this example) will
be recorded to the matlab workspace.
- Recorded data can be accessed through the
variable tg.OutputLog which is automatically
saved to the workspace when stopping the Target
Machine. - The amount of data stored can be specified
under
- Tools ? Real Time Workshop ? Options, Category
xPC Target Code Generation
- The Target machine must be stopped to access the
logged data.
19Saving Data (B)
- Option B Using Host Scopes in xpcrctool
- Make sure the simlink model is not Connected to
Target
- Using xpcrctool interface create a Host
Scope
- If your model is simple, use the Add signals
button to open a signal selection window that
looks like the Simulink Model File.
- Right Click the curser over signal lines and
select Add to scope 2 (Blue lines can be
selected, red lines can not. Go into subsytems to
select signals that are red lines) - When done selecting signals close the model
browser window.
- To Access the Host Scope select
- Tools ? Host Scope Manager
- If you close the Host Scope without saving it
through the Manager window you will have to
rebuild the host scope.
20Adding Host Scope Selecting Signals
Select Host Scope
Add Scope
Add Signals
21Setting Host Scope Parameters (1)
- Number of Sample Select an appropriate number of
samples to give an accurate picture of the data.
Use the programs sampling rate for determining
corresponding time length of sampled data. - Set the fixed Y-axis limits by using
- Plot ? Y-Axis ? Manual
- For now use Y_max 11 and Y_min -11
- Signals can be added through the Add/Remove
button and selecting appropriate signals in the
sub menu.
- Start and Stop the Scope using the interface
buttons
22Setting Host Scope Parameters (2)
- Once Stopped, export the data to the Matlab
workspace using the Export button.
- Be careful, the scope will always export to the
workspace using the same variable names. Make
sure you rename the data variable, both the scope
signals (scopename_data) and time variable
(scopename_time), or else they will be
overwritten next time you export data from the
scope to the workspace. - Data can be saved and plotted in Matlab through
traditional workspace / variable saving commands
and plotting commands (for more information type
help save and help plot) - Use the Host Scope to record and save signals.
Change settings on the Virtual Scope being
generated by the Target Machine and the Physical
Scope to get several data sets.
23Illustration of Host Scope
Number of Samples Setting
Start Stop Buttons
Export and Add/Remove Signals Buttons
24Modify Block Diagram
- Modify your file by adding summers, constants,
gains, and other signals as illustrated by
Set both the Signal Generators amplitude and
the Constant Reference to 0
25Using Modified Block Diagram
- Build and run the modified block diagram
- View the Target Machines Monitor and physical
scope as you change Constant, Virtual Signal
Generator, Gain, and physical signal
generator's setting / values. - Build a Host Scope to record and save to Matlabs
workspace the resulting signals from different
settings. Be sure to rename data exported from
the host scope, preferably with descriptive names
(both time and signal variables). - Are you recording and viewing what you expect?