Challenge

Week 2- 2R Robotic Arm Challenge

Aim:Simulate the forward kinematic of a 2R robotic arm using Matlab.

Theory:

Sir,in kinematics basically velocity and acceleration comes in consideration and force are neglected.So we are going to basic arms of robot dealing with forward kinematics of 2R robot.

where 2R means 2rotating links i.e 2 number of links and R is rotation.

calculation for link1

x0=0

y0=0

x1=l1*cosd(theta1)

y1=l1*sind(theta1)

calculation for link2

x2=x1+l2*cosd(theta2)

y2=y1+l2*sind(theta2)

where

x0,y0=starting point of link1

x1,y1=ending point of link 1 & starting point of link2

x2,y2=ending point of link2

theta1=angle1 with respect to x-axis

theta2=angle2 with respect to x-axis

1.basic program of forward kinematics of 2R robotic arm

clear all
close all
clc

%forward kinematics of 2R robotic arm
%Inputs
l1=1.5;
l2=1;
theta1=60;
theta2=30;
%co-ordinate
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','g')

the above is the output of program.

2.program for arm animation

consider a different angle and different value x and y so that we can simulate a arm.

with the help of linspace command we can provide different angle

theta1=linspace(0,90,10)

theta2=linspace(0.90.10)

for changing the value of angle use for loop command as follows:

for i=1:length(theta1)

THETA1=theta1(i);

for j=1:length(theta2)

THETA2=theta2(j);

end

here we using two time for loop because we have two angle for two links for each angle we need for loop command to assigned the value of different angles.

for forward kinematics copying my above program

now i am explaining my errors and solution slide wise given below

i am getting error while executing the program my expression definition is wrong in linspace function i am using

linspace(0.90.10) instead of linspace(0,90,10) matlab not recognise which one is starting angle and which one is ending angle as per the linspace function definition.

now below slide i am resolving this problem but also getting error

now in next slide i am resolving above error

now resolving further error also getting error because we want robotic arm angle wise graph but this is not done yet because my for loop start at angle1 and end at angle2 and the length of link not calculated because end operator is used above the link calculation.

next step i resolve my further error

we got our first plot but not animated.

to eliminate this now that we using figure ct

where ct=counter

ct is use before the for loop and define ct=1

after the plot command type ct=1

and after executing the program we get 100 independent plot because angle1 value is 10 and angle 2 value is 10.

so to get rid of this line plot we use instead of

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

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

using

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

after that we use

axis([-0.1 2.5 0 2.5])

this axis command logic varies with respect to link of length for example

l1=3

l2=2.5

for plotting the graph value should be greater than length of link

axis([-0.1 3.5 0 3.5])

below code is for animation

clear all
close all
clc

%inputs
l1=2;
l2=1;
%co-ordinate
x0=0;
y0=0;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
ct=1

for i=1:length(theta1)
    Theta1=theta1(i);
    for j=1:1:length(theta2)
        Theta2=theta2(j);
    

   

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 2.5 0 2.5])
pause(0.1)
ct=ct+1;
    end
end

    

final step creating a movie

for creating movie we use

M(ct)=getframe(gcf);

movie(M)
videofile = VideoWriter('forward_kinematic2.avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)

now my program is

clear all
close all
clc

%inputs
l1=2;
l2=1;
%co-ordinate
x0=0;
y0=0;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
ct=1

for i=1:length(theta1)
    Theta1=theta1(i);
    for j=1:1:length(theta2)
        Theta2=theta2(j);    

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 2.5 0 2.5])
pause(0.1)
M(ct)=getframe(gcf);
ct=ct+1;
    end
end
movie(M)
videofile = VideoWriter('forward_kinematic2.avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)


    

sir below is the google drive link for animation of link

https://drive.google.com/file/d/1vTI036_HhadIICP-LvT1PfSpQpQrL5eW/view?usp=sharing

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.