示例#1
0
def waitCloseDataSet(samples, robotHeight, dataset):
    for i in range(samples):
        x = 0
        y = 1
        z = uniform(1.5,2) #height
        
        path = []
            
        
        for k in range(10):
            path.append([x,y,z])
        
        trans = GeneratePath.position_transform(path,robotHeight)
        
        dataset.newSequence()
        
        for k in range(len(trans)):

            if k < 2:
                smile = 0.25
                eyebrow = 0
            elif k < 6:
                smile = 0.25 + k/10
                eyebrow = -k/8
            else:
                smile = 0.75
                eyebrow = -6/8
            
            pupils = pupilTracking(trans[k][1], trans[k][2])
            
            dataset.appendLinked(trans[k],[smile,pupils[0], pupils[1],eyebrow])
    
    return dataset
示例#2
0
def waitFarDataSet(samples,distPref,robotHeight,dataset):
    """
        Generates a dataset with samples number of samples, where each sample is a
        series of identical [x,y,z] cordinates chosen randomly between the "care" and
        "good" distance from the robot.
    """
    careDist,goodDist = distPref
    
    for i in range(samples):

        dist = uniform(goodDist,careDist)   
                
        x = uniform(-dist,dist)
        y = math.sqrt(dist**2 - x**2)        
        z = uniform(1.5,2) #height

        
        path = []
            
        
        for k in range(10):
            path.append([x,y,z])
        
        trans = GeneratePath.position_transform(path,robotHeight)
        
        dataset.newSequence()
        
        for k in range(len(trans)):

            if k < 2:
                smile = 0.25
                eyebrow = 0
            elif k < 6:
                smile = 0.25 - k/5
                eyebrow = k/8
            else:
                smile = -0.75
                eyebrow = 6/8
            
            pupils = pupilTracking(trans[k][1], trans[k][2])
            
            dataset.appendLinked(trans[k],[smile,pupils[0], pupils[1],eyebrow])
    
    return dataset    
        
def waitFarDataSet(samples,distPref,robotHeight,dataset):
    """
        Generates a dataset with samples number of samples, where each sample is a
        series of identical [x,y,z] cordinates chosen randomly between the "care" and
        "good" distance from the robot.
    """
    careDist,goodDist = distPref
    
    for i in range(samples):

        dist = uniform(goodDist,careDist)   
                
        x = uniform(-dist,dist)
        y = math.sqrt(dist**2 - x**2)        
        z = uniform(1.5,2) #height

        
        path = []
            
        
        for k in range(10):
            path.append([x,y,z])
        
        trans = GeneratePath.position_transform(path,robotHeight)
        
        dataset.newSequence()
        
        for k in range(len(trans)):

            if k < 2:
                smile = 0.25
                eyebrow = 0
            elif k < 6:
                smile = 0.25 - k/5
                eyebrow = k/8
            else:
                smile = -0.75
                eyebrow = 6/8
            
            pupils = pupilTracking(trans[k][1], trans[k][2])
            
            dataset.appendLinked(trans[k],[smile,pupils[0], pupils[1],eyebrow])
    
    return dataset    
示例#4
0
def leaveDataSet(samples, enviroment,robotHeight, prefSpeed, distPreferences, dataset ):
    
    xMax,xMin,yMax,yMin = enviroment
    careDist,goodDist = distPreferences
    
    for i in range(samples):
        
        z = uniform(1.5,2) #height
        
        endx = uniform(xMin,xMax)
        endy = yMax
        
        dist = uniform(goodDist,careDist)   
                
        startx = uniform(-dist,dist)
        starty = math.sqrt(dist**2 - startx**2)        
        
        path = GeneratePath.pathSpeed([startx,starty,z],[endx,endy,z],prefSpeed)

        trans = GeneratePath.position_transform(path,robotHeight)
        
        dataset.newSequence()
        
        for k in range(len(trans)):
            target = []
            
            if k  < 2:
                target.append(0.25) #smile
            else:
                target.append(-0.5)
            
            target.extend(pupilTracking(trans[k][1], trans[k][2]))
            target.append(0) #eyebrows

            dataset.appendLinked(trans[k],target)
        
    return dataset
示例#5
0
def approachDataSet(samples, enviroment,robotHeight, prefSpeed, distPreferences, dataset ):
    
    xMax,xMin,yMax,yMin = enviroment
    careDist,goodDist = distPreferences
    
    for i in range(samples):
        
        z = uniform(1.5,2) #height
        
        startx = uniform(xMin,xMax)
        starty = yMax
        
        
        endx = 0
        endy = 1       
        
        path = GeneratePath.pathSpeed([startx,starty,z],[endx,endy,z],prefSpeed)

        trans = GeneratePath.position_transform(path,robotHeight)
        
        dataset.newSequence()
        
        for param in trans:
            target = []
            
            if param[0] < careDist:
                target.append(0.25) #smile
            else:
                target.append(0)
            
            target.extend(pupilTracking(param[1], param[2]))
            target.append(0) #eyebrows

            dataset.appendLinked(param,target)
        
    return dataset
示例#6
0
def testFace(enviroment,tests,speedPreferences, distancePreferences, updateTime, robotHeight, network):
    
    xMax,xMin,yMax,yMin = enviroment
    careDist,goodDist = distancePreferences
    slowSpeed, prefSpeed, fastSpeed = speedPreferences
    
    random.seed()
    """
        Sets up the window for displaying the parametrized face
    """
    center = graphics.Point(200,200)
    win = graphics.GraphWin('Face', 400, 400,autoflush=False) # give title and dimensions
    win.setBackground('white')
    win.setCoords(0, 0, 400, 400)
    
    
    """
        Sets up the window for plotting the position of the person the face is looking at
    """
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    createFigure(enviroment, distancePreferences,fig,ax)    
    
    
    message = graphics.Text(graphics.Point(200, 380), 'Click to start simulation.')
    message.draw(win)
    win.getMouse()
    message.undraw()
    win.update()
    
    
    

    

    
    lingerTestPath = []
    # Linger at comfortable distance
    for i in range(tests.get("lingerFar")):
        z = random.uniform(1.5,2)
        
        startx = random.uniform(xMin,xMax)
        starty = yMax
        
        dist = random.uniform(goodDist,careDist)   
                
        endx = random.uniform(-dist,dist)
        endy = math.sqrt(dist**2 - endx**2)        
        
        
        timesLingering = random.randrange(6,15)
        
        lingerTestPath.extend(GeneratePath.moveAndLinger([startx,starty,z],[endx,endy,z],prefSpeed,timesLingering))
            
    #linger too close
    for i in range(tests.get("lingerClose")):
        z = random.uniform(1.5,2)
        startx = random.uniform(xMin,xMax)
        starty = yMax
        
        #dist = random.uniform(enviroment[3],tooClose)
       # endx = random.uniform(-dist,dist)
        #endy = math.sqrt(dist**2 - endx**2)  
        endx = 0
        endy = 1        
        timesLingering = random.randrange(6,15)
        
        lingerTestPath.extend(GeneratePath.moveAndLinger([startx,starty,z],[endx,endy,z],prefSpeed,timesLingering))
    
    

    
    trans = GeneratePath.position_transform(lingerTestPath,robotHeight)    
    
    
    print("\n---------------- Lingering tests ------------------ \n\n")
    iterateNetThroughPath(lingerTestPath, trans, prefSpeed, network, center, win, updateTime )
    
    
    
    # approach, linger, leave tests
    plt.close()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    
    createFigure(enviroment, distancePreferences,fig,ax)
    


    approachLingerLeavePath = []
    for i in range(tests.get("approachLingerLeaveClose")):
        z = random.uniform(1.5,2)
        startx = random.uniform(xMin,xMax)
        starty = yMax

        stoppx = 0
        stoppy = 1        
        timesLingering = random.randrange(6,15)
        

        exitx = random.uniform(xMin,xMax)
        exity = yMax

        approachLingerLeavePath.extend(GeneratePath.approachLingerLeave(prefSpeed, [startx,starty,z], [stoppx,stoppy,z], [exitx,exity,z], timesLingering))


    trans = GeneratePath.position_transform(approachLingerLeavePath,robotHeight)    

    
    print("\n---------------- Approach Linger Leave Close tests ------------------ \n\n")
    iterateNetThroughPath(approachLingerLeavePath, trans, prefSpeed, network, center, win, updateTime )
    
    message.draw(win)
    win.getMouse()
    message.undraw()
    win.update()
        
    
    plt.close()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    
    createFigure(enviroment, distancePreferences,fig,ax)




    approachLingerLeavePath = []
    
    for i in range(tests.get("approachLingerLeaveFar")):
        z = random.uniform(1.5,2)
        startx = random.uniform(xMin,xMax)
        starty = yMax
        
        dist = random.uniform(goodDist,careDist)
        stoppx = random.uniform(-dist,dist)
        stoppy = math.sqrt(dist**2 - stoppx**2)  

        timesLingering = random.randrange(6,15)
        
        exitx = random.uniform(xMin,xMax)
        exity = yMax

        approachLingerLeavePath.extend(GeneratePath.approachLingerLeave(prefSpeed,[startx,starty,z], [stoppx,stoppy,z], [exitx,exity,z], timesLingering))
    
    
    trans = GeneratePath.position_transform(approachLingerLeavePath,robotHeight)    

    
    print("\n---------------- Approach Linger Leave Far tests ------------------ \n\n")  
    iterateNetThroughPath(approachLingerLeavePath, trans, prefSpeed, network, center, win, updateTime )
    
    message.draw(win)
    win.getMouse()
    message.undraw()
    win.update()
        
    
    plt.close()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    
    createFigure(enviroment, distancePreferences,fig,ax)

    
    #random movement tests
    path = GeneratePath.randomMovement(enviroment,tests.get("randomMove"),random.uniform(1.5,2),prefSpeed)
    trans = GeneratePath.position_transform(path,robotHeight)
    
    print("\n---------------- Random movement tests ------------------ \n\n")
    iterateNetThroughPath(path, trans, prefSpeed, network, center, win, updateTime )
    

        
        
    message = graphics.Text(graphics.Point(200, 380), 'Click to close window.')
    message.draw(win)
    win.getMouse()
    
    win.close()
    plt.close()
示例#7
0
def testFace(enviroment, tests, speedPreferences, distancePreferences,
             updateTime, robotHeight, network):

    xMax, xMin, yMax, yMin = enviroment
    careDist, goodDist = distancePreferences
    slowSpeed, prefSpeed, fastSpeed = speedPreferences

    random.seed()
    """
        Sets up the window for displaying the parametrized face
    """
    center = graphics.Point(200, 200)
    win = graphics.GraphWin('Face', 400, 400,
                            autoflush=False)  # give title and dimensions
    win.setBackground('white')
    win.setCoords(0, 0, 400, 400)
    """
        Sets up the window for plotting the position of the person the face is looking at
    """
    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)
    createFigure(enviroment, distancePreferences, fig, ax)

    message = graphics.Text(graphics.Point(200, 380),
                            'Click to start simulation.')
    message.draw(win)
    win.getMouse()
    message.undraw()
    win.update()

    lingerTestPath = []
    # Linger at comfortable distance
    for i in range(tests.get("lingerFar")):
        z = random.uniform(1.5, 2)

        startx = random.uniform(xMin, xMax)
        starty = yMax

        dist = random.uniform(goodDist, careDist)

        endx = random.uniform(-dist, dist)
        endy = math.sqrt(dist**2 - endx**2)

        timesLingering = random.randrange(6, 15)

        lingerTestPath.extend(
            GeneratePath.moveAndLinger([startx, starty, z], [endx, endy, z],
                                       prefSpeed, timesLingering))

    #linger too close
    for i in range(tests.get("lingerClose")):
        z = random.uniform(1.5, 2)
        startx = random.uniform(xMin, xMax)
        starty = yMax

        #dist = random.uniform(enviroment[3],tooClose)
        # endx = random.uniform(-dist,dist)
        #endy = math.sqrt(dist**2 - endx**2)
        endx = 0
        endy = 1
        timesLingering = random.randrange(6, 15)

        lingerTestPath.extend(
            GeneratePath.moveAndLinger([startx, starty, z], [endx, endy, z],
                                       prefSpeed, timesLingering))

    trans = GeneratePath.position_transform(lingerTestPath, robotHeight)

    print("\n---------------- Lingering tests ------------------ \n\n")
    iterateNetThroughPath(lingerTestPath, trans, prefSpeed, network, center,
                          win, updateTime)

    # approach, linger, leave tests
    plt.close()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    createFigure(enviroment, distancePreferences, fig, ax)

    approachLingerLeavePath = []
    for i in range(tests.get("approachLingerLeaveClose")):
        z = random.uniform(1.5, 2)
        startx = random.uniform(xMin, xMax)
        starty = yMax

        stoppx = 0
        stoppy = 1
        timesLingering = random.randrange(6, 15)

        exitx = random.uniform(xMin, xMax)
        exity = yMax

        approachLingerLeavePath.extend(
            GeneratePath.approachLingerLeave(prefSpeed, [startx, starty, z],
                                             [stoppx, stoppy, z],
                                             [exitx, exity, z],
                                             timesLingering))

    trans = GeneratePath.position_transform(approachLingerLeavePath,
                                            robotHeight)

    print(
        "\n---------------- Approach Linger Leave Close tests ------------------ \n\n"
    )
    iterateNetThroughPath(approachLingerLeavePath, trans, prefSpeed, network,
                          center, win, updateTime)

    message.draw(win)
    win.getMouse()
    message.undraw()
    win.update()

    plt.close()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    createFigure(enviroment, distancePreferences, fig, ax)

    approachLingerLeavePath = []

    for i in range(tests.get("approachLingerLeaveFar")):
        z = random.uniform(1.5, 2)
        startx = random.uniform(xMin, xMax)
        starty = yMax

        dist = random.uniform(goodDist, careDist)
        stoppx = random.uniform(-dist, dist)
        stoppy = math.sqrt(dist**2 - stoppx**2)

        timesLingering = random.randrange(6, 15)

        exitx = random.uniform(xMin, xMax)
        exity = yMax

        approachLingerLeavePath.extend(
            GeneratePath.approachLingerLeave(prefSpeed, [startx, starty, z],
                                             [stoppx, stoppy, z],
                                             [exitx, exity, z],
                                             timesLingering))

    trans = GeneratePath.position_transform(approachLingerLeavePath,
                                            robotHeight)

    print(
        "\n---------------- Approach Linger Leave Far tests ------------------ \n\n"
    )
    iterateNetThroughPath(approachLingerLeavePath, trans, prefSpeed, network,
                          center, win, updateTime)

    message.draw(win)
    win.getMouse()
    message.undraw()
    win.update()

    plt.close()

    fig = plt.figure()
    ax = fig.add_subplot(1, 1, 1)

    createFigure(enviroment, distancePreferences, fig, ax)

    #random movement tests
    path = GeneratePath.randomMovement(enviroment, tests.get("randomMove"),
                                       random.uniform(1.5, 2), prefSpeed)
    trans = GeneratePath.position_transform(path, robotHeight)

    print("\n---------------- Random movement tests ------------------ \n\n")
    iterateNetThroughPath(path, trans, prefSpeed, network, center, win,
                          updateTime)

    message = graphics.Text(graphics.Point(200, 380), 'Click to close window.')
    message.draw(win)
    win.getMouse()

    win.close()
    plt.close()