Skip to content

Commit ef097eb

Browse files
committed
Add visualizations to demos.
1 parent cbb6014 commit ef097eb

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

demo/01_intro.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from math import sqrt
44

55
import numpy as np
6+
import rerun as rr
67
import planning_kit as pkit
78
from planning_kit import StateSpace, Constraint
89

@@ -13,21 +14,38 @@
1314
# We define lower and upper boundaries of the space in R^3.
1415
euclidean = StateSpace.euclidean(-np.ones(3), np.ones(3))
1516

17+
R = 0.95
1618

1719
# A sample is valid if it lies outside a sphere of radius 0.95.
1820
def is_valid(s):
19-
return sqrt(s[0] ** 2 + s[1] ** 2 + s[2] ** 3) > 0.95
21+
return sqrt(s[0] ** 2 + s[1] ** 2 + s[2] ** 3) > R
2022

2123

2224
# Now we can use a variety of the built-in sampling-based motion planning
2325
# algorithms.
26+
start = -np.ones(3)
27+
goal = np.ones(3)
2428
tree = pkit.rrt_connect(
2529
euclidean, # the search space
2630
is_valid, # is a particular sample valid?
27-
start=-np.ones(3), # the start state
28-
goal=np.ones(3), # the goal state
31+
start=start, # the start state
32+
goal=goal, # the goal state
2933
discretization=0.01, # motion validation resolution
3034
# planner-specific parameters
3135
steering_dist=0.1,
3236
n=10000,
3337
)
38+
39+
# Log everything to Rerun!
40+
rr.init("pk.01_intro", spawn=True)
41+
rr.log_view_coordinates("space", xyz="FLU", timeless=True)
42+
rr.log_points("space/rrt_tree", positions=[p for p in tree.points()])
43+
rr.log_line_strip(
44+
"space/shortest_path",
45+
positions=tree.shortest_path(euclidean, start, goal).points(),
46+
)
47+
48+
# Sample the surface of the sphere so we can visualize the keep-out region.
49+
xs = np.random.uniform(low=-1.0, high=1.0, size=(1000, 3))
50+
xs = R * xs / np.linalg.norm(xs, axis=1)[:, None]
51+
rr.log_points("space/sphere", positions=xs)

demo/02_custom_space.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import numpy as np
4+
import rerun as rr
45
from planning_kit import StateSpace
56

67

@@ -24,3 +25,8 @@ def interpolate(self, a, b, alpha):
2425
# Once we wrap our custom implementation in a StateSpace object, we can use it
2526
# as any other.
2627
space = StateSpace.custom(MyEuclideanSpace(dim=3))
28+
29+
# Log everything to Rerun!
30+
rr.init("pk.02_custom_space", spawn=True)
31+
rr.log_view_coordinates("space", xyz="FLU", timeless=True)
32+
rr.log_points("space", positions=[space.sample_uniform() for _ in range(0, 1000)])

demo/03_constraints.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
#!/usr/bin/env python3
22

33
import numpy as np
4+
import rerun as rr
45
from planning_kit import Constraint, StateSpace
56

67

7-
def sphere(s):
8-
return [s[0] ** 2 + s[1] ** 2 + s[2] ** 2 - 1.0]
8+
def sinusoid_xy_plane(amp=1.0, freq=1.0):
9+
def inner(p):
10+
s = np.sin(2.0 * np.pi * freq * p[0])
11+
c = np.cos(2.0 * np.pi * freq * p[1])
12+
z = amp * (s + c)
13+
return [p[2] - z]
914

15+
return inner
1016

11-
sphere_constraint = Constraint(3, 1, sphere)
17+
18+
constraint = Constraint(3, 1, sinusoid_xy_plane(amp=0.1, freq=0.707))
1219

1320
ambient = StateSpace.euclidean(-np.ones(3), np.ones(3))
14-
projected = StateSpace.projected(ambient, sphere_constraint)
21+
projected = StateSpace.projected(ambient, constraint)
22+
23+
# Log everything to Rerun!
24+
rr.init("pk.03_constraints", spawn=True)
25+
rr.log_view_coordinates("space", xyz="FLU", timeless=True)
26+
rr.log_points(
27+
"space/ambient",
28+
positions=[ambient.sample_uniform() for _ in range(0, 500)],
29+
colors=[0.3, 0.3, 0.3],
30+
)
31+
rr.log_points(
32+
"space/constrained", positions=[projected.sample_uniform() for _ in range(0, 2000)]
33+
)

0 commit comments

Comments
 (0)