forked from jstnhuang/ros-rviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ros-rviz-urdf.html
98 lines (90 loc) · 2.68 KB
/
ros-rviz-urdf.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="imports.html">
<dom-module id="ros-rviz-urdf">
<template>
<paper-input label="Robot description topic" value="{{param}}"></paper-input>
</template>
<script>
Polymer({
is: 'ros-rviz-urdf',
properties: {
name: {
type: String,
value: 'Robot model',
},
param: {
type: String,
value: 'robot_description',
notify: true,
},
globalOptions: Object,
isShown: Boolean,
ros: Object,
tfClient: Object,
viewer: Object,
_urdf: Object,
},
observers: [
'_optionsChanged(param, tfClient, ros, globalOptions.colladaLoader, globalOptions.colladaServer)',
],
destroy: function() {
// Nothing to destroy.
},
hide: function() {
if (this.viewer) {
this.viewer.scene.remove(this._urdf);
}
},
show: function() {
if (this.viewer && this.isShown) {
this.viewer.addObject(this._urdf);
}
},
_optionsChanged: function(param, tfClient, ros, colladaLoader, colladaServer) {
var that = this;
this.debounce('updateForOptions', function() {
that.hide();
that._updateDisplay(function() {
that.show();
});
}, 1000);
},
_updateDisplay: function(callback) {
if (!(this.ros && this.tfClient && this.param
&& this.globalOptions.colladaLoader
&& this.globalOptions.colladaServer)) {
return;
}
var getParam = new ROSLIB.Param({
ros: this.ros,
name: this.param
});
var that = this;
getParam.get(function(string) {
var urdfModel = new ROSLIB.UrdfModel({
string: string
});
var loader = ROS3D.COLLADA_LOADER_2;
if (that.globalOptions.colladaLoader === 'collada') {
loader = ROS3D.COLLADA_LOADER;
} else if (that.globalOptions.colladaLoader === 'collada2') {
loader = ROS3D.COLLADA_LOADER_2;
} else {
console.warn('Unknown Collada loader', that.globalOptions.colladaLoader);
loader = ROS3D.COLLADA_LOADER_2;
}
that.hide();
that._urdf = new ROS3D.Urdf({
urdfModel: urdfModel,
path: that.globalOptions.colladaServer,
tfClient: that.tfClient,
tfPrefix: '',
loader: loader
});
callback && callback();
});
},
});
</script>
</dom-module>