Beispiel #1
0
def VisualizeSimData(icList,allplans=False,showtraffic=True,xmin=-100,ymin=-100,xmax=100,ymax=100,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,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()
Beispiel #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()
Beispiel #3
0
def VisualizeSimDataOptimal(icList,scenario_time, scenario,allplans=True,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,icList[0].ownshipLog,scenario, scenario_time,playbkspeed,interval,record,filename)

    #scenario = ScenarioClass(scenario)

    vehicleSize1 = np.abs(xmax - xmin)/3000
    vehicleSize2 = np.abs(ymax - ymin)/3000
    vehicleSize  = np.max([vehicleSize1,vehicleSize2])
    #Tentativa de adicionar o mapa de custos
    anim.AddCostMap(scenario.mapgen,xmin,xmax,ymin,ymax)
    anim.AddObstacles(scenario)
    anim.AddZoom()
    anim.AddWaypoint()
    anim.AddStartGoal()
    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):
        #    pln_aux = []
        #    for k, vec in enumerate(pln):
        #        vec[1] = ic.localCoords[k][0]
        #        vec[2] = ic.localCoords[k][1]
        #        pln_aux.append(vec)

        #    if i == 0:
        #        anim.AddPath(np.array(pln_aux),'k--')
                
        #    if i > 0 and allplans:
        #        anim.AddPath(np.array(pln_aux),'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()