Code covered by the BSD License  

Highlights from
Motion Control Demo

image thumbnail

Motion Control Demo

by

 

30 Oct 2007 (Updated )

Model Based Design Demonstration Based on a Motion Control Case Study

Retrieve_Data.m
%% Retrieve transfer function measurement data from xpctarget
%---------------------------------------------
%|     The Digital Motion Control Demo       |
%---------------------------------------------
%| A practical lesson in Model-Based Design. |
%| Prepared by:                              |
%| Paul Lambrechts, March, 2007              |
%| Copyright 2007, The MathWorks, Inc.       |
%---------------------------------------------
%| Note: This demo is prepared with R2006b   |
%---------------------------------------------

% Get the raw data

if strcmp(xpctargetping,'success')
    fsys=xpctarget.fs;
    hfile=fsys.fopen('data.dat');
    rawdata=fsys.fread(hfile);
    fsys.fclose(hfile);

    % Create the datastructure
    datastruct=readxpcfile(rawdata);

    % Get the data and separate the timevector
    data=datastruct.data;
    time=data(:,end);

    % Assign the signals
    n=data(:,1);
    u1=data(:,2);
    u2=data(:,3);
    Tin=n;
    Rin=data(:,4);
    err=data(:,5);
    disp('Measurement data retrieved from xPC target')
elseif exist('simout','var')
    time = tout;
    n=simout.signals.values(:,1);
    u1=simout.signals.values(:,2);
    u2=simout.signals.values(:,3);
    Tin=n;
    Rin=simout.signals.values(:,4);
    err=simout.signals.values(:,5);
    disp('Virtual measurement data used')
else
    load measdat
    disp('Measurement data loaded from file')
end

% Plot the measured signals
close all
plot(time,[n u1 u2])
title('Measured Signals')
xlabel('time [s]')
ylabel('response [V]')
legend('noise','u1','u2')

Contact us