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

PE_data_Update_Live.m
%% Retrieve parameter estimation data from live measurement
%
% UNDER DEVELOPMENT 
%---------------------------------------------
%|     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 R2007a   |
%---------------------------------------------
%
% 1. open model DMC_system_demo
% 2. select reference block: P2P Parameter Estimation
% 3. select preliminary controller or controller with 10 Hz bandwidth
% 3. select motion system 'Rapid Prototyping' 
% 4. generate code and run 
% 5. run this script

% Show measured response using data from xpctarget

% Ping target
if strcmp(xpctargetping,'failed')
    disp('Error: Target PC not connected')
    return
end

% Read from DATA.DAT
fsys=xpctarget.fs;
hfile=fsys.fopen('data.dat');
if hfile==-1
    disp('Error: file DATA.DAT not found on target PC')
    return
end
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
Tin=data(:,1);
u1=data(:,2);
u2=data(:,3);
Rin=data(:,4);
errm=data(:,5);

disp('Data retrieved from xPC target')

%cd '..\PE'
save temp time Tin Rin errm
clear all
load PE_data
load temp

% here you can specify the initial guess for the parameters to be estimated
J1=1.00e-6;  % motor inertia                   [kgm2]
J2=0.15e-6;  % load  inertia                   [kgm2] 
b1=2e-6;     % motor bearing damping           [Nms/rad]
b2=2e-6;     % load  bearing damping           [Nms/rad]
b12=2e-7;    % internal damping flexible shaft [Nms/rad]
k=0.013;     % stiffness of flexible shaft     [Nm/rad

save PE_data

disp('New data stored in PE_data.mat')

Contact us