-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathmain.jl
110 lines (92 loc) · 2.72 KB
/
main.jl
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
# Main function for Hybrid A* Trailer
#
# Author: Atsushi Sakai(@Atsushi_twi)
#
using PyPlot
include("./lib/trailer_hybrid_a_star.jl")
function main()
println(PROGRAM_FILE," start!!")
# initial state
sx = 14.0 # [m]
sy = 10.0 # [m]
syaw0 = deg2rad(00.0)
syaw1 = deg2rad(00.0)
# goal state
gx = 0.0 # [m]
gy = 0.0 # [m]
gyaw0 = deg2rad(90.0)
gyaw1 = deg2rad(90.0)
# set obstacles
ox = Float64[]
oy = Float64[]
for i in -25:25
push!(ox, Float64(i))
push!(oy, 15.0)
end
for i in -25:-4
push!(ox, Float64(i))
push!(oy, 4.0)
end
for i in -15:4
push!(ox, -4.0)
push!(oy, Float64(i))
end
for i in -15:4
push!(ox, 4.0)
push!(oy, Float64(i))
end
for i in 4:25
push!(ox, Float64(i))
push!(oy, 4.0)
end
for i in -4:4
push!(ox, Float64(i))
push!(oy, -15.0)
end
oox = ox[:]
ooy = oy[:]
# path generation
@time paths = trailer_hybrid_a_star.calc_hybrid_astar_path(sx, sy, syaw0, syaw1, gx, gy, gyaw0, gyaw1, ox, oy,
trailer_hybrid_a_star.XY_GRID_RESOLUTION,
trailer_hybrid_a_star.YAW_GRID_RESOLUTION,
trailer_hybrid_a_star.N_PATHS_NEEDED)
# ====Animation=====
show_animation(paths, oox, ooy, sx, sy, syaw0, syaw1, gx, gy, gyaw0, gyaw1)
println(PROGRAM_FILE," Done!!")
end
function show_animation(paths, oox, ooy, sx, sy, syaw0, syaw1, gx, gy, gyaw0, gyaw1)
plot(oox, ooy, ".k")
trailer_hybrid_a_star.trailerlib.plot_trailer(sx, sy, syaw0, syaw1, 0.0)
trailer_hybrid_a_star.trailerlib.plot_trailer(gx, gy, gyaw0, gyaw1, 0.0)
for i in 1:length(paths)
x = paths[i].x
y = paths[i].y
yaw = paths[i].yaw
yaw1 = paths[i].yaw1
direction = paths[i].direction
steer = 0.0
for ii in 1:length(x)
cla()
plot(oox, ooy, ".k")
plot(x, y, "-r", label="Hybrid A* path")
if ii < length(x)-1
k = (yaw[ii+1] - yaw[ii])/trailer_hybrid_a_star.MOTION_RESOLUTION
if !direction[ii]
k *= -1
end
steer = atan2(trailer_hybrid_a_star.WB*k, 1.0)
else
steer = 0.0
end
trailer_hybrid_a_star.trailerlib.plot_trailer.(x[ii], y[ii], yaw[ii], yaw1[ii], steer)
grid(true)
axis("equal")
pause(0.0001)
end
end
end
if length(PROGRAM_FILE)!=0 &&
contains(@__FILE__, PROGRAM_FILE)
main()
end