39 from os.path
import abspath, dirname, join
42 from ompl
import util
as ou
43 from ompl
import base
as ob
44 from ompl
import geometric
as og
48 sys.path.insert(0, join(dirname(dirname(abspath(__file__))),
'py-bindings'))
49 from ompl
import util
as ou
50 from ompl
import base
as ob
51 from ompl
import geometric
as og
52 from functools
import partial
55 def __init__(self, ppm_file):
57 self.
ppm_.loadFile(ppm_file)
59 space.addDimension(0.0, self.
ppm_.getWidth())
60 space.addDimension(0.0, self.
ppm_.getHeight())
67 partial(Plane2DEnvironment.isStateValid, self)))
69 self.
ss_.getSpaceInformation().setStateValidityCheckingResolution( \
70 1.0 / space.getMaximumExtent())
73 def plan(self, start_row, start_col, goal_row, goal_col):
77 start()[0] = start_row
78 start()[1] = start_col
82 self.
ss_.setStartAndGoalStates(start, goal)
85 if self.
ss_.getPlanner():
86 self.
ss_.getPlanner().clear()
88 ns = self.
ss_.getProblemDefinition().getSolutionCount()
89 print(
"Found %d solutions" % ns)
90 if self.
ss_.haveSolutionPath():
91 self.
ss_.simplifySolution()
92 p = self.
ss_.getSolutionPath()
99 def recordSolution(self):
100 if not self.
ss_ or not self.
ss_.haveSolutionPath():
102 p = self.
ss_.getSolutionPath()
104 for i
in range(p.getStateCount()):
105 w = min(self.
maxWidth_, int(p.getState(i)[0]))
106 h = min(self.
maxHeight_, int(p.getState(i)[1]))
107 c = self.
ppm_.getPixel(h, w)
112 def save(self, filename):
115 self.
ppm_.saveFile(filename)
117 def isStateValid(self, state):
121 c = self.
ppm_.getPixel(h, w)
122 return c.red > 127
and c.green > 127
and c.blue > 127
125 if __name__ ==
"__main__":
126 fname = join(join(join(join(dirname(dirname(abspath(__file__))), \
127 'tests'),
'resources'),
'ppm'),
'floor.ppm')
130 if env.plan(0, 0, 777, 1265):
132 env.save(
"result_demo.ppm")