Challenge

Week 2- 2R Robotic Arm Challenge

Explanation

2R Robotic arm which have 2 Rotating Links (Link_1,Link_2)

considering the Length of Link_1 as 2m & Link_2 as 1.2m.

theta_1 is the angle of Link_1 with respect to datum axis. theta_1 value taken from 0 to 90 with equal division of 10 using linspace command.

theta_2 is the angle of Link_2 with respect to datum axis. theta_2 value taken from 0 to 90 with equal division of 10 using linspace command.

For each theta value of Link_1, Link_2 have different angle of rotation. so that nested for loop is used to show the angle variation of Link_2 with each angle of Link_1.

Starting position of Link_1 is X_0,Y_0 which is the fixed end and X_1,Y_1 is the ending position of Link_1. X_1,Y_1 is the starting position of Link_2. so that while calculating the position of Link_2, summing the Link_1 coordinates to get X_2,Y_2.

for m=1:length(theta_1)

THETA_1=theta_1(m)

       for n=1:length(theta_2)

         THETA_2=theta_2(n)

initially m=1, enters the loop and assign theta_1(m) which is 10degree gets assigned to THETA_1 variable. Then for loop n=1, enters the loop and assign theta_1(n) which is 10degree. and then performing calculations

X_0=0

Y_0=0

 X_1=Length_1*cos(THETA_1)

Y_1=Length_1*sind(THETA_1)

X_2=X_1+Length_2*cosd(THETA_2)

Y_2=Y_1+Length_2*sind(THETA_2)

THETA_1=10 THETA_2= 10,20,30,40,50,60,70,80,90, again

THETA_1=20 THETA_2=10,20,30,40,50,60,70,80,90........THETA_1=90 THETA_2=10,20,30,40,50,60,70,80,90

 Plotting the Link_1 & Link_2 coordinates. Count command is declared before the for loop to calculate each frame. Count-Count+1 is declared at the end of for loop(incrementing the value each time the program is executed).

Pause(0.2) is used to program pauses for 0.2seconds

To create a movie, M(count)=getframe(gcf) is declared. It defines that count having all frames and getframe defines getting frame & saving in an array name'M'

videofile= VideoWriter('Forward_kinematics_2R_Robotic_Arm.avi','uncompressed AVI)- This command is used to save the file in avi video.

open(videofile)

writeVideo(video,M)

close(videofile)

Error occured during program execution

While defining the function name videowriter and writevideo command both are in case sensitive. I entered wrongly at first and then corrected with help of command window message.

youtubelink- https://youtu.be/ZyY1FXHW3Ks

Googledrive link- https://drive.google.com/file/d/112ehltpJMtNbwVV6bnVujHzn-e9TdeLH/view?usp=sharing

clear all
close all
clc
%program to simulate Forward_kinematics_2R_Robotic_arm
%parameter needed to write the program
%Length of Link_1
Length_1=2
%Length of Lnk_2
Length_2=1.2
%theta_1 is the angle of Link_1 with respect to x-axis
theta_1=linspace(0,90,10)
%theta_2 is the angle of Link_2 with respect to x-axis
theta_2=linspace(0,90,10)
%For each angle of Link_1, Link_2 have different angle of rotation. so that
%nested for loop used
count=1   % to count each frame
for m=1:length(theta_1)
    THETA_1=theta_1(m)
    for n=1:length(theta_2)
        THETA_2=theta_2(n)
        %coordinates
        %X_0,Y_0 are the starting point of Link_1
        X_0=0
        Y_0=0
        %X_1,Y_1 are the ending point of Link_1
        X_1=Length_1*cosd(THETA_1)
        Y_1=Length_1*sind(THETA_1)
        %X_1,Y_1 are the starting point of Link_2 and X_2,Y-2 are the
        %ending point of Link_2
        X_2=X_1+Length_2*cosd(THETA_2)
        Y_2=Y_1+Length_2*sind(THETA_2)
        %plotting the coordinates
        plot([X_0 X_1],[Y_0 Y_1],[X_1 X_2],[Y_1 Y_2],'linewidth',4)
        axis([-0.1 3.5 -0.1 3.5])  %defining x& y limits
        pause(0.2)
        %Getting individual frame and saving in a array name'M'
        M(count)=getframe(gcf)
        count=count+1
    end
end
%creating movie file
movie(M)
videofile =VideoWriter('Forward_kinematics_2R_Robotic_arm.avi','uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
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.