-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkers_example.py
More file actions
63 lines (46 loc) · 2.27 KB
/
Copy pathmarkers_example.py
File metadata and controls
63 lines (46 loc) · 2.27 KB
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
"""Draw RViz-style debug markers in the scene from a controller (sim2bot SDK).
Markers let controller / policy code draw debug primitives into Sim2Bot — a
target sphere, a predicted-grasp pose (axes), a planned path (line), labels, etc.
Each marker has an id: re-send the same id to update it; delete by id or clear all.
Install the SDK:
pip install sim2bot
Run, then connect the browser sim (Tools -> Bridge -> Connect):
python examples/markers_example.py
"""
from __future__ import annotations
import math
import time
from sim2bot import Robot
def main() -> None:
with Robot(auto_bridge=True, wait_for_sim=True, wait_for_sim_timeout=30) as robot:
# A target sphere + its label.
robot.marker("target", "sphere", position=[0.4, 0.0, 0.5], scale=0.08,
color=[1.0, 0.3, 0.3, 1.0])
robot.marker("target_label", "text", position=[0.4, 0.0, 0.62], text="target",
color=[1.0, 1.0, 1.0, 1.0])
# A predicted grasp pose drawn as a coordinate triad.
robot.marker("grasp", "axes", position=[0.5, 0.2, 0.4], scale=0.15)
# An arrow (approach direction) and a planned path (polyline).
robot.marker("approach", "arrow", from_=[0.5, 0.2, 0.6], to=[0.5, 0.2, 0.42],
color=[0.2, 1.0, 0.4, 1.0])
robot.marker("path", "line", color=[1.0, 0.8, 0.0, 1.0], points=[
[0.3, -0.3, 0.2], [0.4, -0.1, 0.35], [0.5, 0.1, 0.45], [0.5, 0.2, 0.42],
])
# A point cloud (e.g. a perceived/predicted cloud) — shape "points".
import random
cloud = [[0.45 + random.uniform(-0.1, 0.1), random.uniform(-0.1, 0.1),
0.3 + random.uniform(-0.1, 0.1)] for _ in range(800)]
robot.marker("cloud", "points", points=cloud, scale=0.006,
color=[0.3, 0.9, 1.0, 1.0])
print("Markers drawn. Animating the target for ~10 s...")
t0 = time.time()
while time.time() - t0 < 10.0:
phase = time.time() - t0
y = 0.25 * math.sin(phase)
robot.marker("target", "sphere", position=[0.4, y, 0.5], scale=0.08,
color=[1.0, 0.3, 0.3, 1.0])
time.sleep(0.05)
robot.clear_markers()
print("Cleared.")
if __name__ == "__main__":
main()