Project

Simulate Forward Kinematics of a 2R robotic Arm with MATLAB

Aim: To write a program in MATLAB to simulate forward kinematics of a 2R robotic arm

Objective: 1. The main objective is to determine the motion of the robotic arm manipulator in its workspace using a MATLAB program.

2.Create an animation file for the robotic arm movement in its workspace

Theory

Forward kinematics is the use of kinetic equations of a robot to calculate the position of the end-effector for a specified value for the joint parameter. The kinematic equations are used in robotics, computer games, and animations.

The essential concept of forward kinematic animation is that the positions of particular parts of the model at a specified time are calculated from the position and orientation of the object, together with any information on the joints of an articulated model.

Software used:-MATLAB R2020

Code for the simulation

clear all
close all
clc

L1=4;
L2=2;

theta1=linspace(0,45,10);
theta2=linspace(0,90,30);
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);  %final x position for link 1& starting x position to link2
        y1=L1*sind(THETA1);   %final y position for link 1& starting y position to link2
        
        x2=x1+L2*cosd(THETA2); % final x position for link 2
        y2=y1+L2*sind(THETA2); %final y position for link 2
        
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
         pause(0.01)
         axis([-0 6 0 6])
         M(ct)=getframe(gcf);
         ct=ct+1;
    end
end
movie(M)
videofile=VideoWriter('robot_arm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)


Code Explanation

<!--[if !supportLists]-->1. 1.The length of the arms are assigned to variables L1&L2 where L1=4 & L2=2. Angles are defined as theta1 and theta2 respectively.

<!--[if !supportLists]-->2. 2.Angle 1 referring to theta1=linspace(0,45,10) where value varies from 0 to 45 degrees with 10 equally separated values. theta1 is the angle made by link 1 from the horizontal axis

<!--[if !supportLists]-->3. 3. <!--[endif]-->Angle2 referring to theta2=linspace(0,90,30) where value varies from 0 to 90 degrees with 30 equally separated values. theta2 is the angle made by link 2 from the horizontal axis

<!--[if !supportLists]-->4. 4. <!--[endif]-->for loop is used to compute the position of the arms at different angles. Different iterations are obtained for every varying theta value of theta1 & theta2

<!--[if !supportLists]-->5. 5. <!--[endif]-->We then plot the result .

<!--[if !supportLists]-->6. 6. <!--[endif]-->Counter denoted by ‘ct’ is set to 1. Counter helps in carrying out the iteration to get each plot for each position of links

<!--[if !supportLists]-->7. 7. <!--[endif]-->getframe’ is used to obtain new frames for each iteration.

<!--[if !supportLists]-->8. 8. <!--[endif]-->The frames are then stitched into an .avi format video .

Errors faced

Basic typing error. Forgot to give apostrophe for linewidth. Rectified in the image


Getting an incorrect plot when code executed.

Rectification:- The theta inside the loop was not changed and thus was giving that plot


<iframe frameborder="0" src="//www.youtube.com/embed/LDzN6s9usqE"></iframe>

Conclusions:- The movement of both the links is determined using MATLAB. It is a useful way of determining the movements of links in the determined workspace. Similar codes can also be used to determine the movement of robotic arms having more than two links

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.