src/TrafficSimulator.py
def plot_robots(self,fsize=(12,12),plot_lanes_flag=True,annotate_flag=True,plot_intersection_region_flag=True,plot_reservation_patches_flag=False,plot_only_intersection_flag=False):
        ''' Plot autonomous vehicles in intersection.  Optional flags included for plotting reservation'''
        #TODO:  Add argument parser for all the different flags


        fig = plt.figure(figsize=fsize)
        ax = fig.add_subplot(111,aspect='equal')
        self.fig = fig
        self.axes = ax
        ax.set_ylim([-self.map_height/2.5,self.map_height/2.5])
        ax.set_xlim([-self.map_width/2.5,self.map_width/2.5])
        ax.set_axis_off()
        

        if plot_lanes_flag:
            self.plot_lanes(ax)
        if annotate_flag:
            self.annotate_axis(ax)
        if plot_intersection_region_flag:
            self.add_intersection_regions(ax)               
        if plot_reservation_patches_flag:
            self.add_reservation_patches(self.coordinator,ax)    
        if plot_only_intersection_flag:
            ax.set_ylim([-self.lane_width,self.lane_width])
            ax.set_xlim([-self.lane_width,self.lane_width])
            ticks = np.arange(-self.lane_width,self.lane_width,self.gridsize)
            ax.set_xticks(ticks)
            ax.set_yticks(ticks)

        ax.axhline(0,-self.map_width/2.0,-self.lane_width,linestyle='--',color='k',linewidth=10)
        ax.axhline(0,self.lane_width, self.map_width/2.0,linestyle='--',color='k')
        ax.axvline(0,self.lane_width, self.map_width/2.0, linestyle='--',color='k')
        ax.axvline(0,-self.map_width/2.0,-self.lane_width,linestyle='--',color='k')


        plot_construction_flag = True
        if plot_construction_flag:
            self.plot_construction(ax)

        addToLegend = False
        for robot in self.active_vehicles:
            if robot.intersection_window[0] > 0 and False:
                edge_color_reservation = 'g'
            else:
                edge_color_reservation = None

            current_color = self.robotColor(robot)
            # current_color = self.robotColorSVO(robot)
            car_patch = patches.Rectangle((robot.pose.x-robot.car_length,robot.pose.y-robot.car_width/2.0),robot.car_length,robot.car_width,facecolor=current_color,edgecolor=edge_color_reservation,linewidth=3)
            t = transforms.Affine2D().rotate_around(robot.pose.x, robot.pose.y, robot.pose.phi)
            car_patch.set_transform(t + ax.transData)
            ax.add_patch(car_patch)
            offset_x = -3 - robot.car_length/2.0*np.cos(robot.pose.phi)*20
            offset_y = -3 - robot.car_length/2.0*np.sin(robot.pose.phi)*20
            new_id = robot.agent_id

            ax.annotate(str(new_id),(robot.pose.x,robot.pose.y),xytext=(offset_x, offset_y),size=8,textcoords='offset points',color='black')
            arrow_direction = robot.turn_direction
            dx, dy = self.turn_direction_to_delta_x_y_arrow(robot)
            arrow_length = 0.1*self.lane_width
            plt.arrow(robot.pose.x,robot.pose.y, dx*arrow_length, dy*arrow_length,width=.05)
            # ax.plot(robot.pose.x,robot.pose.y,'o', c='k',markersize=4)            
 Plot autonomous vehicles in intersection.  Optional flags included for plotting reservation
Plot autonomous vehicles in intersection.  Optional flags included for plotting reservation
Plot autonomous vehicles in intersection . Optional flags included for plotting reservation
def plot_robots(self,fsize=(12,12),plot_lanes_flag=True,annotate_flag=True,plot_intersection_region_flag=True,plot_reservation_patches_flag=False,plot_only_intersection_flag=False):
        fig = plt.figure(figsize=fsize)
        ax = fig.add_subplot(111,aspect='equal')
        self.fig = fig
        self.axes = ax
        ax.set_ylim([-self.map_height/2.5,self.map_height/2.5])
        ax.set_xlim([-self.map_width/2.5,self.map_width/2.5])
        ax.set_axis_off()
        if plot_lanes_flag:
            self.plot_lanes(ax)
        if annotate_flag:
            self.annotate_axis(ax)
        if plot_intersection_region_flag:
            self.add_intersection_regions(ax)               
        if plot_reservation_patches_flag:
            self.add_reservation_patches(self.coordinator,ax)    
        if plot_only_intersection_flag:
            ax.set_ylim([-self.lane_width,self.lane_width])
            ax.set_xlim([-self.lane_width,self.lane_width])
            ticks = np.arange(-self.lane_width,self.lane_width,self.gridsize)
            ax.set_xticks(ticks)
            ax.set_yticks(ticks)
        ax.axhline(0,-self.map_width/2.0,-self.lane_width,linestyle='--',color='k',linewidth=10)
        ax.axhline(0,self.lane_width, self.map_width/2.0,linestyle='--',color='k')
        ax.axvline(0,self.lane_width, self.map_width/2.0, linestyle='--',color='k')
        ax.axvline(0,-self.map_width/2.0,-self.lane_width,linestyle='--',color='k')
        plot_construction_flag = True
        if plot_construction_flag:
            self.plot_construction(ax)
        addToLegend = False
        for robot in self.active_vehicles:
            if robot.intersection_window[0] > 0 and False:
                edge_color_reservation = 'g'
            else:
                edge_color_reservation = None
            current_color = self.robotColor(robot)
            car_patch = patches.Rectangle((robot.pose.x-robot.car_length,robot.pose.y-robot.car_width/2.0),robot.car_length,robot.car_width,facecolor=current_color,edgecolor=edge_color_reservation,linewidth=3)
            t = transforms.Affine2D().rotate_around(robot.pose.x, robot.pose.y, robot.pose.phi)
            car_patch.set_transform(t + ax.transData)
            ax.add_patch(car_patch)
            offset_x = -3 - robot.car_length/2.0*np.cos(robot.pose.phi)*20
            offset_y = -3 - robot.car_length/2.0*np.sin(robot.pose.phi)*20
            new_id = robot.agent_id
            ax.annotate(str(new_id),(robot.pose.x,robot.pose.y),xytext=(offset_x, offset_y),size=8,textcoords='offset points',color='black')
            arrow_direction = robot.turn_direction
            dx, dy = self.turn_direction_to_delta_x_y_arrow(robot)
            arrow_length = 0.1*self.lane_width
            plt.arrow(robot.pose.x,robot.pose.y, dx*arrow_length, dy*arrow_length,width=.05)
def plot_robots ( self , fsize = ( 12 , 12 ) , plot_lanes_flag = True , annotate_flag = True , plot_intersection_region_flag = True , plot_reservation_patches_flag = False , plot_only_intersection_flag = False ) : fig = plt . figure ( figsize = fsize ) ax = fig . add_subplot ( 111 , aspect = 'equal' ) self . fig = fig self . axes = ax ax . set_ylim ( [ - self . map_height / 2.5 , self . map_height / 2.5 ] ) ax . set_xlim ( [ - self . map_width / 2.5 , self . map_width / 2.5 ] ) ax . set_axis_off ( ) if plot_lanes_flag : self . plot_lanes ( ax ) if annotate_flag : self . annotate_axis ( ax ) if plot_intersection_region_flag : self . add_intersection_regions ( ax ) if plot_reservation_patches_flag : self . add_reservation_patches ( self . coordinator , ax ) if plot_only_intersection_flag : ax . set_ylim ( [ - self . lane_width , self . lane_width ] ) ax . set_xlim ( [ - self . lane_width , self . lane_width ] ) ticks = np . arange ( - self . lane_width , self . lane_width , self . gridsize ) ax . set_xticks ( ticks ) ax . set_yticks ( ticks ) ax . axhline ( 0 , - self . map_width / 2.0 , - self . lane_width , linestyle = '--' , color = 'k' , linewidth = 10 ) ax . axhline ( 0 , self . lane_width , self . map_width / 2.0 , linestyle = '--' , color = 'k' ) ax . axvline ( 0 , self . lane_width , self . map_width / 2.0 , linestyle = '--' , color = 'k' ) ax . axvline ( 0 , - self . map_width / 2.0 , - self . lane_width , linestyle = '--' , color = 'k' ) plot_construction_flag = True if plot_construction_flag : self . plot_construction ( ax ) addToLegend = False for robot in self . active_vehicles : if robot . intersection_window [ 0 ] > 0 and False : edge_color_reservation = 'g' else : edge_color_reservation = None current_color = self . robotColor ( robot ) car_patch = patches . Rectangle ( ( robot . pose . x - robot . car_length , robot . pose . y - robot . car_width / 2.0 ) , robot . car_length , robot . car_width , facecolor = current_color , edgecolor = edge_color_reservation , linewidth = 3 ) t = transforms . Affine2D ( ) . rotate_around ( robot . pose . x , robot . pose . y , robot . pose . phi ) car_patch . set_transform ( t + ax . transData ) ax . add_patch ( car_patch ) offset_x = - 3 - robot . car_length / 2.0 * np . cos ( robot . pose . phi ) * 20 offset_y = - 3 - robot . car_length / 2.0 * np . sin ( robot . pose . phi ) * 20 new_id = robot . agent_id ax . annotate ( str ( new_id ) , ( robot . pose . x , robot . pose . y ) , xytext = ( offset_x , offset_y ) , size = 8 , textcoords = 'offset points' , color = 'black' ) arrow_direction = robot . turn_direction dx , dy = self . turn_direction_to_delta_x_y_arrow ( robot ) arrow_length = 0.1 * self . lane_width plt . arrow ( robot . pose . x , robot . pose . y , dx * arrow_length , dy * arrow_length , width = .05 )
Plot autonomous vehicles in intersection.
Plot autonomous vehicles in intersection .
''' Plot autonomous vehicles in intersection.  Optional flags included for plotting reservation''' #TODO:  Add argument parser for all the different flags # current_color = self.robotColorSVO(robot) # ax.plot(robot.pose.x,robot.pose.y,'o', c='k',markersize=4)            
self
fsize
plot_lanes_flag
annotate_flag
plot_intersection_region_flag
plot_reservation_patches_flag
plot_only_intersection_flag