Week 2- 2R Robotic Arm Challenge
MATLAB for Mechanical Engineers
AIM:To write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm
Robotics is an emerging field, As a mechanical enginner learning how to write simple programs to simulate robotic arms is a good skill set to have.
When we start learning Robotics,first we learn the kinamatics of the linkages.If we understand the kinamatics of the linkages we can write simple programes that simulate how the robot moves.It has lot of appications.If we know the robot is moved, than we can figur its workspace. Workspace refer to the possible location that the robot can reach.
Used in fields like welding a complex frame.
PROGRAM:
% Forward kinematics of a 2R robotic arm manipulator
clear all
close all
clc
%inputs
l1=3;
l2=2;
theta1=50;
theta2=20;
%coordinates
X0=0;
Y0=0;
X1=l1*cosd(theta1);
Y1=l1*sind(theta2);
X2=X1+l2*cosd(theta2);
Y2=X1+l2*sind(theta2);
%plotting
line([X0 X1],[Y0 Y1],'linewidth',2,'color','b')
line([X1 X2],[Y1 Y2],'linewidth',2,'color','r')
OUTPUT:

Explanation:
- we are here writing a program for robotic arm kinematics.
- First we are having the input values of l1 and l2. so lets first understand basic program of robotic arm and then come to final program.
- In the basic program we will given the first arm angle and second arm angle and we will see the corrseponding plot of the arm given first arm angle as 50 and second arm angle 20 and also the length of the two arms.
- since the arm (first) end is connected to second arm starting lets consider first arm starting point coordinates as x0,yo and ending point as x1,y1 and this x1,y1 coordinates will be given to the second arm starting point (sinces there are connected) and the ending of second arm as x2,y2.
now,
- x0=0,y0=0 (considering as base point)
- x1 y1 will be given as length of arm(l1)*cosd(theta) for x1and length of arm(l1)*sind(theta) for y1.
- Then we will calculate for x2=x1+length of arm*cosd(theta) and y2=y1+length of arm*sind(theta) .
This shows how the arms positions with respect to the given angles.
PROGRAM FOR 2R ROBOTIC ARM ANNNIMATION:
% Forward kinamatics for 2R robot and making the video of output
%inputs
%lengths
l1=3;
l2=2;
%angle
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);
%coordinates
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([-1 5 0 5])
pause(0.2)
m(ct) = getframe(gcf);
ct = ct+1;
end
end
% For makling the video file of the plot
movie(m)
videofile = VideoWriter('forward_kinamatics.avi','Uncompressed AVI');
open (videofile)
writeVideo(videofile,m)
close(videofile)
Explanation:
- This is the final program where we will slove for each angle of arm one how will the second arm tales the position.
- This can be done by using for loop.using for loops i.e., we are using the condition for every angle of arm 1 the second arm takes the position until the next angle of the first arm.
- Angle for first arm have 10 angles (from 0 to 90). for these every angle between 0 to 90 of fitst angle the second arm takes the angles 0 to 90.
- The conditons goes like these:for each one valuse of angle of first arm angle of second arm goes from 0 to 90 and the loop cloise for first angle of first.
GOOGLE LINKS:
FIRST PROGRAM:https://drive.google.com/file/d/1_KJHsu4wl3O9iVwGescX1czaYZRD7jJH/view?usp=sharing
SECOND PROGRAM: https://drive.google.com/file/d/1h9e4X7rbh17G4UkoeTAdDV_UAmdd2z_k/view?usp=sharing