Simulate the forward kinematics of 2R robotic Arm
AIM: Write a program in matlab to simulate the forward kinematics of 2R robotic Arm.
KINEMATICS:
Kinematics is a classical mechanics that describes the motion of points, bodies (objects), and systems of bodies (groups of objects) without considering the forces that cause them to move. To also describe motion, kinematics studies the trajectories of points, lines and other geometric objects.
ROBOT KINEMATICS:
study of the movement of multidegree of freedom kinematic chain that form the structure of robotic systems or study of the motion of a robot manipulator. Joining of two point make the link (arm), this arms perform the rotation or translation motion or transformation between Cartesian coordinate systems can be decomposed into a rotation and a translation, to design a Kinematics models for a robotic mechanism is very crucial for analysing the behaviour of industrial manipulators. Robot kinematics can be divided into two part forward kinematics and inverse kinematics.
FORWARD KINEMATICS:
Forward kinematics is use to kinematic equations of a robot and to compute the position of the end effector from specified values for the joint parameters or to calculating the position and orientation of the end-effector in terms of the joint variables is called as forward kinematics. It is a symmetric model and to solve the straightforward problem, no complexity deriving the equations.
INVERSE KINEMATICS:
Kinematics is the science of motion. In a two-joint robotic arm, given the angles of the joints, the kinematics equations give the location of the tip of the arm. Inverse kinematics refers to the reverse process. Given a desired location for the tip of the robotic arm, what should the angles of the joints be so as to locate the tip of the arm at the desired location. There is usually more than one solution and can at times be a difficult problem to solve.
DIAGRAM:
INPUT DATA:
θ1 = Angle between base (x0,y0) and link (x1,y1)
θ2 = Angle between link 1 (x1,y1) and link 2 (x2,y2)
L1 = length of link 1
L2 = length of link 2
Where,
(x0,y0) - Coordinates for link 1 with base
(x1,y1) - Coordinates at where both link 1 and link 2 are connected
(x2,y2) - Coordinates at the end of link 2
X0 = 0 Y0 = 0
X1 = L1. Cos (θ1) Y1=L1. Sin (θ1)
X2=X1+L2. Cos(θ2) Y2=Y1+L2. Sin(θ2)
CASE 1
To plot a one graph to generate a two link, angle is theta1=45 and theta2= 30
PROGRAM:
clear all
close all
clc
%inputs
%lengths of the links (arm) in meters
%ARM 1
l1 = 2
%ARM 2
l2 = 1
%angles
theta1 = 45
theta2 = 30
%Coordinates of starting point of Arms(link) 1
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','r')
line([x1 x2],[y1 y2],'linewidth',3,'color','b')
xlabel('x axis')
ylabel('y axis')
WORK SPACE:
OUT PLOT FOR CASE1
CONCLUSION
From the above figure we conclude that can the difference between the two arms
Explanation to the Code:
- The input values such as length l1,l2 is 2,1 and the angle theta 1,2 is 40,30.
- Initially the coordinates values are mentioned in x0 y0,x1 y1, x2 y2.
- The length of the link1 is between the base link and link2.
By plotting the graph with the above mentioned angle values we can obtain all the values and the variations made.
CASE 2
To generate the graphical animation for variation of theta value
PROGRAM:
clear all
close all
clc
%inputs
%lengths of the links (arm) in meters
%ARM 1
l1 = 2
%ARM 2
l2 = 1
%angles
theta1 = linspace(30,60,10);
theta2 = linspace(30,60,10);
ct = 0;
for i=1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
%Coordinates of starting point of Arms(link) 1
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 3 0 3])
pause(0.03)
ct = ct+1
M(ct)= getframe(gcf)
end
end
%movie(M);
videofile = VideoWriter('C:\Users\Ramachal Pandey\Desktop\roboarm.avi','uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
WORK SPACE:
OUT PLOT FOR CASE2 (YOUTUBE LINK)
https://youtu.be/rzkZCo9m3C8
CONCLUSION
We are conclude that the animate the forward kinematics of 2R Robotic arm using matlab calculation and explained the proper values.
Explanation to the Code:
- Define the lengths of the links, angles and coordinates and declared counter variable ‘ct’.
- Once the variables are declared, To assigned the value of the variables. The angles are assigned values with help of linspace command as we consider 10 positions of each link between 30º and 60º.
- As we require the link at multiple positions i.e. rotate it. A for loop is written for link 1 and a similar for loop is written for link2 under the first for loop (As the link 2 has to rotate by 60º for every position of link1 from 30° to 60º).
- Now under the for loop we define the coordinates (X1, Y1) and (X2, Y2) using the equations:
X1 = L1. Cos (θ1) Y1=L1. Sin (θ1)
X2=X1+L2. Cos(θ2) Y2=Y1+L2. Sin(θ2)
- The plot command is used to plot the links on the graph. And to animate the plot, getframe command is used (getframe returns a movie frame.
- Both for loops are then ended and the syntax for movie this written.
Syntax for the movie:
%movie (M) it define the command because it not define the program.
videofile=VideoWriter ('Desktopsaveposition videoname.avi', file type) % assigns file name and file format
open(videofile) %opens the videofile
writevideo (videofile, M) %writes the video with plot frames in the array M
close(videofile) %closes the videofile