78 const double rho = 1.23;
80 const double Cl = 0.25;
81 const double Cd = 0.3*Cl;
83 const double g = 9.81;
85 const double Jp = 1e-2;
86 const double xi = 1e-2;
87 const double J1 = 0.25;
88 const double J2 = 0.25;
90 const double gain = 1e-4;
92 const double alpha = 0.0;
97 f1 <<
dot(dT1) == U1*gain;
98 f1 <<
dot(dT2) == U2*gain;
99 f1 <<
dot(dT3) == U3*gain;
100 f1 <<
dot(dT4) == U4*gain;
101 f1 <<
dot(T1) == dT1;
102 f1 <<
dot(T2) == dT2;
103 f1 <<
dot(T3) == dT3;
104 f1 <<
dot(T4) == dT4;
105 f1 <<
dot(W1) == (T1 - W1*xi)/Jp;
106 f1 <<
dot(W2) == (T2 - W2*xi)/Jp;
107 f1 <<
dot(W3) == (T3 - W3*xi)/Jp;
108 f1 <<
dot(W4) == (T4 - W4*xi)/Jp;
109 f1 <<
dot(q1) == - (Omega1*q2)/2 - (Omega2*q3)/2 - (Omega3*q4)/2 - (alpha*q1*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
110 f1 <<
dot(q2) == (Omega1*q1)/2 - (Omega3*q3)/2 + (Omega2*q4)/2 - (alpha*q2*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
111 f1 <<
dot(q3) == (Omega2*q1)/2 + (Omega3*q2)/2 - (Omega1*q4)/2 - (alpha*q3*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
112 f1 <<
dot(q4) == (Omega3*q1)/2 - (Omega2*q2)/2 + (Omega1*q3)/2 - (alpha*q4*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
113 f1 <<
dot(Omega1) == (J3*Omega2*Omega3 - J2*Omega2*Omega3 + (A*Cl*L*rho*(W2*W2 - W4*W4))/2)/J1;
114 f1 <<
dot(Omega2) == -(J3*Omega1*Omega3 - J1*Omega1*Omega3 + (A*Cl*L*rho*(W1*W1 - W3*W3))/2)/J2;
115 f1 <<
dot(Omega3) == (J2*Omega1*Omega2 - J1*Omega1*Omega2 + (A*Cd*rho*(W1*W1 - W2*W2 + W3*W3 - W4*W4))/2)/J3;
116 f1 <<
dot(V1) == (A*Cl*rho*(2*q1*q3 + 2*q2*q4)*(W1*W1 + W2*W2 + W3*W3 + W4*W4))/(2*m);
117 f1 <<
dot(V2) == -(A*Cl*rho*(2*q1*q2 - 2*q3*q4)*(W1*W1 + W2*W2 + W3*W3 + W4*W4))/(2*m);
118 f1 <<
dot(V3) == (A*Cl*rho*(W1*W1 + W2*W2 + W3*W3 + W4*W4)*(q1*q1 - q2*q2 - q3*q3 + q4*q4))/(2*m) -
g;
122 f1 <<
dot(IP1) == P1;
123 f1 <<
dot(IP2) == P2;
124 f1 <<
dot(IP3) == P3;
131 M1 = eye<double>(12);
132 A1 = zeros<double>(12,12);
133 B1 = zeros<double>(12,4);
139 A1(8,4) = 1.0/Jp;
A1(8,8) = -xi/Jp;
140 A1(9,5) = 1.0/Jp;
A1(9,9) = -xi/Jp;
141 A1(10,6) = 1.0/Jp;
A1(10,10) = -xi/Jp;
142 A1(11,7) = 1.0/Jp;
A1(11,11) = -xi/Jp;
150 f2 <<
dot(q1) == - (Omega1*q2)/2 - (Omega2*q3)/2 - (Omega3*q4)/2 - (alpha*q1*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
151 f2 <<
dot(q2) == (Omega1*q1)/2 - (Omega3*q3)/2 + (Omega2*q4)/2 - (alpha*q2*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
152 f2 <<
dot(q3) == (Omega2*q1)/2 + (Omega3*q2)/2 - (Omega1*q4)/2 - (alpha*q3*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
153 f2 <<
dot(q4) == (Omega3*q1)/2 - (Omega2*q2)/2 + (Omega1*q3)/2 - (alpha*q4*(q1*q1 + q2*q2 + q3*q3 + q4*q4 - 1))/(q1*q1 + q2*q2 + q3*q3 + q4*q4);
154 f2 <<
dot(Omega1) == (J3*Omega2*Omega3 - J2*Omega2*Omega3 + (A*Cl*L*rho*(W2*W2 - W4*W4))/2)/J1;
155 f2 <<
dot(Omega2) == -(J3*Omega1*Omega3 - J1*Omega1*Omega3 + (A*Cl*L*rho*(W1*W1 - W3*W3))/2)/J2;
156 f2 <<
dot(Omega3) == (J2*Omega1*Omega2 - J1*Omega1*Omega2 + (A*Cd*rho*(W1*W1 - W2*W2 + W3*W3 - W4*W4))/2)/J3;
157 f2 <<
dot(V1) == (A*Cl*rho*(2*q1*q3 + 2*q2*q4)*(W1*W1 + W2*W2 + W3*W3 + W4*W4))/(2*m);
158 f2 <<
dot(V2) == -(A*Cl*rho*(2*q1*q2 - 2*q3*q4)*(W1*W1 + W2*W2 + W3*W3 + W4*W4))/(2*m);
159 f2 <<
dot(V3) == (A*Cl*rho*(W1*W1 + W2*W2 + W3*W3 + W4*W4)*(q1*q1 - q2*q2 - q3*q3 + q4*q4))/(2*m) -
g;
164 A3 = zeros<double>(6,6);
190 cout <<
"-----------------------------------------------------------\n Using a QuadCopter ODE model in fully nonlinear form:\n-----------------------------------------------------------\n";
191 sim1.
exportAndRun(
"quadcopter_export",
"init_quadcopter.txt",
"controls_quadcopter.txt" );
206 cout <<
"-----------------------------------------------------------\n Using a QuadCopter ODE model in 3-stage format:\n-----------------------------------------------------------\n";
207 sim2.
exportAndRun(
"quadcopter_export",
"init_quadcopter.txt",
"controls_quadcopter.txt" );
returnValue setLinearInput(const DMatrix &A1_, const DMatrix &B1_)
Allows to setup and evaluate output functions based on SymbolicExpressions.
returnValue setLinearOutput(const DMatrix &A3_, const OutputFcn &rhs_)
USING_NAMESPACE_ACADO int main()
#define USING_NAMESPACE_ACADO
virtual returnValue setTimingSteps(uint _timingSteps)
returnValue setModel(const DifferentialEquation &_f)
returnValue set(OptionsName name, int value)
User-interface to automatically generate simulation algorithms for fast optimal control.
virtual returnValue exportAndRun(const std::string &dirName, const std::string &initStates, const std::string &controls, const std::string &results=std::string("results.txt"), const std::string &ref=std::string("ref.txt"))
Expression dot(const Expression &arg)
Allows to setup and evaluate differential equations (ODEs and DAEs) based on SymbolicExpressions.