Week 2- 2R Robotic Arm Challenge
1.https://youtu.be/4A_RsOV74SA
clear all
close all
clc
% Inputs
% Length of robotic arm
l1=1;
l2=0.5;
% angles for the movement of robotic arm
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
ct=1; % counter with starting value assigned as 1
for i= 1:length(theta1) % iterating i from 1 to 10 as theta1 has 10 values
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
% Coordinates of start point of first arm
x0=0;
y0=0;
% coordinates of end point of first arm/start point of second arm
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
%coordinates of end point of second arm
x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);
% ploting
% coordinates of arms assigned over a set of theta1 and theta2
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
% the limits of x-axis and y-axis
axis([-0.1 1.5 0 1.5]);
% to cease the animation from jumping between subsequent figures
pause(0.03)
% collecting frames of figures to comprise a movie/animation
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% To make a movie of the collected frames
movie(M)
% Saving the movies in '.avi' format
videofile=VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
% Writing the movie in the videofile created
writeVideo(videofile,M)
close(videofile)
Explanation of Program:
1.Initially we define the length of the robotic arms,i.e.l1 & l2.
2.set of values for theta1 & theta2 are assigned in & array with 'linspace' command.
3.used the first 'for'command for iterating the values of desired variables.
4. used the second 'for' command for providing movement to second arm.
5.defining the coodinates of the both robotic arms.
6.plotting all coodinate values and writting the commands for changing the appearance of the contour.
7. All pictures/figures assigned to a variabe 'M', one at a time using' ct' followed by termination of for loop.
8.movie command is used to combine all the figures and saved in M file to make movie then saved it in '.avi' formate.