Beispiel #1
0
    def draw_scan(self,
                  process: RoadProcess,
                  view: KRoadView,
                  ray_scanner,
                  scan_results,
                  color=(64, 64, 64)) -> None:
        if scan_results is None:
            return

        position = process.ego_vehicle.position
        contact_size = min(.1, ray_scanner.beam_radius / 2)
        for (endpoint, ray_contacts) in scan_results:
            ray_vector = (endpoint - position)
            view.draw_segment(color, False, position, endpoint,
                              ray_scanner.beam_radius)

            def draw_contact(color, type_):
                if type_ in ray_contacts:
                    view.draw_circle(
                        color,
                        position + ray_vector * ray_contacts[type_].alpha,
                        contact_size)

            draw_contact((255, 255, 255), EntityType.curb)
            # draw_contact((0, 255, 0), EntityType.lane_marking_white_dashed)
            draw_contact((255, 0, 0), EntityType.vehicle)
    def render(self, process: 'KRoadProcess', view: KRoadView) -> None:
        # print('render')
        super().render(process, view)
        for p in self.ego_vehicle.positions:
            view.draw_circle((200, 0, 64), p, .2)

        if self.cross_track is not None:
            view.draw_circle((64, 0, 200), self.cross_track.point, .3)
Beispiel #3
0
    def make_view(self, mode) -> KRoadView:
        """
        Factory method from Process class that returns a KRoadView.
        This implementation puts the view over all shapes in the KRoadProcess, plus a bit of padding.
        Override this to get a different viewport or to use a different view type.
        """
        left, bottom, right, top = self.bounding_box

        # pad bounds by a little bit
        padding = self.__viewport_padding
        horizontal_padding = padding * (right - left)
        vertical_padding = padding * (top - bottom)
        left = left - horizontal_padding
        right = right + horizontal_padding
        bottom = bottom - vertical_padding
        top = top + vertical_padding

        center = Vec2d((left + right) / 2, (top + bottom) / 2)

        horizontal_size = right - left
        vertical_size = top - bottom

        scale = min(self.__max_viewport_resolution[0] / horizontal_size,
                    self.__max_viewport_resolution[1] / vertical_size)

        view_size = (math.ceil(scale * horizontal_size),
                     math.ceil(scale * vertical_size))

        return KRoadView(view_size, center, scale, self.__time_dilation)
Beispiel #4
0
    def make_view(self, mode) -> KRoadView:
        scale = 4.0
        padding = .01
        size = 2 * self.max_distance_from_target * (1.0 + padding)
        view_size = math.ceil(scale * size)

        return KRoadView((view_size, view_size), Vec2d(0, 0), scale,
                         self.time_dilation)
    def make_view(self, mode) -> KRoadView:
        # print('make_view')
        padding = .01
        size = 1.0 * self.view_distance * (1.0 + padding)
        view_size = int(ceil(self.scale * size))

        return KRoadView((view_size, view_size), self.ego_vehicle.position,
                         self.scale, self.time_dilation)
Beispiel #6
0
    def render(self, process: TrajectoryTrackingProcess,
               view: KRoadView) -> None:
        for waypoint in self.render_waypoints:
            view.draw_circle((0, 192, 0), waypoint[0], .6)
        # if process.mirror_steering < 0:
        #     for waypoint in self.mirrored_waypoints:
        #         view.draw_circle((0, 192, 192), waypoint, .5)

        ego = process.ego_vehicle
        position = ego.position
        view.draw_line((192, 0, 192), position,
                       Vec2d(ego.internal_longitudinal_velocity * 1.0 + 10,
                             0).rotated(ego.angle) + position)
        view.draw_line(
            (55, 204, 189), position,
            Vec2d(ego.internal_longitudinal_velocity,
                  ego.internal_lateral_velocity).rotated(ego.angle) * 1.5 +
            position)
Beispiel #7
0
 def begin_render(self, process: 'KRoadProcess', view: KRoadView) -> None:
     super().begin_render(process, view)
     if self.view_follows_ego:
         view.set_view_center(self.ego_vehicle.position)