forked from jstnhuang/ros-rviz
-
Notifications
You must be signed in to change notification settings - Fork 15
/
ros-rviz-point-cloud.html
177 lines (160 loc) · 4.55 KB
/
ros-rviz-point-cloud.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
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-input/paper-input.html">
<link rel="import" href="../ros-service/ros-service.html">
<link rel="import" href="imports.html">
<!--
Version that takes in a point cloud topic.
-->
<dom-module id="ros-rviz-point-cloud">
<template>
<ros-service
id="startPcService"
on-response="_onPcStart"
on-fail="_onPcStartFail"
name="/start_point_cloud"
ros="{{ros}}"
service-type="rws_rviz/StartPointCloud"
></ros-service>
<ros-service
id="stopPcService"
name="/stop_point_cloud"
on-fail="_onPcStopFail"
ros="{{ros}}"
service-type="rws_rviz/StopPointCloud"
></ros-service>
<paper-input label="Topic" value="{{topic}}" on-blur="_onOptionsChanged"></paper-input>
<paper-input label="Camera frame ID" value="{{frameId}}" on-blur="_onOptionsChanged"></paper-input>
</template>
<script>
Polymer({
is: 'ros-rviz-point-cloud',
properties: {
topic: {
type: String,
value: '/head_mount_kinect/depth_registered/points'
},
frameId: {
type: String,
value: '/head_mount_kinect_rgb_optical_frame',
},
globalOptions: Object,
isShown: Boolean,
name: {
type: String,
value: 'Point cloud',
},
tfClient: Object,
viewer: Object,
ros: Object,
_cloud: {
type: Object,
value: null
},
_oldTopic: String,
_sceneNode: Object,
_url: String,
_urlTopic: String, // Backend image topic to stream.
},
ready: function() {
this._updateStream();
var that = this;
window.addEventListener('beforeunload', function(evt) {
that._endStream();
});
this.show();
},
destroy: function() {
if (this._cloud) {
this._cloud.stopStream();
}
this._endStream();
if (this._sceneNode) {
this.viewer.scene.remove(this._sceneNode);
delete this._sceneNode;
}
},
hide: function() {
if (this._cloud) {
this._cloud.stopStream();
}
if (this._sceneNode) {
this.viewer.scene.remove(this._sceneNode);
}
},
show: function() {
if (!this.isShown) {
return;
}
if (this._cloud) {
this._cloud.startStream();
}
if (this._sceneNode) {
this.viewer.scene.add(this._sceneNode);
}
},
_updateDisplay: function() {
var that = this;
if (this._cloud) {
this._cloud.stopStream();
}
if (!this._url) {
return;
}
this._cloud = new ROS3D.DepthCloud({
url: this._url,
f: 525.0,
});
this._cloud.startStream();
this._sceneNode = new ROS3D.SceneNode({
frameID: this.frameId,
tfClient: this.tfClient,
object: this._cloud,
});
// TODO(jstn): I just tried this and it seemed to work.
// Get a real understanding of what's going wrong.
this._sceneNode.scale.x = 0.5;
this._sceneNode.scale.y = 0.5;
this._sceneNode.scale.z = 0.5;
this.viewer.scene.add(this._sceneNode);
},
_computeUrl: function(_urlTopic) {
var url = this.globalOptions.videoServer + '/streams' + _urlTopic + '.webm?enc=webm&bitrate=250000&framerate=15';
return url;
},
_onPcStart: function(evt) {
this._urlTopic = evt.detail.topic;
this._url = this._computeUrl(this._urlTopic);
this._updateDisplay();
},
_onOptionsChanged: function() {
this._updateStream();
},
_updateStream: function() {
this._endStream();
if (!this.topic) {
return;
}
this._oldTopic = this.topic;
this.$.startPcService.call({
topic: this.topic,
camera_frame_id: this.frameId,
client_id: this.globalOptions.clientId
});
},
_endStream: function() {
if (this._oldTopic) {
this.$.stopPcService.call({
topic: this._oldTopic,
client_id: this.globalOptions.clientId
});
}
},
_onPcStartFail: function(evt) {
console.error('Error starting point cloud stream', evt.detail);
},
_onPcStopFail: function(evt) {
console.error('Error stopping point cloud stream', evt.detail);
}
});
</script>
</dom-module>