6from functools
import partial
8from ompl
import base
as ob
9from ompl
import geometric
as og
10from ompl
import tools
as ot
11from vamp_state_space
import (
13 VampStateValidityChecker,
20sys.path.insert(0, os.path.join(os.path.dirname(__file__),
".."))
28POINTS_PER_SPHERE = 300
30a = [0.0, -0.785, 0.0, -2.356, 0.0, 1.571, 0.785]
33b = [2.35, 1.0, 0.0, -0.8, 0, 2.5, 0.785]
54 s: ob.RealVectorStateType, env: vamp.Environment, dimension: int
56 config = s[0:dimension]
57 return vamp.panda.validate(config, env)
60def create_environment(
61 variation: float = 0.01,
63 use_point_cloud: bool =
False,
64 points_per_sphere: int = POINTS_PER_SPHERE,
66 """Create a VAMP environment with either spheres or point cloud obstacles.
68 Returns (env, spheres, point_cloud) where point_cloud is None for sphere mode.
70 spheres = [np.array(sphere)
for sphere
in problem]
71 random.shuffle(spheres)
72 spheres_copy = copy.deepcopy(spheres)
74 for sphere
in spheres_copy:
75 sphere += np.random.uniform(low=-variation, high=variation, size=(3,))
77 env = vamp.Environment()
82 point_cloud = np.vstack(
84 vamp.pointcloud.sphere_sample_surface(
85 center, radius, points_per_sphere, 0.0
87 for center
in spheres_copy
92 r_min, r_max = vamp.panda.min_max_radii()
95 filtered_point_cloud_list, elapsed_ns = vamp.filter_pointcloud(
96 point_cloud, r_min, 2, (0, 0, 0), (-2, -2, -2), (2, 2, 2),
True
100 n_added = env.add_pointcloud(filtered_point_cloud_list, r_min, r_max, 0.01)
102 for sphere
in spheres_copy:
103 env.add_sphere(vamp.Sphere(sphere, radius))
105 return env, spheres, point_cloud
109 variation: float = 0.01,
111 use_point_cloud: bool =
False,
112 points_per_sphere: int = POINTS_PER_SPHERE,
113 visualize: bool =
False,
115 env, spheres, point_cloud = create_environment(
116 variation, radius, use_point_cloud, points_per_sphere
121 dimension = robot.dimension()
122 space = VampStateSpace(robot=robot)
125 motion_validator = VampMotionValidator(si=si, env=env, robot=robot)
126 state_validity_checker = VampStateValidityChecker(si=si, env=env, robot=robot)
132 si.setMotionValidator(motion_validator)
133 si.setStateValidityChecker(state_validity_checker)
137 ss.setPlanner(planner)
140 start = si.allocState()
141 start[0:dimension] = a
142 goal = si.allocState()
143 goal[0:dimension] = b
144 ss.setStartAndGoalStates(start, goal)
147 planning_start = time.time()
148 result = ss.solve(5.0)
150 path = ss.getSolutionPath()
151 print(f
"Planning time: {time.time() - planning_start}")
152 print(f
"Generated path with {path.getStateCount()} states")
155 visualizer = ViserVisualizer(
156 robot_name=
"panda", robot_dimension=dimension, port=8080
159 if point_cloud
is not None:
160 pc_colors = np.tile([204, 102, 51], (point_cloud.shape[0], 1))
161 visualizer.add_point_cloud(point_cloud, color=pc_colors)
163 for sphere
in spheres:
164 visualizer.add_sphere(sphere, radius, color=(0.8, 0.4, 0.2))
166 path.interpolate(int(path.getStateCount() * 15))
167 states = path.getStates()
168 trajectory = np.array([list(state[0:dimension])
for state
in states])
169 visualizer.visualize_trajectory(trajectory)
170 visualizer.play_until_key_pressed()
172 print(f
"No solution found (time: {time.time() - planning_start})")
176 variation: float = 0.01,
178 use_point_cloud: bool =
False,
179 points_per_sphere: int = POINTS_PER_SPHERE,
182 env, spheres, point_cloud = create_environment(
183 variation, radius, use_point_cloud, points_per_sphere
188 dimension = robot.dimension()
189 space = VampStateSpace(robot=robot)
192 motion_validator = VampMotionValidator(si=si, env=env, robot=robot)
193 state_validity_checker = VampStateValidityChecker(si=si, env=env, robot=robot)
196 si.setMotionValidator(motion_validator)
197 si.setStateValidityChecker(state_validity_checker)
202 start = si.allocState()
203 start[0:dimension] = a
204 goal = si.allocState()
205 goal[0:dimension] = b
206 ss.setStartAndGoalStates(start, goal)
211 env_label =
"PointCloud" if use_point_cloud
else "Sphere"
212 benchmark =
ot.Benchmark(ss, f
"Vamp Cage Planning Benchmark ({env_label})")
213 for planner
in planners:
214 benchmark.addPlanner(planner)
220 req.runCount = n_trials
221 req.displayProgress =
True
222 benchmark.benchmark(req)
224 log_file =
"vamp_cage_planning_benchmark_python.log"
225 benchmark.saveResultsToFile(log_file)
226 db_path =
"vamp_cage_planning_benchmark_python.db"
227 ot.readBenchmarkLog(db_path, [log_file], moveitformat=
False)
228 print(f
"Database saved to {db_path}")
231 import plannerarena.app
233 print(f
"Displaying benchmark results from {db_path}")
234 plannerarena.app.DATABASE = os.path.abspath(db_path)
235 plannerarena.app.run()
238 "PlannerArena not found, please install it from https://github.com/ompl/plannerarena"
243 variation: float = 0.01,
244 benchmark: bool =
False,
245 use_point_cloud: bool =
False,
248 visualize: bool =
False,
251 planBenchmark(variation, radius, use_point_cloud, n_trials=n_trials)
253 planOnce(variation, radius, use_point_cloud, visualize=visualize)
256if __name__ ==
"__main__":
Kinematic Planning by Interior-Exterior Cell Exploration.
Lazy Bi-directional KPIECE with one level of discretization.
RRT-Connect (RRTConnect).
Rapidly-exploring Random Trees.
Create the set of classes typically needed to solve a geometric problem.