Project

Forward Kinematic Simulation of 2R Robotic Arm

%Forward Kinematic Simulation of a 2R Robotic Arm
clear all
close all
clc

%inputs 
l1=1;
l2=0.5;
theta1=linspace(0,90,20);
theta2=linspace(0,90,20);

%Co-ordinates
ct=1;
for i=1:length(theta1)
    THETA1=theta1(i);
    for j=1:length(theta2)
    THETA2=theta2(j);
    
    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],[x1 x2], [y1 y2],'linewidth',3)
    axis([-0.1 1.5 0 1.5]);
    pause(0.000001);
    
    M(ct)= getframe(gcf);
    ct=ct+1;
    
    end
   
end

%Animation
movie(M)
videofile=VideoWriter('Forward_Kinematic_Simulation.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M);
close(videofile);

Aim:

The aim of my program is to simulate the forward kinematics of a 2R robotic arm. Such a simulation will help one to visualize the exact motion of a robotic arm of any specific length and angular freedom, and to determine the work envelope for the robotic arm

Explanation of the code:

1. Inputs

The code starts by declaring the input variables which is required in the further calculations, namely lengths and angular freedom of both the arms

2. Co-ordinate Calculation:

In the next step, a logic is developed to determine the consecutive coordinates of the arms while they move in space. The logic is scripted in the MATLAB editor window in the standard MATLAB syntax. The logic relies on simple geometrical relations between the arms and a for loop is used to repeatedly execute the logic by plugging the updated variable in the equation for the required number of times.

3. Animation:

The required commands with proper syntax are declared to save the plot in terms of frames and are then made in a movie by putting them together. The clip is saved as a '.avi' file in the same location as that of the program on the computer

Errors Encountered:

1. Error due to a simple typographical error. The spelling of color was used as 'colour' which was the cause of the error.

2. Case Sensitive error due to capitalization of the first letter of the called functions

3. Error due to use of 'pause' command before the counter

4.Error in plotting due to use of 'sin' instead of 'sind' when the value is declared in degrees instead of radians

Steps Taken to Improve :

1. Typing carefully to ensure proper case and spelling

2. Checking if the units and operators correspond to each other or not

3. Keeping the indentation level of the loop constant to ensure a good structure of the code.

Conclusion:

The simulation of the robotic arm was successful, the plot was exported into a clip of a short length. A few errors were naturally encountered, which made the learning experience complete.

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.