Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamics Updates #100

Merged
merged 10 commits into from
Dec 26, 2023
3 changes: 2 additions & 1 deletion gym/f110_gym/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gymnasium as gym

gym.register(
id="f110-v0", entry_point="f110_gym.envs:F110Env",
id="f110-v0",
entry_point="f110_gym.envs:F110Env",
)
5 changes: 3 additions & 2 deletions gym/f110_gym/envs/base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
Replacement of the old RaceCar, Simulator classes in C++
Author: Hongrui Zheng
"""
from __future__ import annotations
import numpy as np
from f110_gym.envs.dynamic_models import DynamicModel
from f110_gym.envs.action import CarAction
Expand Down Expand Up @@ -407,7 +408,7 @@ def __init__(
self.params = params
self.agent_poses = np.empty((self.num_agents, 3))
self.agent_steerings = np.empty((self.num_agents,))
self.agents = []
self.agents: list[RaceCar] = []
self.collisions = np.zeros((self.num_agents,))
self.collision_idx = -1 * np.ones((self.num_agents,))
self.model = model
Expand Down Expand Up @@ -512,7 +513,7 @@ def step(self, control_inputs):
for i, agent in enumerate(self.agents):
# update agent's information on other agents
opp_poses = np.concatenate(
(self.agent_poses[0:i, :], self.agent_poses[i + 1:, :]), axis=0
(self.agent_poses[0:i, :], self.agent_poses[i + 1 :, :]), axis=0
)
agent.update_opp_poses(opp_poses)

Expand Down
6 changes: 3 additions & 3 deletions gym/f110_gym/envs/cubic_spline.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def calc_position(self, x):
i = self.__search_index(x)
dx = x - self.x[i]
position = (
self.a[i] + self.b[i] * dx + self.c[i] * dx ** 2.0 + self.d[i] * dx ** 3.0
self.a[i] + self.b[i] * dx + self.c[i] * dx**2.0 + self.d[i] * dx**3.0
)

return position
Expand All @@ -86,7 +86,7 @@ def calc_first_derivative(self, x):

i = self.__search_index(x)
dx = x - self.x[i]
dy = self.b[i] + 2.0 * self.c[i] * dx + 3.0 * self.d[i] * dx ** 2.0
dy = self.b[i] + 2.0 * self.c[i] * dx + 3.0 * self.d[i] * dx**2.0
return dy

def calc_second_derivative(self, x):
Expand Down Expand Up @@ -205,7 +205,7 @@ def calc_curvature(self, s):
ddx = self.sx.calc_second_derivative(s)
dy = self.sy.calc_first_derivative(s)
ddy = self.sy.calc_second_derivative(s)
k = (ddy * dx - ddx * dy) / ((dx ** 2 + dy ** 2) ** (3 / 2))
k = (ddy * dx - ddx * dy) / ((dx**2 + dy**2) ** (3 / 2))
return k

def calc_yaw(self, s):
Expand Down
Loading
Loading