Exemple #1
0
def makePlanner(space, start, goal):
    """Creates a MotionPlan object for the given space, start, and goal.
    Returns (planner,optimizing) where optimizing is True if the planner should
    continue be run after the first solution path has been found"""
    #This sets a Probabilistic Road Map (PRM) planner that connects
    #a random point to its 10 nearest neighbors. If knn is set to 0,
    #the points are connected as long as they lie
    #within distance 0.1 of one another
    # MotionPlan.setOptions(type="prm",knn=10,connectionThreshold=1)
    #This line sets a Rapidly-exploring Random Tree (RRT) planner that
    #repeatedly extends the tree toward a random point at maximum
    #distance 0.25.  It uses the bidirectional=True option, which grows
    #trees from both the start and the goal
    #MotionPlan.setOptions(type="rrt",connectionThreshold=2.0,perturbationRadius=2.5,bidirectional=True)
    #MotionPlan.setOptions(type="sbl",connectionThreshold=5.0,gridResolution=1.0,perturbationRadius=1.5,bidirectional=True)
    optimizing = False

    #Optimizing planners.  Make sure to uncomment optimizing = True below.
    #This sets the PRM algorithm with shortcutting
    # MotionPlan.setOptions(type="prm",knn=10,connectionThreshold=1.0,shortcut=True)
    #This sets the RRT* algorithm
    MotionPlan.setOptions(type="rrt*",
                          connectionThreshold=2.0,
                          perturbationRadius=2.5)
    #This sets a fast-marching method algorithm (Note: this does not work properly with rotations)
    #MotionPlan.setOptions(type="fmm*")
    #This sets a random-restart + shortcutting RRT
    # MotionPlan.setOptions(type="rrt",connectionThreshold=2.0,perturbationRadius=2.5,bidirectional=True,restart=True,shortcut=True,restartTermCond="{foundSolution:1,maxIters:1000}")
    optimizing = True

    #create the planner, and return it along with the termination criterion
    planner = MotionPlan(space)
    return planner, optimizing
Exemple #2
0
    def __init__(self,
                 space,
                 x_bound=1.0,
                 y_bound=1.0,
                 milestones=(0, 0),
                 initial_points=4000):
        self.space = space
        #PRM planner
        MotionPlan.setOptions(type="prm",
                              knn=10,
                              connectionThreshold=0.05,
                              ignoreConnectedComponents=True)
        self.optimizingPlanner = False
        # we first plan a bit without goals just to have a good skeleton
        self.initial_points = initial_points
        self.x_bound = x_bound
        self.y_bound = y_bound
        self.milestones = milestones
        self.times = 0
        self.planner = MotionPlan(space)
        print('planning initial roadmap with {} points'.format(initial_points))
        self.planner.planMore(self.initial_points)
        self.connected = False
        # we now add each of the chosen points as a milestone:
        self.G = self.planner.getRoadmap()
        self.start_milestones = len(self.G[0])
        for milestone in self.milestones:
            self.planner.addMilestone(milestone)
        self.components = int(self.planner.getStats()['numComponents'])
        print(self.components)

        self.path = []
        self.G = None
Exemple #3
0
def makePlanner(space, start, goal):
    """Creates a MotionPlan object for the given space, start, and goal.
    Returns (planner,optimizing) where optimizing is True if the planner should
    continue be run after the first solution path has been found"""
    #TODO: In lab3c, you should tune these parameters
    #
    #This sets a Probabilistic Road Map (PRM) planner that connects
    #a random point to its 10 nearest neighbors. If knn is set to 0,
    #the points are connected as long as they lie
    #within distance 0.1 of one another
    # MotionPlan.setOptions(type="prm",knn=10,connectionThreshold=0.1)
    #This line sets a Rapidly-exploring Random Tree (RRT) planner that
    #repeatedly extends the tree toward a random point at maximum
    #distance 0.25.  It uses the bidirectional=True option, which grows
    #trees from both the start and the goal
    #MotionPlan.setOptions(type="rrt",connectionThreshold=0.1,perturbationRadius=0.25,bidirectional=True)
    optimizing = False

    #Optimizing planners, for use in Lab3C, part 2.  Make sure to uncomment optimizing = True below.
    #This sets the PRM algorithm with shortcutting
    #MotionPlan.setOptions(type="prm",knn=10,connectionThreshold=0.1,shortcut=True)
    #This sets the RRT* algorithm
    #MotionPlan.setOptions(type="rrt*",connectionThreshold=0.1,perturbationRadius=0.25)
    #This sets a fast-marching method algorithm
    #MotionPlan.setOptions(type="fmm*")
    #This sets a random-restart + shortcutting RRT
    MotionPlan.setOptions(type="rrt",connectionThreshold=0.1,perturbationRadius=0.25,bidirectional=True,restart=True,shortcut=True)
    optimizing = True

    #create the planner and return it along with the termination criterion
    planner = MotionPlan(space)
    return planner,optimizing
Exemple #4
0
def planTransit(world, objectIndex, hand):
    globals = Globals(world)
    cspace = TransitCSpace(globals, hand)
    obj = world.rigidObject(objectIndex)
    robot = world.robot(0)
    qmin, qmax = robot.getJointLimits()

    #get the start config
    q0 = robot.getConfig()
    q0arm = [q0[i] for i in hand.armIndices]
    if not cspace.feasible(q0arm):
        print "Warning, arm start configuration is infeasible"
    #get the pregrasp config -- TODO: what if the ik solver doesn't work?
    qpregrasp = None
    qpregrasparm = None
    solver = hand.ikSolver(robot, obj.getTransform()[1], [0, 0, 1])
    print "Trying to find pregrasp config..."
    solver.setMaxIters(100)
    solver.setTolerance(1e-3)
    res = solver.solve()
    if res:
        qpregrasp = robot.getConfig()
        qpregrasparm = [qpregrasp[i] for i in hand.armIndices]
        if not cspace.feasible(qpregrasparm):
            print "Pregrasp config infeasible"
            cspace.close()
            return None
    if qpregrasp == None:
        print "Pregrasp solve failed"
        cspace.close()
        return None

    print "Planning transit motion to pregrasp config..."
    MotionPlan.setOptions(connectionThreshold=5.0, perturbationRadius=0.5)
    planner = MotionPlan(cspace, 'sbl')
    planner.setEndpoints(q0arm, qpregrasparm)
    iters = 0
    step = 10
    while planner.getPath() == None and iters < 1000:
        planner.planMore(step)
        iters += step
    cspace.close()
    if planner.getPath() == None:
        print "Failed finding transit path"
        return None
    print "Success, found path with", len(planner.getPath()), "milestones"

    #lift arm path to whole configuration space path
    path = []
    for qarm in planner.getPath():
        path.append(q0[:])
        for qi, i in zip(qarm, hand.armIndices):
            path[-1][i] = qi

    #add a path to the grasp configuration
    return path + [hand.open(path[-1], 0)]
Exemple #5
0
def planTransfer(world, objectIndex, hand, shift):
    """Plan a transfer path for the robot given in world, which is currently
    holding the object indexed by objectIndex in the hand hand.
    
    The desired motion should translate the object by shift without rotating
    the object.
    """
    globals = Globals(world)
    obj = world.rigidObject(objectIndex)
    cspace = TransferCSpace(globals, hand, obj)
    robot = world.robot(0)
    qmin, qmax = robot.getJointLimits()

    #get the start config
    q0 = robot.getConfig()
    q0arm = [q0[i] for i in hand.armIndices]
    if not cspace.feasible(q0arm):
        print "Warning, arm start configuration is infeasible"
        print "TODO: Complete 2.a to bypass this error"
        raw_input()
        cspace.close()
        return None

    #TODO: get the ungrasp config using an IK solver
    qungrasp = None
    qungrasparm = None
    print "TODO: Complete 2.b to find a feasible ungrasp config"
    raw_input()
    solver = hand.ikSolver(robot, vectorops.add(obj.getTransform()[1], shift),
                           (0, 0, 1))

    #plan the transfer path between q0arm and qungrasparm
    print "Planning transfer motion to ungrasp config..."
    MotionPlan.setOptions(connectionThreshold=5.0, perturbationRadius=0.5)
    planner = MotionPlan(cspace, 'sbl')
    planner.setEndpoints(q0arm, qungrasparm)
    #TODO: do the planning
    print "TODO: Complete 2.c to find a feasible transfer path"
    raw_input()

    cspace.close()
    #lift arm path to whole configuration space path
    path = []
    for qarm in planner.getPath():
        path.append(q0[:])
        for qi, i in zip(qarm, hand.armIndices):
            path[-1][i] = qi

    qpostungrasp = hand.open(qungrasp, 1.0)
    return path + [qpostungrasp]
Exemple #6
0
    def __init__(self, space, start, goal, initial_points=1000):
        GLProgram.__init__(self)
        self.space = space

        #PRM planner
        MotionPlan.setOptions(
            type="prm*", knn=10, connectionThreshold=0.2
        )  # Change type based on what planner you want to use
        self.optimizingPlanner = True

        self.planner = MotionPlan(space)
        self.start = start
        self.goal = goal
        self.planner.addMilestone(start)
        self.planner.addMilestone(goal)
        self.components = int(self.planner.getStats()['numComponents'])
        print(self.components)
        self.path = []
        self.G = None
Exemple #7
0
def planFree(world, hand, qtarget):
    """Plans a free-space motion for the robot's arm from the current
    configuration to the destination qtarget"""
    globals = Globals(world)
    cspace = TransitCSpace(globals, hand)
    robot = world.robot(0)
    qmin, qmax = robot.getJointLimits()

    #get the start/goal config
    q0 = robot.getConfig()
    q0arm = [q0[i] for i in hand.armIndices]
    qtargetarm = [qtarget[i] for i in hand.armIndices]

    if not cspace.feasible(q0arm):
        print "Warning, arm start configuration is infeasible"
    if not cspace.feasible(qtargetarm):
        print "Warning, arm goal configuration is infeasible"

    print "Planning transit motion to target config..."
    MotionPlan.setOptions(connectionThreshold=5.0, perturbationRadius=0.5)
    planner = MotionPlan(cspace, 'sbl')
    planner.setEndpoints(q0arm, qtargetarm)
    iters = 0
    step = 10
    while planner.getPath() == None and iters < 1000:
        planner.planMore(step)
        iters += step
    cspace.close()
    if planner.getPath() == None:
        print "Failed finding transit path"
        return None
    print "Success"

    #lift arm path to whole configuration space path
    path = []
    for qarm in planner.getPath():
        path.append(q0[:])
        for qi, i in zip(qarm, hand.armIndices):
            path[-1][i] = qi
    return path
Exemple #8
0
    def __init__(self, space, start=(0.1, 0.5), goal=(0.9, 0.5)):
        GLProgram.__init__(self)
        self.space = space
        #PRM planner
        MotionPlan.setOptions(type="prm", knn=10, connectionThreshold=0.1)
        self.optimizingPlanner = False

        #FMM* planner
        #MotionPlan.setOptions(type="fmm*")
        #self.optimizingPlanner = True

        #RRT planner
        #MotionPlan.setOptions(type="rrt",perturbationRadius=0.25,bidirectional=True)
        #self.optimizingPlanner = False

        #RRT* planner
        #MotionPlan.setOptions(type="rrt*")
        #self.optimizingPlanner = True

        #random-restart RRT planner
        #MotionPlan.setOptions(type="rrt",perturbationRadius=0.25,bidirectional=True,shortcut=True,restart=True,restartTermCond="{foundSolution:1,maxIters:1000}")
        #self.optimizingPlanner = True

        #OMPL planners:
        #Tested to work fine with OMPL's prm, lazyprm, prm*, lazyprm*, rrt, rrt*, rrtconnect, lazyrrt, lbtrrt, sbl, bitstar.
        #Note that lbtrrt doesn't seem to continue after first iteration.
        #Note that stride, pdst, and fmt do not work properly...
        #MotionPlan.setOptions(type="ompl:rrt",suboptimalityFactor=0.1,knn=10,connectionThreshold=0.1)
        #self.optimizingPlanner = True

        self.planner = MotionPlan(space)
        self.start = start
        self.goal = goal
        self.planner.setEndpoints(start, goal)
        self.path = []
        self.G = None
    def __init__(self,
                 space,
                 milestones=(0, 0),
                 initial_points=4000,
                 steps=100):
        self.space = space
        #PRM planner
        MotionPlan.setOptions(type="prm",
                              knn=20,
                              connectionThreshold=0.5,
                              ignoreConnectedComponents=True)
        self.optimizingPlanner = False
        # we first plan a bit without goals just to have a good skeleton
        self.initial_points = initial_points
        self.steps = steps
        self.milestones = milestones
        self.times = 0
        self.planner = MotionPlan(space)
        for milestone in self.milestones:
            self.planner.addMilestone(milestone.tolist())
        self.components = int(self.planner.getStats()['numComponents'])
        # print(self.components)
        print('planning initial roadmap with {} points'.format(initial_points))

        self.planner.planMore(self.initial_points)
        self.connected = False
        # we now add each of the chosen points as a milestone:
        self.G = self.planner.getRoadmap()
        self.start_milestones = len(self.G[0])

        self.path = []
        self.milestone_2 = 1
        self.G = None
        self.count = 0
        self.connected_list = {0}
        self.total_milestones = set(list(range(len(self.milestones))))
Exemple #10
0
    def __init__(self,
                 space,
                 start=(0.1, 0.5),
                 goal=(0.9, 0.5),
                 x_bound=1.0,
                 y_bound=1.0,
                 milestones=(0, 0),
                 initial_points=1000):
        GLProgram.__init__(self)
        self.space = space
        #PRM planner
        MotionPlan.setOptions(type="prm",
                              knn=10,
                              connectionThreshold=1,
                              ignoreConnectedComponents=True)
        self.optimizingPlanner = False
        # we first plan a bit without goals just to have a good skeleton
        self.initial_points = initial_points
        self.x_bound = x_bound
        self.y_bound = y_bound
        self.milestones = milestones
        self.times = 0
        self.planner = MotionPlan(space)
        print('planning initial roadmap with {} points'.format(initial_points))
        self.planner.planMore(self.initial_points)
        self.connected = False
        #FMM* planner
        #MotionPlan.setOptions(type="fmm*")
        #self.optimizingPlanner = True

        #RRT planner
        #MotionPlan.setOptions(type="rrt",perturbationRadius=0.25,bidirectional=True)
        #self.optimizingPlanner = False

        #         RRT* planner
        #         MotionPlan.setOptions(type="rrt*")
        #         self.optimizingPlanner = True

        #random-restart RRT planner
        #MotionPlan.setOptions(type="rrt",perturbationRadius=0.25,bidirectional=True,shortcut=True,restart=True,restartTermCond="{foundSolution:1,maxIters:1000}")
        #self.optimizingPlanner = True

        #OMPL planners:
        #Tested to work fine with OMPL's prm, lazyprm, prm*, lazyprm*, rrt, rrt*, rrtconnect, lazyrrt, lbtrrt, sbl, bitstar.
        #Note that lbtrrt doesn't seem to continue after first iteration.
        #Note that stride, pdst, and fmt do not work properly...
        #MotionPlan.setOptions(type="ompl:rrt",suboptimalityFactor=0.1,knn=10,connectionThreshold=0.1)
        #self.optimizingPlanner = True
        # we then add start, goal and milestones
        self.start = start
        self.goal = goal
        #         self.planner.setEndpoints(start,goal)
        # we now add each of the chosen points as a milestone:
        self.G = self.planner.getRoadmap()
        self.start_milestones = len(self.G[0])
        print(self.start_milestones)
        for milestone in self.milestones:
            self.planner.addMilestone(milestone)
        self.components = int(self.planner.getStats()['numComponents'])
        print(self.components)
        self.G = self.planner.getRoadmap()
        self.end_milestones = len(self.G[0])
        print(self.end_milestones)
        #         self.planner.addMilestone(self.start)
        #         self.planner.addMilestone(self.goal)
        self.path = []
        self.G = None