예제 #1
0
    def display_traffic_bigmap(cls, env, road, surface):
        """
            Display the road vehicles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        """
        commands = {}
        ego_car = env.vehicle
        # dt = 1.5 / env.SIMULATION_FREQUENCY
        # ego_car_vx = ego_car.velocity * math.cos(ego_car.heading * 180 / np.pi)
        # ego_car_vy = ego_car.velocity * math.sin(ego_car.heading * 180 / np.pi)
        # vehicle_dx = ego_car_vx * dt
        # vehicle_dy = ego_car_vy * dt
        for v in road.vehicles:
            # v.position -= [vehicle_dx,vehicle_dy]
            # if np.linalg.norm(v.position - ego_car.position) < 75:
            #     if v.lane_index in ego_car.lanes_around or hasattr(v,"state"):
            VehicleGraphics.display(v, surface, command_dict=commands)
            # else:
            #     if not hasattr(v, "state"):
            #         env.road.vehicles.remove(v)
        # print(commands)
        # m.send_message(commands)
        return commands
예제 #2
0
    def display_traffic(cls, road, surface):
        """
            Display the road vehicles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        """
        for v in road.vehicles:
            VehicleGraphics.display(v, surface)
예제 #3
0
    def display_traffic(cls, road, surface, offscreen=False):
        """
            Display the road vehicles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        """
        print("[INFO] in display_traffic, offscreen={}".format(offscreen))
        for v in road.vehicles:
            VehicleGraphics.display(v, surface, offscreen=offscreen)
예제 #4
0
    def display_obstacles(road, surface, offscreen=False):
        """
            Display the obstacles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        :param offscreen: whether the rendering should be done offscreen or not
        """
        for o in road.obstacles:
            VehicleGraphics.display(o, surface, offscreen=offscreen)
    def display_traffic(cls, road, surface, simulation_frequency=15, offscreen=False):
        """
            Display the road vehicles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        :param simulation_frequency: simulation frequency
        """
        if road.record_history:
            for v in road.vehicles:
                VehicleGraphics.display_history(v, surface, simulation=simulation_frequency, offscreen=offscreen)
        for v in road.vehicles:
            VehicleGraphics.display(v, surface, offscreen=offscreen)
예제 #6
0
    def display_traffic(cls, road, surface):
        """
            Display the road vehicles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        """
        commands = {}
        for v in road.vehicles:
            VehicleGraphics.display(v, surface, command_dict=commands)
        # print(commands)
        # m.send_message(commands)
        return commands
예제 #7
0
    def display(self) -> None:
        """Display the road and vehicles on a pygame window."""
        if not self.enabled:
            return
        self.sim_surface.move_display_window_to(self.window_position())
        RoadGraphics.display(self.env.road, self.sim_surface)
        if self.vehicle_trajectory:
            VehicleGraphics.display_trajectory(self.vehicle_trajectory,
                                               self.sim_surface,
                                               offscreen=self.offscreen)

        RoadGraphics.display_road_objects(self.env.road,
                                          self.sim_surface,
                                          offscreen=self.offscreen)

        if self.agent_display:
            self.agent_display(self.agent_surface, self.sim_surface)
            if not self.offscreen:
                if self.config["screen_width"] > self.config["screen_height"]:
                    self.screen.blit(self.agent_surface,
                                     (0, self.config["screen_height"]))
                else:
                    self.screen.blit(self.agent_surface,
                                     (self.config["screen_width"], 0))

        RoadGraphics.display_traffic(
            self.env.road,
            self.sim_surface,
            simulation_frequency=self.env.config["simulation_frequency"],
            offscreen=self.offscreen)

        VehicleGraphics.display(self.env.vehicle,
                                self.sim_surface,
                                offscreen=self.offscreen,
                                ego=True)

        # ObservationGraphics.display(self.env.observation_type, self.sim_surface)

        if not self.offscreen:
            self.screen.blit(self.sim_surface, (0, 0))
            if self.env.config["real_time_rendering"]:
                self.clock.tick(self.env.config["simulation_frequency"])
            pygame.display.flip()

        if self.SAVE_IMAGES and self.directory:
            pygame.image.save(
                self.sim_surface,
                str(self.directory / "highway-env_{}.png".format(self.frame)))
            self.frame += 1
예제 #8
0
    def display_traffic(road: Road, surface: WorldSurface, simulation_frequency: int = 15, offscreen: bool = False) \
            -> None:
        """
        Display the road vehicles on a surface.

        :param road: the road to be displayed
        :param surface: the pygame surface
        :param simulation_frequency: simulation frequency
        :param offscreen: render without displaying on a screen
        """
        if road.record_history:
            for v in road.vehicles:
                VehicleGraphics.display_history(v, surface, simulation=simulation_frequency, offscreen=offscreen)
        for v in road.vehicles:
            VehicleGraphics.display(v, surface, offscreen=offscreen)