コード例 #1
0
def doOne(seed, flip90=False):
    rg = RobotGrid(angStep, collisionBuffer, 2.2, seed)
    xPos, yPos = utils.hexFromDia(nDia, pitch=22.4)
    for ii, (xp, yp) in enumerate(zip(xPos, yPos)):
        if flip90:
            xrot = cos * xp + sin * yp
            yrot = sin * xp - cos * yp
            rg.addRobot(ii, xrot, yrot, hasApogee)
        else:
            rg.addRobot(ii, xp, yp, hasApogee)
    rg.initGrid()
    for ii in range(rg.nRobots):
        r = rg.getRobot(ii)
        r.setXYUniform()  # r.setXYUniform can give nan values for alpha beta?

    # set all positioners randomly (they are initialized at 0,0)

    rg.decollide2()

    rg.pathGen()  # calling decollide twice breaks things?

    robotsFolded = 0
    for r in rg.allRobots:
        if r.alpha == 0 and r.beta == 180:
            robotsFolded += 1

    # if rg.didFail:
    #     filename = "seed_%i"%seed
    #     if flip90:
    #         filename += "_flipped"
    #     else:
    #         filename += "_notflipped"
    #     utils.plotOne(1, rg, figname=filename+".png", isSequence=False, internalBuffer=collisionBuffer)

    return robotsFolded
コード例 #2
0
ファイル: movieExample.py プロジェクト: csayres/EPFL_sandbox
    epsilon = angStep * 2.2
    seed1 = 0
    seed2 = 1
    hasApogee = True
    figOffset = 0
    # maxPathSteps = int(700.0/angStep)
    posDict = OrderedDict()
    posDict[24] = [0, -22.4]
    posDict[17] = [0, 0]
    posDict[21] = [0, 22.4]
    posDict[19] = [19.39896904, -11.20000000]
    posDict[20] = [19.39896904, 11.20000000]
    posDict[16] = [-19.39896904, -11.20000000]
    posDict[25] = [-19.39896904, 11.20000000]

    rg = RobotGrid(angStep, collisionBuffer, epsilon, seed1)
    for posID, (xp, yp) in posDict.items():
        rg.addRobot(posID, xp, yp, hasApogee)

    # xPos, yPos = utils.hexFromDia(nDia, pitch=pitch)
    # for ii, (xp,yp) in enumerate(zip(xPos,yPos)):
    #     rg.addRobot(ii, xp, yp, hasApogee)
    rg.initGrid()
    for ii in range(rg.nRobots):
        r = rg.getRobot(ii)
        r.setXYUniform()
    # set all positioners randomly (they are initialized at 0,0)
    rg.decollide2()
    rg.pathGen()
    plotMovie(rg)
コード例 #3
0
ファイル: moveSeven.py プロジェクト: csayres/EPFL_sandbox
def generatePath(seed=0, plot=False, movie=False):
    nDia = 3
    pitch = 22.4

    hasApogee = True
    rg = RobotGrid(angStep, collisionBuffer, epsilon, seed)

    # epfl grid is sideways
    # xPos, yPos = utils.hexFromDia(nDia, pitch=pitch)
    # for ii, (xp, yp), posID in enumerate(zip(xPos, yPos, posList)):
    #     rg.addRobot(posID, xp, yp, hasApogee)
    # rg.initGrid()

    for posID, (xp, yp) in posDict.items():
        # print("loading pos %i [%.2f, %.2f]"%(posID, xp, yp))
        rg.addRobot(posID, xp, yp, hasApogee)
    rg.initGrid()

    for ii in range(rg.nRobots):
        r = rg.getRobot(ii)
        # print("loading pos %i [%.2f, %.2f]"%(r.id, r.xPos, r.yPos))
        # print("robotID", r.id)
        r.setXYUniform()
    # set all positioners randomly (they are initialized at 0,0)
    rg.decollide2()
    rg.pathGen()
    if rg.didFail:
        print("path gen failed")
        raise (RuntimeError, "path gen failed")
    rg.smoothPaths(smoothPts)
    rg.simplifyPaths()
    rg.setCollisionBuffer(collisionBuffer - collisionShrink)
    rg.verifySmoothed()

    if rg.smoothCollisions:
        print("smoothing failed with ", rg.smoothCollisions)
        raise (RuntimeError, "smoothing failed")

    if movie:
        plotMovie(rg, filename="movie_%i" % seed)

    # find the positioner with the most interpolated steps
    forwardPath = {}
    reversePath = {}

    for robotID, r in zip(posDict.keys(), rg.allRobots):

        assert robotID == r.id
        if plot:
            plotTraj(r, "seed_%i_" % seed, dpi=250)

        # bp = numpy.array(r.betaPath)
        # sbp = numpy.array(r.interpSmoothBetaPath)
        ibp = numpy.array(r.simplifiedBetaPath)

        # ap = numpy.array(r.alphaPath)
        # sap = numpy.array(r.interpSmoothAlphaPath)
        iap = numpy.array(r.simplifiedAlphaPath)

        # generate kaiju trajectory (for robot 23)
        # time = angStep * stepNum / speed

        alphaTimesR = iap[:, 0] * angStep / RobotMaxSpeed
        alphaDegR = iap[:, 1]
        betaTimesR = ibp[:, 0] * angStep / RobotMaxSpeed
        betaDegR = ibp[:, 1]

        armPathR = {}  # reverse path
        armPathR["alpha"] = [(pos, time)
                             for pos, time in zip(alphaDegR, alphaTimesR)]
        armPathR["beta"] = [(pos, time)
                            for pos, time in zip(betaDegR, betaTimesR)]

        reversePath[robotID] = armPathR

        # build forward path
        alphaTimesF = numpy.abs(alphaTimesR - alphaTimesR[-1])[::-1]
        alphaDegF = alphaDegR[::-1]
        betaTimesF = numpy.abs(betaTimesR - betaTimesR[-1])[::-1]
        betaDegF = betaDegR[::-1]

        armPathF = {}  # reverse path
        armPathF["alpha"] = [(pos, time)
                             for pos, time in zip(alphaDegF, alphaTimesF)]
        armPathF["beta"] = [(pos, time)
                            for pos, time in zip(betaDegF, betaTimesF)]

        forwardPath[robotID] = armPathF

    return forwardPath, reversePath
コード例 #4
0
def generatePath(seed=0, plot=False):
    nDia = 3
    pitch = 22.4

    hasApogee = True
    rg = RobotGrid(angStep, collisionBuffer, epsilon, seed)
    xPos, yPos = utils.hexFromDia(nDia, pitch=pitch)
    for ii, (xp, yp) in enumerate(zip(xPos, yPos)):
        rg.addRobot(ii, xp, yp, hasApogee)
    rg.initGrid()
    for ii in range(rg.nRobots):
        r = rg.getRobot(ii)
        r.setXYUniform()
    # set all positioners randomly (they are initialized at 0,0)
    rg.decollide2()
    rg.pathGen()
    if rg.didFail:
        print("path gen failed")
        raise (RuntimeError, "path gen failed")
    rg.smoothPaths(smoothPts)
    rg.simplifyPaths()
    rg.setCollisionBuffer(collisionBuffer - collisionShrink)
    rg.verifySmoothed()

    if rg.smoothCollisions:
        print("smoothing failed with ", rg.smoothCollisions)
        raise (RuntimeError, "smoothing failed")

    # find the positioner with the most interpolated steps
    useRobot = None
    maxSteps = 0
    for i, r in enumerate(rg.allRobots):
        m = len(r.simplifiedBetaPath)  # beta path is usually more complicated
        if m > maxSteps:
            maxSteps = m
            useRobot = r

    if plot:
        plotTraj(useRobot, "seed_%i_" % seed, dpi=250)

    # bp = numpy.array(useRobot.betaPath)
    # sbp = numpy.array(useRobot.interpSmoothBetaPath)
    ibp = numpy.array(useRobot.simplifiedBetaPath)

    # ap = numpy.array(useRobot.alphaPath)
    # sap = numpy.array(useRobot.interpSmoothAlphaPath)
    iap = numpy.array(useRobot.simplifiedAlphaPath)

    # generate kaiju trajectory (for robot 23)
    # time = angStep * stepNum / speed

    alphaTimesR = iap[:, 0] * angStep / RobotMaxSpeed
    alphaDegR = iap[:, 1]
    betaTimesR = ibp[:, 0] * angStep / RobotMaxSpeed
    betaDegR = ibp[:, 1]

    armPathR = {}  # reverse path
    armPathR["alpha"] = [(pos, time)
                         for pos, time in zip(alphaDegR, alphaTimesR)]
    armPathR["beta"] = [(pos, time) for pos, time in zip(betaDegR, betaTimesR)]

    reversePath = {robotID: armPathR}

    # build forward path
    alphaTimesF = numpy.abs(alphaTimesR - alphaTimesR[-1])[::-1]
    alphaDegF = alphaDegR[::-1]
    betaTimesF = numpy.abs(betaTimesR - betaTimesR[-1])[::-1]
    betaDegF = betaDegR[::-1]

    armPathF = {}  # reverse path
    armPathF["alpha"] = [(pos, time)
                         for pos, time in zip(alphaDegF, alphaTimesF)]
    armPathF["beta"] = [(pos, time) for pos, time in zip(betaDegF, betaTimesF)]

    forwardPath = {robotID: armPathF}

    return forwardPath, reversePath, maxSteps
コード例 #5
0
ファイル: unwind.py プロジェクト: csayres/EPFL_sandbox
async def main():

    # Set logging level to DEBUG
    #log.set_level(20)

    # Initialise the FPS instance.
    fps = FPS(layout="grid7.txt")
    await fps.initialise()

    hasApogee = True
    seed = 0  # ignored we're setting ppositions manually
    rg = RobotGrid(angStep, collisionBuffer, epsilon, seed)

    # epfl grid is sideways
    # xPos, yPos = utils.hexFromDia(nDia, pitch=pitch)
    # for ii, (xp, yp), posID in enumerate(zip(xPos, yPos, posList)):
    #     rg.addRobot(posID, xp, yp, hasApogee)
    # rg.initGrid()

    for posID, (xp, yp) in posDict.items():
        # print("loading pos %i [%.2f, %.2f]"%(posID, xp, yp))
        rg.addRobot(posID, xp, yp, hasApogee)
    rg.initGrid()

    #print("fps.positioners", fps.positioners)
    for ii in range(rg.nRobots):
        r = rg.getRobot(ii)
        # print("loading pos %i [%.2f, %.2f]"%(r.id, r.xPos, r.yPos))
        # print("robotID", r.id)
        await fps.positioners[r.id].update_position()
        alpha, beta = fps.positioners[r.id].position
        print("IIII", r.id, alpha, beta)
        r.setAlphaBeta(alpha, beta)
    # set all positioners randomly (they are initialized at 0,0)
    # rg.decollide2()
    rg.pathGen()
    if rg.didFail:
        print("path gen failed")
        raise (RuntimeError, "path gen failed")
    rg.smoothPaths(smoothPts)
    rg.simplifyPaths()
    rg.setCollisionBuffer(collisionBuffer - collisionShrink)
    rg.verifySmoothed()

    if rg.smoothCollisions:
        print("smoothing failed with ", rg.smoothCollisions)
        raise (RuntimeError, "smoothing failed")

    # find the positioner with the most interpolated steps
    reversePath = {}

    for robotID, r in zip(posDict.keys(), rg.allRobots):

        assert robotID == r.id

        # bp = numpy.array(r.betaPath)
        # sbp = numpy.array(r.interpSmoothBetaPath)
        ibp = numpy.array(r.simplifiedBetaPath)

        # ap = numpy.array(r.alphaPath)
        # sap = numpy.array(r.interpSmoothAlphaPath)
        iap = numpy.array(r.simplifiedAlphaPath)

        # generate kaiju trajectory (for robot 23)
        # time = angStep * stepNum / speed

        alphaTimesR = iap[:, 0] * angStep / RobotMaxSpeed
        alphaDegR = iap[:, 1]
        betaTimesR = ibp[:, 0] * angStep / RobotMaxSpeed
        betaDegR = ibp[:, 1]

        armPathR = {}  # reverse path
        armPathR["alpha"] = [(pos, time)
                             for pos, time in zip(alphaDegR, alphaTimesR)]
        armPathR["beta"] = [(pos, time)
                            for pos, time in zip(betaDegR, betaTimesR)]

        reversePath[robotID] = armPathR

    await fps.send_trajectory(reversePath)
    await fps.shutdown()