-
Notifications
You must be signed in to change notification settings - Fork 3
/
md_tutorial_2PDO.html
315 lines (297 loc) · 15.7 KB
/
md_tutorial_2PDO.html
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
42
43
44
45
46
47
48
49
50
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>CANopenDemo: CANopen PDO Example</title>
<link rel="icon" href="CANopenNode.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="CANopenNode.png"/></td>
<td id="projectalign">
<div id="projectname">CANopenDemo
</div>
<div id="projectbrief">CANopenNode demo, tutorial and testing</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search',false);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
</div><!-- top -->
<div id="doc-content">
<div><div class="header">
<div class="headertitle"><div class="title">CANopen PDO Example</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>A <b>PDO</b> (Process Data Object) is providing real-time data transfer of object entries of a CANopen device's object dictionary. The transfer of PDO is performed with no protocol overhead. The PDO correspond to objects in the object dictionary and provide the interface to the application objects. Data type and mapping of application objects into a PDO is determined by a corresponding PDO mapping structure within the object dictionary.</p>
<p>This chapter describes PDO configuration and some experimenting with the <a class="el" href="md_demo_2README.html">demoDevice</a>. Example runs with CANopen devices as specified in <a class="elRef" href="CANopenNode/index.html#md_README">tutorial/README.md</a>.</p>
<h1><a class="anchor" id="autotoc_md82"></a>
Basic principles</h1>
<p>TPDO with specific 11-bit CAN identifier is transmitted by one device and recieved by zero or more devices as RPDO. PDO communication parameters(COB-ID, transmission type, etc.) are in the Object Dictionary at index 0x1400+ and 0x1800+. PDO mapping parameters (size and contents of the PDO) are in the Object Dictionary at index 0x1600+ and 0x1A00+.</p>
<p>Each PDO can be configured with any valid 11-bit CAN identifier. Lower numbers have higher priorities on CAN bus. As a general rule, each CAN message is identified with own CAN-ID, which must be unique and produced by single source. The same is with PDO objects: Any TPDO produced on the CANopen network must have unique CAN-ID and there can be zero to many RPDOs (from different devices) configured to match the CAN-ID of the TPDO of interest.</p>
<p>CANopen standard provides pre-defined connection sets for four RPDOs and four TPDOs on each device with specific 7-bit Node-ID. These are default values and are usable in configuration, where CANopen network contains a master device, which directly communicates with many slaves. In de-centralized systems, where devices operate without a master, it makes sense to configure CAN-IDs of the RPDOs to the non-default values. For default CAN identifiers see <a class="elRef" href="CANopenNode/group__CO__Default__CAN__ID__t.html">Default CANopen identifiers</a>.</p>
<p>PDOs can be configured with Object Dictionary Editor or can be configured dynamically inside device running in CANopenNetwork, could be in NMT operational state.</p>
<p>Configure PDO by writing to the OD variables in the following procedure:</p>
<ul>
<li>Disable the PDO by setting bit-31 to 1 in PDO communication parameter, COB-ID</li>
<li>Node-Id can be configured only when PDO is disabled.</li>
<li>Disable mapping by setting PDO mapping parameter, sub index 0 to 0</li>
<li>Configure mapping</li>
<li>Enable mapping by setting PDO mapping param, sub 0 to number of mapped objects</li>
<li>Enable the PDO by setting bit-31 to 0 in PDO communication parameter, COB-ID</li>
</ul>
<h2><a class="anchor" id="autotoc_md83"></a>
PDO communication parameter</h2>
<ol type="1">
<li>COB-ID used by PDO:<ul>
<li>bit 31: If set, PDO does not exist / is not valid</li>
<li>bit 30: If set, NO RTR is allowed on this PDO (ignored by CANopenNode)</li>
<li>bit 11-29: set to 0</li>
<li>bit 0-10: 11-bit CAN-ID</li>
</ul>
</li>
<li>Transmission type:<ul>
<li>Value 0: synchronous (acyclic)</li>
<li>Value 1-240: synchronous (cyclic every (1-240)-th sync)</li>
<li>Value 241-253: not used</li>
<li>Value 254: event-driven (manufacturer-specific)</li>
<li>Value 255: event-driven (device profile and application profile specific)</li>
</ul>
</li>
<li>Inhibit time in multiple of 100µs, if the transmission type is set to 254 or 255 (0 = disabled). Only with TPDO.</li>
<li>(unavailable)</li>
<li>Event timer interval in ms, if the transmission type is set to 254 or 255 (0 = disabled). Deadline monitoring with RPDO.</li>
<li>SYNC start value, only with TPDO.<ul>
<li>Value 0: Counter of the SYNC message shall not be processed.</li>
<li>Value 1-240: The SYNC message with the counter value equal to this value shall be regarded as the first received SYNC message.</li>
</ul>
</li>
</ol>
<h2><a class="anchor" id="autotoc_md84"></a>
PDO mapping parameter</h2>
<ul>
<li>subindex 0: Number of mapped application objects in PDO:<ul>
<li>Value 0: mapping is disabled.</li>
<li>Value 1: sub-index 0x01 is valid.</li>
<li>Value 2-8: sub-indexes 0x01 to (0x02 to 0x08) are valid.</li>
</ul>
</li>
<li>subindex 1-8: Application object 1-8:<ul>
<li>bit 16-31: index</li>
<li>bit 8-15: sub-index</li>
<li>bit 0-7: data length in bits</li>
</ul>
</li>
</ul>
<h1><a class="anchor" id="autotoc_md85"></a>
Read current PDO configuration in demoDevice</h1>
<p>Set the default Node-ID to 4 for demoDevice: </p><pre class="fragment">cocomm "set node 4"
</pre> <h2><a class="anchor" id="autotoc_md86"></a>
RPDOs</h2>
<p>RPDO communication parameters, COB-ID used by RPDO and RPDO mapping parameters, number of mapped application objects: </p><pre class="fragment">cocomm "r 0x1400 1 x32" "r 0x1401 1 x32" "r 0x1402 1 x32" "r 0x1403 1 x32"
cocomm "r 0x1600 0 u8" "r 0x1601 0 u8" "r 0x1602 0 u8" "r 0x1603 0 u8"
[1] 0x00000204
[2] 0x00000304
[3] 0x80000404
[4] 0x80000504
[1] 2
[2] 4
[3] 0
[4] 0
</pre><p> RPDO 1 is enabled, accepts CAN messages with CAN-ID = 0x204 and has mapped two objects. RPDO 2 is enabled, accepts CAN messages with CAN-ID = 0x304 and has mapped four objects. RPDO 3 and RPDO 4 are disabled.</p>
<p>Read communication and mapping parameter for RPDO 1: </p><pre class="fragment">pc=0x1400; pm=0x1600
cocomm "[1] r $pc 1 x32" "[2] r $pc 2 u8" "[5] r $pc 5 u16"
cocomm "[0] r $pm 0 u8"; for i in {1..8}; do cocomm "[$i] r $pm $i x32"; done
[1] 0x00000204
[2] 255
[5] 0
[0] 2
[1] 0x62000108
[2] 0x62000208
[3] 0x62000308
[4] 0x62000408
[5] 0x62000508
[6] 0x62000608
[7] 0x62000708
[8] 0x62000808
</pre><p> Mapping parameter shows, that OD variable at index 0x6200, subindex 0x01 and OD variable at index 0x6200, subindex 0x02 are mapped to that RPDO. Both have length of 8 bits, that means RPDO must have two data bytes. See <a class="el" href="md_demo_2demoDevice.html">demo/demoDevice.md</a> for documentation about OD variables. In our case 0x6200 are digital outputs on the device. Transmission type of RPDO 1 is 255, which means, every received PDO is processed. Event timer is 0, so timeout monitoring is not used.</p>
<p>To conclude: if basicDevice is in NMT operational state and it receives a CAN message with 11-bit CAN identifier equal to 0x204 and data length of two bytes, then data from that message will be written into OD variables 0x6200,1 and 0x6200,2. Furthermore, if CANopen device has digital outputs in its hardware, those OD variables will most likely be written to them. Received CAN message is usually named PDO in CANopen network and is transmitted from known device as TPDO.</p>
<p>Read communication and mapping parameter for RPDO 2: </p><pre class="fragment">pc=0x1401; pm=0x1601
cocomm "[1] r $pc 1 x32" "[2] r $pc 2 u8" "[5] r $pc 5 u16"
cocomm "[0] r $pm 0 u8"; for i in {1..8}; do cocomm "[$i] r $pm $i x32"; done
[1] 0x00000304
[2] 255
[5] 0
[0] 4
[1] 0x64110110
[2] 0x64110210
[3] 0x64110310
[4] 0x64110410
[5] 0x00000000
[6] 0x00000000
[7] 0x00000000
[8] 0x00000000
</pre><p> RPDO 2 accepts 0x304 CAN-ID, 8 bytes long and maps to four 16-bit analog outputs.</p>
<h2><a class="anchor" id="autotoc_md87"></a>
TPDOs</h2>
<p>TPDO communication parameters, COB-ID used by TPDO and TPDO mapping parameters, number of mapped application objects: </p><pre class="fragment">cocomm "r 0x1800 1 x32" "r 0x1801 1 x32" "r 0x1802 1 x32" "r 0x1803 1 x32"
cocomm "r 0x1A00 0 u8" "r 0x1A01 0 u8" "r 0x1A02 0 u8" "r 0x1A03 0 u8"
[1] 0x40000184
[2] 0x40000284
[3] 0xC0000384
[4] 0xC0000484
[1] 2
[2] 4
[3] 0
[4] 0
</pre><p> Read communication and mapping parameter for TPDO 1: </p><pre class="fragment">pc=0x1800; pm=0x1A00
cocomm "[1] r $pc 1 x32" "[2] r $pc 2 u8" "[3] r $pc 3 u16" "[5] r $pc 5 u16" "[6] r $pc 6 u8"
cocomm "[0] r $pm 0 u8"; for i in {1..8}; do cocomm "[$i] r $pm $i x32"; done
[1] 0x40000184
[2] 255
[3] 0
[5] 0
[6] 0
[0] 2
[1] 0x60000108
[2] 0x60000208
[3] 0x60000308
[4] 0x60000408
[5] 0x60000508
[6] 0x60000608
[7] 0x60000708
[8] 0x60000808
</pre><p> TPDO 1 has mapped 2*8 digital inputs. It has CAN-ID 0x184 and 2 data bytes, when sent. Transmission type is 255, so it sends on event timer or on application specified event like change-of-state of digital inputs. TPDO 1 is always transmitted on communication reset. Set event timer to send some more: </p><pre class="fragment">cocomm "w 0x1800 5 u16 500"
# observe candump
cocomm "w 0x1800 5 u16 0"
</pre><p> Read communication and mapping parameter for TPDO 2: </p><pre class="fragment">pc=0x1801; pm=0x1A01
cocomm "[1] r $pc 1 x32" "[2] r $pc 2 u8" "[3] r $pc 3 u16" "[5] r $pc 5 u16" "[6] r $pc 6 u8"
cocomm "[0] r $pm 0 u8"; for i in {1..8}; do cocomm "[$i] r $pm $i x32"; done
[1] 0x40000284
[2] 255
[3] 0
[5] 0
[6] 0
[0] 4
[1] 0x64010110
[2] 0x64010210
[3] 0x64010310
[4] 0x64010410
[5] 0x00000000
[6] 0x00000000
[7] 0x00000000
[8] 0x00000000
</pre><p> TPDO 2 has mapped 4 16-bit analog inputs. It has CAN-ID 0x284 and 8 data bytes, when sent.</p>
<h1><a class="anchor" id="autotoc_md88"></a>
Configure TPDO 3 in demoDevice</h1>
<p>One 32-bit OD variable will be mapped to TPDO 3: 0x2110,1. See <a class="el" href="md_demo_2README.html">demoDevice</a>, section "OD variable mapped to TPDO".</p>
<p>Disable TPDO, if not already disabled, configure mapping and enable TPDO with default CAN-ID: </p><pre class="fragment">cocomm "w 0x1802 1 u32 0x80000000"
cocomm "w 0x1A02 0 u8 0"
cocomm "w 0x1A02 1 u32 0x21100120"
cocomm "w 0x1A02 0 u8 1"
cocomm "w 0x1802 1 u32 0x00000384"
</pre><p> candump shows one TPDO: </p><pre class="fragment">can0 384 [4] 00 00 00 00
</pre><p> Use event timer, watch candump: </p><pre class="fragment">cocomm "w 0x1802 5 u16 500"
</pre><p> Write something to 0x2110,1 via SDO: </p><pre class="fragment">cocomm "w 0x2110 1 u32 0xAB00CDEF"
#candump: can0 384 [4] EF CD 00 AB
</pre><p> Disable event timer and test change-of-state mechanism, used by application in demoDevice. SDO write will change the value of the variable mapped to TPDO and application will trigger TPDO when change-of-state is detected. Observe candump between the commands (ignore SDO messages): </p><pre class="fragment">cocomm "w 0x1802 5 u16 0"
cocomm "w 0x2110 1 u32 0x12345678"
cocomm "w 0x2110 1 u32 0x12345678" # same data, no TPDO
cocomm "w 0x2110 1 u32 0xAABBCCDD"
</pre><h1><a class="anchor" id="autotoc_md89"></a>
Configure RPDO in one or several remote devices to accept TPDO 3 from demoDevice</h1>
<p>Use any free RPDO and configure it to accept PDO with CAN-ID = 0x384 and data length of 4 bytes. Provide OD variables for data from demoDevice and map RPDO to them.</p>
<h1><a class="anchor" id="autotoc_md90"></a>
Other mapping features</h1>
<p>CANopenNode enables mapping length smaller than variable length. For example, only two bytes of variable of type uint32_t can be mapped, where its little end will be used.</p>
<p>To adjust the length of TPDO or RPDO, dummy entries can be used for mapping, for example:</p>
<table class="markdownTable">
<tr class="markdownTableHead">
<th class="markdownTableHeadNone">Data Type </th><th class="markdownTableHeadNone">dummy mapping </th></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">int8_t </td><td class="markdownTableBodyNone">0x00020008 </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">int16_t </td><td class="markdownTableBodyNone">0x00030016 </td></tr>
<tr class="markdownTableRowOdd">
<td class="markdownTableBodyNone">int32_t </td><td class="markdownTableBodyNone">0x00040032 </td></tr>
<tr class="markdownTableRowEven">
<td class="markdownTableBodyNone">int64_t </td><td class="markdownTableBodyNone">0x00150064 </td></tr>
</table>
<p>CANopenNode granularity is 8 bits, so smallest mappable length is one byte.</p>
<h1><a class="anchor" id="autotoc_md91"></a>
Other communication options</h1>
<p>More deterministic transmission of PDOs may be configured with usage of CANopen SYNC messages. See CANopen documentation. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0
</small></address>
</div><!-- doc-content -->
</body>
</html>