Challenge

Week 2- 2R Robotic Arm Challenge

FORWARD KINEMATICS OF A 2R ROBOTIC ARM.”
i. To write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.
ii. Create an animation file of the plot.

1. Basic:-

1.1 Concept of kinematics:

In Kinematics only Velocity and Acceleration Analysis of various parts are to be done. Forces are neglected.

1.2 The origin of Robotics and linking with humans:

The links are the smallest unit of the Machine, similar to the cell in the Human Body. By a combination of the link, pair is formed and pair together forms a chain which further causes linkage formation, and at last, the combination of Linkage (also known as Mechanism) forms Machine. The Machine is the basis of the Robotics. The simplest explanation for the origin of Robotics/machines and linking with Humans is as follows.


1.3 Mechanical linkage:

A mechanical linkage is an assembly of bodies connected to manage forces and movement. The movement of a body, or link, is studied using geometry so the link is considered to be rigid. The connections between links are modeled as providing ideal movement, pure rotation, or sliding for example, and are called joints. A linkage modeled as a network of rigid links and ideal joints is called a Kinematic chain. For example, The basic linkage mechanism in practice is a deployable mirror linkage constructed as shown below.


1.4 Approach:

In our Project, we are going to use the basic arms of the robot to do that we are dealing with the linkage known as Forward kinematics of a 2R Robotic arm (where 2R means 2-rotating Link i.e 2 is a number of links and R is rotation). we are taking two links as a representative of the Robotic arm in which Link-1 is Hinged at (X0, Y0) and making an angle(theta1), while Link-2 is hinged at the end of the Link-1 and making an angle(theta2).


We need to Animate the Arm and find out its behavior under different conditions. Our Approach to Getting the final Program and a series of steps that we will perform during the entire Problem is shown below in the Step chart.


2. Detailed Procedure and Explanation:-

2.1 Procedure and Explanation for Matlab:

Step-1: Calculating the position of Link-1.

From the fixed Support, the initial value of X and Y for the Link-1 (X0, Y0) and the final value is (X1, Y1)

X0=0

Y0=0

Link1 length L1=1

X1= L1* cosd(theta1)

Y1 =L1* sind(theta1)

* Here sind and Cosd denotes the value in degrees

Step-2: Calculating the position of the Link-2.

For the Link-2 starting point is the Ending point if the Link-1 ie (X1, Y1) and the Ending point is (X2, Y2)

Link2 length L2=0.5

X2 = X1+L2* cosd(theta2)

Y2 = Y1+L2* sind(theta2)

where angle1=theta1

and angle2=theta2

Step-3: Writing Basic Program.

Basic Program represents the basic idea about the plot where we get only 2D plot but no animation.

To get the basic plot first We are Providing the basic input as L1= 2 and L2=1

In meters also theta1 = 45 and theta2 = 30 in degree


And providing basic condition as above in step-1 and step-2, and for plotting we are using the command Line not plot because plot command gives us an error

Link1 ( [ X0 X1 ], [ Y0 Y1 ] )

Similarly,

Link2 ( [ X1 X2], [Y1 Y2] )

close all
clear all
clc
% Program for the kinematices of robotices arm
%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)
%ploting
line([x0 x1], [y0 y1],'linewidth', 3, 'color' ,'r')
line([x1 x2], [y1 y2],'linewidth', 3, 'color' ,'b')
The output of the Programm is a simple plot as shown below.


But in this, we are not getting the animated plot to do that we are using a separate program in the next step.

Step-4: Program for Arm Animation and Error Elimination.

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

Angle1 = linspace (0 , 90, 10)
Angle2 = linspace (0, 90, 10)
Where:-

In linsapce command the first value represents the starting point of the angle, similarly, the second point represents the ending point of the angle and at last, the third point represents the number of values between them

To change the angle we are using For-loop command as shown below.

for i = 1: length(theta1)
THETA1 = theta1(i)
THETA2 = theta2(i)

Now, here is the value of (i) changes we are taking the values of theta1 and 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 manner. for each value of theta1, each position of the link1, link2 can take multiple positions and which is depend’s on theta2.

Further, if it is THETA1 then THETA2 required another for-loop. 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);
End
for kinematic calculation, we are copying our first program below the line THETA2 = theta2(j) and change the angle to ANGLE accordingly as follows.

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])
line([x1 x2],[y1 y2])
we got our first plot but not animation as follows.


To eliminate this we are typing 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 executing the command we get 100 independent plots (because our angle1 value is 10 and angle2 value is also 10).

Therefore to get rid of this we are using plot command instead of line command.

line([x0 x1],[y0 y1])

line([x1 x2],[y1 y2])

Again we get the same result but the most recent link as a plot result. To prevent this we are using the hold on and pause command. Here we get the result as a 1st result (error) but animated.

Now we are going to remove the 2nd plot command and make the first plot as below

plot([x0 x1],[y0 y1],[x1 x2],[y1 y2])

we get an animated plot with random color changes as shown below.


Now removing the hold on the command and including the axis command, adjusting the pause interval gives us a better result.

for axis([-0.3 3.6 -0.3 3.6]) and for pause interval as pause (0.1). we get our Required Result but further, we need to make a movie of it, which is the next step.

Step-5: Creating a movie.

To create movie type M(ct)=getframe(gcf) just below the pause(0.01) and at extreme end command type Movie(M)

Where:- ct represents every frame and getframe command represents getting the current figure in the gcf window. Further, we are going to save all the figures in the array called (M).

Further, we are creating avi file to get this we are using following commands.

Movie(M)

videofile = VideoWriter(‘forward_kinematics.avi’);

open(videofile)

writeVideo(videofile, M)

close(videofile)

Note:- while using the writeVideo 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 command but it gives us the large avi file. Hence in this program, we are not using it.


The final program is as shown below:

clear all
close all
clc
% Inputs
L1=2;
L2=1;
theta1 = linspace(90,0,10);
theta2 = linspace(90,0,60);
ct=1;
for i= 1:length(theta1) %represents the no of value in angle1
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.3 3.6 -0.3 3.6])
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)

=> I am unable to attache the video file

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.