Exemple #1
0
def VisualizeSimData(icList,
                     allplans=False,
                     showtraffic=True,
                     xmin=-100,
                     ymin=-100,
                     xmax=100,
                     ymax=100,
                     playbkspeed=1,
                     interval=30,
                     record=False,
                     filename=""):
    '''
    ic: icarous object
    allplans: True - plot all computed plans, False - plot only the mission plan
    xmin,ymin : plot axis min values
    xmax,ymax : plot axis max values
    interval  : Interval between frames
    '''
    if record:
        import matplotlib
        matplotlib.use('Agg')
    from Animation import AgentAnimation
    anim = AgentAnimation(xmin, ymin, xmax, ymax, playbkspeed, interval,
                          record, filename)

    vehicleSize1 = np.abs(xmax - xmin) / 100
    vehicleSize2 = np.abs(ymax - ymin) / 100
    vehicleSize = np.max([vehicleSize1, vehicleSize2])
    for j, ic in enumerate(icList):
        anim.AddAgent('ownship' + str(j),
                      vehicleSize,
                      'r',
                      ic.ownshipLog,
                      show_circle=True,
                      circle_rad=ic.daa_radius)
        for i, pln in enumerate(ic.localPlans):
            if i == 0:
                anim.AddPath(np.array(pln), 'k--')

            if i > 0 and allplans:
                anim.AddPath(np.array(pln), 'k--')
        tfids = ic.trafficLog.keys()
        if showtraffic:
            for key in tfids:
                anim.AddAgent('traffic' + str(key), vehicleSize, 'b',
                              ic.trafficLog[key])
        for fence in ic.localFences:
            fence.append(fence[0])
            anim.AddFence(np.array(fence), 'c-.')
    for fix in icList[0].localMergeFixes:
        anim.AddZone(fix[::-1][1:3], icList[0].params['COORD_ZONE'], 'r')
        anim.AddZone(fix[::-1][1:3], icList[0].params['SCHEDULE_ZONE'], 'b')
        anim.AddZone(fix[::-1][1:3], icList[0].params['ENTRY_RADIUS'], 'g')

    anim.run()
Exemple #2
0
def VisualizeSimData(icList,allplans=False,showpaths=True,showtrace=True,showtraffic=True,xmin=-100,ymin=-100,xmax=100,ymax=100,playbkspeed=1,interval=30,record=False,filename="",network=[]):
    '''
    ic: icarous object
    allplans: True - plot all computed plans, False - plot only the mission plan
    xmin,ymin : plot axis min values
    xmax,ymax : plot axis max values
    interval  : Interval between frames
    '''
    if record:
        import matplotlib; matplotlib.use('Agg')
    from Animation import AgentAnimation
    anim= AgentAnimation(xmin,ymin, xmax,ymax,showtrace,playbkspeed,interval,record,filename)

    vehicleSize1 = np.abs(xmax - xmin)/100
    vehicleSize2 = np.abs(ymax - ymin)/100
    vehicleSize  = np.max([vehicleSize1,vehicleSize2])
    homePos = icList[0].home_pos
    getLocPos = lambda pos: np.array(ConvertToLocalCoordinates(homePos,pos))
    for j,ic in enumerate(icList):
        anim.AddAgent(ic.callsign,vehicleSize,'r',ic.ownshipLog,show_circle=True,circle_rad=ic.daa_radius)
        for i,pln in enumerate(ic.plans):
            planTime = pln[0][0]
            planPositions = np.array(GetPlanPositions(ic.plans[i],0.1))
            points = np.array(list(map(getLocPos,planPositions)))
            if i == 0:
                planWPs = np.array(pln)[:,1:] 
                labels = [[TcpType.getString(val[3]),TcpType.getString(val[4]),TcpType.getString(val[5])]\
                           for val in planWPs]
                if showpaths:
                    anim.AddPath(np.array(list(map(getLocPos,planWPs))),'k--',points,labels,time=planTime)

            if i > 0 and allplans:
                planWPs = np.array(pln)[:,1:] 
                if showpaths:
                    anim.AddPath(np.array(list(map(getLocPos,planWPs))),'k--',points,time=planTime)
        tfids = ic.trafficLog.keys()
        for key in tfids:
            if showtraffic or key[0:2] == 'tf':
                anim.AddAgent('traffic_'+str(key),vehicleSize,'b',ic.trafficLog[key])
        for fence in ic.localFences:
            fence.append(fence[0])
            anim.AddFence(np.array(fence),'c-.')
    for fix in icList[0].localMergeFixes:
        anim.AddZone(fix[::-1][1:3],icList[0].params['COORD_ZONE'],'r')
        anim.AddZone(fix[::-1][1:3],icList[0].params['SCHEDULE_ZONE'],'b')
        anim.AddZone(fix[::-1][1:3],icList[0].params['ENTRY_RADIUS'],'g')

    for plan in network:
        planWPs = np.array(plan)[:,1:]
        anim.AddPath(np.array(list(map(getLocPos,planWPs))),'k--',color2='k')


    anim.run()