-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiLQGames-bicycle-dynamics.jl
73 lines (66 loc) · 2.32 KB
/
iLQGames-bicycle-dynamics.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
using Test
using BenchmarkTools
using Infiltrator
using iLQGames:
iLQGames,
iLQSolver,
GeneralGame,
Unicycle4D,
NPlayerUnicycleCost,
AffineStrategy,
SystemTrajectory,
dynamics,
n_states,
n_controls,
horizon,
player_costs,
quadraticize,
_quadraticize_ad,
generate_nplayer_navigation_game,
solve!,
ProximityCost
using iLQGames.TestUtils
using StaticArrays
using LinearAlgebra
# generate a game
T_horizon = 10.
ΔT = 0.1
"--------------------------------- Unicycle4D ---------------------------------"
x01 = @SVector [-3., 0., 0., 0.]
x02 = @SVector [0., 3., -pi/2, 0.]
x03 = @SVector [-3., 3., -pi/4, 0.]
x04 = @SVector [3.0, 0, -pi, 0]
x05 = @SVector [10.0, 0, 0, 0]
x0 = vcat(x01, x02, x03, x04, x05)
# goal states (goal position of other player with opposite orientation)
xg1 = @SVector [3., 0., 0., 0.]
xg2 = @SVector [0., -3., -pi/2, 0.]
xg3 = @SVector [3., -3., -pi/4, 0.]
xg4 = @SVector [-3., 0., 0, 0.]
xg5 = @SVector [-10.0, 0, -pi, 0]
g = generate_nplayer_navigation_game(Unicycle4D, NPlayerUnicycleCost, T_horizon,
ΔT, xg1, xg2, xg3, xg4,xg5;
proximitycost=ProximityCost([2.0, 2.0, 2.0, 2.0, 2.0],
[0., 50.0, 50.0, 50.0, 50.0]))
dyn = dynamics(g)
nx = n_states(dyn)
nu = n_controls(dyn)
pcs = player_costs(g)
h = horizon(g)
zero_op = zero(SystemTrajectory{h, ΔT, nx, nu})
quad_sanity_check(g)
# solve the lq game
solver = iLQSolver(g; state_regularization=5.0, control_regularization=5.0)
# - setup initial_strategy
steer_init(k::Int) = cos(k/h*pi) * deg2rad(0)
acc_init(k::Int) = -cos(k/h*pi)*0.1
γ_init = SizedVector{h}([AffineStrategy((@SMatrix zeros(nu, nx)),
(@SVector [steer_init(k), 0.7*acc_init(k),
steer_init(k), acc_init(k),
steer_init(k), acc_init(k),
steer_init(k), acc_init(k),
steer_init(k), acc_init(k)])) for k in 1:h])
# generate initial operating point from simulating initial strategy
# solve the game
a,b,c = solve!(copy(zero_op), copy(γ_init), g, solver, x0) #converged, current_op, current_strategy
@infiltrate