Skip to content

Commit

Permalink
Revert "linting"
Browse files Browse the repository at this point in the history
This reverts commit ff7a3a1
  • Loading branch information
luigiberducci committed Feb 1, 2024
1 parent 0f58eda commit 511ff02
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 66 deletions.
8 changes: 7 additions & 1 deletion examples/video_recording.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ def main():
planner = PurePursuitPlanner(track=track, wb=0.17145 + 0.15875)

poses = np.array(
[[track.raceline.xs[0], track.raceline.ys[0], track.raceline.yaws[0],]]
[
[
track.raceline.xs[0],
track.raceline.ys[0],
track.raceline.yaws[0],
]
]
)

obs, info = env.reset(options={"poses": poses})
Expand Down
2 changes: 1 addition & 1 deletion examples/waypoint_follow.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def get_actuation(pose_theta, lookahead_point, position, lookahead_distance, whe
speed = lookahead_point[2]
if np.abs(waypoint_y) < 1e-6:
return speed, 0.0
radius = 1 / (2.0 * waypoint_y / lookahead_distance ** 2)
radius = 1 / (2.0 * waypoint_y / lookahead_distance**2)
steering_angle = np.arctan(wheelbase / radius)
return speed, steering_angle

Expand Down
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",
)
64 changes: 28 additions & 36 deletions gym/f110_gym/envs/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def from_string(action: str):
return SpeedAction
else:
raise ValueError(f"Unknown action type {action}")



class LongitudinalAction:
def __init__(self) -> None:
self._type = None
Expand All @@ -40,10 +39,7 @@ def type(self) -> str:

@property
def space(self) -> gym.Space:
return gym.spaces.Box(
low=self.lower_limit, high=self.upper_limit, dtype=np.float32
)

return gym.spaces.Box(low=self.lower_limit, high=self.upper_limit, dtype=np.float32)

class AcclAction(LongitudinalAction):
def __init__(self, params: Dict) -> None:
Expand All @@ -54,7 +50,6 @@ def __init__(self, params: Dict) -> None:
def act(self, action: Tuple[float, float], state, params) -> float:
return action


class SpeedAction(LongitudinalAction):
def __init__(self, params: Dict) -> None:
super().__init__()
Expand All @@ -65,12 +60,15 @@ def act(
self, action: Tuple[float, float], state: np.ndarray, params: Dict
) -> float:
accl = pid_accl(
action, state[3], params["a_max"], params["v_max"], params["v_min"],
action,
state[3],
params["a_max"],
params["v_max"],
params["v_min"],
)

return accl


class SteerAction:
def __init__(self) -> None:
self._type = None
Expand All @@ -85,13 +83,10 @@ def act(self, steer_action: Any, **kwargs) -> float:
@property
def type(self) -> str:
return self._type

@property
def space(self) -> gym.Space:
return gym.spaces.Box(
low=self.lower_limit, high=self.upper_limit, dtype=np.float32
)

return gym.spaces.Box(low=self.lower_limit, high=self.upper_limit, dtype=np.float32)

class SteeringAngleAction(SteerAction):
def __init__(self, params: Dict) -> None:
Expand All @@ -101,11 +96,14 @@ def __init__(self, params: Dict) -> None:

def act(
self, action: Tuple[float, float], state: np.ndarray, params: Dict
) -> float:
sv = pid_steer(action, state[2], params["sv_max"],)
) -> float:
sv = pid_steer(
action,
state[2],
params["sv_max"],
)
return sv



class SteeringSpeedAction(SteerAction):
def __init__(self, params: Dict) -> None:
super().__init__()
Expand All @@ -114,10 +112,9 @@ def __init__(self, params: Dict) -> None:

def act(
self, action: Tuple[float, float], state: np.ndarray, params: Dict
) -> float:
) -> float:
return action


class SteerActionEnum(Enum):
Steering_Angle = 1
Steering_Speed = 2
Expand All @@ -131,12 +128,11 @@ def from_string(action: str):
else:
raise ValueError(f"Unknown action type {action}")


class CarAction:
def __init__(self, control_mode: list[str, str], params: Dict) -> None:
def __init__(self, control_mode : list[str, str], params: Dict) -> None:
long_act_type_fn = None
steer_act_type_fn = None
if type(control_mode) == str: # only one control mode specified
if type(control_mode) == str: # only one control mode specified
try:
long_act_type_fn = LongitudinalActionEnum.from_string(control_mode)
except ValueError:
Expand All @@ -146,24 +142,24 @@ def __init__(self, control_mode: list[str, str], params: Dict) -> None:
raise ValueError(f"Unknown control mode {control_mode}")
if control_mode == "steering_speed":
warnings.warn(
f"Only one control mode specified, using {control_mode} for steering and defaulting to acceleration for longitudinal control"
f'Only one control mode specified, using {control_mode} for steering and defaulting to acceleration for longitudinal control'
)
long_act_type_fn = LongitudinalActionEnum.from_string("accl")
else:
warnings.warn(
f"Only one control mode specified, using {control_mode} for steering and defaulting to speed for longitudinal control"
f'Only one control mode specified, using {control_mode} for steering and defaulting to speed for longitudinal control'
)
long_act_type_fn = LongitudinalActionEnum.from_string("speed")

else:
if control_mode == "accl":
warnings.warn(
f"Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering speed for steering"
f'Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering speed for steering'
)
steer_act_type_fn = SteerActionEnum.from_string("steering_speed")
else:
warnings.warn(
f"Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering angle for steering"
f'Only one control mode specified, using {control_mode} for longitudinal control and defaulting to steering angle for steering'
)
steer_act_type_fn = SteerActionEnum.from_string("steering_angle")

Expand All @@ -172,9 +168,9 @@ def __init__(self, control_mode: list[str, str], params: Dict) -> None:
steer_act_type_fn = SteerActionEnum.from_string(control_mode[1])
else:
raise ValueError(f"Unknown control mode {control_mode}")

self._longitudinal_action: LongitudinalAction = long_act_type_fn(params)
self._steer_action: SteerAction = steer_act_type_fn(params)
self._longitudinal_action : LongitudinalAction = long_act_type_fn(params)
self._steer_action : SteerAction = steer_act_type_fn(params)

@abstractmethod
def act(self, action: Any, **kwargs) -> Tuple[float, float]:
Expand All @@ -188,12 +184,8 @@ def type(self) -> Tuple[str, str]:

@property
def space(self) -> gym.Space:
low = np.array(
[self._steer_action.lower_limit, self._longitudinal_action.lower_limit]
).astype(np.float32)
high = np.array(
[self._steer_action.upper_limit, self._longitudinal_action.upper_limit]
).astype(np.float32)
low = np.array([self._steer_action.lower_limit, self._longitudinal_action.lower_limit]).astype(np.float32)
high = np.array([self._steer_action.upper_limit, self._longitudinal_action.upper_limit]).astype(np.float32)

return gym.spaces.Box(low=low, high=high, shape=(2,), dtype=np.float32)

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
9 changes: 4 additions & 5 deletions gym/f110_gym/envs/f110_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
# gym imports
import gymnasium as gym

from f110_gym.envs.action import CarAction, from_single_to_multi_action_space
from f110_gym.envs.action import (CarAction,
from_single_to_multi_action_space)
from f110_gym.envs.integrator import IntegratorType
from f110_gym.envs.rendering import make_renderer

Expand Down Expand Up @@ -239,9 +240,7 @@ def configure(self, config: dict) -> None:

if hasattr(self, "action_space"):
# if some parameters changed, recompute action space
self.action_type = CarAction(
self.config["control_input"], params=self.params
)
self.action_type = CarAction(self.config["control_input"], params=self.params)
self.action_space = from_single_to_multi_action_space(
self.action_type.space, self.num_agents
)
Expand Down Expand Up @@ -273,7 +272,7 @@ def _check_done(self):
temp_y[idx2] = -right_t - temp_y[idx2]
temp_y[np.invert(np.logical_or(idx1, idx2))] = 0

dist2 = delta_pt[0, :] ** 2 + temp_y ** 2
dist2 = delta_pt[0, :] ** 2 + temp_y**2
closes = dist2 <= 0.1
for i in range(self.num_agents):
if closes[i] and not self.near_starts[i]:
Expand Down
4 changes: 2 additions & 2 deletions gym/f110_gym/envs/f110_env_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def _check_done(self):
temp_y[idx2] = -right_t - temp_y[idx2]
temp_y[np.invert(np.logical_or(idx1, idx2))] = 0

dist2 = delta_pt[0, :] ** 2 + temp_y ** 2
dist2 = delta_pt[0, :] ** 2 + temp_y**2
closes = dist2 <= 0.1
for i in range(self.num_agents):
if closes[i] and not self.near_starts[i]:
Expand Down Expand Up @@ -291,7 +291,7 @@ def _check_done(self):
temp_y = -right_t - delta_pt[1]
else:
temp_y = 0
dist2 = delta_pt[0] ** 2 + temp_y ** 2
dist2 = delta_pt[0] ** 2 + temp_y**2
close = dist2 <= 0.1
# close = dist_to_start <= self.start_thresh
if close and not self.near_start:
Expand Down
16 changes: 3 additions & 13 deletions gym/f110_gym/envs/reset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ def make_reset_fn(type: str | None, track: Track, num_agents: int, **kwargs) ->
refline = {"cl": track.centerline, "rl": track.raceline}[refline_token]
reset_fn = {"grid": GridResetFn, "random": AllTrackResetFn}[reset_token]
shuffle = {"static": False, "random": True}[shuffle_token]
options = {"cl": {"move_laterally": True}, "rl": {"move_laterally": False}}[
refline_token
]
options = {"cl": {"move_laterally": True}, "rl": {"move_laterally": False}}[refline_token]

except Exception as ex:
raise ValueError(
f"Invalid reset function type: {type}. Expected format: <refline>_<resetfn>_<shuffle>"
) from ex
raise ValueError(f"Invalid reset function type: {type}. Expected format: <refline>_<resetfn>_<shuffle>") from ex

return reset_fn(
reference_line=refline,
num_agents=num_agents,
shuffle=shuffle,
**options,
**kwargs,
)
return reset_fn(reference_line=refline, num_agents=num_agents, shuffle=shuffle, **options, **kwargs)
Empty file.
6 changes: 5 additions & 1 deletion tests/legacy_scan_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

env = gym.make(
"f110_gym:f110-v0",
config={"map": map_name, "num_agents": 1, "params": params,},
config={
"map": map_name,
"num_agents": 1,
"params": params,
},
)

scan = np.empty((num_test, 1080))
Expand Down
5 changes: 4 additions & 1 deletion tests/test_f110_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def _make_env(self, config={}):
}
conf = deep_update(conf, config)

env = gym.make("f110_gym:f110-v0", config=conf,)
env = gym.make(
"f110_gym:f110-v0",
config=conf,
)
return env

def test_gymnasium_api(self):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def _make_env(config={}, render_mode=None) -> F110Env:
}
config = deep_update(base_config, config)

env = gym.make("f110_gym:f110-v0", config=config, render_mode=render_mode,)
env = gym.make(
"f110_gym:f110-v0",
config=config,
render_mode=render_mode,
)

return env

Expand Down
3 changes: 2 additions & 1 deletion tests/test_scan_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _test_map_scan(self, map_name: str, debug=False):
test_pose = self.test_poses[i]
new_scan[i, :] = scan_sim.scan(pose=test_pose, rng=scan_rng)
diff = self.sample_scans[map_name] - new_scan
mse = np.mean(diff ** 2)
mse = np.mean(diff**2)

if debug:
# plotting
Expand All @@ -69,6 +69,7 @@ def _test_map_scan(self, map_name: str, debug=False):

self.assertLess(mse, 2.0)


def test_map_spielberg(self, debug=False):
self._test_map_scan("Spielberg", debug=debug)

Expand Down

0 comments on commit 511ff02

Please sign in to comment.