Function definition is misplaced or improperly nested. Please help!!
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Trying to run this code, it gives me the error "Function definition is misplaced or improperly nested." Please help"!
varInput = load('quadData.mat');
qDat = varInput.quadrotor;
[n,~] = size(qDat);
Xi_0 = [qDat(1,2:4)'; qDat(1,8:10)'];
v = qDat(:,5:7);
omega = qDat(:,11:13);
t=qDat(:,1);
dt=qDat(2,1) - qDat(1,1);
T_initial = qDat(1,1);
T_final = qDat(end,1);
phi=qDat(:,8);
th=qDat(:,9);
psi=qDat(:,10);
q_tr=[cos(0.5*psi).*cos(0.5*th).*cos(0.5*phi)+sin(0.5*psi).*sin(0.5*th).*sin(0.5*phi),cos(0.5*psi).*cos(0.5*th).*sin(0.5*phi)-sin(0.5*psi).*sin(0.5*th).*cos(0.5*phi),cos(0.5*psi).*sin(0.5*th).*cos(0.5*phi)+sin(0.5*psi).*cos(0.5*th).*sin(0.5*phi),sin(0.5*psi).*cos(0.5*th).*cos(0.5*phi)-cos(0.5*psi).*sin(0.5*th).*sin(0.5*phi)]
Xi_0=[qDat(1,2:4)';q_tr(1,:)'];
pose_dot(1,Xi_0,dt,v,omega);
[t_out,Xi] = ode45(@pose_dot,[T_initial T_final],Xi_0);
figure
plot(t_out,Xi(:,4:7),':');
hold on
plot(t,q_tr,'-');
legend('q_0', 'q_q','q_2','q_3','q_{0,true}','q_{1,true}','q_{2,true}','q_{3,true}');
grid on
title('Quanternions vs. Time Graph');
xlabel('Time s');
ylabel('Quanternion');
figure
plot(t_out,Xi(:,1:3),':');
hold on
plot(t,qDat(:,2:4),'-');
legend('x_{calc}','y_{calc}','z_{calc}','x_{true}','y_{true}','z_{true}');
grid on
title('Position vs. Time');
xlabel('Time s');
ylabel('Position m');
function function Xi_dot = pose_dot(t,Xi,dt,v,omega);
ind = floor(t/dt) + 1;
nu = [v(ind,:)'; 0.5*Xi(4:7)];
q0 = Xi(4);
q1 = Xi(5);
q2 = Xi(6);
q3 = Xi(7);
Xi_dot=[q0^2+q1^2-q2^2-q3^2 2*(q2*q1-q0*q3) 2*(q3*q1+q0*q2) 0 0 0 0;2*(q2*q1+q0*q3) q0^2-q1^2+q2^2-q3^2 2*(q3*q2-q0*q1) 0 0 0 0;2*(q3*q1-q0*q2) 2*(q3*q2-q0*q1) q0^2-q1^2-q2^2+q3^2 0 0 0 0;0 0 0 0 -omega(ind,1) -omega(ind,2) -omega(ind,3);0 0 0 omega(ind,1) 0 omega(ind,3) -omega(ind,2);0 0 0 omega(ind,2) -omega(ind,3) 0 omega(ind,1);0 0 0 omega(ind,3) omega(ind,2) -omega(ind,1) 0]*nu;
end
0 Kommentare
Antworten (1)
Rik
am 8 Okt. 2019
Replace this
function function Xi_dot = pose_dot(t,Xi,dt,v,omega);
with this
function Xi_dot = pose_dot(t,Xi,dt,v,omega)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!