All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
1. Aim: - To simulate the forward kinematics of a 2R Robotic Arm. 2. Objective: - Write a program in MATLAB to simulate the forward kinematics of a 2R Robotic Arm. Create an animation for the plot obtained in the MATLAB program. Understand the working of the robotic arm in the 2D workspace. 3. Theory: - …
Gaurav Hole
updated on 18 Jan 2022
1. Aim: -
To simulate the forward kinematics of a 2R Robotic Arm.
2. Objective: -
3. Theory: -
Forward kinematics refers to computing the position of the end-effector from specified values for the joint parameters. The essential concept of forward kinematic animation is that the positions of particular parts of the model at a specified time are calculated from the position and orientation of the object.
In this report for forward kinematics of the 2R robotic arm, we have used a simple robotic arm.
In the below figure
The 1st link was hinged to a fixed support with creating an angle of 45 degrees and a length of 1meter. The 2nd link was joined to 1stlink with joint with creating an angle of 30 degrees and length of 0.5 meter
Link 1st
Starting point (x0, y0) (0,0)
Ending point (x1, y1) (L1cos, L1 sin)
Link 2nd
Starting point (x1, y1) (L1cos θ, L1 sin θ)
Ending point (x2, y2) (x1+ L2 cos θ, y2+ sin θ)
4. Methodology: -
5. Detailed Procedure and Explanation: -
5.1 Calculating the position of Link-1
The initial value of X and Y for the 1st link (X0, Y0) and the final value is (X1, Y1)
X0=0
Y0=0
X1= L1* cosd(A1) [1]
Y1 =L1* sind(A1) [1]
We are using sind and cosd here because we are using the value in degree, not in radian. [1]
5.2 Calculating the position of the Link-2.
For the 2nd link, the starting point is the Ending point of the 1st link i.e. (X1, Y1) and the Ending point is (X2, Y2)
X2 = X1+l2* cosd(A2) [1]
Y2 = Y1+l2* sind(A2) [1]
5.3 Writing Basic Program.
To get the basic plot first We are Providing the basic input as
L1= 1 & L2=0.5 in meter
θ 1 = 45 & θ 2 = 30 in degree
for plotting, we are using the command Line not plot because the plot command gives us an error
Line ([ X0 X1], [ Y0 Y1])
Similarly,
Line ([ X1 X2], [Y1 Y2])
6. Program for basics plot: -
% Forward kinematics of a 2r robotics arm manipulator
clearvars
close all
clc
%Inputs
l1 = 1;
l2 = 0.5;
theta1 = 45;
theta2 = 30;
%Coordinates
x0 = 0;
y0 = 0;
x1 = l1*cosd(theta1);
y1 = l1*sind(theta1);
x2 = x1+l2*cosd(theta2);
y2 = y1+l2*sind(theta2);
%Plotting
line([x0 x1],[y0 y1],'linewidth',3,'color','b');
line([x1 x2],[y1 y2],'linewidth',3,'color','r');
6.1 Output of the program: -
But in this, we are not getting the animated plot to do that we are using a separate program in the next step.
7. Program for Arm Animation
7.1 Explanation: -
Here we are taking multiple angles and multiple values of (X, Y). Initially, we are providing the inputs for the angle with the help of linspace command as follows
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
In linsapce command
Linspace(X1,X2,N): - N is equally space value between X1 and X2.
To change the angle, we are using For-loop command as shown below.
for i = 1: length(theta2)
THETA1 = theta1(i)
THETA2 = theta2(i)
Now, here is the value of (i) changes we are taking the values of theta1, theta2 from the original arrays, and assigning them to the variable called THETA1, THETA2.
We use the value of (i) to take a particular value for theta1 and theta2 and then we are going to perform forward kinematics calculation hence, rearranging the Program in the following manners. for each value of theta1, each position of the link1, link2 can take multiple positions and which is depends on theta2.
for each value of angle1, we are looping the value of angle2, which is as follows.
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);
%plottig
line([x0 x1],[y0 y1],'LineWidth',3,'color','r');
line([x1 x2],[y1 y2],'LineWidth',3,'color','b');
end
end
7.2 Output for the above program
we got our first plot but it’s not an animation. As follow,
To animate we are adding figure(ct) before plotting and outside for-loop ct=1 And after the plot command type ct=ct+1
(i.e. we increment the value each time program gets executed in the for-loop) and execute the command we get 100 independent plots (because our theta1 value is 10 and theta2 value is also 10).
Therefore, we are using the plot command instead of the line. But we are only getting a single link plotted on the graph because MATLAB ren only the most recent command, so we are using the hold on command and pause command but it’s not as we are expecting.
Now we are going to remove the 2nd plot command and make the single plot command for two links as below,
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',3);
Now removing the hold on the command and including the axis command, adjusting the pause interval is gives us a better result.
for axis([-0.1 1.5 0 1.5]);
and for pause intervals as pause (0.03)
.
8. Movie for animation: -
To create movie type M(ct)=getframe(gcf)
just below the pause (0.03
) and at below end command type Movie(M)
Were,
ct
: - every frame
getfram
: - getting the current figure in the gcf
window.
Further, we are going to save all the figures in the array called (M).
to create a movie, we are using the following command,
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
8.1 Error and solution while programming: -
# 1st error
We are getting errors in the movie because we are saved all figures in the array (M) and we write it after the (ct) frame. it’s a wrong flow of code writing in MATLAB so we write array (M) before (ct)frame.
Solution: -
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'LineWidth',3);
axis([-0.1 1.5 0 1.5]);
M(ct)= getframe(gcf);
ct = ct+1;
pause(0.03);
#2nd error
while using the writeVideo
command and VideoWriter
command use it as it is because it is case sensitive hence any mistake can give an error in the program execution. Also, we can use Uncompress.AVI command but it gives us the large AVI file.
Solution: -
movie(M);
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
9. Final Program: -
% forward kinematics of a 2r robotics arm manipulator animation
clearvars
close all
clc
%inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
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)
10. Final output
https://drive.google.com/file/d/1dyWMZEvRCCPjwb03KHoR_TSgy5fZftqQ/view?usp=sharing
Hence, we are able to Program the 2R robotic Arm, with the help of this program. By small adjustments in the program, we can use it in multiple applications. such as by changing the Data in the below lines and small adjustments in the program we can get multiple outputs such as we can move the arm in multiple directions and multiple speeds.
theta1 = linspace(90,0,10);
theta2 = linspace(90,0,10);
for the above change commands output as follows,
https://drive.google.com/file/d/1Tl8o35yAvmu1CxbeOOnxFEvj0nWZSkJo/view?usp=sharing
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2-Highway Assistant-Lane Changing Assistant
AIM: - Develop model as per given requirement and generate AUTOsar software compile code. OBJECTIVE: - This model must be developed in MATLAB Simulink per MBD guidelines. Code Generation Profile must be Autosar Coder. Simulink Data Dictionary must be created for the model & must be linked to the model. All the input…
30 Apr 2022 02:11 PM IST
Project 1- Traffic Jam Assistant Feature
Aim: - To Build a Simulink model for Traffic Jam Assistant as per the requirement document and create requirements tagging. To check a model under standard guidelines with help of a model adviser. (MABB guidelines) To build an embedded code for the model. Objective: - Development of MATLAB Simulink model as per requirement.…
12 Apr 2022 07:35 AM IST
Project 2 Adaptive Cruise Control
Aim: - To Build a Simulink model as per the requirement document and create requirements tagging. To check a model under standard guidelines with help of a model adviser. (MABB guidelines) To build an embedded code for the model. Objective: - Developing Adaptive Cruise Control feature as per the Requirement Document using…
04 Apr 2022 08:35 AM IST
Project 1 (Mini Project on Vehicle Direction Detection
Aim: - To Build a Simulink model as per requirement document and create requirements tagging. To check a model under standard guidelines with help of model adviser. (MABB guidelines) To build an embedded code for model. Objective: - Development of MATLAB Simulink model as per requirement. Tag the requirements to the simulink…
01 Apr 2022 11:49 AM IST
Related Courses
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.