Project

Forward Kinematics of a 2R Robotic Arm

Forward Kinematics Simulator of a 2R Robotic Arm

Aim: To develop a MATLAB script to simulate the forward kinematics of a 2R robotic arm by simulating the profiles of the angles projected by the two linkages along with the x-axis. To utilize real time relative positions of the end points of the links as functions of the angle subjected by the links to the horizontal.

Method:

  1. By using vector decomposition, the end-point of link 1 or the start point of link 2 (X1, Y1) was computed relative to the start point of link 1(X0,Y0), where the datum was placed.
  2. Vector sum for the components of the two links was used to determine the end-point of link 2. (X2, Y2)
  3. The projected angles of the two links were simulated to take on range of angles between 0° and 90°.
  4. A MATLAB script was developed to iterate the profiles of the two links for iterations of first quadrant angles.
  5. To the purpose of step 4, a nested for loop was utilized to iterate between range of angles for link 2 for every iteration of the projected angle of link 1.
  6. A plot command was used to plot the profiles of the two links by plotting the start and end points of the links.
  7. Subsequently, a pause command is used to freeze frames in between iterations. Thus, an animation or frames of the generated profiles of the plots of the two links is generated thereby simulating the motion of the robotic arm.
  8. Thereafter, the ‘getframe’, ‘movie’, and ‘VideoWriter’ commands are utilized to stitch the frames of the generated profiles and subsequently, write the animation to desired format and name.
  9. Finally, the ‘open’ and ‘close’ commands were utilized to playback the movie of the generated animation once the plots simulation was complete.

Animation:

Code:

%%              Matlab for M.E.
%              Week 1 Challenge
%         Authored by Amandeep Singh

%% Forward Kinematics simulator of a Robotics Arm

clear all
close all
clc

%% Purpose:
% To develop a matlab animation simulating the forward kinenmatics or
% motion of a 2R robotic arm.

%% Apporoach
% utilize real time relative positions of the end points of the links as
% functions of the angle subjected by the links to the horizontal.
% The animation was created by plotting the varying positions of the links
% in real time, accomplished via a nested for loop and plot pause command
% Finally, getframe and videoWriter commands were utilized to create and
% write the animation to a movie playable via media. 
%% Inputs
l1 = 1; % length of link 1
l2= 0.5; % length of link 2
theta1 = linspace(0,90,30); % range of motion angle for link 1
theta2 = linspace(0,90,30); % range of motion angle for link 2

%% Setting up for loop for the variation in theta
counter = 1;   % counter for each iteration
for i = 1:length(theta1)  % for loop to iterate the position of link 1
    Theta1 = theta1(i);
    for j = 1:length(theta2)  % for loop to itereate the position of link 2 relevant to link 1
    Theta2 = theta2(j) ;       
    
    x0 = 0;  % start points of link 1
    y0 = 0;

   x1 = l1*cosd(Theta1); % end points of link 1 and start points of link 2
   y1 = l1*sind(Theta1);

   x2 = x1 + l2*cosd(Theta2); % end points of link 2
   y2 = y1 + l2*sind(Theta2);

    % Plotting
   
    plot([x0 x1], [y0 y1],[x1 x2], [y1 y2], 'linewidth', 4) %plotting the end points relative to the start point of link1
    axis([ 0 1.5 0 1.5])
    pause(0.01)% freezez the frames in between iterations
    M(counter) = getframe(gcf);  % captures the current figures generated at each count
    counter = counter + 1; % since we increase count for each subsequent iteration
    end    
end
movie(M) % generates a movie by stitching all the frames in the array M
videofile = VideoWriter('forward_kinematics', 'MPEG-4'); % writes the movie of M to videofile under name and file format
open(videofile) % after the animation movie is defined, opens the videofile
writeVideo(videofile,M) % writes the the animation to the videofile
close(videofile) % close after the animation is done playing, 
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.