%inputs
l1 = 1;
l2 = 0.8;
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
ct = 1;
x0 = 0;
y0 = 0;
for i = 1:lenth(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1+{l2*cosd(THETA2)};
y2 = y1+{l2*sind(THETA2)};
plot([xo x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis([-0.1 1.5 0 1.5]);
M(ct) = getframe(gcf);
ct = ct+1;
end
end
Movie(m)
videofile = VideoWriter('forwardkinematics.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
In the first step basic inputs for the program were provided. In the second step create a simple program forplotting points and checking for plotting errors.
Then a new document is opened and ceate a new program for animating the plots for various angels of theta with respective no of times the program to be executed.
In the new program for loop is used for creating animation.
where two loops were genenrated for two respective arms for their kinematic motion.
In the first loop we have to provide the ittration for theta1 and a new variable THETA1 is derived, in the second loop we have to provide the ittration for theta2 and a new variable THETA2 is generated.
In the next step we have to give the co ordinate values for the arm and respective formulas were used to create new co ordinates based on the corresponding lengths of the arms provided.
Plotting the animation is the major part which can be created through some steps.
1) we can plot animation using line and pause command where the plotting occurs at a particular interval of time based on the time which we provided for the program.
e.g.: hold on
line([x0 x1],[y0 y1],'linecolor','b');
line([x1 x2],[y1 y2],'linecolor','r');
here line colour command is used for the respective arms of rquired colours.
2)using direct plot in matrix format where the co ordinates are provided drectly for the command.
e.g.: plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis([-0.1 1.5 0 1.5]);
in this case we need to provide the axis co ordinates for better view of ploting.
next for continuous plotting, increment command is given inside the secondary loop itself.
to create movie file VideoWriter command is uded.
while creating program i faced the issue in getframe comand which i coudn't rectify.