Skip to content

Commit

Permalink
Merge branch 'dev-qtgraph-rendering' into dev-model-scale
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadAmine998 committed Oct 1, 2024
2 parents 78e394e + f2dcf44 commit 9f022c2
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ permissions:

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
env:
QT_QPA_PLATFORM: offscreen

steps:
- name: Update apt
run: sudo apt update

- name: Install openGL
run: sudo apt install freeglut3-dev
run: sudo apt install -y freeglut3-dev libglib2.0-0 libsm6 libxrender1 libxext6 libxkbcommon-x11-0 libdbus-1-dev

- uses: actions/checkout@v2

Expand Down
2 changes: 1 addition & 1 deletion docs/customized_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ You can change the default paramters (identified on concrete floor with the defa
'v_max': 20.0,
'width': 0.31,
'length': 0.58}
env = gym.make('f110_gym:f110-v0', params=params_dict)
env = gym.make('f110_gym:f110-v0', config={'params': params_dict})
2. Or you could update the parameters of a specific vehicle in the list of vehicles (or all vehicles):

Expand Down
16 changes: 15 additions & 1 deletion f1tenth_gym/envs/observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,13 @@ def observe(self):
lap_count = self.env.lap_counts[i]

x, y, theta = agent.state[xi], agent.state[yi], agent.state[yawi]
vx, vy = agent.state[vxi], 0.0
vlong = agent.state[vxi]
delta = agent.state[deltai]
beta = (
0.0 if len(agent.state) < 7 else agent.state[slipi]
) # set 0.0 when KST Model
vx = vlong * np.cos(beta)
vy = vlong * np.sin(beta)
angvel = (
0.0 if len(agent.state) < 7 else agent.state[yaw_ratei]
) # set 0.0 when KST Model
Expand Down Expand Up @@ -284,5 +286,17 @@ def observation_factory(env, type: str | None, **kwargs) -> Observation:
"beta",
]
return FeaturesObservation(env, features=features)
elif type == "frenet_dynamic_state":
features = [
"pose_x",
"pose_y",
"delta",
"linear_vel_x",
"linear_vel_y",
"pose_theta",
"ang_vel_z",
"beta",
]
return FeaturesObservation(env, features=features)
else:
raise ValueError(f"Invalid observation type {type}.")
50 changes: 25 additions & 25 deletions f1tenth_gym/envs/rendering/rendering_pyqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(
self.render_fps = render_fps

# create the canvas
self.app = QtWidgets.QApplication([])
self.app = QtWidgets.QApplication.instance() or QtWidgets.QApplication([])
self.window = pg.GraphicsLayoutWidget()
self.window.setWindowTitle("F1Tenth Gym")
self.window.setGeometry(0, 0, self.render_spec.window_size, self.render_spec.window_size)
Expand Down Expand Up @@ -272,34 +272,33 @@ def render(self) -> Optional[np.ndarray]:
Optional[np.ndarray]
if render_mode is "rgb_array", returns the rendered frame as an array
"""
if self.draw_flag:

# draw cars
for i in range(len(self.agent_ids)):
self.cars[i].render()
# draw cars
for i in range(len(self.agent_ids)):
self.cars[i].render()

# call callbacks
for callback_fn in self.callbacks:
callback_fn(self)
# call callbacks
for callback_fn in self.callbacks:
callback_fn(self)

if self.follow_agent_flag:
ego_x, ego_y = self.cars[self.agent_to_follow].pose[:2]
self.canvas.setXRange(ego_x - 10, ego_x + 10)
self.canvas.setYRange(ego_y - 10, ego_y + 10)
else:
self.canvas.autoRange()
agent_to_follow_id = (
self.agent_ids[self.agent_to_follow]
if self.agent_to_follow is not None
else None
)
self.bottom_info_renderer.render(
text=f"Focus on: {agent_to_follow_id}"
)
if self.follow_agent_flag:
ego_x, ego_y = self.cars[self.agent_to_follow].pose[:2]
self.canvas.setXRange(ego_x - 10, ego_x + 10)
self.canvas.setYRange(ego_y - 10, ego_y + 10)
else:
self.canvas.autoRange()

agent_to_follow_id = (
self.agent_ids[self.agent_to_follow]
if self.agent_to_follow is not None
else None
)
self.bottom_info_renderer.render(
text=f"Focus on: {agent_to_follow_id}"
)

if self.render_spec.show_info:
self.top_info_renderer.render(text=INSTRUCTION_TEXT)

self.time_renderer.render(text=f"{self.sim_time:.2f}")
self.clock.update()
self.app.processEvents()
Expand All @@ -318,7 +317,7 @@ def render(self) -> Optional[np.ndarray]:
ptr.setsize(height * width * 4)
frame = np.array(ptr).reshape(height, width, 4) # Copies the data

return frame
return frame[:, :, :3] # remove alpha channel

def render_points(
self,
Expand Down Expand Up @@ -400,3 +399,4 @@ def close(self) -> None:
Close the rendering environment.
"""
self.app.exit()

2 changes: 1 addition & 1 deletion f1tenth_gym/envs/track/cubic_spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def calc_arclength_inaccurate(self, x: float, y: float) -> tuple[float, float]:
+ t * (self.s[min_dist_segment + 1] - self.s[min_dist_segment])
)

return s, 0.0
return s, ey

def _calc_tangent(self, s: float) -> np.ndarray:
"""
Expand Down
2 changes: 1 addition & 1 deletion f1tenth_gym/envs/track/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def cartesian_to_frenet(self, x, y, phi, s_guess=0):
ey: lateral deviation
ephi: heading deviation
"""
s, ey = self.centerline.spline.calc_arclength(x, y, s_guess)
s, ey = self.centerline.spline.calc_arclength_inaccurate(x, y)
if s > self.centerline.spline.s[-1]:
# Wrap around
s = s - self.centerline.spline.s[-1]
Expand Down

0 comments on commit 9f022c2

Please sign in to comment.