-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutil.py
41 lines (30 loc) · 949 Bytes
/
util.py
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
32
33
34
35
36
37
38
39
40
41
import os
import math
import numpy as np
import pandas as pd
table_path = os.path.dirname(os.path.abspath(__file__)) + "/lookuptable.csv"
def search_nearest_one_from_lookuptable(tx, ty, tyaw, lookup_table):
mind = float("inf")
minid = -1
for (i, table) in enumerate(lookup_table):
dx = tx - table[0]
dy = ty - table[1]
dyaw = tyaw - table[2]
d = math.sqrt(dx ** 2 + dy ** 2 + dyaw ** 2)
if d <= mind:
minid = i
mind = d
return lookup_table[minid]
def get_lookup_table():
data = pd.read_csv(table_path)
return np.array(data)
def calc_spline_course(sp, ds=0.1):
s = list(np.arange(0, sp.s[-1], ds))
rx, ry, ryaw, rk = [], [], [], []
for i_s in s:
ix, iy = sp.calc_position(i_s)
rx.append(ix)
ry.append(iy)
ryaw.append(sp.calc_yaw(i_s))
rk.append(sp.calc_curvature(i_s))
return rx, ry, ryaw, rk, s