Skip to content

Commit

Permalink
Fix rendering of tires to be correct
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadAmine998 committed Sep 24, 2024
1 parent ab7a6ec commit 0348928
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions f1tenth_gym/envs/rendering/pyqt_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,13 @@ def _get_tire_vertices(pose, length, width, tire_width, tire_length, index, stee
vertices (np.ndarray, (4, 2)): corner vertices of the vehicle body
"""
pose_arr = np.array(pose)
pose_arr[2] = pose_arr[2] + steering
H = get_trmtx(pose_arr)
if index == 'fl':
# Shift back, rotate
H_shift = get_trmtx(np.array([-(length/2 - tire_length/2), -(width/2 - tire_width/2), 0]))
H_steer = get_trmtx(np.array([0, 0, steering]))
H_back = get_trmtx(np.array([length/2 - tire_length/2, width/2 - tire_width/2, 0]))
H = get_trmtx(pose_arr)
H = H.dot(H_back).dot(H_steer).dot(H_shift)
fl = H.dot(np.asarray([[length / 2], [width / 2], [0.0], [1.0]])).flatten()
fr = H.dot(np.asarray([[length / 2], [width / 2 - tire_width], [0.0], [1.0]])).flatten()
rr = H.dot(np.asarray([[length / 2 - tire_length], [width / 2 - tire_width], [0.0], [1.0]])).flatten()
Expand All @@ -187,6 +191,13 @@ def _get_tire_vertices(pose, length, width, tire_width, tire_length, index, stee
[[rl[0], rl[1]], [fl[0], fl[1]], [fr[0], fr[1]], [rr[0], rr[1]], [rl[0], rl[1]]]
)
elif index == 'fr':
# Shift back, rotate
H_shift = get_trmtx(np.array([-(length/2 - tire_length/2), -(-width/2 + tire_width/2), 0]))
H_steer = get_trmtx(np.array([0, 0, steering]))
H_back = get_trmtx(np.array([length/2 - tire_length/2, -width/2 + tire_width/2, 0]))
H = get_trmtx(pose_arr)
H = H.dot(H_back).dot(H_steer).dot(H_shift)

fl = H.dot(np.asarray([[length / 2], [-width / 2 + tire_width], [0.0], [1.0]])).flatten()
fr = H.dot(np.asarray([[length / 2], [-width / 2], [0.0], [1.0]])).flatten()
rr = H.dot(np.asarray([[length / 2 - tire_length], [-width / 2], [0.0], [1.0]])).flatten()
Expand Down

0 comments on commit 0348928

Please sign in to comment.