racer2d 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- racer2d/__init__.py +21 -0
- racer2d/__main__.py +23 -0
- racer2d/assets/car.png +0 -0
- racer2d/car.py +105 -0
- racer2d/env.py +151 -0
- racer2d/logger.py +73 -0
- racer2d/maps/map1_oval/background.png +0 -0
- racer2d/maps/map1_oval/border_mask.png +0 -0
- racer2d/maps/map1_oval/config.json +42 -0
- racer2d/maps/map1_oval/thumbnail.png +0 -0
- racer2d/maps/map2_rectangle/background.png +0 -0
- racer2d/maps/map2_rectangle/border_mask.png +0 -0
- racer2d/maps/map2_rectangle/config.json +42 -0
- racer2d/maps/map2_rectangle/thumbnail.png +0 -0
- racer2d/maps/map3_figure8/background.png +0 -0
- racer2d/maps/map3_figure8/border_mask.png +0 -0
- racer2d/maps/map3_figure8/config.json +42 -0
- racer2d/maps/map3_figure8/thumbnail.png +0 -0
- racer2d/maps/map4_wavy/background.png +0 -0
- racer2d/maps/map4_wavy/border_mask.png +0 -0
- racer2d/maps/map4_wavy/config.json +42 -0
- racer2d/maps/map4_wavy/thumbnail.png +0 -0
- racer2d/maps/map5_lshape/background.png +0 -0
- racer2d/maps/map5_lshape/border_mask.png +0 -0
- racer2d/maps/map5_lshape/config.json +42 -0
- racer2d/maps/map5_lshape/thumbnail.png +0 -0
- racer2d/maps/map6_rally/background.png +0 -0
- racer2d/maps/map6_rally/border_mask.png +0 -0
- racer2d/maps/map6_rally/config.json +62 -0
- racer2d/maps/map6_rally/thumbnail.png +0 -0
- racer2d/maps/map7_obstacle_ring/background.png +0 -0
- racer2d/maps/map7_obstacle_ring/border_mask.png +0 -0
- racer2d/maps/map7_obstacle_ring/config.json +42 -0
- racer2d/maps/map7_obstacle_ring/thumbnail.png +0 -0
- racer2d/maps/map8_obstacle_rally/background.png +0 -0
- racer2d/maps/map8_obstacle_rally/border_mask.png +0 -0
- racer2d/maps/map8_obstacle_rally/config.json +62 -0
- racer2d/maps/map8_obstacle_rally/thumbnail.png +0 -0
- racer2d/maps_registry.py +24 -0
- racer2d/menu.py +78 -0
- racer2d/play.py +121 -0
- racer2d/random_policy.py +48 -0
- racer2d/sim.py +58 -0
- racer2d/tools/generate_maps.py +324 -0
- racer2d/track.py +60 -0
- racer2d-0.1.0.dist-info/LICENSE +21 -0
- racer2d-0.1.0.dist-info/METADATA +235 -0
- racer2d-0.1.0.dist-info/RECORD +51 -0
- racer2d-0.1.0.dist-info/WHEEL +5 -0
- racer2d-0.1.0.dist-info/entry_points.txt +4 -0
- racer2d-0.1.0.dist-info/top_level.txt +1 -0
racer2d/__init__.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""racer2d: a human-playable 2D top-down racing game, a behavior-cloning
|
|
2
|
+
data logger, and a Gymnasium environment wrapping the same simulation.
|
|
3
|
+
"""
|
|
4
|
+
__version__ = "0.1.0"
|
|
5
|
+
|
|
6
|
+
from .env import RacerEnv, available_maps
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import gymnasium
|
|
10
|
+
|
|
11
|
+
gymnasium.register(
|
|
12
|
+
id="Racer2D-v0",
|
|
13
|
+
entry_point="racer2d.env:RacerEnv",
|
|
14
|
+
)
|
|
15
|
+
except Exception:
|
|
16
|
+
# Registration is a convenience (lets gymnasium.make("Racer2D-v0", ...)
|
|
17
|
+
# work); importing racer2d directly to use RacerEnv() still works fine
|
|
18
|
+
# without it, so a registration hiccup shouldn't break the import.
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
__all__ = ["RacerEnv", "available_maps", "__version__"]
|
racer2d/__main__.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Entry point: python -m racer2d (or the `racer2d-play` console script)"""
|
|
2
|
+
import pygame
|
|
3
|
+
|
|
4
|
+
from .menu import run_menu
|
|
5
|
+
from .play import run_race, WIDTH, HEIGHT
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
pygame.init()
|
|
10
|
+
screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
|
11
|
+
pygame.display.set_caption("Racer2D")
|
|
12
|
+
|
|
13
|
+
while True:
|
|
14
|
+
map_id = run_menu(screen)
|
|
15
|
+
if map_id is None:
|
|
16
|
+
break
|
|
17
|
+
run_race(screen, map_id)
|
|
18
|
+
|
|
19
|
+
pygame.quit()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
main()
|
racer2d/assets/car.png
ADDED
|
Binary file
|
racer2d/car.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Top-down car with a kinematic-bicycle-model physics core.
|
|
2
|
+
|
|
3
|
+
This is the standard model real arcade racers (and self-driving research
|
|
4
|
+
stacks) use for a top-down car: the heading change each tick is derived from
|
|
5
|
+
an actual front-wheel steering angle and the car's wheelbase, scaled by
|
|
6
|
+
current speed - not an arbitrary fixed "rotation speed". That single change
|
|
7
|
+
is what gets rid of the old model's glitches: it makes braking/reversing and
|
|
8
|
+
steering fall out of real geometry instead of ad hoc per-case hacks, so
|
|
9
|
+
there's no path left for the car to ever move opposite to its own velocity
|
|
10
|
+
sign (the old "lurches backward when you press forward" bug).
|
|
11
|
+
"""
|
|
12
|
+
import math
|
|
13
|
+
|
|
14
|
+
import pygame
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Car:
|
|
18
|
+
"""(x, y) is always the car's CENTER, matching track centerline points."""
|
|
19
|
+
|
|
20
|
+
MAX_SPEED = 5.2
|
|
21
|
+
MAX_REVERSE_SPEED = 3.5
|
|
22
|
+
|
|
23
|
+
ENGINE_ACCEL = 0.40 # speeding up under throttle
|
|
24
|
+
BRAKE_DECEL = 0.65 # slowing down when throttle opposes current motion
|
|
25
|
+
REVERSE_ACCEL = 0.28 # speeding up in reverse once stopped
|
|
26
|
+
COAST_DECEL = 0.10 # rolling/engine resistance with no throttle at all
|
|
27
|
+
|
|
28
|
+
WHEELBASE = 18.0 # px between front/rear axle - sets turn tightness
|
|
29
|
+
MAX_STEER_DEG = 18.0 # max front-wheel angle
|
|
30
|
+
MIN_SPEED_TO_STEER = 0.02
|
|
31
|
+
|
|
32
|
+
def __init__(self, img_path, start_pos, start_angle=0.0):
|
|
33
|
+
self.img = pygame.image.load(img_path).convert_alpha()
|
|
34
|
+
self.start_pos = tuple(start_pos)
|
|
35
|
+
self.start_angle = start_angle
|
|
36
|
+
self.reset()
|
|
37
|
+
|
|
38
|
+
def reset(self):
|
|
39
|
+
self.x, self.y = self.start_pos
|
|
40
|
+
self.angle = self.start_angle
|
|
41
|
+
self.speed = 0.0
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def vel(self):
|
|
45
|
+
"""Backwards-compatible alias some callers/logging use."""
|
|
46
|
+
return self.speed
|
|
47
|
+
|
|
48
|
+
def step(self, throttle: float, steering: float):
|
|
49
|
+
"""Advance physics by one tick. throttle/steering are in [-1, 1]."""
|
|
50
|
+
throttle = max(-1.0, min(1.0, throttle))
|
|
51
|
+
steering = max(-1.0, min(1.0, steering))
|
|
52
|
+
|
|
53
|
+
if throttle > 1e-3:
|
|
54
|
+
if self.speed < 0:
|
|
55
|
+
self.speed += self.BRAKE_DECEL * throttle # braking out of reverse
|
|
56
|
+
else:
|
|
57
|
+
self.speed += self.ENGINE_ACCEL * throttle # accelerating forward
|
|
58
|
+
elif throttle < -1e-3:
|
|
59
|
+
if self.speed > 0:
|
|
60
|
+
self.speed += self.BRAKE_DECEL * throttle # braking out of forward motion
|
|
61
|
+
else:
|
|
62
|
+
self.speed += self.REVERSE_ACCEL * throttle # accelerating backward
|
|
63
|
+
else:
|
|
64
|
+
if self.speed > 0:
|
|
65
|
+
self.speed = max(0.0, self.speed - self.COAST_DECEL)
|
|
66
|
+
elif self.speed < 0:
|
|
67
|
+
self.speed = min(0.0, self.speed + self.COAST_DECEL)
|
|
68
|
+
|
|
69
|
+
self.speed = max(-self.MAX_REVERSE_SPEED, min(self.MAX_SPEED, self.speed))
|
|
70
|
+
|
|
71
|
+
# Kinematic bicycle model: yaw rate = (speed / wheelbase) * tan(steer angle).
|
|
72
|
+
# Turning scales with speed (no spinning in place) and naturally reverses
|
|
73
|
+
# direction when speed is negative, matching how a car actually steers
|
|
74
|
+
# in reverse - no manual sign-flipping needed.
|
|
75
|
+
if abs(self.speed) > self.MIN_SPEED_TO_STEER:
|
|
76
|
+
steer_rad = math.radians(steering * self.MAX_STEER_DEG)
|
|
77
|
+
yaw_rate_deg = math.degrees((self.speed / self.WHEELBASE) * math.tan(steer_rad))
|
|
78
|
+
self.angle -= yaw_rate_deg
|
|
79
|
+
|
|
80
|
+
radians = math.radians(self.angle)
|
|
81
|
+
self.x -= math.sin(radians) * self.speed
|
|
82
|
+
self.y -= math.cos(radians) * self.speed
|
|
83
|
+
|
|
84
|
+
def bounce(self):
|
|
85
|
+
"""Call after a step() that ended up overlapping a wall: the caller
|
|
86
|
+
is expected to have already restored (x, y) to the last safe spot
|
|
87
|
+
(see play.py) so the car can never end up embedded in a wall - only
|
|
88
|
+
damping the velocity here, with no position change, means a slow
|
|
89
|
+
crawl into a wall can't "stick": the car is always left exactly on
|
|
90
|
+
the last valid tile with a speed that pushes it away next tick."""
|
|
91
|
+
self.speed = -self.speed * 0.5
|
|
92
|
+
|
|
93
|
+
def get_mask_and_topleft(self):
|
|
94
|
+
rotated = pygame.transform.rotate(self.img, self.angle)
|
|
95
|
+
rect = rotated.get_rect(center=(self.x, self.y))
|
|
96
|
+
mask = pygame.mask.from_surface(rotated)
|
|
97
|
+
return mask, rect.topleft
|
|
98
|
+
|
|
99
|
+
def draw(self, surface, camera_x=0.0, camera_y=0.0):
|
|
100
|
+
rotated = pygame.transform.rotate(self.img, self.angle)
|
|
101
|
+
rect = rotated.get_rect(center=(self.x - camera_x, self.y - camera_y))
|
|
102
|
+
surface.blit(rotated, rect.topleft)
|
|
103
|
+
|
|
104
|
+
def get_position(self):
|
|
105
|
+
return self.x, self.y
|
racer2d/env.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""Gymnasium-compatible environment wrapping the 2D racer simulation.
|
|
2
|
+
|
|
3
|
+
Observation: the rendered RGB frame the car "sees" (uint8, HxWx3) - the same
|
|
4
|
+
camera-following viewport the human game draws. Action: continuous
|
|
5
|
+
``[steer, throttle]``, each in [-1, 1].
|
|
6
|
+
|
|
7
|
+
This mirrors the human game's free-play design: hitting a wall/obstacle is a
|
|
8
|
+
soft bounce (see racer2d.sim.step_and_resolve), not a terminal state, so
|
|
9
|
+
``terminated`` is always False - there's no "game over" to learn around.
|
|
10
|
+
``truncated`` fires once ``max_steps`` is reached, if set.
|
|
11
|
+
|
|
12
|
+
Reward is a 0.0 stub: this project's primary use case is behavior cloning
|
|
13
|
+
from logged human play (see racer2d.logger), not reinforcement learning.
|
|
14
|
+
Everything a reward function would need - off-track/collision, checkpoint
|
|
15
|
+
index, lap count, speed, pose - is already in ``info`` each step, so a real
|
|
16
|
+
reward can be layered on top later (e.g. a wrapper) without changing the
|
|
17
|
+
env's observation/action shape.
|
|
18
|
+
"""
|
|
19
|
+
import os
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
import pygame
|
|
23
|
+
from gymnasium import Env, spaces
|
|
24
|
+
|
|
25
|
+
from .car import Car
|
|
26
|
+
from .track import Track
|
|
27
|
+
from .maps_registry import list_maps
|
|
28
|
+
from .sim import camera_offset, step_and_resolve, advance_progress
|
|
29
|
+
|
|
30
|
+
WIDTH, HEIGHT = 1280, 800
|
|
31
|
+
CAR_IMG = os.path.join(os.path.dirname(__file__), "assets", "car.png")
|
|
32
|
+
DEFAULT_MAP = "map1_oval"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def available_maps():
|
|
36
|
+
"""Map ids usable as ``map_id=`` (or ``reset(options={"map_id": ...})``)."""
|
|
37
|
+
return [m["id"] for m in list_maps()]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class RacerEnv(Env):
|
|
41
|
+
metadata = {"render_modes": ["human", "rgb_array"], "render_fps": 60}
|
|
42
|
+
|
|
43
|
+
def __init__(self, map_id=DEFAULT_MAP, render_mode=None, max_steps=None):
|
|
44
|
+
super().__init__()
|
|
45
|
+
if render_mode not in (None, *self.metadata["render_modes"]):
|
|
46
|
+
raise ValueError(f"Unsupported render_mode: {render_mode!r}")
|
|
47
|
+
self.map_id = map_id
|
|
48
|
+
self.render_mode = render_mode
|
|
49
|
+
self.max_steps = max_steps
|
|
50
|
+
|
|
51
|
+
# SDL needs a video driver before any surface/image can be created.
|
|
52
|
+
# "dummy" renders nothing to a screen (fast, works on headless CI/
|
|
53
|
+
# training boxes) but still fully supports the rest of pygame -
|
|
54
|
+
# set it up front, before pygame.init(), unless the caller wants an
|
|
55
|
+
# actual visible window or has already configured pygame themselves.
|
|
56
|
+
if not pygame.get_init():
|
|
57
|
+
if render_mode != "human":
|
|
58
|
+
os.environ.setdefault("SDL_VIDEODRIVER", "dummy")
|
|
59
|
+
pygame.init()
|
|
60
|
+
|
|
61
|
+
if render_mode == "human":
|
|
62
|
+
self._screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
|
63
|
+
pygame.display.set_caption("Racer2D")
|
|
64
|
+
else:
|
|
65
|
+
# A display surface must exist before other surfaces can be
|
|
66
|
+
# created, even under the dummy driver where nothing is shown.
|
|
67
|
+
self._screen = pygame.display.set_mode((WIDTH, HEIGHT))
|
|
68
|
+
|
|
69
|
+
self._frame_surface = pygame.Surface((WIDTH, HEIGHT))
|
|
70
|
+
|
|
71
|
+
# action = [steer, throttle], matching the column order already used
|
|
72
|
+
# by racer2d.logger's logged CSVs.
|
|
73
|
+
self.action_space = spaces.Box(low=-1.0, high=1.0, shape=(2,), dtype=np.float32)
|
|
74
|
+
self.observation_space = spaces.Box(low=0, high=255, shape=(HEIGHT, WIDTH, 3), dtype=np.uint8)
|
|
75
|
+
|
|
76
|
+
self.track = None
|
|
77
|
+
self.car = None
|
|
78
|
+
self._next_checkpoint = 0
|
|
79
|
+
self._laps_completed = 0
|
|
80
|
+
self._steps = 0
|
|
81
|
+
|
|
82
|
+
def reset(self, *, seed=None, options=None):
|
|
83
|
+
super().reset(seed=seed)
|
|
84
|
+
map_id = (options or {}).get("map_id", self.map_id)
|
|
85
|
+
self.track = Track(map_id)
|
|
86
|
+
self.car = Car(CAR_IMG, self.track.start_pos, self.track.start_angle)
|
|
87
|
+
self._next_checkpoint = 0
|
|
88
|
+
self._laps_completed = 0
|
|
89
|
+
self._steps = 0
|
|
90
|
+
|
|
91
|
+
obs = self._render_obs()
|
|
92
|
+
info = self._info(crashed=False)
|
|
93
|
+
if self.render_mode == "human":
|
|
94
|
+
self.render()
|
|
95
|
+
return obs, info
|
|
96
|
+
|
|
97
|
+
def step(self, action):
|
|
98
|
+
if self.track is None:
|
|
99
|
+
raise RuntimeError("Call reset() before step().")
|
|
100
|
+
steer = float(np.clip(action[0], -1.0, 1.0))
|
|
101
|
+
throttle = float(np.clip(action[1], -1.0, 1.0))
|
|
102
|
+
|
|
103
|
+
crashed = step_and_resolve(self.car, self.track, steer, throttle)
|
|
104
|
+
if not crashed:
|
|
105
|
+
self._next_checkpoint, self._laps_completed = advance_progress(
|
|
106
|
+
self.track, self.car, self._next_checkpoint, self._laps_completed
|
|
107
|
+
)
|
|
108
|
+
self._steps += 1
|
|
109
|
+
|
|
110
|
+
obs = self._render_obs()
|
|
111
|
+
reward = 0.0
|
|
112
|
+
terminated = False
|
|
113
|
+
truncated = self.max_steps is not None and self._steps >= self.max_steps
|
|
114
|
+
info = self._info(crashed=crashed)
|
|
115
|
+
if self.render_mode == "human":
|
|
116
|
+
self.render()
|
|
117
|
+
return obs, reward, terminated, truncated, info
|
|
118
|
+
|
|
119
|
+
def _render_obs(self):
|
|
120
|
+
cam_x, cam_y = camera_offset(
|
|
121
|
+
self.car.x, self.car.y, self.track.width, self.track.height, WIDTH, HEIGHT
|
|
122
|
+
)
|
|
123
|
+
self.track.draw(self._frame_surface, cam_x, cam_y)
|
|
124
|
+
self.car.draw(self._frame_surface, cam_x, cam_y)
|
|
125
|
+
# pygame surfaces are (width, height, 3); transpose to the
|
|
126
|
+
# conventional (height, width, 3) image-array layout.
|
|
127
|
+
arr = pygame.surfarray.array3d(self._frame_surface)
|
|
128
|
+
return np.transpose(arr, (1, 0, 2))
|
|
129
|
+
|
|
130
|
+
def _info(self, crashed):
|
|
131
|
+
return {
|
|
132
|
+
"map_id": self.track.map_id,
|
|
133
|
+
"pos": self.car.get_position(),
|
|
134
|
+
"angle": self.car.angle,
|
|
135
|
+
"speed": self.car.vel,
|
|
136
|
+
"checkpoint_idx": self._next_checkpoint,
|
|
137
|
+
"laps_completed": self._laps_completed,
|
|
138
|
+
"off_track": crashed,
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
def render(self):
|
|
142
|
+
if self.render_mode == "human":
|
|
143
|
+
self._screen.blit(self._frame_surface, (0, 0))
|
|
144
|
+
pygame.display.flip()
|
|
145
|
+
return None
|
|
146
|
+
if self.render_mode == "rgb_array":
|
|
147
|
+
return self._render_obs()
|
|
148
|
+
return None
|
|
149
|
+
|
|
150
|
+
def close(self):
|
|
151
|
+
pygame.quit()
|
racer2d/logger.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Per-episode frame + action logging for behavior-cloning / imitation datasets."""
|
|
2
|
+
import csv
|
|
3
|
+
import os
|
|
4
|
+
import time
|
|
5
|
+
import uuid
|
|
6
|
+
|
|
7
|
+
import pygame
|
|
8
|
+
|
|
9
|
+
# Must NOT be derived from __file__: once this package is pip-installed,
|
|
10
|
+
# __file__ points into site-packages, which is the wrong place to write user
|
|
11
|
+
# data (often not even writable). Default to ./data in the caller's current
|
|
12
|
+
# directory instead - same convention most CLI tools use - overridable via
|
|
13
|
+
# RACER2D_DATA_DIR for scripts/notebooks that want a fixed location.
|
|
14
|
+
DATA_DIR = os.environ.get("RACER2D_DATA_DIR") or os.path.join(os.getcwd(), "data")
|
|
15
|
+
|
|
16
|
+
FRAME_COLUMNS = [
|
|
17
|
+
"frame_idx", "timestamp", "steer", "throttle",
|
|
18
|
+
"pos_x", "pos_y", "angle", "speed", "checkpoint_idx", "lap_progress", "off_track", "lap",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
INDEX_COLUMNS = [
|
|
22
|
+
"episode_id", "map_id", "created_at", "num_frames", "outcome", "duration_s", "laps_completed",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class EpisodeLogger:
|
|
27
|
+
def __init__(self, map_id, num_checkpoints, data_dir=None):
|
|
28
|
+
self.map_id = map_id
|
|
29
|
+
self.num_checkpoints = max(num_checkpoints, 1)
|
|
30
|
+
self.data_dir = data_dir or DATA_DIR
|
|
31
|
+
self.episode_id = time.strftime("%Y%m%d_%H%M%S_") + uuid.uuid4().hex[:6]
|
|
32
|
+
self.episode_dir = os.path.join(self.data_dir, map_id, self.episode_id)
|
|
33
|
+
os.makedirs(self.episode_dir, exist_ok=True)
|
|
34
|
+
|
|
35
|
+
self.actions_path = os.path.join(self.episode_dir, "actions.csv")
|
|
36
|
+
self._actions_file = open(self.actions_path, "w", newline="")
|
|
37
|
+
self._writer = csv.writer(self._actions_file)
|
|
38
|
+
self._writer.writerow(FRAME_COLUMNS)
|
|
39
|
+
|
|
40
|
+
self.frame_idx = 0
|
|
41
|
+
self.laps_completed = 0
|
|
42
|
+
self.start_time = time.time()
|
|
43
|
+
|
|
44
|
+
def log_frame(self, surface, steer, throttle, pos, angle, speed, checkpoint_idx, off_track, laps_completed):
|
|
45
|
+
frame_path = os.path.join(self.episode_dir, f"frame_{self.frame_idx:06d}.png")
|
|
46
|
+
pygame.image.save(surface, frame_path)
|
|
47
|
+
|
|
48
|
+
lap_progress = checkpoint_idx / self.num_checkpoints
|
|
49
|
+
self._writer.writerow([
|
|
50
|
+
self.frame_idx, round(time.time() - self.start_time, 3),
|
|
51
|
+
round(steer, 4), round(throttle, 4),
|
|
52
|
+
round(pos[0], 2), round(pos[1], 2), round(angle, 2), round(speed, 3),
|
|
53
|
+
checkpoint_idx, round(lap_progress, 4), int(off_track), laps_completed,
|
|
54
|
+
])
|
|
55
|
+
self.frame_idx += 1
|
|
56
|
+
self.laps_completed = laps_completed
|
|
57
|
+
|
|
58
|
+
def close(self, outcome):
|
|
59
|
+
self._actions_file.close()
|
|
60
|
+
os.makedirs(self.data_dir, exist_ok=True)
|
|
61
|
+
index_path = os.path.join(self.data_dir, "episodes_index.csv")
|
|
62
|
+
is_new = not os.path.isfile(index_path)
|
|
63
|
+
with open(index_path, "a", newline="") as f:
|
|
64
|
+
writer = csv.writer(f)
|
|
65
|
+
if is_new:
|
|
66
|
+
writer.writerow(INDEX_COLUMNS)
|
|
67
|
+
writer.writerow([
|
|
68
|
+
self.episode_id, self.map_id,
|
|
69
|
+
time.strftime("%Y-%m-%d %H:%M:%S"),
|
|
70
|
+
self.frame_idx, outcome,
|
|
71
|
+
round(time.time() - self.start_time, 2),
|
|
72
|
+
self.laps_completed,
|
|
73
|
+
])
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Oval Circuit",
|
|
3
|
+
"width": 1280,
|
|
4
|
+
"height": 800,
|
|
5
|
+
"start_pos": [
|
|
6
|
+
1120.0,
|
|
7
|
+
400.0
|
|
8
|
+
],
|
|
9
|
+
"start_angle": 170.41642929236485,
|
|
10
|
+
"checkpoints": [
|
|
11
|
+
[
|
|
12
|
+
906.6737118494091,
|
|
13
|
+
632.8114914447126,
|
|
14
|
+
90
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
456.3119524647569,
|
|
18
|
+
658.6862691031603,
|
|
19
|
+
90
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
169.2230654064494,
|
|
23
|
+
454.625290164516,
|
|
24
|
+
90
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
300.5887450304571,
|
|
28
|
+
202.01010126776671,
|
|
29
|
+
90
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
733.6433545677415,
|
|
33
|
+
125.3801214870955,
|
|
34
|
+
90
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
"finish_line": [
|
|
38
|
+
1120.0,
|
|
39
|
+
400.0,
|
|
40
|
+
90
|
|
41
|
+
]
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Rectangle Ring",
|
|
3
|
+
"width": 1280,
|
|
4
|
+
"height": 800,
|
|
5
|
+
"start_pos": [
|
|
6
|
+
160.0,
|
|
7
|
+
140.0
|
|
8
|
+
],
|
|
9
|
+
"start_angle": -90.0,
|
|
10
|
+
"checkpoints": [
|
|
11
|
+
[
|
|
12
|
+
777.1428571428572,
|
|
13
|
+
140.0,
|
|
14
|
+
90
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
1120.0,
|
|
18
|
+
288.57142857142856,
|
|
19
|
+
90
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
1120.0,
|
|
23
|
+
622.8571428571429,
|
|
24
|
+
90
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
571.4285714285714,
|
|
28
|
+
660.0,
|
|
29
|
+
90
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
160.0,
|
|
33
|
+
548.5714285714286,
|
|
34
|
+
90
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
"finish_line": [
|
|
38
|
+
160.0,
|
|
39
|
+
140.0,
|
|
40
|
+
90
|
|
41
|
+
]
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Figure-Eight",
|
|
3
|
+
"width": 1280,
|
|
4
|
+
"height": 800,
|
|
5
|
+
"start_pos": [
|
|
6
|
+
640.0,
|
|
7
|
+
400.0
|
|
8
|
+
],
|
|
9
|
+
"start_angle": -118.3170629045318,
|
|
10
|
+
"checkpoints": [
|
|
11
|
+
[
|
|
12
|
+
1038.3716857408417,
|
|
13
|
+
508.25317547305485,
|
|
14
|
+
90
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
1038.3716857408417,
|
|
18
|
+
291.7468245269452,
|
|
19
|
+
90
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
640.0,
|
|
23
|
+
399.99999999999994,
|
|
24
|
+
90
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
241.6283142591583,
|
|
28
|
+
508.2531754730549,
|
|
29
|
+
90
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
241.62831425915823,
|
|
33
|
+
291.74682452694515,
|
|
34
|
+
90
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
"finish_line": [
|
|
38
|
+
640.0,
|
|
39
|
+
400.0,
|
|
40
|
+
90
|
|
41
|
+
]
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Serpentine Loop",
|
|
3
|
+
"width": 1280,
|
|
4
|
+
"height": 800,
|
|
5
|
+
"start_pos": [
|
|
6
|
+
970.0,
|
|
7
|
+
400.0
|
|
8
|
+
],
|
|
9
|
+
"start_angle": -135.52506030956707,
|
|
10
|
+
"checkpoints": [
|
|
11
|
+
[
|
|
12
|
+
770.3589838486225,
|
|
13
|
+
625.7883832488648,
|
|
14
|
+
90
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
509.6410161513776,
|
|
18
|
+
625.7883832488648,
|
|
19
|
+
90
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
309.99999999999983,
|
|
23
|
+
400.00000000000017,
|
|
24
|
+
90
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
440.3589838486222,
|
|
28
|
+
54.21161675113518,
|
|
29
|
+
90
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
839.6410161513777,
|
|
33
|
+
54.21161675113518,
|
|
34
|
+
90
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
"finish_line": [
|
|
38
|
+
970.0,
|
|
39
|
+
400.0,
|
|
40
|
+
90
|
|
41
|
+
]
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "L-Shape Circuit",
|
|
3
|
+
"width": 1280,
|
|
4
|
+
"height": 800,
|
|
5
|
+
"start_pos": [
|
|
6
|
+
150,
|
|
7
|
+
150
|
|
8
|
+
],
|
|
9
|
+
"start_angle": -90.0,
|
|
10
|
+
"checkpoints": [
|
|
11
|
+
[
|
|
12
|
+
900,
|
|
13
|
+
150,
|
|
14
|
+
90
|
|
15
|
+
],
|
|
16
|
+
[
|
|
17
|
+
900,
|
|
18
|
+
420,
|
|
19
|
+
90
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
1130,
|
|
23
|
+
420,
|
|
24
|
+
90
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
1130,
|
|
28
|
+
680,
|
|
29
|
+
90
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
430,
|
|
33
|
+
680,
|
|
34
|
+
90
|
|
35
|
+
]
|
|
36
|
+
],
|
|
37
|
+
"finish_line": [
|
|
38
|
+
150,
|
|
39
|
+
150,
|
|
40
|
+
90
|
|
41
|
+
]
|
|
42
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|