|
3 | 3 | from math import sqrt |
4 | 4 |
|
5 | 5 | import numpy as np |
| 6 | +import rerun as rr |
6 | 7 | import planning_kit as pkit |
7 | 8 | from planning_kit import StateSpace, Constraint |
8 | 9 |
|
|
13 | 14 | # We define lower and upper boundaries of the space in R^3. |
14 | 15 | euclidean = StateSpace.euclidean(-np.ones(3), np.ones(3)) |
15 | 16 |
|
| 17 | +R = 0.95 |
16 | 18 |
|
17 | 19 | # A sample is valid if it lies outside a sphere of radius 0.95. |
18 | 20 | 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 |
20 | 22 |
|
21 | 23 |
|
22 | 24 | # Now we can use a variety of the built-in sampling-based motion planning |
23 | 25 | # algorithms. |
| 26 | +start = -np.ones(3) |
| 27 | +goal = np.ones(3) |
24 | 28 | tree = pkit.rrt_connect( |
25 | 29 | euclidean, # the search space |
26 | 30 | 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 |
29 | 33 | discretization=0.01, # motion validation resolution |
30 | 34 | # planner-specific parameters |
31 | 35 | steering_dist=0.1, |
32 | 36 | n=10000, |
33 | 37 | ) |
| 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) |
0 commit comments