forked from facebookresearch/pyrobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvis_3d_map.py
55 lines (43 loc) · 1.41 KB
/
vis_3d_map.py
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
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from __future__ import print_function
import signal
import sys
import time
import open3d
from pyrobot import Robot
def signal_handler(sig, frame):
print("Exit")
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def main():
bot = Robot("locobot")
vis = open3d.Visualizer()
vis.create_window("3D Map")
pcd = open3d.PointCloud()
coord = open3d.create_mesh_coordinate_frame(1, [0, 0, 0])
vis.add_geometry(pcd)
vis.add_geometry(coord)
# We update the viewer every a few seconds
update_time = 4
while True:
start_time = time.time()
pts, colors = bot.base.base_state.vslam.get_3d_map()
pcd.clear()
# note that open3d.Vector3dVector is slow
pcd.points = open3d.Vector3dVector(pts)
pcd.colors = open3d.Vector3dVector(colors / 255.0)
vis.update_geometry()
vis.poll_events()
vis.update_renderer()
s_t = time.time()
while time.time() - s_t < update_time:
vis.poll_events()
vis.update_renderer()
time.sleep(0.1)
end_time = time.time()
process_time = end_time - start_time
print("Updating every {0:.2f}s".format(process_time))
if __name__ == "__main__":
main()