Skip to content

Commit

Permalink
Implement frenet to cartesian to frenet transformations
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadAmine998 committed Mar 18, 2024
1 parent a9d10d9 commit 0114dc4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions gym/f110_gym/envs/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,22 @@ def cartesian_to_frenet(self, x, y, phi):
phi: yaw angle
returns:
s: distance along the raceline
s: distance along the centerline
ey: lateral deviation
ephi: heading deviation
"""
s, ey = self.raceline.spline.calc_arclength(x, y)
phi = phi - self.raceline.spline.calc_yaw(s)
s, ey = self.centerline.spline.calc_arclength(x, y)

# Use the normal to calculate the signed lateral deviation
normal = self.centerline.spline._calc_normal(s)
x_eval = self.centerline.spline.sx.calc_position(s)
y_eval = self.centerline.spline.sy.calc_position(s)
dx = x - x_eval
dy = y - y_eval
distance_sign = np.sign(np.dot([dx, dy], normal))
ey = ey * distance_sign

phi = phi - self.centerline.spline.calc_yaw(s)

return s, ey, phi

Expand Down

0 comments on commit 0114dc4

Please sign in to comment.