Challenge

Week 2- 2R Robotic Arm Challenge

close all
clear all
clc
% To simulate the forward kinematics of a 2R Robotic Arm
% Initially we should assume some values is as following :

% Length of Link 1 (m)
L1 = 1;
% Length of Link 2 (m)
L2 = 0.5;
% Angle for link 1  (Degree)
theta1 = linspace(0,90,10);
% Angle for link 2  (Degree)
theta2 = linspace(0,90,10);
ct = 1 
for i = 1:10
    THETA1 = theta1(i);
    for j =1:10
        THETA2 = theta2(j);
         % Co-ordinates at the base of 1 st link
         X0 = 0
         Y0 = 0
         % Co-ordinates at the base of 2 nd link or at the end of 1 st link
         X1 = L1*cosd(THETA1);
         Y1 = L1*sind(THETA1);
         % Co-ordinates at the end of 2 nd link
         X2 = X1 + L2*cosd(THETA2);
         Y2 = Y1 + L2*sind(THETA2);
         % Plotting 
         
         plot([X0 X1],[Y0 Y1],[X1 X2],[Y1 Y2],'LineWidth',3);
         axis([-1 1.5 0 1.5])
         pause(0.05)
         M(ct) = getframe(gcf)
         ct = ct + 1
         
    end
end
movie(M)
videofile = VideoWriter('Forward_kinematics_of_a_2R_Robotic_Arm.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

EXPLANATION:

Assumption done initially is explained as following :

1) % Length of Link 1 (meter) assumed as
L1 = 1;
% Length of Link 2 (meter) assumed as
L2 = 0.5;

2) % Angle for link 1 (Degree)
theta1 = linspace(0,90,10);
% Angle for link 2 (Degree)
theta2 = linspace(0,90,10);

'Linspace' command is used for showing (X1,X2,n) angles bet 0 to 90 degree with equally spaced for 10 nos.Theta is the angle between link and imaginary horizontal plane parallel to x axis .

3) for i = 1:10
THETA1 = theta1(i);
for j =1:10
THETA2 = theta2(j);

For loop is used for showing angles in a sequence from 1 to 10. Eg :(0,10,20,30,40,50,60,70,80,90)

4) % Co-ordinates at the base of 1 st link
X0 = 0
Y0 = 0
% Co-ordinates at the base of 2 nd link or at the end of 1 st link
X1 = L1*cosd(THETA1);
Y1 = L1*sind(THETA1);
% Co-ordinates at the end of 2 nd link
X2 = X1 + L2*cosd(THETA2);
Y2 = Y1 + L2*sind(THETA2);

As assumption according to theta length of link in x & y axis is calculated and formulated

5) plot([X0 X1],[Y0 Y1],[X1 X2],[Y1 Y2],'LineWidth',3);
axis([-1 1.5 0 1.5])
pause(0.05)
ct = ct + 1
M(ct) = getframe(gcf)

Plotting of graph is generated using x & y co-ordinates ,with pause command for playback time ,axis for representation coordinates

6) movie(M)
videofile = VideoWriter("Forward_kinematics_of_a_2R_Robotic_Arm.m")
open(videofile)
writeVideo(videofile)
close(videofile)

Above commands will remain same for creation of animation .

ERRORS:

Solution :

% Co-ordinates at the base of 2 nd link or at the end of 1 st link
X1 = L1*cosd(THETA1);
Y1 = L1*sind(THETA2);
% Co-ordinates at the end of 2 nd link
X2 = X1 + L2*cosd(THETA1);
Y2 = Y1 + L2*sind(THETA2);

Steps taken to overcome errors

% Co-ordinates at the base of 2 nd link or at the end of 1 st link
X1 = L1*cosd(THETA1);
Y1 = L1*sind(THETA1);
% Co-ordinates at the end of 2 nd link
X2 = X1 + L2*cosd(THETA2);
Y2 = Y1 + L2*sind(THETA2);

https://youtu.be/zCFdsS1mh44

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.