Skip to content

Commit

Permalink
Merge pull request #140 from f1tenth/fix_frenet_conversion_and_add_fr…
Browse files Browse the repository at this point in the history
…enet_obs

Fix frenet conversion and add frenet obs
  • Loading branch information
nandantumu authored Sep 17, 2024
2 parents a7ebea5 + 11ca8de commit 5a301bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
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}.")
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 @@ -276,7 +276,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 5a301bd

Please sign in to comment.