Skip to content

Instantly share code, notes, and snippets.

@PeterMitrano
Created March 11, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterMitrano/1e6234f0f200e9adba0428e1a35fc6fb to your computer and use it in GitHub Desktop.
Save PeterMitrano/1e6234f0f200e9adba0428e1a35fc6fb to your computer and use it in GitHub Desktop.
demo that is satisfied cannot be overridden in python
from functools import partial
from math import sin, cos
import numpy as np
from ompl import base as ob
from ompl import control as oc
class MySampleableGoalRegion(ob.GoalSampleableRegion):
def __init__(self, si: oc.SpaceInformation):
self.goal_state = [0, 0.5, 0.0]
super().__init__(si)
self.threshold = 0.1
self.setThreshold(self.threshold)
#################################
## Comment this out, and it works
#################################
def isSatisfied(self, state: ob.CompoundState, distance):
print("is satisfied?")
return True
def distanceGoal(self, state: ob.CompoundState):
dx = state.getX() - self.goal_state[0]
dy = state.getY() - self.goal_state[1]
dyaw = state.getYaw() - self.goal_state[2]
dist = np.linalg.norm([dx, dy, dyaw])
return dist
def sampleGoal(self, state_out: ob.CompoundState):
state_out.setX(self.goal_state[0])
state_out.setX(self.goal_state[1])
state_out.setYaw(self.goal_state[2])
def maxSampleCount(self):
return 100
def main():
space = ob.RealVectorStateSpace(4)
si = ob.SpaceInformation(space)
s = MySampleableGoalRegion(si)
state = ob.State(space)
s.isSatisfied(s, 4)
def isStateValid(spaceInformation, state):
# perform collision checking or check if other constraints are
# satisfied
return spaceInformation.satisfiesBounds(state)
def propagate(start, control, duration, state):
state.setX(start.getX() + control[0] * duration * cos(start.getYaw()))
state.setY(start.getY() + control[0] * duration * sin(start.getYaw()))
state.setYaw(start.getYaw() + control[1] * duration)
def plan():
space = ob.SE2StateSpace()
bounds = ob.RealVectorBounds(2)
bounds.setLow(-1)
bounds.setHigh(1)
space.setBounds(bounds)
cspace = oc.RealVectorControlSpace(space, 2)
cbounds = ob.RealVectorBounds(2)
cbounds.setLow(-.3)
cbounds.setHigh(.3)
cspace.setBounds(cbounds)
ss = oc.SimpleSetup(cspace)
ss.setStatePropagator(oc.StatePropagatorFn(propagate))
si = ss.getSpaceInformation()
planner = oc.RRT(si)
planner.setIntermediateStates(True)
ss.setPlanner(planner)
si.setPropagationStepSize(.1)
# create a start state
start = ob.State(space)
start().setX(-0.5)
start().setY(0.0)
start().setYaw(0.0)
ss.setStartState(start)
goal = MySampleableGoalRegion(si)
ss.setGoal(goal)
ss.solve(1.0)
if __name__ == "__main__":
plan()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment