Challenge

Week 2- 2R Robotic Arm Challenge

%forward kinematics of 2r robotic arm
clear all 
close all 
clc

%HERE l1 is length of 1st arm and l2 is second arm which is fixed to arm1
l1=2;
l2=1;

%inputs of arm angles
%in linspace command 1st value represents starting point of angle
%2nd point refers ending point of angle and last point refers no of values

angle1=linspace(0,90,10);
angle2=linspace(0,90,10);

%to  give in seperate plot counter(ct) variable is used
ct=1;

%the first loop starting from 1 to max value angle 1
%the value of i changes and here i is length of angle 1
%angle 1 is assinged to a variable ANGLE1

for i=1:length(angle1)
    ANGLE1=angle1(i);

%the 2nd loop starting from 1 to max value angle 2
%here j is length of angle2
%angle2 is assinged to a variable ANGLE2
     for j=1:length(angle2) 
           ANGLE2=angle2(j);

%calculating position of link 1
%from fixed bottom the initial value of X and Y is (x0,y0)
%from fixed bottom final value of x and y is (x1,x2)

x0=0;
y0=0;

x1=l1*cosd(ANGLE1);
y1=l1*sind(ANGLE1);

%calculating position of link 2
%link 2 starts from link 1 ending point(x1,y1)
%end point of linl 2 is (x2 y2)

x2=x1+l2*cosd(ANGLE2);
y2=y1+l2*sind(ANGLE2);

%plot function is used to plot the images
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)

%axis of x and y coordinates
axis([-0.3 3.5 0.3 3.5])

%pause command gives the better visualization of the plot
pause(0.01);

%ALL total frames resulting are stored in  array M
%getframe captures the individual frame in gcf 
M(ct)= getframe(gcf);

%ct represents every frame the counter(ct) is incremented by  1(ct+1)
ct=ct+1;

    end 
end

%movie command is used to create video of all frames generated
movie(M)

%videowriter command is used to assign the video format of the video
%here avi format is used
videofile = VideoWriter('forward_kinematics.avi','uncompressed AVI');

%openfile command is used to open the video 
open(videofile)

%writevideo is used to write the video with plot frames
writeVideo(videofile,M)
%close command is used to close the video file
close(videofile)

google drive link https://drive.google.com/file/d/1_Kq7WhPqRGitntDGMacUIZg8k0gNrqQw/view?usp=sharing

https://drive.google.com/file/d/1_Kq7WhPqRGitntDGMacUIZg8k0gNrqQw/view?usp=sharing

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.