39from ompl
import util
as ou
40from ompl
import base
as ob
41from ompl
import geometric
as og
55 def __init__(self, si):
56 super(MyValidStateSampler, self).__init__(si)
57 self.name_ =
"my sampler"
64 def sample(self, state):
65 z = self.rng_.uniformReal(-1, 1)
67 if z > 0.25
and z < 0.5:
68 x = self.rng_.uniformReal(0, 1.8)
69 y = self.rng_.uniformReal(0, 0.2)
70 i = self.rng_.uniformInt(0, 3)
84 state[0] = self.rng_.uniformReal(-1, 1)
85 state[1] = self.rng_.uniformReal(-1, 1)
95def isStateValid(state):
105 and fabs(state[1] < 0.8)
112def allocOBValidStateSampler(si):
119def allocMyValidStateSampler(si):
120 return MyValidStateSampler(si)
123def plan(samplerIndex):
131 space.setBounds(bounds)
137 ss.setStateValidityChecker(isStateValid)
140 start = space.allocState()
146 goal = space.allocState()
152 ss.setStartAndGoalStates(start, goal)
155 si = ss.getSpaceInformation()
156 if samplerIndex == 1:
158 si.setValidStateSamplerAllocator(allocOBValidStateSampler)
159 elif samplerIndex == 2:
161 si.setValidStateSamplerAllocator(allocMyValidStateSampler)
165 ss.setPlanner(planner)
168 solved = ss.solve(10.0)
170 print(
"Found solution:")
172 print(ss.getSolutionPath())
174 print(
"No solution found")
177if __name__ ==
"__main__":
178 print(
"Using default uniform sampler:")
180 print(
"\nUsing obstacle-based sampler:")
182 print(
"\nUsing my sampler:")
Generate valid samples using obstacle based sampling. First sample an invalid state,...
The lower and upper bounds for an Rn space.
A state space representing Rn. The distance function is the L2 norm.
Abstract definition of a state sampler.
Probabilistic RoadMap planner.
Create the set of classes typically needed to solve a geometric problem.