-
Notifications
You must be signed in to change notification settings - Fork 0
/
PID_plotjuggler.xml
428 lines (427 loc) · 26.5 KB
/
PID_plotjuggler.xml
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
<?xml version='1.0' encoding='UTF-8'?>
<root>
<tabbed_widget name="Main Window" parent="main_window">
<Tab tab_name="Surge" containers="1">
<Container>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="P I + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/surge/ffTerm" color="#17becf"/>
<curve name="/bluerov/pid_debug/surge/ffDTerm" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/surge/pTerm" color="#1ac938"/>
<curve name="/bluerov/pid_debug/surge/iTerm" color="#d62728"/>
</plot>
</DockArea>
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/surge/error" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/surge/error_saturated" color="#9467bd"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.000532" left="1649437369.097648" bottom="-0.000013"/>
<limitY/>
<curve name="/bluerov/pid_debug/surge/ref_d_filtered" color="#1ac938"/>
<curve name="/bluerov/pid_debug/surge/ref_d" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/surge/ref" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/surge/state" color="#d62728"/>
</plot>
</DockArea>
<DockArea name="PI output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/surge/output" color="#bcbd22"/>
<curve name="/bluerov/thrust_body_request/wrench/force/x" color="#1f77b4"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Sway" containers="1">
<Container>
<DockSplitter count="1" orientation="-" sizes="1">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="PI + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/sway/ffDTerm" color="#d62728"/>
<curve name="/bluerov/pid_debug/sway/ffTerm" color="#1ac938"/>
<curve name="/bluerov/pid_debug/sway/iTerm" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/sway/pTerm" color="#f14cc1"/>
</plot>
</DockArea>
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.000067" left="1649437369.097648" bottom="-0.000027"/>
<limitY/>
<curve name="/bluerov/pid_debug/sway/ref_d_filtered" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/sway/ref_d" color="#bcbd22"/>
<curve name="/bluerov/pid_debug/sway/ref" color="#17becf"/>
<curve name="/bluerov/pid_debug/sway/state" color="#9467bd"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/sway/error_saturated" color="#bcbd22"/>
<curve name="/bluerov/pid_debug/sway/error" color="#1f77b4"/>
</plot>
</DockArea>
<DockArea name="PI output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/thrust_body_request/wrench/force/y" color="#bcbd22"/>
<curve name="/bluerov/pid_debug/sway/output" color="#9467bd"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Heave" containers="1">
<Container>
<DockSplitter count="1" orientation="-" sizes="1">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="PI + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/heave/ffDTerm" color="#17becf"/>
<curve name="/bluerov/pid_debug/heave/ffTerm" color="#bcbd22"/>
<curve name="/bluerov/pid_debug/heave/pTerm" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/heave/iTerm" color="#d62728"/>
</plot>
</DockArea>
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.113505" left="1649437369.097648" bottom="-0.214165"/>
<limitY/>
<curve name="/bluerov/pid_debug/heave/state" color="#17becf"/>
<curve name="/bluerov/pid_debug/heave/ref_d" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/heave/ref_d_filtered" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/heave/ref" color="#1ac938"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/heave/error" color="#9467bd"/>
<curve name="/bluerov/pid_debug/heave/error_saturated" color="#17becf"/>
</plot>
</DockArea>
<DockArea name="PI output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.500000" left="1649437369.097648" bottom="-20.500000"/>
<limitY/>
<curve name="/bluerov/pid_debug/heave/output" color="#9467bd"/>
<curve name="/bluerov/thrust_body_request/wrench/force/z" color="#f14cc1"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Yaw Rate" containers="1">
<Container>
<DockSplitter count="1" orientation="-" sizes="1">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="PI + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw_rate/iTerm" color="#d62728"/>
<curve name="/bluerov/pid_debug/yaw_rate/pTerm" color="#1ac938"/>
<curve name="/bluerov/pid_debug/yaw_rate/ffTerm" color="#17becf"/>
<curve name="/bluerov/pid_debug/yaw_rate/ffDTerm" color="#bcbd22"/>
</plot>
</DockArea>
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.000000" left="1649437369.097648" bottom="-0.000003"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw_rate/ref" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/yaw_rate/ref_d" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/yaw_rate/ref_d_filtered" color="#9467bd"/>
<curve name="/bluerov/pid_debug/yaw_rate/state" color="#bcbd22"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw_rate/error" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/yaw_rate/error_saturated" color="#d62728"/>
</plot>
</DockArea>
<DockArea name="PI output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw_rate/output" color="#1ac938"/>
<curve name="/bluerov/thrust_body_request/wrench/torque/z" color="#ff7f0e"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Yaw" containers="1">
<Container>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="PID + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw/ffTerm" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/yaw/ffDTerm" color="#d62728"/>
<curve name="/bluerov/pid_debug/yaw/dTerm" color="#1ac938"/>
<curve name="/bluerov/pid_debug/yaw/pTerm" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/yaw/iTerm" color="#f14cc1"/>
</plot>
</DockArea>
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw/error" color="#d62728"/>
<curve name="/bluerov/pid_debug/yaw/error_saturated" color="#1ac938"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="92.263272" left="1649437369.097648" bottom="-2.250324"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw/ref" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/yaw/ref_d" color="#d62728"/>
<curve name="/bluerov/pid_debug/yaw/ref_d_filtered" color="#1ac938"/>
<curve name="/bluerov/pid_debug/yaw/state" color="#ff7f0e"/>
</plot>
</DockArea>
<DockArea name="PID output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/yaw/output" color="#1f77b4"/>
<curve name="/bluerov/thrust_body_request/wrench/torque/z" color="#17becf"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Depth" containers="1">
<Container>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="PID + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437806.246221" top="0.100000" left="1649437798.945392" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/depth/dTerm" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/depth/iTerm" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/depth/pTerm" color="#9467bd"/>
<curve name="/bluerov/pid_debug/depth/ffDTerm" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/depth/ffTerm" color="#9467bd"/>
</plot>
</DockArea>
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437806.246221" top="0.100000" left="1649437798.945392" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/depth/error" color="#1ac938"/>
<curve name="/bluerov/pid_debug/depth/error_saturated" color="#ff7f0e"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437806.246221" top="2.020713" left="1649437798.945392" bottom="-0.049286"/>
<limitY/>
<curve name="/bluerov/pid_debug/depth/ref" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/depth/ref_d" color="#9467bd"/>
<curve name="/bluerov/pid_debug/depth/ref_d_filtered" color="#17becf"/>
<curve name="/bluerov/pid_debug/depth/state" color="#bcbd22"/>
</plot>
</DockArea>
<DockArea name="PID output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437806.246302" top="0.100000" left="1649437798.945392" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/depth/output" color="#17becf"/>
<curve name="/bluerov/thrust_body_request/wrench/force/z" color="#d62728"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Roll" containers="1">
<Container>
<DockSplitter count="1" orientation="-" sizes="1">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="PID + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/roll/dTerm" color="#1ac938"/>
<curve name="/bluerov/pid_debug/roll/iTerm" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/roll/ffTerm" color="#f14cc1"/>
<curve name="/bluerov/pid_debug/roll/ffDTerm" color="#9467bd"/>
<curve name="/bluerov/pid_debug/roll/pTerm" color="#17becf"/>
</plot>
</DockArea>
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.023657" left="1649437369.097648" bottom="-0.011735"/>
<limitY/>
<curve name="/bluerov/pid_debug/roll/ref" color="#bcbd22"/>
<curve name="/bluerov/pid_debug/roll/ref_d" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/roll/ref_d_filtered" color="#d62728"/>
<curve name="/bluerov/pid_debug/roll/state" color="#1f77b4"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/roll/error" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/roll/error_saturated" color="#d62728"/>
</plot>
</DockArea>
<DockArea name="PID output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/roll/output" color="#1ac938"/>
<curve name="/bluerov/thrust_body_request/wrench/torque/x" color="#ff7f0e"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<Tab tab_name="Pitch" containers="1">
<Container>
<DockSplitter count="2" orientation="-" sizes="0.500596;0.499404">
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="PID + FF terms">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/pitch/pTerm" color="#1f77b4"/>
<curve name="/bluerov/pid_debug/pitch/iTerm" color="#d62728"/>
<curve name="/bluerov/pid_debug/pitch/ffTerm" color="#1ac938"/>
<curve name="/bluerov/pid_debug/pitch/ffDTerm" color="#ff7f0e"/>
<curve name="/bluerov/pid_debug/pitch/dTerm" color="#f14cc1"/>
</plot>
</DockArea>
<DockArea name="Errors (with/without saturation)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/pitch/error" color="#9467bd"/>
<curve name="/bluerov/pid_debug/pitch/error_saturated" color="#17becf"/>
</plot>
</DockArea>
</DockSplitter>
<DockSplitter count="2" orientation="|" sizes="0.5;0.5">
<DockArea name="State, Ref. and Ref. Derivative (with/without filter)">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.001307" left="1649437369.097648" bottom="-0.053590"/>
<limitY/>
<curve name="/bluerov/pid_debug/pitch/ref" color="#9467bd"/>
<curve name="/bluerov/pid_debug/pitch/ref_d" color="#17becf"/>
<curve name="/bluerov/pid_debug/pitch/ref_d_filtered" color="#bcbd22"/>
<curve name="/bluerov/pid_debug/pitch/state" color="#d62728"/>
</plot>
</DockArea>
<DockArea name="PID output and Applied Force">
<plot flip_y="false" flip_x="false" style="Lines" mode="TimeSeries">
<range right="1649437396.830323" top="0.100000" left="1649437369.097648" bottom="-0.100000"/>
<limitY/>
<curve name="/bluerov/pid_debug/pitch/output" color="#bcbd22"/>
<curve name="/bluerov/thrust_body_request/wrench/torque/y" color="#f14cc1"/>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<currentTabIndex index="5"/>
</tabbed_widget>
<use_relative_time_offset enabled="0"/>
<!-- - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - -->
<Plugins>
<plugin ID="DataLoad CSV">
<default delimiter="0" time_axis=""/>
</plugin>
<plugin ID="DataLoad ROS bags">
<use_header_stamp value="false"/>
<discard_large_arrays value="true"/>
<max_array_size value="100"/>
<boolean_strings_to_number value="true"/>
<remove_suffix_from_strings value="true"/>
</plugin>
<plugin ID="DataLoad ULog"/>
<plugin ID="ROS Topic Subscriber">
<use_header_stamp value="true"/>
<discard_large_arrays value="true"/>
<max_array_size value="100"/>
<boolean_strings_to_number value="true"/>
<remove_suffix_from_strings value="true"/>
</plugin>
<plugin ID="UDP Server"/>
<plugin ID="WebSocket Server"/>
<plugin ID="Fast Fourier Transform"/>
<plugin ID="Quaternion to RPY"/>
<plugin ID="Reactive Script Editor">
<library code="--[[ Helper function to create a series from arrays

 new_series: a series previously created with ScatterXY.new(name)
 prefix: prefix of the XYPlot, before the index of the array
 suffix_X: suffix to complete the name of the series containing the X value. If [nil], use the index of the array.
 suffix_Y: suffix to complete the name of the series containing the Y value
 timestamp: usually the tracker_time variable
 
 Example:
 
 Assuming we have multiple series in the form:
 
 /trajectory/node.{X}/position/x
 /trajectory/node.{X}/position/y
 
 where {N} is the index of the array (integer). We can create a reactive series from the array with:
 
 new_series = ScatterXY.new("my_trajectory") 
 CreateSeriesFromArray( new_series, "/trajectory/node", "position/x", "position/y", tracker_time );
]]--

function CreateSeriesFromArray( new_series, prefix, suffix_X, suffix_Y, timestamp )
 
 --- clear previous values
 new_series:clear()
 
 --- Append points to new_series
 index = 0
 while(true) do

 x = index;
 -- if not nil, get the X coordinate from a series
 if suffix_X ~= nil then 
 series_x = XYPlotView.find( string.format( "%s.%d/%s", prefix, index, suffix_X) )
 if series_x == nil then break end
 x = series_x:atTime(timestamp)	 
 end
 
 series_y = XYPlotView.find( string.format( "%s.%d/%s", prefix, index, suffix_Y) )
 if series_y == nil then break end 
 y = series_y:atTime(timestamp)
 
 new_series:push_back(x,y)
 index = index+1
 end
end

--[[ Similar to the built-in function GetSeriesNames(), but select only the names with a give prefix. ]]--

function GetSeriesNamesByPrefix(prefix)
 -- GetSeriesNames(9 is a built-in function
 all_names = GetSeriesNames()
 filtered_names = {}
 for i, name in ipairs(all_names) do
 -- check the prefix
 if name:find(prefix, 1, #prefix) then
 table.insert(filtered_names, name);
 end
 end
 return filtered_names
end

--[[ Modify an existing series, applying offsets to all their X and Y values

 series: an existing XYPlot, obtained with XYPlotView.find(name)
 delta_x: offset to apply to each x value
 delta_y: offset to apply to each y value 

]]--

function ApplyOffsetInPlace(series, delta_x, delta_y)
 -- use C++ indeces, not Lua indeces
 for index=0, series:size()-1 do
 x,y = series:at(index)
 series:set(index, x + delta_x, y + delta_y)
 end
end



function myerrorhandler( err ) 
	return
end

function UTMTrajectory( new_series, X, Y, timeOffset, delta_t, timestamp)
	series_x = nil
	series_y = nil
	x = nil
	y = nil
 
	if new_series == nil or X == nil or Y == nil then return end

	if math.fmod(timestamp - timeOffset, delta_t+1) >= delta_t then
		Delete(new_series)
	end

	series_x = XYPlotView.find( string.format( "%s", X) )
	if series_x ~= nil then x = series_x:atTime(timestamp) end
 
 	series_y = XYPlotView.find( string.format( "%s", Y) )
 	if series_y ~= nil then y = series_y:atTime(timestamp) end
 
	if x ~= nil and y ~=nil then
 		new_series:push_back(x,y)
	end
end

function Trajectory( new_series, X, Y, x_offset, y_offset, timeOffset, delta_t, timestamp)
	series_x = nil
	series_y = nil
	x = nil
	y = nil
 
	if new_series == nil or X == nil or Y == nil then return end

	if math.fmod(timestamp - timeOffset, delta_t+1) >= delta_t then
		Delete(new_series)
	end

 	series_x = XYPlotView.find( string.format( "%s", X) )
 	if series_x ~= nil then x = series_x:atTime(timestamp) end	

 	series_y = XYPlotView.find( string.format( "%s", Y) )
 	if series_y ~= nil then y = series_y:atTime(timestamp) end

	if x ~= nil and y ~=nil then
 		new_series:push_back(x + x_offset, y + y_offset)
	end
end

function CopySeries(new_series, series_name, timeOffset, delta_t, timestamp)
	value = nil
	series = nil

	if new_series == nil or series_name == nil then return end

	if math.fmod(timestamp - timeOffset, delta_t+1) >= delta_t then
		Delete(new_series)
	end
	
	series = XYPlotView.find( string.format( "%s", series_name) )
	if series ~= nil then value = series:atTime(timestamp) end
	
	if value ~= nil then
		new_series:push_back(timestamp-timeOffset, value)
	end
end

function CopySeriesAngles(new_series, series_name, timeOffset, delta_t, timestamp)
	value = nil
	series = nil

	if new_series == nil or series_name == nil then return end

	if math.fmod(timestamp - timeOffset, delta_t+1) >= delta_t then
		Delete(new_series)
	end
	
	series = XYPlotView.find( string.format( "%s", series_name) )
	if series ~= nil then value = series:atTime(timestamp) end
	
	if value ~= nil then
		new_series:push_back(timestamp-timeOffset, WrapAngles(value))
	end
end

function WrapAngles(value)
 value = math.fmod(value + 180,360)
 if (value < 0) then
 	value = value + 360;
 end
 return value - 180;
end

function Delete(series)
	series:clear()
end

"/>
<scripts/>
</plugin>
<plugin ID="CSV Exporter"/>
<plugin ID="ROS /rosout Visualization"/>
<plugin ID="ROS Topic Re-Publisher"/>
</Plugins>
<!-- - - - - - - - - - - - - - - -->
<previouslyLoaded_Datafiles/>
<previouslyLoaded_Streamer name="ROS Topic Subscriber"/>
<!-- - - - - - - - - - - - - - - -->
<customMathEquations/>
<snippets/>
<!-- - - - - - - - - - - - - - - -->
</root>