Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
classdef SCDclass_taskmdsloadprevETHCAT < SCDclass_task
% This is a special class which loads previous
% values of the EtherCAT1 real-time network
properties
modelbus
node
workspacedatabasestructure
end
properties(Access=private)
logdecimate
nint16
nfloat32 % not yet implemented
end
methods
function obj=SCDclass_taskmdsloadprevETHCAT(id, varargin)
obj@SCDclass_task(id, varargin);
obj.cparser.addRequired('modelbus',@(x) ischar(x));
obj.cparser.addParameter('node', 0, @(x) (isnumeric(x) && ((x==1) || x==2)));
obj=obj.parseconstructorcommon(id, varargin);
obj.modelbus=obj.cparser.Results.modelbus;
obj.node=obj.cparser.Results.node;
switch(obj.node)
case 2
obj.workspacedatabasestructure='SCDsimdata.SCDnode02simdata.ethercat';
otherwise
error('SCDclass_taskmdsloadprevETHCAT:constructor','Class not implemented for node %d',obj.node);
%obj.workspacedatabasestructure='';
end
obj.classname=mfilename;
obj.logdecimate=2;
obj.nint16=20;
obj.nfloat32=10; % not yet implemented
end
function init(obj, shot)
mdsconnect(obj.mdsserver);
mdsopen(obj.mdstree, shot);
switch(obj.node)
case 2
obj.actualizeNode(shot);
end
catch
fprintf('\n');
warning('SCDclass_taskmdsloadprevETHCAT:init','Error initializing ETHCAT bus for node %d.',obj.node);
end
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
end
function [obj, value] = getdata(obj,shot)
switch(obj.node)
case 2
[~,value]=obj.getdataNodeETHCAT1(shot);
end
end
function printinfo(obj)
obj.printinfocommon;
fprintf(' Init model bus: %s, node: %d, ws base struct: %s\n',obj.modelbus, obj.node, obj.workspacedatabasestructure);
end
function entrystring = genMARTe2entry(obj, shot)
% TODO: this is a workaround which works by chance, need a more accurate fix
entrystring = '';
end
end
methods(Access = private)
function obj = actualizeNode(obj, shot)
dd=SCDconf_getdatadict(obj.datadictionary);
adcbus=dd.getEntry(obj.modelbus).getValue;
[~,data]=obj.getdata(shot);
T=timeseries;
if obj.verbose==1
fprintf('Actualizing data for bus: ''%s'' (%s, shot %d) 0%% ', obj.modelbus, obj.classname, shot);
end
for ii=1:obj.nint16
T.Time=data.Time;
T.Data=int16(data.Data(:,ii));
assignin('base','temp',T);
assigncmd=sprintf('%s.%s=temp;',obj.workspacedatabasestructure, adcbus.Elements(ii).Name);
evalin('base',assigncmd);
if obj.verbose==1 && mod(ii,obj.logdecimate)==0
fprintf('%.0f%% ', ii/obj.nint16*100);
end
end
evalin('base','clear temp');
if obj.verbose==1
fprintf('100%% \n');
end
end
%%
% Node 02 loading functions
function [obj, value] = getdataNodeETHCAT1(obj, shot)
mdsnodename='node02';
mdsopen('rtc',shot);
T=timeseries;
timebase=mdsvalue(['dim_of(\top.' mdsnodename '.ethcat1.in.int16_001)']);
d_time = double(mdsvalueraw(['\top.' mdsnodename '.params:d_time']))*1.0e-6;
%timebase = round(timebase.*1/d_time)*d_time-d_time/2;
timebase = round(timebase.*1/d_time)*d_time-d_time/100;
T.Time=timebase;
T.Data=zeros(numel(timebase),obj.nint16);
datamatrix=zeros(numel(timebase),obj.nint16);
if obj.verbose==1
fprintf('Getting data for bus: ''%s'' (%s, shot %d) 0%% ', obj.modelbus, obj.classname, shot);
end
for ii=1:obj.nint16
channelstr=sprintf(['\\top.' mdsnodename '.ethcat1.in.int16_%03d.raw'],ii);
datamatrix(:,ii)=int16(mdsvalueraw(channelstr));
if obj.verbose==1 && mod(ii,obj.logdecimate)==0
fprintf('%.0f%% ', ii/192*100);
end
end
T.Data=datamatrix; % this speeds up a lot the loading
value=T;
if obj.verbose==1
fprintf('100%% \n');
end
end
end
end