Project

Program in Matlab to simulate the forward kinematics of a 2R Robotic Arm.

OBJECTIVE :

  1. To write a program in Matlab to simulate the forward kinematic of a Robotic Arm with 2 linkages.
  2. To create an animation video of the plot

TERMINOLOGY:

Kinematics : A branch of mechanics that describes the motion of object without reference to the cause of motion.The word “kinematics” comes from a Greek word “kinesis” meaning motion.

Forward Kinematics : It refers to calculate the relation between end effector and joint angles in linkage. In forward kinematics the angle (θ-Theta) made by the joint angles is the input which can be used to determine the coordinate of the end effector.

PROGRAMMING IN MATLAB :

Inputs:

L1 = 3 m

L2 = 2 m

θ 1 = Range of values between 0 to 135 degree

θ 2 = Range of values between 0 to 90 degree

In forward kinematcs we can calculate the coordinate of the manipulator or end effector if the angle is given.

Coordinates for Link 1:

X0 Y0 - Initial coordinate of Link 1

X1 Y1 - Final coordinate of Link 1

Coordinates for Link 2:

X1 Y1 - Initial coordinate of Link 2

X2 Y2 - Final coordinate of Link 2

clear all
close all
clc
%Program in Matlab to simulate the forward kinematics of a 2R Robotic Arm
%Inputs
L1 = 3;
L2 = 2;
theta1 = linspace(0,135,22.5);
theta2 = linspace(0,90,10);

ct=1;
for i = 1:length(theta1)
    THETA1= theta1(i);
     for j = 1:length(theta2)
         THETA2= theta2(j);
         
         X0 = 0;
         Y0 = 0;
         X1 = X0+L1*cosd(THETA1);
         Y1 = Y0+L1*sind(THETA1);
         X2 = X1+L2*cosd(THETA2);
         Y2 = Y1+L2*sind(THETA2);
         
         plot([X0 X1],[Y0 Y1],[X1 X2],[Y1 Y2],'linewidth',4);
         axis([-3 6 0 7])
         pause(0.03)
         M(ct)=getframe(gcf);
         ct = ct+1;
         
     end
end

movie(M);
videofile = VideoWriter('ForwardKinematics_sim.avi')
open(videofile);
writevideo(videofile,M);
close(videofile);

EXPLANATION

  1. An array of theta 1 and theta 2 is generated using the linspace command.
  2. A frame counting variable ‘ct’ is set to start at vaue 1.
  3. 2 for loops are initiated such that for each value of theta 1 position of the links is calculated using value of theta 2.They are stored in variables THETA 1 and THETA 2 respectively for each iteration.
  4. A kinematic link graph is generated using the plot command. Value of axis is set for X and Y.
  5. An array M is created to store the image generated of the current frame using the ‘getframe(gcf)’ function.
  6. The VideoWriter command creates a video file with the name ‘ForwardKinematics_sim’ and saves it in .avi format.
  7. The writevideo command insert the frame stored in array M into the videofile.

ERRORS

Error 1:

  • This error was generated for not using , (comma) - delimiters.

Error 2:

  • Error was generate for not assigning the right array name to variable THETA2
  • Array name was created as 'theta2'.

Error 3:

  • Error was generated for assigning multiple input of X and Y values

RESULT:

A simulation video of forward kinematic of a robotic arm was created.

Youtube Link

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.