SpaceTimePlanning.py
1 from os.path import abspath, dirname, join
2 import sys
3 import math
4 try:
5  from ompl import util as ou
6  from ompl import base as ob
7  from ompl import geometric as og
8 except ImportError:
9  # if the ompl module is not in the PYTHONPATH assume it is installed in a
10  # subdirectory of the parent directory called "py-bindings."
11  sys.path.insert(0, join(dirname(dirname(abspath(__file__))), 'py-bindings'))
12  from ompl import util as ou
13  from ompl import base as ob
14  from ompl import geometric as og
15 from functools import partial
16 
17 def isStateValid(spaceInformation, state):
18  p = state[0][0]
19  t = spaceInformation.getStateSpace().getStateTime(state)
20  return t >= 0 and p < math.inf
21 
23  def checkMotion(self, s1, s2):
24  if not si.isValid(s2):
25  return False
26  delta_pos = si.getStateSpace().distanceSpace(s1, s2)
27  # delta_t = si.getStateSpace().distanceTime(s1, s2)
28  t1 = si.getStateSpace().getStateTime(s1)
29  t2 = si.getStateSpace().getStateTime(s2)
30  delta_t = t2 - t1
31  if delta_t <= 0 :
32  return False
33  if (delta_pos / delta_t) > si.getStateSpace().getVMax() :
34  return False
35  return True
36 
37 vMax = 0.2
38 vector_space = ob.RealVectorStateSpace(1)
39 bounds = ob.RealVectorBounds(1)
40 bounds.setLow(-1.0)
41 bounds.setHigh(1.0)
42 vector_space.setBounds(bounds)
43 
44 space = ob.SpaceTimeStateSpace(vector_space, vMax)
45 space.setTimeBounds(0.0, 10.0);
46 
47 si = ob.SpaceInformation(space)
48 si.setMotionValidator(SpaceTimeMotionValidator(si))
49 si.setStateValidityChecker(ob.StateValidityCheckerFn( \
50  partial(isStateValid, si)))
51 
52 pdef = ob.ProblemDefinition(si)
53 
54 start = ob.State(space)
55 start()[0][0] = 0.0
56 goal = ob.State(space)
57 goal()[0][0] = 1.0
58 pdef.setStartAndGoalStates(start, goal)
59 
60 strrt = og.STRRTstar(si)
61 strrt.setRange(vMax)
62 strrt.setProblemDefinition(pdef)
63 strrt.setup()
64 
65 result = strrt.solve(1.0)
66 print("Done planning.")
67 
68 if result:
69  print("Found path of length", pdef.getSolutionPath().length())
70  print("Path:", pdef.getSolutionPath().printAsMatrix())
71 else:
72  print("No solution found.")
The base class for space information. This contains all the information about the space planning is d...
Definition of a problem to be solved. This includes the start state(s) for the system and a goal spec...
Definition of an abstract state.
Definition: State.h:113
A state space consisting of a space and a time component.
A state space representing Rn. The distance function is the L2 norm.
Abstract definition for a class checking the validity of motions – path segments between states....
std::function< bool(const State *)> StateValidityCheckerFn
If no state validity checking class is specified (StateValidityChecker), a std::function can be speci...
Space-Time RRT* (STRRTstar)
Definition: STRRTstar.h:129
The lower and upper bounds for an Rn space.