Challenge

Week 2- 2R Robotic Arm Challenge

Objective:

         To write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm and create an animation file on the plot.

Theory:

         Kinematics is a subfield of physics, developed in classical mechanics, that describes the motion of points, bodies, and systems of bodies without considering the forces that cause them to move.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.

         We can obtain the calculations and figure out the position and orientation of any point on the robot, if we know the geometry and the every single joint points. We can know about the workspace of the manipulator, if we are able to know about how the robot is going to move.

Matlab program:

% A program to simulate the forward kinematics of a 2R Robotic Arm
clear all
close all
clc

% Inputs

l1 = 1;
l2 = 0.5;

theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);


ct = 1;
for i = 1:length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        x0 = 0;
        y0 = 0;

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

        x2 = x1+l2*cosd(THETA2);
        y2 = y1+l2*sind(THETA2);
        
        
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 1.5 0 1.5])
        pause(0.1)
        M(ct) = getframe(gcf)
        ct = ct+1;
    end

end
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

Explanation:

 clear - This MATLAB function removes all variables from the current workspace, releasing them from system memory.

close - This MATLAB function closes the current figure.

clc - This MATLAB function clears all the text from the Command Window, resulting in a clear screen.

l1 - Length of the first link is denoted by l1.

l2 - Length of the second link is denoted by l2.

theta1 - Angle made by the link 1 with ground is indicated by theta1.

theta2 - Angle made by the link 2 with horizontal is theta2.

linspace - This MATLAB function returns a row vector of 100 evenly spaced points between x1 and x2.

ct - 

for - This MATLAB function executes a group of statements in a loop for a specified number of times.

i - Index denoting the value of theta1 array.

j - Index denoting the value of theta2 array.

length(theta1) - It indicates the number of values in the array theta1.

length(theta2) -  It indicates the number of values in the array theta2.

THETA1, THETA2 - It indicates the single values from the array of theta1 and theta2 respectively.

x0, y0 - This denotes the coordinates of the base.

x1, y1 - It denotes the coordinates at the end of first link and starting of the second link.

x2,y2 - It denotes the coordinates of the manilpulator.

plot - This MATLAB function creates a 2-D line plot of the data in Y versus the corresponding values in X.

linewidth - Line width is used to adjust the width of any line in the graph. Line width operation mostly executes inside the plot operation.

axis - This MATLAB function specifies the limits for the current axes.

pause - This MATLAB function pauses the playback or recording.

M(ct) - This is the array in which the figure indicating to the first value of theta1 array is recorded.

getframe - This MATLAB function captures the current axes as it appears on the screen as a movie frame.

end - This function indicates the end of the for loop.

movie - This MATLAB function plays the movie frames in array M once.

VideoWriter - VideoWriter object is used to create a video file from an array or MATLAB movie.

open(videofile) - This MATLAB function opens the specified file or variable in the appropriate application.

writeVideo - This MATLAB function writes data from an array to the video file.

close(videofile) - This MATLAB function indicates to close file after writing video data.

Result:

        The google drive link of the animation file is shown below.

 https://drive.google.com/file/d/1Ype5nbIs8gdzW7siuEnBdHnypq49e6N8/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.