0% found this document useful (0 votes)
15 views8 pages

Final

The document contains MATLAB code for generating different trajectory paths including circular, infinity, spiral, helical, and sliding mode control trajectories. The code provides the MATLAB code to generate the trajectories and plots the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views8 pages

Final

The document contains MATLAB code for generating different trajectory paths including circular, infinity, spiral, helical, and sliding mode control trajectories. The code provides the MATLAB code to generate the trajectories and plots the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MATLAB program for circular trajectory

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

% Generate spiral trajectory


t = linspace(0, n_turns*2*pi, 1000); % parameterization of the spiral
r = linspace(r_start, r_end, length(t)); % radius increases linearly
z = linspace(z_start, z_end, length(t)); % z-coordinate increases linearly
x = r .* cos(t); % x-coordinate of the spiral
y = r .* sin(t); % y-coordinate of the spiral

% Plot spiral trajectory


plot3(x, y, z);
xlabel('x');
ylabel('y');
zlabel('z');
grid on;

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:

You might also like