Challenge

Week 2- 2R Robotic Arm Challenge

1. Solution:- Need to write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video, and also need to create an animation file of the plot.

Explanation:-As we know that robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion or translational displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.

Forward kinematics refers to the use of the kinematic equations of a robot to compute the position of the end- effector from specified values for the joint parameters.

Robotic arms used in various industrial applications such as drilling, welding, metal cutting , painting etc.

we have a 2R Robotic arm as shown in the figure:

Here, the link-1 is attached to the base (hinged support) and end of link one is connected to link-2. And at the end of link-2 is connected to the end effector, which performs the desired operation. In this project we need to restrict the movement of the links in a 2D plane. That means we need to animate the arm and find out its behavior in different conditions. Our approach is to get the final program by doing a series of steps.

Step Wise Explanation:-

  • In input the length of both link1 and link2 are 1m and 0.5m taken respectively.
  • The angle traced by both the links are varied over a range to simulate the robotic arm.
  • In base position x0, y0 is taken as origin (0,0)
  • Now we used two for loop to iterate different angles for link1 and link2 both.

For a particular value of theta1 and theta2, the end position of link-1 is calculated by these equations. x1=x0+L1⋅cos(θ1)x1=x0+L1⋅cos(θ1)

y1=y0+L1⋅sin(θ1)y1=y0+L1⋅sin(θ1)

and the end position of link-1 is also at the start position of link two. The end position for link-2 is calculated by these equations.

x2=x1+L2⋅cos(θ2)x2=x1+L2⋅cos(θ2)

y2=y1+L2⋅sin(θ2)

  • Now we plotting various equation for the simulation of robotic arm
  • After that we need to combine all the captured frame to create a movie.
  • Now a videofile of ".avi" type is created to save the animated movie
  • after writing the movie in that video file, we closed the file and our animation is created.

Program for the 2R Robotic Arm :-

close all
clear all
clc
%  Program for the kinematices of robotices arm
%inputs
l1 = 1
l2 = 0.5
for i = 1: length(angle1)
A1=a1(i)                      % i.e ANGLE1 = angle1(i)
for j = 1: length(angle2)
A2=a2(j);                    % i.e ANGLE2 = angle2(j)
End
%coordinates
x0=0;
y0=0;
x1 = l1* cosd(A1);
y1 = l1* sind(A1);
x2 = x1+l2* cosd(A2);
y2 = y1+l2* sind(A2);
%plotting
line([x0 x1],[y0 y1])
line([x1 x2],[y1 y2])

In 1st attempt we got output for this Code is, that means the error we got:-

The Final code that we implemented :-

% A Program to animate Forward Kinematics of 2R Robotic Arm
clear        % Removing the variable from memory
close all    % Closes all plot
clc          % clearing the command window         

% Inputs
L1=1;        % Length of Link1
L2=0.5;      % Length of Link2
theta1= linspace(0,90,10);  % Angle traced by Link1 in degree
theta2= linspace(0,90,10);  % Angle traced by Link2 in degree
ct=1;        % Variables for frame is declared

% Here we used for loop to take different angle values
for i=1:length(theta1)
    Theta1=theta2(i);       % 
    for j=1:length(theta2)  % Taking particular angle traced by link-1 in order
        Theta2=theta2(j);   % Iterating all values of theta2 for all value of theta1
        x0=0;               % Initializing base condition for link1
        y0=0;               

        x1=L1*cosd(Theta1); % Calculating the x1 coordinates of end point of Link1
        y1=L1*sind(Theta1); % Calculating the y1 coordinates of end point of Link1
        
        x2=x1+L2*cosd(Theta2);% Calculating the x2 coordinates of end point of Link2
        y2=y1+L2*sind(Theta2);% Calculating the y2 coordinates of end point of Link2
        
        % Plotting various equation for simulation of Robotic arm
        plot([x0 x1],[y0 y1],[x1 x2],[y1  y2],'linewidth',3)
        axis([-0.1 1.5 -0.1 1.5]) % Axis is defined
        pause(0.03)               % give a pause for moving to the next plot
        M(ct)=getframe(gcf);  % Capturing the current plot for combining the later
        ct=ct+1;              % Incrment in thc ct for covering the all plot to M
    end
end 

movie(M);           % Making the movie from collected FRAME
% A video file is created of avi type to save animation
videofile=VideoWriter('ForwardKinenatics.avi','Uncompressed AVI');
open(videofile);    % opening of videofile 
writeVideo(videofile,M);% writing the movie in the created video file
close(videofile);   % video file is closed
 

Now the Final output that we got :-

1.

2.

Output Animation:-

The output is obtained in form of an animated video clip. This animation can be viewed by visiting the link mentioned below.

https://youtu.be/XLVNRFHmLnM

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.