mirror of
https://github.com/AtsushiSakai/PythonRobotics.git
synced 2026-02-11 09:16:51 -05:00
it can generate path but not correct ...
This commit is contained in:
@@ -121,76 +121,105 @@ def generate_path(q0, q1, maxc):
|
|||||||
return paths
|
return paths
|
||||||
|
|
||||||
|
|
||||||
# def generate_local_course(L: : Float64,
|
def interpolate(ind, l, m, maxc, ox, oy, oyaw, px, py, pyaw, directions):
|
||||||
# lengths: : Array{Float64},
|
print(ind, len(px), l)
|
||||||
# mode: : Array{String},
|
|
||||||
# maxc: : Float64,
|
|
||||||
# step_size: : Float64)
|
|
||||||
# npoint = trunc(Int64, L / step_size) + length(lengths) + 3
|
|
||||||
# # println(npoint, ",", L, ",", step_size, ",", L/step_size)
|
|
||||||
|
|
||||||
# px = fill(0.0, npoint)
|
if m == "S":
|
||||||
# py = fill(0.0, npoint)
|
px[ind] = ox + l / maxc * math.cos(oyaw)
|
||||||
# pyaw = fill(0.0, npoint)
|
py[ind] = oy + l / maxc * math.sin(oyaw)
|
||||||
# directions = fill(0, npoint)
|
pyaw[ind] = oyaw
|
||||||
# ind = 2
|
else: # curve
|
||||||
|
ldx = math.sin(l) / maxc
|
||||||
|
if m == "L": # left turn
|
||||||
|
ldy = (1.0 - math.cos(l)) / maxc
|
||||||
|
elif m == "R": # right turn
|
||||||
|
ldy = (1.0 - math.cos(l)) / -maxc
|
||||||
|
gdx = math.cos(-oyaw) * ldx + math.sin(-oyaw) * ldy
|
||||||
|
gdy = -math.sin(-oyaw) * ldx + math.cos(-oyaw) * ldy
|
||||||
|
px[ind] = ox + gdx
|
||||||
|
py[ind] = oy + gdy
|
||||||
|
|
||||||
# if lengths[1] > 0.0
|
if m == "L": # left turn
|
||||||
# directions[1] = 1
|
pyaw[ind] = oyaw + l
|
||||||
# else
|
elif m == "R": # right turn
|
||||||
# directions[1] = -1
|
pyaw[ind] = oyaw - l
|
||||||
# end
|
|
||||||
|
|
||||||
# if lengths[1] > 0.0
|
if l > 0.0:
|
||||||
# d = step_size
|
directions[ind] = 1
|
||||||
# else
|
else:
|
||||||
# d = -step_size
|
directions[ind] = -1
|
||||||
# end
|
|
||||||
|
|
||||||
# pd = d
|
return px, py, pyaw, directions
|
||||||
# ll = 0.0
|
|
||||||
|
|
||||||
# for (m, l, i) in zip(mode, lengths, 1: length(mode))
|
|
||||||
|
|
||||||
# if l > 0.0
|
def generate_local_course(L, lengths, mode, maxc, step_size):
|
||||||
# d = step_size
|
npoint = math.trunc(L / step_size) + len(lengths) + 4
|
||||||
# else
|
# println(npoint, ",", L, ",", step_size, ",", L/step_size)
|
||||||
# d = -step_size
|
|
||||||
# end
|
|
||||||
|
|
||||||
# # set prigin state
|
px = [0.0 for i in range(npoint)]
|
||||||
# ox, oy, oyaw = px[ind], py[ind], pyaw[ind]
|
py = [0.0 for i in range(npoint)]
|
||||||
|
pyaw = [0.0 for i in range(npoint)]
|
||||||
|
directions = [0.0 for i in range(npoint)]
|
||||||
|
ind = 1
|
||||||
|
|
||||||
# ind -= 1
|
if lengths[0] > 0.0:
|
||||||
# if i >= 2 & & (lengths[i - 1] * lengths[i]) > 0
|
directions[0] = 1
|
||||||
# pd = - d - ll
|
else:
|
||||||
# else
|
directions[0] = -1
|
||||||
# pd = d - ll
|
|
||||||
# end
|
|
||||||
|
|
||||||
# while abs(pd) <= abs(l)
|
if lengths[0] > 0.0:
|
||||||
# ind += 1
|
d = step_size
|
||||||
# px, py, pyaw, directions = interpolate(
|
else:
|
||||||
# ind, pd, m, maxc, ox, oy, oyaw, px, py, pyaw, directions)
|
d = -step_size
|
||||||
# pd += d
|
|
||||||
# end
|
|
||||||
|
|
||||||
# ll = l - pd - d # calc remain length
|
pd = d
|
||||||
|
ll = 0.0
|
||||||
|
|
||||||
# ind += 1
|
for (m, l, i) in zip(mode, lengths, range(len(mode))):
|
||||||
# px, py, pyaw, directions = interpolate(
|
if l > 0.0:
|
||||||
# ind, l, m, maxc, ox, oy, oyaw, px, py, pyaw, directions)
|
d = step_size
|
||||||
# end
|
else:
|
||||||
|
d = -step_size
|
||||||
|
|
||||||
# # remove unused data
|
# set origin state
|
||||||
# while px[end] == 0.0
|
ox, oy, oyaw = px[ind], py[ind], pyaw[ind]
|
||||||
# pop!(px)
|
|
||||||
# pop!(py)
|
|
||||||
# pop!(pyaw)
|
|
||||||
# pop!(directions)
|
|
||||||
# end
|
|
||||||
|
|
||||||
# return px, py, pyaw, directions
|
ind -= 1
|
||||||
|
if i >= 1 and (lengths[i - 1] * lengths[i]) > 0:
|
||||||
|
pd = - d - ll
|
||||||
|
else:
|
||||||
|
pd = d - ll
|
||||||
|
|
||||||
|
while abs(pd) <= abs(l):
|
||||||
|
ind += 1
|
||||||
|
px, py, pyaw, directions = interpolate(
|
||||||
|
ind, pd, m, maxc, ox, oy, oyaw, px, py, pyaw, directions)
|
||||||
|
pd += d
|
||||||
|
|
||||||
|
ll = l - pd - d # calc remain length
|
||||||
|
|
||||||
|
ind += 1
|
||||||
|
px, py, pyaw, directions = interpolate(
|
||||||
|
ind, l, m, maxc, ox, oy, oyaw, px, py, pyaw, directions)
|
||||||
|
|
||||||
|
# remove unused data
|
||||||
|
while px[-1] == 0.0:
|
||||||
|
px.pop()
|
||||||
|
py.pop()
|
||||||
|
pyaw.pop()
|
||||||
|
directions.pop()
|
||||||
|
|
||||||
|
return px, py, pyaw, directions
|
||||||
|
|
||||||
|
|
||||||
|
def pi_2_pi(angle):
|
||||||
|
while(angle > math.pi):
|
||||||
|
angle = angle - 2.0 * math.pi
|
||||||
|
|
||||||
|
while(angle < -math.pi):
|
||||||
|
angle = angle + 2.0 * math.pi
|
||||||
|
|
||||||
|
return angle
|
||||||
|
|
||||||
|
|
||||||
def calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size):
|
def calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size):
|
||||||
@@ -199,17 +228,20 @@ def calc_paths(sx, sy, syaw, gx, gy, gyaw, maxc, step_size):
|
|||||||
|
|
||||||
paths = generate_path(q0, q1, maxc)
|
paths = generate_path(q0, q1, maxc)
|
||||||
for path in paths:
|
for path in paths:
|
||||||
# x, y, yaw, directions = generate_local_course(
|
x, y, yaw, directions = generate_local_course(
|
||||||
# path.L, path.lengths, path.ctypes, maxc, step_size * maxc)
|
path.L, path.lengths, path.ctypes, maxc, step_size * maxc)
|
||||||
pass
|
|
||||||
|
|
||||||
# # convert global coordinate
|
# convert global coordinate
|
||||||
# path.x = [cos(-q0[3]) * ix + sin(-q0[3]) * iy + q0[1] for (ix, iy) in zip(x, y)]
|
path.x = [math.cos(-q0[2]) * ix + math.sin(-q0[2])
|
||||||
# path.y = [-sin(-q0[3]) * ix + cos(-q0[3]) * iy + q0[2] for (ix, iy) in zip(x, y)]
|
* iy + q0[0] for (ix, iy) in zip(x, y)]
|
||||||
# path.yaw = common_func.pi_2_pi.([iyaw + q0[3] for iyaw in yaw])
|
path.y = [-math.sin(-q0[2]) * ix + math.cos(-q0[2])
|
||||||
# path.directions = directions
|
* iy + q0[1] for (ix, iy) in zip(x, y)]
|
||||||
# path.lengths = [l/maxc for l in path.lengths]
|
path.yaw = [pi_2_pi(iyaw + q0[2]) for iyaw in yaw]
|
||||||
# path.L = path.L/maxc
|
path.directions = directions
|
||||||
|
path.lengths = [l / maxc for l in path.lengths]
|
||||||
|
path.L = path.L / maxc
|
||||||
|
|
||||||
|
# print(paths)
|
||||||
|
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user