This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
forked from AutonomyLab/rosdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrosdash-widgets.js
3556 lines (3414 loc) · 96 KB
/
rosdash-widgets.js
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
ROSDASH = ROSDASH || new Object();
//////////////////////////////////// output
// A text box.
ROSDASH.Text = function (block)
{
this.block = block;
}
ROSDASH.Text.prototype.addWidget = function (widget)
{
// set title and content by config
if (undefined !== this.block.config.title)
{
widget.widgetTitle = this.block.config.title;
}
if (undefined !== this.block.config.content)
{
widget.widgetTitle = this.block.config.content;
}
return widget;
}
//@input content
//@output none
ROSDASH.Text.prototype.run = function (input)
{
// if json, transform into string
if (typeof input[0] == "object" || typeof input[0] == "array")
{
try {
input[0] = JSON.stringify(input[0]);
} catch (error)
{
input[0] = "Error: " + error.message;
// update content by input
ROSDASH.updateWidgetContent(this.block.id, input[0]);
console.error(error);
return;
}
}
// update content by input
ROSDASH.updateWidgetContent(this.block.id, input[0]);
return;
}
// A text box with speaking library.
ROSDASH.Speech = function (block)
{
this.block = block;
this.canvas_id = this.block.id;
this.content = this.block.config.content || "";
}
ROSDASH.Speech.prototype.addWidget = function (widget)
{
//@todo add a button for speak
widget.widgetTitle += ' <input type="button" id="' + this.canvas_id + '" value="speak" /><span id="audio"></span>';
widget.widgetContent = this.content;
return widget;
}
ROSDASH.Speech.prototype.init = function ()
{
// if button does not exist
if ($("#" + this.canvas_id).length <= 0)
{
return false;
}
var that = this;
// append the callback function to button
$("#" + this.canvas_id).click(function ()
{
// speak by speak.js
speak(that.content);
});
return true;
}
//@input the content to speak
//@output none
ROSDASH.Speech.prototype.run = function (input)
{
// transform into string
if (typeof input[0] == "object" || typeof input[0] == "array")
{
this.content = JSON.stringify(input[0]);
var substrings = string.split(this.content);
// if the input has only one element with key as "data" (i.e. rostype == "String")
if (substrings.length == 2 && ("data" in input[0]))
{
this.content = JSON.stringify(input[0].data);
}
} else
{
this.content = input[0];
}
// if new message comes, speak
//speak(this.content);
ROSDASH.updateWidgetContent(this.block.id, this.content);
return;
}
// Table
ROSDASH.Table = function (block)
{
this.block = block;
this.titles = this.block.config.table_titles || [""];
}
ROSDASH.Table.prototype.addWidget = function (widget)
{
widget.widgetContent = {
"aaData" : [[]],
"aoColumns" : [],
"iDisplayLength": 25,
"aLengthMenu": [[1, 25, 50, -1], [1, 25, 50, "All"]],
"bPaginate": true,
"bAutoWidth": false
};
for (var i in this.titles)
{
widget.widgetContent.aoColumns.push({sTitle : this.titles[i]});
widget.widgetContent.aaData[0].push("");
}
return widget;
}
//@input contents
//@output none
ROSDASH.Table.prototype.run = function (input)
{
// if not a matrix, transform into matrix
if (typeof input[0] != "array" && typeof input[0] != "object")
{
var tmp = input[0];
input[0] = new Array();
input[0].push(new Array());
input[0][0].push(tmp);
}
// for content
var aaData = new Array();
for (var i in input[0])
{
var tmp = new Array();
for (var j in input[0][i])
{
// handle special cases
if (typeof input[0][i][j] == "number")
{
tmp.push("" + input[0][i][j]);
} else if (undefined === input[0][i][j])
{
tmp.push("");
} else
{
tmp.push(input[0][i][j]);
}
}
// make content long enough
while (tmp.length < this.titles.length)
{
tmp.push("");
}
aaData.push(tmp);
}
// if empty
if (aaData.length == 0)
{
var tmp = new Array();
for (var j = 0; j < this.titles.length; ++ j)
{
tmp.push("");
}
aaData.push(tmp);
}
// make content long enough
if (aaData[0].length < this.titles.length)
{
for (var j = aaData[0].length; j < this.titles.length; ++ j)
{
aaData[0].push("");
}
}
$("#panel").sDashboard("refreshTableById", this.block.id, aaData);
}
// V U meter
ROSDASH.Vumeter = function (block)
{
this.block = block;
this.canvas_id = this.block.id;
// the default config for vumeter
this.config = (("config" in this.block) && ("vumeter" in this.block.config)) ? this.block.config.vumeter : {
chart: {
type: 'gauge',
plotBorderWidth: 1,
plotBackgroundColor: {
linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
stops: [
[0, '#FFF4C6'],
[0.3, '#FFFFFF'],
[1, '#FFF4C6']
]
},
plotBackgroundImage: null,
height: 200
},
title: {
text: 'VU meter'
},
pane: [{
startAngle: -45,
endAngle: 45,
background: null,
center: ['25%', '145%'],
size: 300
}, {
startAngle: -45,
endAngle: 45,
background: null,
center: ['75%', '145%'],
size: 300
}],
yAxis: [{
min: 0,
max: 1,
minorTickPosition: 'outside',
tickPosition: 'outside',
labels: {
rotation: 'auto',
distance: 20
},
plotBands: [{
from: 0,
to: 6,
color: '#C02316',
innerRadius: '100%',
outerRadius: '105%'
}],
pane: 0,
title: {
text: 'VU<br/><span style="font-size:8px">Channel A</span>',
y: -40
}
}, {
min: 0,
max: 1000,
minorTickPosition: 'outside',
tickPosition: 'outside',
labels: {
rotation: 'auto',
distance: 20
},
plotBands: [{
from: 0,
to: 6,
color: '#C02316',
innerRadius: '100%',
outerRadius: '105%'
}],
pane: 1,
title: {
text: 'VU<br/><span style="font-size:8px">Channel B</span>',
y: -40
}
}],
plotOptions: {
gauge: {
dataLabels: {
enabled: false
},
dial: {
radius: '100%'
}
}
},
series: [{
data: [-20],
yAxis: 0
}, {
data: [-20],
yAxis: 1
}]
};
this.meter = undefined;
this.left_val = this.block.config.left || 0;
this.right_val = this.block.config.right || 0;
}
ROSDASH.Vumeter.prototype.addWidget = function (widget)
{
widget.widgetContent = '<div id="' + this.canvas_id + '" style="width:80%; height:80%; margin: 0 auto;"></div>';
return widget;
}
ROSDASH.Vumeter.prototype.init = function ()
{
var that = this;
this.meter = $('#' + this.canvas_id).highcharts(that.config,
// Let the music play
function (chart)
{
// update vumeter periodically
setInterval(function()
{
chart.series[0].points[0].update(that.left_val, false);
chart.series[1].points[0].update(that.right_val, false);
chart.redraw();
}, 500);
});
return true;
}
//@input left value, and right value
//@output meter object
ROSDASH.Vumeter.prototype.run = function (input)
{
this.left_val = parseFloat(input[0]) || this.left_val;
this.right_val = parseFloat(input[1]) || this.right_val;
return {o0 : this.meter};
}
//////////////////////////////////// input
// toggle button (don't use the name of switch because it is used)
//@todo an array of buttons
ROSDASH.ToggleButton = function (block)
{
this.block = block;
this.canvas_id = "togglebutton_" + this.block.id;
this.button_id = "togglebutton2_" + this.block.id;
this.value = true;
// if multiple toggle buttons
if (("config" in this.block) && ("button_num" in this.block.config))
{
this.button_id = new Array();
this.value = new Array();
for (var i = 0; i < this.block.config.button_num; ++ i)
{
this.button_id.push("togglebutton2_" + this.block.id + "_" + i);
this.value.push(true);
}
}
}
ROSDASH.ToggleButton.prototype.addWidget = function (widget)
{
widget.widgetContent = '<input id="' + this.canvas_id + '" type="checkbox" checked />';
return widget;
}
ROSDASH.ToggleButton.prototype.init = function ()
{
var that = this;
// if a single button
if (typeof this.button_id != "array")
{
$('#' + this.canvas_id).wrap('<div id="' + this.button_id + '" class="switch" data-on-label="YES" data-off-label="NO" />').parent().bootstrapSwitch();
$('#' + this.button_id).on('switch-change', function (e, data) {
that.value = data.value;
});
//$('#toggle-state-switch').bootstrapSwitch('toggleState');
//$('#toggle-state-switch').bootstrapSwitch('setState', false); // true || false
} else // if multiple buttons
{
for (var i in this.button_id)
{
$('#' + this.canvas_id).wrap('<div id="' + this.button_id[i] + '" class="switch" data-on-label="YES" data-off-label="NO" />').parent().bootstrapSwitch();
$('#' + this.button_id[i]).on('switch-change', function (e, data) {
//@bug [i] does not work?
that.value[i] = data.value;
});
}
}
return true;
}
//@input none
//@output the value of button or value list of buttons
ROSDASH.ToggleButton.prototype.run = function (input)
{
return {o0: this.value};
}
// a virtual joystick, support tablet
ROSDASH.VirtualJoystick = function (block)
{
this.block = block;
this.canvas_id = "VirtualJoystick-" + this.block.id;
this.joy_obj;
this.unlock = false;
this.joy = {
header :
{
seq : 0,
stamp :
{
sec : parseInt(new Date().getTime() / 1000),
nsec : parseInt(new Date().getTime() % 1000 * 1000000)
},
frame_id : ""
},
axes : [0, 0, 0, 0, 0, 0],
buttons : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
};
this.prev_joy;
}
ROSDASH.VirtualJoystick.prototype.addWidget = function (widget)
{
widget.widgetTitle = this.block.id + ' <input type="button" id="' + this.canvas_id + '-lock" value="unlock" />';
widget.widgetContent = '<div id="' + this.canvas_id + '" style="width:100%; height:100%; -webkit-user-select: none; -moz-user-select: none;"></div>';
return widget;
}
ROSDASH.VirtualJoystick.prototype.init = function ()
{
var that = this;
// click to change lock or unlock
$("#" + that.canvas_id + "-lock").click(function ()
{
if ("lock" == $("#" + that.canvas_id + "-lock").val())
{
that.unlock = false;
$("#" + that.canvas_id + "-lock").val("click to unlock");
} else
{
that.unlock = true;
$("#" + that.canvas_id + "-lock").val("click to lock");
}
});
//console.log("touchscreen for VirtualJoystick is", VirtualJoystick.touchScreenAvailable() ? "available" : "not available");
this.joy_obj = new VirtualJoystick({
container : document.getElementById(this.canvas_id),
mouseSupport : true
});
return true;
}
//@input none
//@output joy msg, VirtualJoystick object
ROSDASH.VirtualJoystick.prototype.run = function (input)
{
this.joy = {
header :
{
seq : this.joy.header.seq + 1,
stamp :
{
sec : parseInt(new Date().getTime() / 1000),
nsec : parseInt(new Date().getTime() % 1000 * 1000000)
},
frame_id : ""
},
axes : [Number(this.joy_obj.left() - this.joy_obj.right()), Number(this.joy_obj.up() - this.joy_obj.down()), 0, 0, 0, 0],
buttons : [Number(this.unlock), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
};
// check if joy is changed
if (undefined !== this.prev_joy)
{
var flag = false;
for (var i in this.joy.axes)
{
if (this.joy.axes[i] != this.prev_joy.axes[i])
{
flag = true;
break;
}
}
for (var i in this.joy.buttons)
{
if (this.joy.buttons[i] != this.prev_joy.buttons[i])
{
flag = true;
break;
}
}
if (! flag)
{
return {
o0: undefined,
o1: this.joy_obj
};
}
}
// deep copy
this.prev_joy = $.extend(true, [], this.joy);
return {
o0: this.joy,
o1: this.joy_obj
};
}
//////////////////////////////////// datatypes
//@deprecated constant value
ROSDASH.Constant = function (block)
{
this.block = block;
}
//@input none
//@output the value of the constant
ROSDASH.Constant.prototype.run = function (input)
{
//@todo put is_number into std_msgs.json
// if a number
if ("Float32" == this.block.constname)
{
return {o0: parseFloat(this.block.value)};
} else
{
return {o0: this.block.value};
}
}
// An array consisting of several data
ROSDASH.multiArray = function (block)
{
this.block = block;
this.array = new Array();
}
//@input each value
//@output an array of all the values
ROSDASH.multiArray.prototype.run = function (input)
{
this.array = new Array();
for (var i in input)
{
this.array.push(input[i]);
}
return {o0: this.array};
}
ROSDASH.multiArray.prototype.addTo = function (pos, value)
{
this.array.push(value);
}
// Memorable array, can memorize historic data with fixed length
ROSDASH.memArray = function (block)
{
this.block = block;
this.data = new Array();
//@todo change to config
if (undefined === this.block.config.max_length || this.block.config.max_length < 0)
{
this.block.config.max_length = 100;
}
}
//@input one new data
//@output an array of historic data with length of this.max_length
ROSDASH.memArray.prototype.run = function (input)
{
this.data.push(input[0]);
// if exceeds
if (this.block.config.max_length < this.data.length)
{
// cut the beginning ones
this.data.splice(0, this.data.length - this.block.config.max_length);
}
return {o0: this.data};
}
// A json object.
ROSDASH.Json = function (block)
{
this.block = block;
this.json = new Array();
}
//@input an array of data as keys and values of json
//@output a json with keys and values
ROSDASH.Json.prototype.run = function (input)
{
var count = 0;
for (var i in input)
{
++ count;
if (count % 2)
{
continue;
}
this.json[input[i - 1]] = input[i];
}
return {o0: this.json};
}
ROSDASH.Json.prototype.addTo = function (key, value)
{
this.json[key] = value;
}
//////////////////////////////////// datatype operations
// Add an element to an array or json.
ROSDASH.AddTo = function (block)
{
this.block = block;
}
ROSDASH.AddTo.prototype.run = function (input)
{
switch (typeof input[0])
{
case "array":
// call corresponding block method to add
var a = new ROSDASH.multiArray();
a.run(input[0]);
a.addTo(input[1]);
break;
case "object":
var a = new ROSDASH.Json();
a.run(input[0]);
a.addTo(input[1], input[2]);
break;
}
return {o0 : a};
}
// Extract the value from an array or json.
ROSDASH.ValueAt = function (block)
{
this.block = block;
}
ROSDASH.ValueAt.prototype.run = function (input)
{
var value;
switch (typeof input[0])
{
case "array":
value = input[0][input[1]];
break;
case "object":
value = input[0][input[1]];
break;
}
return {o0 : value};
}
// Transform json into string.
ROSDASH.jsonToStr = function (block)
{
this.block = block;
}
//@input json
//@output the corresponding string
ROSDASH.jsonToStr.prototype.run = function (input)
{
var str = "";
if (typeof input[0] == "object" || typeof input[0] == "array")
{
str = JSON.stringify(input[0]);
} else
{
str += input[0];
}
return {o0: str};
}
// Parse string into json.
ROSDASH.StrToJson = function (block)
{
this.block = block;
}
ROSDASH.StrToJson.prototype.run = function (input)
{
return {o0 : JSON.parse(input[0])};
}
//////////////////////////////////// arithmetics
// Add inputs up.
ROSDASH.Addition = function (block)
{
this.block = block;
}
//@input all elements to be added
//@output sum
ROSDASH.Addition.prototype.run = function (input)
{
var sum = input[0];
for (var i = 1; i < input.length; ++ i)
{
sum += input[i];
}
return {o0: sum};
}
//@todo not tested
ROSDASH.Division = function (block)
{
this.block = block;
}
ROSDASH.Division.prototype.run = function (input)
{
var output;
if (typeof input[0] == "object")
{
output = new Object();
for (var i in input[0])
{
output[i] = input[0][i] / input[1];
}
} else if (typeof input[0] == "array")
{
output = new Array();
for (var i in input[0])
{
output[i] = input[0][i] / input[1];
}
} else
{
output = input[0] / input[1];
}
return {o0: output};
}
//@todo need to be checked
ROSDASH.Reshape = function (block)
{
this.block = block;
this.len = 0;
}
ROSDASH.Reshape.prototype.vectorize = function (data)
{
if (typeof data == "object" || typeof data == "array")
{
var v = new Array();
for (var i in data)
{
v = v.concat(this.vectorize(data[i]));
}
return v;
} else
{
++ this.len;
return [ data ];
}
}
ROSDASH.Reshape.prototype.run = function (input)
{
// if not an array
if (typeof input[0] != "object" && typeof input[0] != "array")
{
return input[0];
}
this.len = 0;
// vectorize
var vector = this.vectorize(input[0]);
var is_int1 = false, is_int2 = false;
// if input[1] is int
if (typeof input[1] === 'number' && parseFloat(input[1]) == parseInt(input[1], 10) && !isNaN(input[1]) && input[1] > 0)
{
is_int1 = true;
}
// if input[2] is int
if (typeof input[2] === 'number' && parseFloat(input[2]) == parseInt(input[2], 10) && !isNaN(input[2]) && input[2] > 0)
{
is_int2 = true;
}
var row, column;
if (! is_int1 && ! is_int2)
{
return input[0];
} else if (! is_int2)
{
row = input[1];
column = Math.ceil(this.len / row);
if (column <= 0)
{
column = 1;
}
} else if (! is_int1)
{
column = input[2];
row = Math.ceil(this.len / column);
if (row <= 0)
{
row = 1;
}
} else
{
row = input[1];
column = input[2];
}
var output = new Array();
for (var i = 0; i < column; ++ i)
{
var o = new Array();
for (var j = 0; j < row; ++ j)
{
if (i * row + j < vector.length)
{
o.push(vector[i * row + j]);
} else
{
switch (typeof vector[0])
{
case "number":
o.push(0);
break;
case "string":
o.push(" ");
break;
default:
o.push(" ");
//o.push(undefined);
}
}
}
output.push(o);
}
if (1 == input[1])
{
return {o0: o};
} else
{
return {o0: output};
}
}
//////////////////////////////////// functional flow
// switch-case function
ROSDASH.Switch = function (block)
{
this.block = block;
}
//@input the input value and all cases
//@output true if the case matches the input value, false if not
ROSDASH.Switch.prototype.run = function (input)
{
//@todo design default value and compulsory inputs
if (input.length < 2)
{
console.error("input not enough: " + this.block.id);
return undefined;
}
var output = new Object();
// if input[1] is an array of cases
if (typeof input[1] == "array")
{
for (var i in input[1])
{
if (input[0] == input[1][i])
{
output["o" + i] = true;
} else
{
output["o" + i] = false;
}
}
} else // if not, means all the following inputs are cases
{
// avoid input[0]
for (var i = 0; i < input.length - 1; ++ i)
{
if (input[0] == input[i + 1])
{
output["o" + i] = true;
} else
{
output["o" + i] = false;
}
}
}
return output;
}
//////////////////////////////////// ROS
// A list of all ros items (transformed for table)
ROSDASH.RosList = function (block)
{
this.block = block;
}
ROSDASH.RosList.prototype.run = function (input)
{
var output = new Array();
var max = Math.max( Math.max(ROSDASH.rosNames.topic["_"].length, ROSDASH.rosNames.service["_"].length), ROSDASH.rosNames.param["_"].length);
// rotate the table @todo should I rotate that?
for (var i = 0; i < max; ++ i)
{
var tmp = new Array();
if (ROSDASH.rosNames.topic["_"].length > i)
{
tmp[0] = ROSDASH.rosNames.topic["_"][i];
} else
{
tmp[0] = " ";
}
if (ROSDASH.rosNames.service["_"].length > i)
{
tmp[1] = ROSDASH.rosNames.service["_"][i];
} else
{
tmp[1] = " ";
}
if (ROSDASH.rosNames.param["_"].length > i)
{
tmp[2] = ROSDASH.rosNames.param["_"][i];
} else
{
tmp[2] = " ";
}
output.push(tmp);
}
return {o0: output};
}
// ROS topic
ROSDASH.Topic = function (block)
{
this.block = block;
this.ros_msg = {error: "cannot connect to this topic"};
this.topic;
}
// subscribe a ROS topic for once
ROSDASH.Topic.prototype.initRos = function ()
{
this.topic = new ROSLIB.Topic({
ros : ROSDASH.ros,
name : this.block.rosname,
messageType : this.block.rostype
});
var self = this;
// subscribe a ROS topic
this.topic.subscribe(function (message)
{
self.ros_msg = message;
//listener.unsubscribe();
});
return true;
}
//@input ROS topic message to publish
//@output ROS topic message
ROSDASH.Topic.prototype.run = function (input)
{
// if should publish, publish
if (undefined !== input[0])
{
var msg;
if (typeof input[0] == "string" && this.block.rostype == 'std_msgs/String')
{
msg = new ROSLIB.Message({data: input[0]});
} else
{
msg = new ROSLIB.Message(input[0]);
}
this.topic.publish(msg);
}
return {o0: this.ros_msg};
}
// ROS service
ROSDASH.Service = function (block)
{
this.block = block;
this.service;
this.result = "cannot connect to this service";
}
ROSDASH.Service.prototype.initRos = function ()
{
// First, we create a Service client with details of the service's name and service type.
this.service = new ROSLIB.Service({
ros : ROSDASH.ros,
name : this.block.rosname,
messageType : this.block.rostype
});
return true;
}
ROSDASH.Service.prototype.run = function (input)
{
var msg = (undefined !== input[0]) ? input[0] : {A : 1, B : 2};
var request = new ROSLIB.ServiceRequest(msg);
var that = this;
this.service.callService(request, function (result) {
that.result = jQuery.extend(true, {}, result);
});
return {o0: this.result};
}
// ROS param
ROSDASH.Param = function (block)
{
this.block = block;
this.param;
this.output = "cannot connect to this param";
}
ROSDASH.Param.prototype.initRos = function ()
{
// First, we create a Service client with details of the service's name and service type.
this.param = new ROSLIB.Param({
ros : ROSDASH.ros,
name : this.block.rosname
});
return true;
}
ROSDASH.Param.prototype.run = function (input)
{
var that = this;
this.param.get(function (value) {
that.output = value;