@@ -121,76 +121,105 @@ def generate_path(q0, q1, maxc):
121121 return paths
122122
123123
124- # def generate_local_course(L: : Float64,
125- # lengths: : Array{Float64},
126- # mode: : Array{String},
127- # maxc: : Float64,
128- # step_size: : Float64)
129- # npoint = trunc(Int64, L / step_size) + length(lengths) + 3
130- # # println(npoint, ",", L, ",", step_size, ",", L/step_size)
131-
132- # px = fill(0.0, npoint)
133- # py = fill(0.0, npoint)
134- # pyaw = fill(0.0, npoint)
135- # directions = fill(0, npoint)
136- # ind = 2
137-
138- # if lengths[1] > 0.0
139- # directions[1] = 1
140- # else
141- # directions[1] = -1
142- # end
143-
144- # if lengths[1] > 0.0
145- # d = step_size
146- # else
147- # d = -step_size
148- # end
149-
150- # pd = d
151- # ll = 0.0
152-
153- # for (m, l, i) in zip(mode, lengths, 1: length(mode))
154-
155- # if l > 0.0
156- # d = step_size
157- # else
158- # d = -step_size
159- # end
160-
161- # # set prigin state
162- # ox, oy, oyaw = px[ind], py[ind], pyaw[ind]
163-
164- # ind -= 1
165- # if i >= 2 & & (lengths[i - 1] * lengths[i]) > 0
166- # pd = - d - ll
167- # else
168- # pd = d - ll
169- # end
170-
171- # while abs(pd) <= abs(l)
172- # ind += 1
173- # px, py, pyaw, directions = interpolate(
174- # ind, pd, m, maxc, ox, oy, oyaw, px, py, pyaw, directions)
175- # pd += d
176- # end
177-
178- # ll = l - pd - d # calc remain length
179-
180- # ind += 1
181- # px, py, pyaw, directions = interpolate(
182- # ind, l, m, maxc, ox, oy, oyaw, px, py, pyaw, directions)
183- # end
184-
185- # # remove unused data
186- # while px[end] == 0.0
187- # pop!(px)
188- # pop!(py)
189- # pop!(pyaw)
190- # pop!(directions)
191- # end
192-
193- # return px, py, pyaw, directions
124+ def interpolate (ind , l , m , maxc , ox , oy , oyaw , px , py , pyaw , directions ):
125+ print (ind , len (px ), l )
126+
127+ if m == "S" :
128+ px [ind ] = ox + l / maxc * math .cos (oyaw )
129+ py [ind ] = oy + l / maxc * math .sin (oyaw )
130+ pyaw [ind ] = oyaw
131+ else : # curve
132+ ldx = math .sin (l ) / maxc
133+ if m == "L" : # left turn
134+ ldy = (1.0 - math .cos (l )) / maxc
135+ elif m == "R" : # right turn
136+ ldy = (1.0 - math .cos (l )) / - maxc
137+ gdx = math .cos (- oyaw ) * ldx + math .sin (- oyaw ) * ldy
138+ gdy = - math .sin (- oyaw ) * ldx + math .cos (- oyaw ) * ldy
139+ px [ind ] = ox + gdx
140+ py [ind ] = oy + gdy
141+
142+ if m == "L" : # left turn
143+ pyaw [ind ] = oyaw + l
144+ elif m == "R" : # right turn
145+ pyaw [ind ] = oyaw - l
146+
147+ if l > 0.0 :
148+ directions [ind ] = 1
149+ else :
150+ directions [ind ] = - 1
151+
152+ return px , py , pyaw , directions
153+
154+
155+ def generate_local_course (L , lengths , mode , maxc , step_size ):
156+ npoint = math .trunc (L / step_size ) + len (lengths ) + 4
157+ # println(npoint, ",", L, ",", step_size, ",", L/step_size)
158+
159+ px = [0.0 for i in range (npoint )]
160+ py = [0.0 for i in range (npoint )]
161+ pyaw = [0.0 for i in range (npoint )]
162+ directions = [0.0 for i in range (npoint )]
163+ ind = 1
164+
165+ if lengths [0 ] > 0.0 :
166+ directions [0 ] = 1
167+ else :
168+ directions [0 ] = - 1
169+
170+ if lengths [0 ] > 0.0 :
171+ d = step_size
172+ else :
173+ d = - step_size
174+
175+ pd = d
176+ ll = 0.0
177+
178+ for (m , l , i ) in zip (mode , lengths , range (len (mode ))):
179+ if l > 0.0 :
180+ d = step_size
181+ else :
182+ d = - step_size
183+
184+ # set origin state
185+ ox , oy , oyaw = px [ind ], py [ind ], pyaw [ind ]
186+
187+ ind -= 1
188+ if i >= 1 and (lengths [i - 1 ] * lengths [i ]) > 0 :
189+ pd = - d - ll
190+ else :
191+ pd = d - ll
192+
193+ while abs (pd ) <= abs (l ):
194+ ind += 1
195+ px , py , pyaw , directions = interpolate (
196+ ind , pd , m , maxc , ox , oy , oyaw , px , py , pyaw , directions )
197+ pd += d
198+
199+ ll = l - pd - d # calc remain length
200+
201+ ind += 1
202+ px , py , pyaw , directions = interpolate (
203+ ind , l , m , maxc , ox , oy , oyaw , px , py , pyaw , directions )
204+
205+ # remove unused data
206+ while px [- 1 ] == 0.0 :
207+ px .pop ()
208+ py .pop ()
209+ pyaw .pop ()
210+ directions .pop ()
211+
212+ return px , py , pyaw , directions
213+
214+
215+ def pi_2_pi (angle ):
216+ while (angle > math .pi ):
217+ angle = angle - 2.0 * math .pi
218+
219+ while (angle < - math .pi ):
220+ angle = angle + 2.0 * math .pi
221+
222+ return angle
194223
195224
196225def 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):
199228
200229 paths = generate_path (q0 , q1 , maxc )
201230 for path in paths :
202- # x, y, yaw, directions = generate_local_course(
203- # path.L, path.lengths, path.ctypes, maxc, step_size * maxc)
204- pass
205-
206- # # convert global coordinate
207- # path.x = [cos(-q0[3]) * ix + sin(-q0[3]) * iy + q0[1] for (ix, iy) in zip(x, y)]
208- # path.y = [-sin(-q0[3]) * ix + cos(-q0[3]) * iy + q0[2] for (ix, iy) in zip(x, y)]
209- # path.yaw = common_func.pi_2_pi.([iyaw + q0[3] for iyaw in yaw])
210- # path.directions = directions
211- # path.lengths = [l/maxc for l in path.lengths]
212- # path.L = path.L/maxc
231+ x , y , yaw , directions = generate_local_course (
232+ path .L , path .lengths , path .ctypes , maxc , step_size * maxc )
233+
234+ # convert global coordinate
235+ path .x = [math .cos (- q0 [2 ]) * ix + math .sin (- q0 [2 ])
236+ * iy + q0 [0 ] for (ix , iy ) in zip (x , y )]
237+ path .y = [- math .sin (- q0 [2 ]) * ix + math .cos (- q0 [2 ])
238+ * iy + q0 [1 ] for (ix , iy ) in zip (x , y )]
239+ path .yaw = [pi_2_pi (iyaw + q0 [2 ]) for iyaw in yaw ]
240+ path .directions = directions
241+ path .lengths = [l / maxc for l in path .lengths ]
242+ path .L = path .L / maxc
243+
244+ # print(paths)
213245
214246 return paths
215247
0 commit comments