Experiment 2:
Name: Aditya Shinde
Batch: C
MIS number: 612209037
Aim : Write a MATLAB program for polynomial trajectory generation
%question:
%a standard arm manipulator, the second joint is to move from an initial
%position of 20 degrees to a final position of 68 degrees in four
%seconds assume that the joint starts and finishes at zero velocity. find
%the cubic polynomial that satisfies this motion. calculate the position,
%velocity and accelaration of this joint at intervals of 1 [Link]
%against time
clear all;close all;clc;
sol=linsolve([0 0 0 1;64 16 4 1;0 0 1 0;48 8 1 0],[20;68;0;0])
f=@(x)(sol(1)*x^3+sol(2)*x^2+sol(3)*x+sol(4));
df=@(x)(3*sol(1)*x^2+2*sol(2)*x+sol(3));
d2f=@(x)(6*sol(1)*x+2*sol(2));
theta=[];
velocity=[];
acc=[];
time=[];
for x=0:4
time=[time x];
theta=[theta f(x)];
velocity=[velocity df(x)];
acc=[acc d2f(x)];
end
hold on
plot(time,theta,'r','Marker','square')
plot(time,velocity,'b','Marker','square')
plot(time,acc,'g','Marker','square')
xlabel("Time")
ylabel("Units")
legend('Displacement','Velocity','Accelaration','Location','northwest')
title("Displacement,Velocity and Accelaration")
grid on
hold off
%Write a matlab program to implement the joint space trajectory for the
%following three cases:
%1)3rd order polynomial: force the angular velocity to be zero at start and
%at the finish, given that initiallly, theta=120 and after 1 second
%theta=60
%2)5th order polynomial, angular velocity and acc. at start and end to be
%zero and initial and final displacement same
%3)use 2 3rd order poly with via point, ang velocity zero at start and end,
%initially at 60 degrees, then at 120 degrees after 1 second and after
%another second at 30 degrees
%prob 1
clear all;close all;clc;
sol=linsolve([0 0 0 1;1 1 1 1;0 0 1 0;3 2 1 0],[120;60;0;0])
f=@(x)(sol(1)*x^3+sol(2)*x^2+sol(3)*x+sol(4));
df=@(x)(3*sol(1)*x^2+2*sol(2)*x+sol(3));
d2f=@(x)(6*sol(1)*x+2*sol(2));
theta=[];
velocity=[];
acc=[];
time=[];
for x=0:0.1:1
time=[time x];
theta=[theta f(x)];
velocity=[velocity df(x)];
acc=[acc d2f(x)];
end
figure()
hold on
plot(time,theta,'r','Marker','square')
plot(time,velocity,'b','Marker','square')
plot(time,acc,'g','Marker','square')
xlabel("Time")
ylabel("Units")
legend('Displacement','Velocity','Accelaration','Location','northwest')
title("Displacement,Velocity and Accelaration")
grid on
hold off
%prob 2
clear all;close all;clc;
sol=linsolve([0 0 0 0 0 1;1 1 1 1 1 1;0 0 0 0 1 0;5 4 3 2 1 0;0 0 0 2 0 0;20
12 6 2 0 0],[120;60;0;0;0;0])
f=@(x)(sol(1)*x^5+sol(2)*x^4+sol(3)*x^3+sol(4)*x^2+sol(5)*x+sol(6));
df=@(x)(5*sol(1)*x^4+4*x^3*sol(2)+3*x^2*sol(3)+2*x*sol(4)+sol(5));
d2f=@(x)(20*x^3*sol(1)+12*x^2*sol(2)+6*x*sol(3)+2*sol(4));
theta=[];
velocity=[];
acc=[];
time=[];
for x=0:0.1:1
time=[time x];
theta=[theta f(x)];
velocity=[velocity df(x)];
acc=[acc d2f(x)];
end
figure()
hold on
plot(time,theta,'r','Marker','square')
plot(time,velocity,'b','Marker','square')
plot(time,acc,'g','Marker','square')
xlabel("Time")
ylabel("Units")
legend('Displacement','Velocity','Accelaration','Location','northwest')
title("Displacement,Velocity and Accelaration")
grid on
hold off
%poly1
clear all;close all;clc;
sol=linsolve([0 0 0 1;1 1 1 1;0 0 1 0;3 2 1 0],[60;120;0;0])
f=@(x)(sol(1)*x^3+sol(2)*x^2+sol(3)*x+sol(4));
df=@(x)(3*sol(1)*x^2+2*sol(2)*x+sol(3));
d2f=@(x)(6*sol(1)*x+2*sol(2));
theta=[];
velocity=[];
acc=[];
time=[];
for x=0:0.1:1
time=[time x];
theta=[theta f(x)];
velocity=[velocity df(x)];
acc=[acc d2f(x)];
end
%poly2
sol=linsolve([1 1 1 1;8 4 2 1;3 2 1 0;12 4 1 0],[120;30;0;0])
f=@(x)(sol(1)*x^3+sol(2)*x^2+sol(3)*x+sol(4));
df=@(x)(3*sol(1)*x^2+2*sol(2)*x+sol(3));
d2f=@(x)(6*sol(1)*x+2*sol(2));
for x=1:0.1:2
time=[time x];
theta=[theta f(x)];
velocity=[velocity df(x)];
acc=[acc d2f(x)];
end
figure()
hold on
plot(time,theta,'r','Marker','square')
plot(time,velocity,'b','Marker','square')
plot(time,acc,'g','Marker','square')
xlabel("Time")
ylabel("Units")
legend('Displacement','Velocity','Accelaration','Location','northwest')
title("Displacement,Velocity and Accelaration")
grid on
%the trajectory of prismatic joint is given by d(t)=8+68*t^2-20*t^3. what
%are the initial and final positions of velocity and accelaration for this
%joint if t_end=1;
f=@(t)(8+68*t^2-20*t^3);
df=@(t)(68*2*t-20*3*t^2);
d2f=@(t)(68*2-20*6*t);
d=[];
v=[];
a=[];
time=[];
for t=0:0.1:1
time=[time t];
d=[d f(t)];
v=[v df(t)];
a=[a d2f(t)];
end
figure()
hold on
plot(time,d,'r','Marker','square')
plot(time,v,'b','Marker','square')
plot(time,a,'g','Marker','square')
xlabel("Time")
ylabel("Units")
legend('Displacement','Velocity','Accelaration','Location','northwest')
title("Displacement,Velocity and Accelaration")
grid on
hold off