Week 2- 2R Robotic Arm Challenge
clear all
close all
clc
%inputs%
l1 = 1;
l2 = 0.5;
t1 = linspace(1,90,10);
t2 = linspace(1,90,20);
ct=1;
for i = 1:length(t1)
THETA1 = t1(i);
for j = 1:length(t2)
THETA2 = t2(j);
x0=0;
y0=0;
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
x2=x1 + l2*cosd(THETA2);
y2=y1 + l2*sind(THETA2);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2])
axis([0 3 0 1.5])
pause(0.001)
M(ct) = getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile=videowriter('robotic_arm_animation.avi','Uncompressed AVI');
open(videofile)
writevideo(videofile,M)
close(videofile)
code explanation :-
l1,l2 are the fixed length and t1,t2 are the angle between the horizontal varires from 1 to 90 degrees with 10 equal angles from 1 to 90.
the 'for' loop starts from 1 to each value of the length of the t1, t2 and returns to i and j stored in the variable THETA1,THETA2 respectively.
formula
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
x2=x1 + l2*cosd(THETA2);
y2=y1 + l2*sind(THETA2);
plotting,usually the plot syntax plot(x,y) for 'nth' plot (x1,y1,.....xn,yn)
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2])
here x1=[x0 x1],y1=[y0 y1] , x2=[x1 x2],y2=[y1 y2]
axis([0 3 0 1.5]) here x axis starts from 0 to 3 , y axis starts from 0 to 1.5
M(ct) = getframe(gcf) where gcf collect the figure window frame by frame and stored in variable 'M'.
movie(M) plays the movie frames in array M once. To create a movie frame from the current figure or axes.
errors :-
Cannot find an exact (case-sensitive) match for 'videowriter'
The closest match is: VideoWriter in M:\original matlab
installation\Polyspace\R2021a\toolbox\matlab\audiovideo\VideoWriter.m
Error in robotic_animation (line 32)
videofile=videowriter('robotic_arm_animation.avi','Uncompressed AVI');
here the error is the case sensitive error videowriter=VideoWriter and writevideo=writeVideo.
result:-
