Problems with Matlab and "Handle"

조회 수: 35 (최근 30일)
DJ V
DJ V 2024년 11월 7일 13:26
댓글: Cris LaPierre 2024년 11월 7일 14:59
I'm asking for help, which is consistent with how your company chooses to describe this selection on your web site. You people keep saying that I'm asking you to debug my software. No. I simply lack the experience with the "handle" statement. I was also told by the professor that I should be able to get Simulink to produce an output for, say, Pn that can move the plane in a particular direction. How does one do that? If I simply enter a different initial condition, the output stays the same during the run and the plane doesn't move. Your software won't let me load the simulink file. Says I've already loaded 10 files in 24 hours. What???
The errors in Matlab are as follows:
Error using matlab.graphics.chart.primitive.Line/set
Invalid or deleted object.
Error in EqnsOfMotionback>drawPlaneBody (line 137)
set(handle, 'XData', XYZ(1,:), 'YData',XYZ(2,:), 'ZData',XYZ(3,:));
Error in EqnsOfMotionback (line 107)
handle = drawPlaneBody(pn(k),pe(k),pd(k),phi(k),theta(k),psi(k),handle);
%Initial Conditions
pn0 = 0.0; %Initial north position
pe0 = 0.0; %initial east position
pd0 = -100.0; %initial east position
u0 =0.0; %initial velocity along body x-axis
v0 = 0.0; %initial velocity along body y-axis
w0 = 0.0; %initial velocity along body z-axis
phi0 = 0.0; %initial roll angle
theta0 = 0.0; %initial pitch angle
psi0 = 0.0; %initial yaw rate
l0 = 0; %initial moment about ib axis
m0 = 0; %initial moment about jb axis
n0 = 0; %initial moment about kb axis
p0 = 0; %initial roll rate along ib in Fb
q0 = 0; %initial pitch rate along jb in Fb
r0 = 0; %initial yaw rate along kb in Fb
l = l0;
m = m0;
n = n0;
Va0 = (u0^2 + v0^2 + w0^2)^0.5; %initial velocity
%Initial forces producing acceleration - fx, fy, fz
fx = 0; %Force in the ib direction.
fy = 0; %Force in the jb direciton.
fz = 0; %Force in the kb direction.
%Plane is initially aligned so that ib,jb, and kb
%correspond to x, y, z.
%Physical Parameters
mass = 13.5; % kg
Jx = 0.8244; %kg m^2
Jy = 1.135;
Jz = 1.759;
Jxz = 0.1204;
S_wing = 0.55;
b = 2.8956;
c = 0.18994;
Sprop = 0.2027;
rho = 1.2682;
e = 0.9;
AR = (b^2)/S_wing;
gravity = 9.81;
%Gamma Values
G = Jx * Jz - (Jxz^2);
G1 = (Jxz * (Jx - Jy + Jz))/ G ;
G2 = (Jz * (Jz - Jy) + (Jxz^2))/ G;
G3 = Jz / G;
G4 = Jxz / G;
G5 = (Jz - Jx) / Jy;
G6 = Jxz / Jy;
G7 = ((Jx - Jy) * Jx + (Jxz ^ 2)) / G;
G8 = Jx / G;
%Establish the parameters to pass to the subroutines
phi = phi0;
theta = theta0;
psi = psi0;
dt = 0.1;
n=0;
total_time = 20; % total simulation time in seconds
time_step = 0.1; % time step in seconds
num_steps = total_time / time_step; % number of steps
mass = 13.5;
p = 0;
q = 0;
r = 0;
v=0;
q=0;
w=0;
y0 = 0.0;
mass = 13.5;
tim=0;
%***************************************
%Matlab Runge Kutta Routine - NEED HELP
handle=[];
Pn = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pn.mat", "ans").ans;
Pe = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pe.mat", "ans").ans;
Pd = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\Pd.mat", "ans").ans;
Phi = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\phi.mat","ans").ans;
Psi = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\psi.mat","ans").ans;
Theta = load("C:\Users\1537268928E\OneDrive - United States Air Force\Desktop\theta.mat","ans").ans;
pn=Pn.Data;
pe=Pe.Data;
pd=Pd.Data;
phi=Phi.Data;
psi=Psi.Data;
theta=Theta.Data;
length(pn)
pn
pe
pd
phi
psi
theta
%Draw and update the plane's position.
for k = 1:num_steps
%Draw or update the plane.
handle = drawPlaneBody(pn(k),pe(k),pd(k),phi(k),theta(k),psi(k),handle);
pause(0.1); %Pause to visualize the movement
end
function handle = drawPlaneBody(pn,pe,pd,phi,theta,psi,handle)
%define points on plane in local NED coordintates
NED = airplanepoints;
%rotate plane by (phi; theta; psi)
NED = rotate(NED, phi, theta, psi);
%translate plane to [pn; pe; pd]
NED = translate(NED, pn, pe, pd);
%transform vertices from NED to XYZ
R = [...
0, 1, 0;...
1, 0 , 0;...
0, 0, -1;...
];
XYZ = R* NED;
%plot plane
if isempty(handle)
handle = plot3(XYZ(1,:),XYZ(2,:),XYZ(3,:),'b');
xlim([-50 50]);
ylim([-50 50]);
zlim([0 125]);
grid on;%show grid
xlabel('X');ylabel('Y');zlabel('Z');%label axes
else
set(handle, 'XData', XYZ(1,:), 'YData',XYZ(2,:), 'ZData',XYZ(3,:));
drawnow
end
end
function XYZ = airplanepoints
%define points on the aircraft in local NED
XYZ = [...
0 0 0;%point1
-2 1 1;%point2
-2 1 -1;%point3
0 0 0;%point1
-2 -1 1;%point4
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
-2 -1 1;%point4
0 0 0;%point1
-2 1 -1;%point3
-2 -1 -1;%point5
0 0 0;%point1
-2 1 1;%point2
-18 0 0;%point6
-2 1 -1;%point3
-18 0 0;%point6
-2 -1 -1;%point5
-18 0 0;%point6
-2 -1 1;%point4
-18 0 0;%point6
-2 1 1;%point2
0 0 0;%point1
-5 0 0;%point7
-5 -10 0;%point8
-8 -10 0;%point9
-8 10 0;%point10
-5 10 0;%point11
-5 0 0;%point7
-15.5 0 0;%point12
-15.5 2 0;%point13
-17.5 2 0;%point14
-17.5 -2 0;%point15
-15.5 -2 0;%point16
-15.5 0 0;%point12
-18 0 0;%point6
-18 0 -3;%point17
-15.5 0 0;%point15
-18 0 0;%point16
]';
end
function XYZ=rotate(XYZ,phi,theta,psi)
%define rotation matrix
R_roll = [1, 0, 0;
0, cos(phi), -sin(phi);
0, sin(phi), cos(phi)];
R_pitch = [cos(theta), 0, sin(theta);
0, 1, 0;
-sin(theta), 0, cos(theta)];
R_yaw = [cos(psi), -sin(psi), 0;
sin(psi), cos(psi), 0;
0, 0, 1];
R = R_roll*R_pitch*R_yaw;
%rotate vertices
XYZ =R*XYZ;
end
function XYZ = translate(XYZ, pn, pe, pd)
XYZ = XYZ + repmat([pn;pe;pd],1,size(XYZ,2));
end
  댓글 수: 1
Cris LaPierre
Cris LaPierre 2024년 11월 7일 14:59
Just a clarification on your opening lines. While MathWorks does host this forum, by and large, the contributions come from community members like yourself who volunteer their time to answer questions posted here. Even when staff members like myself do answer questions, it is not in an official capacity and does not represent a company response.
If you need official support from MathWorks, please contact Support: https://www.mathworks.com/support/contact_us.html

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Unit Conversions에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by