-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathdraw_debug.py
More file actions
74 lines (59 loc) · 2.11 KB
/
draw_debug.py
File metadata and controls
74 lines (59 loc) · 2.11 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
64
65
66
67
68
69
70
71
72
73
74
import time
import os
import numpy as np
import genesis as gs
def main():
gs.init(backend=gs.cpu)
# Scene setup
viewer_options = gs.options.ViewerOptions(
camera_pos=(5.0, -5.0, 2.5),
camera_lookat=(0.0, 0.0, 0.0),
camera_fov=40,
)
scene = gs.Scene(
viewer_options=viewer_options,
show_viewer=True,
)
# Add a plane for reference
scene.add_entity(morph=gs.morphs.Plane())
scene.build()
# Create debug objects
# Debug box
debug_box = scene.draw_debug_box(
bounds=[[-0.25, -0.25, 0], [0.25, 0.25, 0.5]],
color=(1, 0, 1, 1),
wireframe=True,
wireframe_radius=0.005, # Magenta
)
# Debug line
debug_line = scene.draw_debug_line(
start=(0.5, -0.25, 0.5), end=(0.5, 0.25, 0.5), radius=0.01, color=(1, 0, 0, 1)
) # Red
# Debug arrow
debug_arrow = scene.draw_debug_arrow(pos=(1, 0, 0), vec=(0, 0, 1), radius=0.02, color=(1, 0, 0, 0.5)) # Green
# Debug sphere
debug_sphere = scene.draw_debug_sphere(pos=(1.5, 0, 0.5), radius=0.1, color=(0, 0, 1, 0.5)) # Blue with alpha
# Debug multiple spheres
sphere_positions = np.array([[2, 0, 0.3], [2, 0, 0.5], [2, 0, 0.7]])
debug_spheres = scene.draw_debug_spheres(poss=sphere_positions, radius=0.05, color=(1, 1, 0, 0.5)) # Yellow
# Transformation matrix for frame (identity matrix with translation)
T = np.eye(4)
T[:3, 3] = [2.5, 0, 0.5]
debug_frame = scene.draw_debug_frame(T=T, axis_length=0.5, origin_size=0.03, axis_radius=0.02)
# Simulation loop
horizon = 500 if "PYTEST_VERSION" not in os.environ else 5
for step in range(horizon):
scene.step()
time.sleep(0.01)
# Clear individual objects after 200 steps
if step == 100:
scene.clear_debug_object(debug_box)
elif step == 200:
scene.clear_debug_object(debug_line)
elif step == 300:
scene.clear_debug_object(debug_arrow)
# All remaining objects are removed
elif step == 400:
scene.clear_debug_objects()
if __name__ == "__main__":
main()