Function definition is misplaced or improperly nested. Please help!!
35 次查看(过去 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 中查找有关 Axes Appearance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!