author | Edouard Tisserant |
Sun, 20 May 2012 22:42:37 +0200 | |
changeset 2048 | 5726f2bbdace |
parent 2045 | 62e102935f3e |
child 2059 | b74955d211c7 |
permissions | -rw-r--r-- |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
1 |
/* |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
2 |
* Ethercat CIA402 node execution code |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
3 |
* |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
4 |
* */ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
5 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
6 |
#include "ecrt.h" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
7 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
8 |
#ifdef _WINDOWS_H |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
9 |
#include "iec_types.h" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
10 |
#else |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
11 |
#include "iec_std_lib.h" |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
12 |
#endif |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
13 |
|
2034 | 14 |
IEC_INT beremiz__IW%(location)s_0; |
15 |
IEC_INT *__IW%(location)s_0 = &beremiz__IW%(location)s_0; |
|
16 |
||
17 |
%(MCL_headers)s |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
18 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
19 |
IEC_UINT __InactiveMask = 0x4f; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
20 |
IEC_UINT __ActiveMask = 0x6f; |
2034 | 21 |
IEC_UINT __PowerMask = 0x10; |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2036
diff
changeset
|
22 |
IEC_BOOL __FirstTick = 1; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
23 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
24 |
typedef enum { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
25 |
__Unknown, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
26 |
__NotReadyToSwitchOn, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
27 |
__SwitchOnDisabled, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
28 |
__ReadyToSwitchOn, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
29 |
__SwitchedOn, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
30 |
__OperationEnabled, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
31 |
__QuickStopActive, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
32 |
__FaultReactionActive, |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
33 |
__Fault, |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
34 |
} __CIA402NodeState; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
35 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
36 |
typedef struct { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
37 |
%(entry_variables)s |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
38 |
__CIA402NodeState state; |
2034 | 39 |
axis_s* axis; |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
40 |
} __CIA402Node; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
41 |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
42 |
static __CIA402Node __CIA402Node_%(location)s; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
43 |
|
2034 | 44 |
%(extern_located_variables_declaration)s |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
45 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
46 |
int __init_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
47 |
{ |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2036
diff
changeset
|
48 |
%(init_entry_variables)s |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
49 |
*__IW%(location)s_0 = __MK_AllocAxis(&(__CIA402Node_%(location)s.axis)); |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
50 |
return 0; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
51 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
52 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
53 |
void __cleanup_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
54 |
{ |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
55 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
56 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
57 |
void __retrieve_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
58 |
{ |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
59 |
IEC_UINT statusword_inactive = *(__CIA402Node_%(location)s.StatusWord) & __InactiveMask; |
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
60 |
IEC_UINT statusword_active = *(__CIA402Node_%(location)s.StatusWord) & __ActiveMask; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
61 |
|
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2036
diff
changeset
|
62 |
if (__FirstTick) { |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2036
diff
changeset
|
63 |
%(init_axis_params)s |
2045 | 64 |
__FirstTick = 0; |
2041
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2036
diff
changeset
|
65 |
} |
ce3727171207
Defining all slaves as Etherlab master subplugin instead of editing them in an editor with vertical notebook
laurent
parents:
2036
diff
changeset
|
66 |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
67 |
// CIA402 node state computation |
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
68 |
__CIA402Node_%(location)s.state = __Unknown; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
69 |
switch (statusword_inactive) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
70 |
case 0x00: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
71 |
__CIA402Node_%(location)s.state = __NotReadyToSwitchOn; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
72 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
73 |
case 0x40: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
74 |
__CIA402Node_%(location)s.state = __SwitchOnDisabled; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
75 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
76 |
case 0x0f: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
77 |
__CIA402Node_%(location)s.state = __FaultReactionActive; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
78 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
79 |
case 0x08: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
80 |
__CIA402Node_%(location)s.state = __Fault; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
81 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
82 |
default: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
83 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
84 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
85 |
switch (statusword_active) { |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
86 |
case 0x21: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
87 |
__CIA402Node_%(location)s.state = __ReadyToSwitchOn; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
88 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
89 |
case 0x23: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
90 |
__CIA402Node_%(location)s.state = __SwitchedOn; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
91 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
92 |
case 0x27: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
93 |
__CIA402Node_%(location)s.state = __OperationEnabled; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
94 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
95 |
case 0x07: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
96 |
__CIA402Node_%(location)s.state = __QuickStopActive; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
97 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
98 |
default: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
99 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
100 |
} |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
101 |
if (__CIA402Node_%(location)s.state == __Unknown) { |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
102 |
return; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
103 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
104 |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
105 |
__CIA402Node_%(location)s.axis->PowerFeedback = __CIA402Node_%(location)s.state == __OperationEnabled; |
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
106 |
__CIA402Node_%(location)s.axis->ActualPosition = (IEC_REAL)(*(__CIA402Node_%(location)s.ActualPosition)) * __CIA402Node_%(location)s.axis->RatioDenominator / __CIA402Node_%(location)s.axis->RatioNumerator; |
2034 | 107 |
|
108 |
__MK_UpdateAxis(*__IW%(location)s_0); |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
109 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
110 |
|
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
111 |
void __publish_%(location)s() |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
112 |
{ |
2034 | 113 |
__MK_ComputeAxis(*__IW%(location)s_0); |
114 |
||
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
115 |
IEC_BOOL power = ((*(__CIA402Node_%(location)s.StatusWord) & __PowerMask) > 0) && __CIA402Node_%(location)s.axis->Power; |
2034 | 116 |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
117 |
// CIA402 node state transition computation |
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
118 |
switch (__CIA402Node_%(location)s.state) { |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
119 |
case __SwitchOnDisabled: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
120 |
*(__CIA402Node_%(location)s.ControlWord) = (*(__CIA402Node_%(location)s.ControlWord) & ~0x87) | 0x06; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
121 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
122 |
case __ReadyToSwitchOn: |
2034 | 123 |
case __OperationEnabled: |
124 |
if (!power) { |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
125 |
*(__CIA402Node_%(location)s.ControlWord) = (*(__CIA402Node_%(location)s.ControlWord) & ~0x8f) | 0x07; |
2034 | 126 |
break; |
127 |
} |
|
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
128 |
case __SwitchedOn: |
2034 | 129 |
if (power) { |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
130 |
*(__CIA402Node_%(location)s.ControlWord) = (*(__CIA402Node_%(location)s.ControlWord) & ~0x8f) | 0x0f; |
2034 | 131 |
} |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
132 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
133 |
case __Fault: |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
134 |
*(__CIA402Node_%(location)s.ControlWord) = (*(__CIA402Node_%(location)s.ControlWord) & ~0x8f) | 0x80; |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
135 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
136 |
default: |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
137 |
break; |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
138 |
} |
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
139 |
|
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
140 |
if (__CIA402Node_%(location)s.axis->CSP && *(__CIA402Node_%(location)s.ModesOfOperationDisplay) == 0x08) { |
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
141 |
*(__CIA402Node_%(location)s.TargetPosition) = (IEC_DINT)(__CIA402Node_%(location)s.axis->PositionSetPoint * __CIA402Node_%(location)s.axis->RatioNumerator / __CIA402Node_%(location)s.axis->RatioDenominator); |
2036
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
142 |
} |
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
143 |
else { |
2043
27d4cb689a79
Adding plugin icons and replacing reference to DS402 by CIA402
laurent
parents:
2041
diff
changeset
|
144 |
*(__CIA402Node_%(location)s.TargetPosition) = *(__CIA402Node_%(location)s.ActualPosition); |
2036
7c31fab22c74
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
laurent
parents:
2035
diff
changeset
|
145 |
} |
2032
766078d83e22
Adding support for DS402 node subplugin (only simple state transition implemented)
laurent
parents:
diff
changeset
|
146 |
} |