To talk on Icrontic, just register!

It only takes 30 seconds.

Have an account? Sign in:

Forgot?
physics88
New to the neighborhood
physics88
1 Posts

MATLAB Projectile Motion

I am doing a catapult project where I have to launch something using MATLAB. The mechanism I am implmenting is the crank slider. What I am trying to do is to start when the crank slider is flat, and then create an initial velocity of the links before sending the ball into the air (this is when the the crank slider has been rotated CCW for 90 degrees).

I am having trouble with the projectile motion of the code. Can someone help me out on how to create the continuous range and velocity plots? I have attached my code for you to see.

I just need some help on how to create the projectile motion code, since I think I have to write two statements about the path of the ball, one before the lanch and one after the launch.



Code:
 
% Definitions
R2D = 180/pi; % rad to deg
D2R = pi/180; % deg to rad
F2M = 0.3040; % feet to meter
m = 45.46; % kg
g = -9.8; % gravity (m/s^2)
j = sqrt(-1);
dt = 0.001; %1000Hz

R1 = 15*F2M; %m
R2 = 15*F2M;
 

% Initial conditions
xBall = [0; 0]; % theta/omega
 

% Machine initial conditions
Torque = (-1)*m*g*R1; % N-m
Pmotor = 1119000; % W
Tbreak = (4404 / 0.738)*2.3; % break torque in N-m
 

% Ball
I = m*(R1^2);
 

for launch=0:1:20
times_launched = launch + 1;
 

% Main loop
iter = 0;
for time=0:dt:1
 
% Index
iter = iter + 1;
 

% Torque generation and check
if( (xBall(2,1)) < ((Pmotor)/Tbreak) )
Torque = Tbreak;
else
Torque = (Pmotor)/xBall(2,1);
end
 


% From 0 degrees to 90 degrees
if ((xBall(1,1)*R2D) >= 0 ) || ((xBall(1,1)*R2D) < 90)
% Calculate net torque
Tgrav = ( m*g*cos(xBall(1,1)))*R1;
Tnet = Torque + Tgrav;

% Calculate instantaneous angular acceleration
alphaB = Tnet/I;

% Calculate the derivative of the state
xdot = [ xBall(2,1); alphaB ];

% Integration of the state
xBall = xBall + xdot*dt;

% Dependent states
pBall = R1*( cos(xBall(1,1)) + j*sin(xBall(1,1)) );
vBall = xBall(2,1) * R1;
Power = (Tnet/R1) * vBall;
 


elseif ( ((xBall(1,1)*R2D) >= 90) || ((xBall(1,1)*R2D) <= 180) )

% Calculate net torque
Tgrav = ( m*g*cos( xBall(1,1)) )*R1;
Tnet = Torque + Tgrav;

% Calculate instantaneous angular acceleration
alphaB = Tnet/I;

% Calculate the derivative of the state
xdot = [ xBall(2,1); alphaB ];

% Integration of the state
xBall = xBall + xdot*dt;

% Dependent states
pBall = real(vBall) * time;
Power = (Tnet/R1) * vBall;

end;
 

DATA(iter,:) = [ iter time xBall' alphaB Tnet xBall(1,1)*R2D ...
real(pBall) imag(pBall) real(vBall) imag(vBall) vBall Power ];

end;

end;
 


%% Trajectory of Projectile (y vs. x)
figure(1);
plot( DATA(:,8), DATA(:,9), '.' );
title ('Trajectory (y vs. x) of projectile during launch')
xlabel('x')
ylabel('y')
 

%% Range (x) vs. time
figure(2);
subplot (211), plot(DATA(:,2), DATA(:,8), '.' );
title ('Range(x) as a function of time')
ylabel('Range(x)')
 

%% Altitude (y) vs. time
subplot (212), plot(DATA(:,2), DATA(:,9), '.' );
title ('Altitude(y) as a function of time')
xlabel('time')
ylabel('Altitude(y)')
 

%% Velocity (x and y components) vs. time
figure(3);
subplot (211), plot(DATA(:,2), DATA(:,10), '.' );
title ('Velocity (x and y) as a function of time')
ylabel('Velocity(x)')

subplot (212), plot(DATA(:,2), DATA(:,11), '.' );
xlabel('time')
ylabel('Velocity(y)')
 

%% Velocity (total) vs. time
figure(4);
plot(DATA(:,2), DATA(:,12), '.' );
title ('Velocity(total) as a function of time')
xlabel('time')
ylabel('Velocity (total))')
 

%% Power vs. time
figure(5);
plot(DATA(:,2), DATA(:,13), '.' );
title ('Power as a function of time')
xlabel('time')
ylabel('Power')

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help projectile motion juice34 Matlab Help 12 15 Oct 2008 11:13pm
Batch-processing in MATLAB geodave Matlab Help 6 18 Jul 2008 12:58am
Writing new files from Matlab raulinhoo Matlab Help 6 5 Jun 2008 8:31pm
Closing external programs in matlab raulinhoo Matlab Help 2 4 Jun 2008 3:55pm

Go Back   Icrontic Forums > Tech: Software > General Software > Matlab Help
Jump to
This Thread Search this Thread
Search this Thread:

Advanced Search


Current time: 11:46am (GMT)
Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Get Vanilla instead. Trust me.