-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnpy_fn.py
More file actions
31 lines (23 loc) · 1.07 KB
/
npy_fn.py
File metadata and controls
31 lines (23 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
class Mppi_npy():
def __init__(self,ref_path,T):
self.ref_path = ref_path
# ref_path info
self.prev_waypoints_idx = 0
self.T = T
def get_nearest_waypoint(self, x, y):
"""search the closest waypoint to the vehicle on the reference path"""
SEARCH_IDX_LEN = 200 # [points] forward search range
prev_idx = self.prev_waypoints_idx
dx = x - self.ref_path[prev_idx:(prev_idx + SEARCH_IDX_LEN), 0]
dy = y - self.ref_path[prev_idx:(prev_idx + SEARCH_IDX_LEN), 1]
d = dx**2 + dy**2
nearest_idx = np.argmin(d) + prev_idx
# get reference values of the nearest waypoint
ref_x = self.ref_path[nearest_idx:(nearest_idx + self.T),0]
ref_y = self.ref_path[nearest_idx:(nearest_idx + self.T),1]
ref_yaw = self.ref_path[nearest_idx:(nearest_idx + self.T),2]
ref_v = self.ref_path[nearest_idx:(nearest_idx + self.T),3]
# update nearest waypoint index
self.prev_waypoints_idx = nearest_idx
return ref_x, ref_y, ref_yaw, ref_v