Function definition is misplaced or improperly nested. Please help!!
10 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Rik
2019 年 10 月 8 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!