Is this formula correct for simulate 3D Water rocket
조회 수: 11 (최근 30일)
이전 댓글 표시
I want to simulate 3D Water Rocket only use Acceleration data collected from Sensor GY86
But after I run
The results gave me have a lot of line and isn't correct
I don't know if i use this Calculation is correct or enough or i am missing some steps in formula
I have tried this
function Water_rocket_simulator
clc
close all
clear all
load('Acce and Gyro xyz')
%% CONSTANTS
g = 9.81;
%% INPUT DATA
x = 0;
y = 0;
z = 0;
v0 = 30;
alpha = 90;
t = 0;
dt = 0.01;
%% FIGURE
figure('name','Water Rocket','color','white','numbertitle','off');
hold on
fig_rocket = plot3(x,y,z,'ro','MarkerSize',10,'markerfacecolor','r');
ht = title(sprintf('t = %0.2f s',t));
xlabel('X axis Latitude');
ylabel('Y axis Longtitude');
zlabel('Z axis heights');
grid on
axis equal
axis([1 300 1 300 1 300]);
%% CALCULATION
alpha = alpha/180*pi;
vx = v0*cos(alpha);
vy = v0*cos(alpha);
vz = v0*sin(alpha);
while z>-0.01
t = t+dt;
ax = AccelerationX(:,1)/1000;
ay = AccelerationY(:,1)/1000;
az = AccelerationZ(:,1)/1000;
vx = vx+ax*dt;
vy = vy+ay*dt;
vz = vz+az*dt;
x = x+vx*dt+0.5*ax*dt.^2;
y = y+vy*dt+0.5*ay*dt.^2;
z = z+vz*dt+0.5*az*dt.^2;
plot3(x,y,z,'o','markersize',1,'color','k');
xlabel('X axis Latitude');
ylabel('Y axis Longtitude');
zlabel('Z axis Heights');
grid on
set(fig_rocket,'xdata',x,'ydata',y,'zdata',z);
set(ht,'string',sprintf('t = %0.2f s',t));
pause(0.002);
end
end
댓글 수: 1
Alan Stevens
2021년 6월 29일
Perhaps you need something like
for i = 2:numel(AccelerationX)
t(i) = t(i-1) + dt;
ax(i) = Acceleration(i,1)/1000;
% similarly for ay and az
vx(i) = vx(i-1)+ax(i)*dt;
% ...etc
x(i) = x(i-1) + vx(i)*dt +0.5*ax(i)*dt^2;
% ...etc
end
답변 (1개)
Alan Stevens
2021년 6월 28일
Probably
vy = v0*cos(alpha);
should be more like
vy = v0*cos(alpha)*cos(beta);
where beta is an angle that will point the rocket out of the x-z plane.
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!