Week 3.2 - 2R Robotic Arm Challenge
Objective:- Simulating forward kinematics of a 2R Robotic arm using MATLAB program.
Theory:-
A robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints moving in either rotational motion or translational displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand. Forward kinematics refers to the use of the kinematics equations of a robot to compute the position of the end-effector from specified values for the joint parameters.
Construction of robotic ARM:-
- Let, l1 & l2 be the length of the link -1 & link-2 respectively.
- Let, theta 1 > be the angle formed by link-1 with horizontal.
- Let, theta 2 > be the angle formed by link-2 with horizontal.
- Let, the starting and end coordinates of link - 1 to be (x0, y0) and (x1, y1).
- Let, the starting and end coordinates of link - 2 to be (x1, y1) and (x2, y2).
MATLAB Program:-
%to animate the plot with robotic arm program
clear all
close all
clc
%Inputs
%Length of Link(L1) and Link((L2) in meter
l1= 1;
l2=0.5;
%angle traced by link-1 in degrees (theta1)
theta1 = linspace(0,90,40);
%angle traced by link-2 in degrees (theta2)
theta2 = linspace(0,90,40);
ct=1;
for i= 1:length(theta1)
THETA1 = theta1(i); %taking particular values of angle traced by link-1 in order.
for j=1:length(theta2) %Iterating all values of theta2 for particular value of theta1
THETA2=theta2(j); %taking particular values of angle traced by link-2 in order.
%Initialising the base coordinates of link-1
x0 = 0;
y0 = 0;
%Calculating the coordinates of end point of link-1
x1 = l1*cosd(THETA1);
y1 = l2*sind(THETA1);
%Calculating the coordinates of end point of link-2
%End coordinates for link-1 are the start coordintes for link-2
x2 = x1+ l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
%plotting the robotic arm for simulation
plot([x0 x1], [y0 y1], [x1 x2], [y1 y2], 'linewidth',3);
%Pausing the current plot for a while before moving to the next
%plot
axis([-0.1 1.5 0 1.5]);
pause(0.03);
%Capturing the current plot to combine later
M(ct) = getframe(gcf);
%Incrementing ct so that each frame is captured in M
ct = ct+1;
end
end
%Making a movie from collected frames
movie(M)
%Creating a videofile of '.avi' format to save the animation
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
%writing the movie in videofile created
open(videofile);
writeVideo(videofile, M);
close(videofile);
Code explanation;
- Providing the input variables like.
- Predefining the length/values of the robotic arms.
- Providing the values for theta – 1, and theta – 2 using linspace command for theta = 0 to 90 degrees for 15 values.
- Providing the cr (compression ratio) value as a specific digit.
- Now use the ‘for’ command for iterating the values of the desired variable.
- Again use the ‘for’ command to provide movement to the second robotic arm.
- Providing the Eqn for the x1, y1, x2, y2 or say defining the coordinates of both the robotic arms.
- Plotting all the coordinates values and providing the axis no.
- Using the pause command to make the plot look realistic.
- Incrementing the cr or compression ratio value by +1 each time it executes for a loop.
- All figures are assigned to a variable M, one at a time using cr.
- Enabling the ‘for’ loop twice.
- At the end saving the movie in .avi format.
Output:-
Video Link:- https://youtu.be/fssr4BOB0lg