Challenge

Week 2- 2R Robotic Arm Challenge

AIM : TO SIMULATE THE 'FORWARD KINEMATICS' OF A 2R ROBOTIC ARM USING A MATLAB.

OBJECTIVE :

1. Write a program in matlab to 'SIMULATE FORWARD KINEMATICS' of a 2R robotic arm.

2. To create a animation and movie from their plot obtained through programing.

INPUTS :

(x0,y0) = strating point of the link

(x1,y1) = ending point of link 1, and starting point of link 2.

(x2,y2) = ending point of link 2.

l1 = length of link 1.

l2 = lenght of link 2.

theta1 = angle of link 1 with x-axis

theta2 = angle of link 2 with x-axis

2R ROBOTIC ARM ANIMATION LINK :

https://youtu.be/4KScXU201nk

PROGRAM :

close  all
clear all
clc

ct = 1;
% inputs
l1 = 1;
l2 = 1.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);

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],'linewidth',3,'color','b');
hold on
plot([x1,x2],[y1,y2],'linewidth',3,'color','r');
axis([-0.5 3 0 3]);
hold off
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)

EXPLANATION :

  • Start programming in MATLAB with three commands,as all the previous calculation are erased.
  • clear all : This command clears all the data stored in the workspace previously.
  • close all : this command closes all the previous figure and plots.
  • clc : this n command clears the command window.
  • We define all the inputs initially.
  • Firstly we define a length of the robotic arms, l1 and l2.
  • Set of values for theta1 and theta2, assigned in and array with linespace command.
  • Uses of for command for iterating the values of the desired variable.
  • Again we use for command for providing movement to the second robotic arm.
  • Defines the coordinates of both the robotic arms.
  • Plotting all the coordinates values and writingg command for changing the appearance of the contours.
  • All figures are assigned to a variable ,M, one at a time using ct followed by terminated of for loop.

In the last, movie command is used to combine all the figures saved in the M file to make an animation/movie and saving it in.avi format.

CONCLUSION :

Thus, to simulate and animation for forward kinematics of 2R robotic arm using MATLAB has been done.

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.