Final
Final
Final
CODE:
%112009011_Gagandeep Singh
clc
clear all
close all
stepsize=0.001;
t=0:stepsize:1000;
xr=8*sin(0.01*t);
yr=0.5*cos(0.01*t);
figure;
subplot(3,1,1);
plot(xr,yr);
title('Circular Trajectory')
xlabel('x(cm)');
ylabel('y(cm)')
subplot(3,1,2);
plot(t,xr)
xlabel('Time(sec)');
ylabel('y(cm)')
subplot(3,1,3);
plot(t,yr);
xlabel('Time(sec)');
ylabel('y(cm)')
OUTPUT:
MATLAB program for infinity.
CODE:
clc
clear all
close all
Fs = 50;
wps=[0 0 0;2 -2 0;4 0 0;6 2 0;8 0 0;6 -2 0; 4 0 0;2 2 0;0 0 0];
t = 0:(size(wps,1)-1);
traj = waypointTrajectory(wps, t, 'SampleRate', Fs);
waypointTable = waypointInfo(traj);
waypoints = waypointTable.Waypoints;
pos = traj();
while ~isDone(traj)
pos(end+traj.SamplesPerFrame,:) = traj();
end
% Plot generated positions and specified waypoints.
plot(pos(:,1),pos(:,2), waypoints(:,1),waypoints(:,2), '--o')
title('Position')
xlabel('X (m)')
ylabel('Y (m)')
zlabel('Z (m)')
legend({'Position', 'Waypoints'})
OUTPUT:
MATLAB program for spiral trajectory.
CODE:
%112009011_Gagandeep Singh
clc
close all
clear all
% Define parameters
n_turns = 5; % number of turns in the spiral
r_start = 1; % starting radius of the spiral
r_end = 5; % ending radius of the spiral
z_start = 0; % starting z-coordinate
z_end = 10; % ending z-coordinate
OUTPUT:
MATLAB program for helical trajectory.
CODE:
%112009011_Gagandeep Singh
%3D-Spiral path stepsize 0.001;
stepsize=0.001;
t=0:stepsize:1000;
xr=8*sin(0.01*t);
yr=0.5*cos(0.01*t);
zr=t;
figure(1)
plot3(xr,yr,zr);
xlabel('x')
ylabel('y')
zlabel('z')
title('Helical Trajectory');
grid on
figure(2)
subplot(3,1,1)
plot(t,xr)
ylabel('x');
xlabel('Time');
title('xr');
grid on
subplot(3,1,2)
plot(t,yr)
ylabel('y');
xlabel('Time');
title('yr');
grid on
subplot(3,1,3)
plot(t,zr);
ylabel('z');
xlabel('Time');
title('zr');
OUTPUT:
MATLAB program for sliding mode control.
CODE:
clc
clear all
close all
x1=0.1;
x2=0.1;
M=0.5;
k=10;
L=2.5;
g=9.8;
a=5;
stepsize=0.001;
phi=0.01;
z=1;
for t=0:stepsize:20
s=a*x1+x2;
u=(M*L^2)*(-a*x2 + (L/g)*sin(x1))-k*sign(s);
x1dot=x2;
x2dot=(-g/L)*sin(x1)+(1/(M*(L^2)))*u;
x1 = x1dot*stepsize + x1;
x2 = x2dot*stepsize + x2;
st1(z)=x1;
st2(z)=x2;
st3(z)=u;
z=z+1;
hold on;
end
t=0:stepsize:20;
hold on
figure(1)
subplot(3,1,1)
plot(t,st1);
xlabel('Time');
ylabel('y(cm)');
hold on
subplot(3,1,2)
plot(t,st2)
xlabel('Time');
ylabel('y(cm)');
grid on
subplot(3,1,3)
plot(t,st3);
xlabel('Time');
ylabel('y(cm)');
grid on
figure(2)
plot(st1,st2);
grid on
OUTPUT: