Skip to content

Commit f840bec

Browse files
committed
added quadrotor
1 parent a8212c7 commit f840bec

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

test/problems/quadrotor.jl

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Quadrotor optimal control problem definition used by tests and examples.
2+
#
3+
# Returns a NamedTuple with fields:
4+
# - ocp :: the CTParser-defined optimal control problem
5+
# - obj :: reference optimal objective value (Ipopt / MadNLP, Collocation)
6+
# - name :: a short problem name
7+
# - init :: NamedTuple of components for CTSolvers.initial_guess
8+
function Quadrotor(; T=1, g=9.8, r=0.1)
9+
10+
ocp = @def begin
11+
t [0, T], time
12+
x R⁹, state
13+
u R⁴, control
14+
15+
x(0) == zeros(9)
16+
17+
(x₁)(t) == x₂(t)
18+
(x₂)(t) ==
19+
u₁(t) * cos(x₇(t)) * sin(x₈(t)) * cos(x₉(t)) + u₁(t) * sin(x₇(t)) * sin(x₉(t))
20+
(x₃)(t) == x₄(t)
21+
(x₄)(t) ==
22+
u₁(t) * cos(x₇(t)) * sin(x₈(t)) * sin(x₉(t)) - u₁(t) * sin(x₇(t)) * cos(x₉(t))
23+
(x₅)(t) == x₆(t)
24+
(x₆)(t) == u₁(t) * cos(x₇(t)) * cos(x₈(t)) - g
25+
(x₇)(t) == u₂(t) * cos(x₇(t)) / cos(x₈(t)) + u₃(t) * sin(x₇(t)) / cos(x₈(t))
26+
(x₈)(t) == -u₂(t) * sin(x₇(t)) + u₃(t) * cos(x₇(t))
27+
(x₉)(t) ==
28+
u₂(t) * cos(x₇(t)) * tan(x₈(t)) + u₃(t) * sin(x₇(t)) * tan(x₈(t)) + u₄(t)
29+
30+
dt1 = sin(2π * t / T)
31+
df1 = 0
32+
dt3 = 2sin(4π * t / T)
33+
df3 = 0
34+
dt5 = 2t / T
35+
df5 = 2
36+
37+
0.5(
38+
(x₁(t) - dt1)^2 +
39+
(x₃(t) - dt3)^2 +
40+
(x₅(t) - dt5)^2 +
41+
x₇(t)^2 +
42+
x₈(t)^2 +
43+
x₉(t)^2 +
44+
r * (u₁(t)^2 + u₂(t)^2 + u₃(t)^2 + u₄(t)^2),
45+
) min
46+
end
47+
48+
init = @init ocp begin
49+
x(t) := 0.1 * ones(9)
50+
u(t) := 0.1 * ones(4)
51+
end
52+
53+
return (ocp=ocp, obj=4.2679623758, name="quadrotor", init=init)
54+
end

0 commit comments

Comments
 (0)