Challenge

Week 3.2 - 2R Robotic Arm Challenge

AIM :-

Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.

OBJECTIVE:-

  • Write a program to simulate forward kinematics of a 2R Robotic Arm
  • Animating and creating a movie from the plots obtained from the program

INPUTS:

(x0, y0) = starting point of link1

(x1, y1) = end point of link1 / starting point of link 2

(x2, y2) = end point of link 2

l1 = length of link attached to the base

l2 = length of link between the first link and the end effector

theta1 = angle made by link 1 with x-axis

theta2 = angle made by link 2 with x-axis

Coding logic:-

close all
clc

% Inputs
l1 = 1;
l2 = 0.5;
x0 = 0;
y0 = 0;


theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);

ct=1;

for i = 1:length(theta1)
    for j = 1:length(theta2)


        x1 = l1*cosd(theta1(i));
        y1 = l1*sind(theta1(i));
        
        x2 = x1 + l2*cosd(theta2(j));
        y2 = y1 + l2*sind(theta2(j));

       %Plotting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([0 1.5 0 1.5])
        pause(0.003)
        
      %title
      title('2R Robotics Animation')
      M(ct)=getframe(gcf);
      ct=ct+1;
      

    end
end
        
      movie(M)
      videofile=VideoWriter('Forward Kinematics')
      open(videofile)
      writeVideo(videofile,M)
      close(videofile)
     
      

Explanation of the coding logic :-

  • Initially we define the length of the robotic arms, i.e. l1 and
  • Set of values for theta1 and theta2 are assigned in and array with linspace command.
  • Use of for command for iterating the values of the desired variable.
  • Again using for command for providing movement to the second robotic arm.
  • Defining the coordinates of both the robotic arms.
  • Plotting all the coordinate values and writing commands for changing the appearance of the contours.
  • All figures are assigned to a variable M, one at a time using ct followed by termination of for loop.
  • Lastly, movie command is used to combine all the figures saved in the M file to make an animation/movie and thereafter saving it in .avi forma

Error faced while programming :-

The one error is found in the programming is Line no 34- M(ct)

The steps are taken for that to overcome the errors are ct enter into Line no- 15

Results :

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

Conclusion:-

A practical scenario regarding the functioning of the robotic arm and its workspace has been experienced by simulating the forward kinematics with a program in MATLAB.

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.