コード例 #1
0
    def animate(self, frame_idx): # update animation by dt
        self.ax.clear()
        # scale to the large topo
        xscale = 10.5
        yscale = 10.3
        xoffset = 0
        yoffset = 40
        dt = 0.1
        # add one pedestrian to test simulation
        #pedestrian = Pedestrian.Pedestrian(pedestrian_type='1')
        #pedestrian.prim_queue.enqueue(((self.start_walk_lane, self.end_walk_lane, 60), 0))
        #if pedestrian.state[0] < self.end_walk_lane[0]: # if not at the destination
            #pedestrian.prim_next(dt)
            #draw_pedestrian(pedestrian,self.background)

        # Just add cars to image to test simulation
        #self.add_car_to_sim
        for car in self.cars:
            # print('car.x'+str(car.x))
            # print('car.x'+str(car.y))
            print(car.x)
            f = open('car_pos.txt','a')
            f.writelines([str(car.x),' ', str(car.y),' ', str(car.yaw), '\n'])
            f.close()
            draw_car(self.background, car.x*SCALE_FACTOR,car.y*SCALE_FACTOR+yoffset,car.yaw)
        # update background
        the_parking_lot = [self.ax.imshow(self.background)] # update the stage
        self.background.close()
        self.background = parking_lot.get_background()
        all_artists = the_parking_lot
        return all_artists
コード例 #2
0
 async def update_simulation(self):
     frame_idx = 0
     self.fig = plt.figure()
     while True:
         frame_idx +=1 
         f = open('car_pos.txt','a')
         f.write('FRAME'+str(frame_idx)+'\n')
         self.ax = self.fig.add_axes([0,0,1,1]) # get rid of white border
         plt.axis('off')
         self.background = parking_lot.get_background()
         await trio.sleep(0)
         ani = animation.FuncAnimation(self.fig, self.animate, frames=1, interval=1**3, blit=True, repeat=False)
         plt.pause(0.001)
         plt.draw()
         await trio.sleep(0)
         f.close()
         print('------------Figure updating-------------')
コード例 #3
0
 async def update_simulation(self):
     frame_idx = 0
     self.fig = plt.figure()
     while True:
         frame_idx += 1
         #ped = pickle.load( open('pedestrain_file', "rb" ) )
         self.ax = self.fig.add_axes([0, 0, 1,
                                      1])  # get rid of white border
         plt.axis('off')
         self.background = parking_lot.get_background()
         ani = animation.FuncAnimation(self.fig,
                                       self.animate,
                                       frames=1,
                                       interval=1**3,
                                       blit=True,
                                       repeat=False)
         plt.pause(0.001)
         plt.draw()
         await trio.sleep(1)
         print('------------Figure updating-------------')
コード例 #4
0
    def animate(self, frame_idx):  # update animation by dt
        global ind
        ind = ind + 1
        self.ax.clear()
        # scale to the large topo
        xoffset = 0
        yoffset = 0
        f = open('pedestrian_file_new.pkl', 'ab')
        pickle.dump('FRAME' + str(ind) + '\n', f)
        for pedestrian in self.peds:
            draw_pedestrian(pedestrian, self.background)
            pickle.dump(pedestrian, f)
        f.close()

        f = open('car_pos_new.txt', 'a')
        f.write('FRAME' + str(ind) + '\n')
        for car in self.cars:
            draw_car(self.background, car.x * SCALE_FACTOR_SIM + xoffset,
                     car.y * SCALE_FACTOR_SIM + yoffset, car.yaw)
            f.writelines(
                [str(car.x), ' ',
                 str(car.y), ' ',
                 str(car.yaw), '\n'])
        f.close()
        # to check parking spot locations
        if show_all_spots:
            for key, value in parking_spots.items():
                xd = int(value[0] * SCALE_FACTOR_PLAN * SCALE_FACTOR_SIM +
                         xoffset)
                yd = int(value[1] * SCALE_FACTOR_PLAN * SCALE_FACTOR_SIM +
                         yoffset)
                #                print(value[0], value[1])
                #                print(xd, yd)
                hd = np.deg2rad(-value[2])
                draw_car(self.background, xd, yd, hd)
        the_parking_lot = [self.ax.imshow(self.background)]  # update the stage
        self.background.close()
        self.background = parking_lot.get_background()
        all_artists = the_parking_lot
        return all_artists
コード例 #5
0
def animate(frame_idx): # update animation by dt
    global background
    ax.clear()
    car_at_this_frame = []
    # scale to the large topo
    xoffset = 0
    yoffset = 0
    dt = 0.1

    with open('car_pos.txt') as f:
        i = 0
        begin = 0
        end = 0
        lines = f.readlines() 
        for line in lines: 
            i += 1
            if line.strip() == 'FRAME'+ str(frame_idx):
                begin = i
            if line.strip() == 'FRAME'+ str(frame_idx+1):
                end = i
                break
       
        car_at_this_frame = lines[begin:end-1]
        for car in car_at_this_frame:
             car = car.split(' ')     
             try:
                 draw_car(background, float(car[0])*SCALE_FACTOR_SIM,float(car[1])*SCALE_FACTOR_SIM+yoffset,float(car[2]))
             except EOFError:
                 break    
        f.close() 
        
    with open('pedestrian_file.pkl','rb') as f:
        i = 0
        begin = 0
        end = 0
        while True:
            i += 1
            pedestrian=pickle.load(f)
            if pedestrian == 'FRAME'+ str(frame_idx)+'\n':
                begin = i
            if pedestrian == 'FRAME'+ str(frame_idx+1)+'\n':
                end = i
                break
    
    with open('pedestrian_file.pkl','rb') as f:
        i = 0
        while True:
            i = i+1
            try:
                pedestrian=pickle.load(f)
                if i > begin and i < end:
                    draw_pedestrian(pedestrian,background)
                if i >= end:
                    break
            except EOFError:
                break
    
    # update background
    if add_parked_cars:
        for key,value in grey_cars.items():
            xd = int(value[0]*SCALE_FACTOR_PLAN*SCALE_FACTOR_SIM+xoffset)
            yd = int(value[1]*SCALE_FACTOR_PLAN*SCALE_FACTOR_SIM+yoffset)
            hd = np.deg2rad(-value[2])
            draw_grey_car(background,float(xd),float(yd),float(hd))
    the_parking_lot = [ax.imshow(background)] # update the stage
    background.close()
    background = parking_lot.get_background()
    all_artists = the_parking_lot
    return all_artists
コード例 #6
0
from variables.parking_data import parking_spots, grey_cars
import components
import component.pedestrian as Pedestrian
    
add_parked_cars = True
# set to True to save video
save_video = False
# creates figure
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) # get rid of white border
plt.axis('off')
frame = plt.gca()
frame.axes.get_yaxis().set_visible(False)
frame.axes.get_xaxis().set_visible(False)

background = parking_lot.get_background()

start_walk_lane = (2908,665)
end_walk_lane = (3160,665)


dt = 0.1

def animate(frame_idx): # update animation by dt
    global background
    ax.clear()
    car_at_this_frame = []
    # scale to the large topo
    xoffset = 0
    yoffset = 0
    dt = 0.1