Project

Simulation/Forward Kinematics of a 2R Robotic Arm using MATLAB

Simulation/Forward Kinematic of a 2R Robotic Arm

Aim:-

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

Principle:-

Forward kinematics refers to the use of the kinematic equations of a robot to determine the position of the manipulator from specified values for the joint parameters. The kinematics equations of the robot are used in robotics and animation.

Theory:-

Robot kinematics refers to the analytical study of the motion of a robot manipulator, robotic arm is the most useful mechanical device which is used where accuracy and precision are needed. These things work similarly to the human arm and can be programmed as well. The traditional robotic arm will have n number of links, which are connected by joints with which links are rotated or translated. These links and joints form a Kinetic chain which has a Manipulator at the last link.

The above kinematics is made on Matlab Software

Steps Used-

Step 1 -: Calculating the position of Link 1

  • Calculating the Start Point and the End Point for link 1

Start Point = (x0,y0) =(0,0)

End Point =(x1,y1) = (L1cos(theta1),L1sin(theta1)

Step 2 -: Calculating the position of Link 2

  • Calculating the Start Point and the End Point for link 2

Start Point = (x1,y1) =(L1cos(theta1),L1sin(theta1))

End Point =(x2,y2) = (x1+L2cos(theta2),y1+L2sin(theta2))

Step 3 -: Calculating the Solution Set

[x0,y0],[x1,y1],[x2,y2]

Step 4 -:Plotting of a graph and its animation

We have used different values for each value of theta1 and theta2 for both links and stitch together to make an animation

_____________________________________________________________________________________________

CODE->

%Program with an animation plot forward kinematics of robotic arm
clear all
close all
clc
%Inputs
l1=1;
l2=0.5;

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

%For loop using
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);

%Plotting

plot([x0 x1],[y0,y1],[x1 x2],[y1,y2],'linewidth',3)
axis([-0.1 1.5 0 1.5])
pause(0.03)

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 of the above code -:

Comments are used to make the code user friendly

  • clear all - used to clear all the workspace variables
    close all - used to close all the plot output window
    clc - used to clear the command window
  • l1=1; - used to initialize the length of link 1 with 1m
    l2=0.5; - used to initialize the length of link 2 with 0.5m
  • theta1=linspace(0,90,10); - theta1 stores the value of angle of link 1
    theta2=linspace(0,90,10); - theta2 stores the value of angle of link 2

linspace command is used to greater 10 numbers between 0 to 90 with an equal interval or gap

  • For loop is used to repeat statements a specific number of times
  • ct =2 - counter is initialized to 1
  • for i=1:length(theta1) - for loop between 1 to length of theta1 range
    THETA1=theta1(i); - initialized value of different i values in THETA1
    for j=1:length(theta2) - for loop between 1 to length of theta1 range
    THETA2=theta2(j); - initialized value of different i values in THETA2
  • x0=0;
    y0=0;
  • x1=l1*cosd(THETA1); -cosd give the cosine value of THEATA1 in degree
    y1=l1*sind(THETA1); -sind give the sine value of THEATA1 in degree
  • x2=x1+l2*cosd(THETA2); - Intializing the x2 coordinate value
    y2=y1+l2*sind(THETA2); - Intilizing the y2 coordinate value
  • plot([x0 x1],[y0,y1],[x1 x2],[y1,y2],'linewidth',3)

plot method was used to generates xy plot , linewidth was used to give width to the line in the plot

  • axis([-0.1 1.5 0 1.5]) used to sets axis limits taken range (-0.1 to 1.5) for x axis and (0 to 1.5) for yaxis
  • pause(0.03) - is used to pause the video for 0.03 sec for smoother plotting and animation
  • M(ct) = getframe(gcf);

gets a frame from the figure or plot

  • end - used to terminate the for loop
  • movie(M) - plays the movie in matrix M once.
  • videofile= VideoWriter('forward_kinematics.avi','Uncompressed AVI') - additionally applies uncompressed avi properties to this video write data on avi file
  • open(videofile) - used to open videofile for writing video data
  • writeVideo(videofile,M) - to Write video data to file
  • close(videofile) - used to close file for writing video data

Result:-

Click on the link below to view the Simulation of the 2R Robotic Arm

Youtube link for an animation

https://youtu.be/PR3v3rtqLKs

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.