Project

MATLAB program to simulate Forward Kinematics of a 2R robotic arm

AIM:

To write a Matlab program for simulating the motion of two R robotic Arm.

OBJECTIVE:

To get the various positions of robot arm manipulator to understand possible work areas and create an animation file to get a clear understanding.

clear all
close all
clc

%Program to simulate kinematics of 2 Arm Robot
%Initial Inputs

%Length of first arm L1
%Length of second arm L2

l1 = 1;
l2 = 0.5;

%angle of first arm with horizontal theta1
%angle of second arm with horizontal theta2

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

%For loop to get all possible positions of second link with respect to
%positions of first link

%counter statement for first figure
ct = 1; 
%for loop
for i = 1:length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
    THETA2 = theta2(j);
    
%starting point
x0 = 0;
y0 = 0;

%end points of first arm and starting point of second arm
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);

%end points of second arm
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);

%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
xlabel('x axis')
ylabel('y axis')
axis([0 1.6 0 1.6])
pause(0.03)
%saving the figures in array called M
M(ct) = getframe(gcf);
%incrementing the counter to get next frame after one is obtained
ct = ct+1;
    end   
end

%creating movie out of the frames
movie(M)
video = VideoWriter('forwards kinematics of robot','uncompressed AVI')
%writing all frames in video
open(video)
writeVideo(video,M)
close(video)

CODE EXPLANATION

Initial inputs are given like length of each arm L1 and L2 as one and a half unit respectively

“Linspace’ command is used to allot equally spaced respective angles of both arms with the horizontal direction to have a consistent input of the angles

For loop is used here to define all the unique inputs of theta2 for all the inputs of theta1. As we have allotted 10 values of theta1 and theta2, for each input of theta1 starting zero degrees, theta 2 will be executed for 10 times

Plot command is used to plot various co-ordinates of the links with unique angle inputs in a ‘for ‘loop shown above.

To make animation later we are saving all the unique plot figures in an array 'M’ and using counter command starting from the very first plot and incrementing it with one after one loop is executed.

Creating a movie with the frames stored in array ‘M’, ‘Videowriter’ command is used to name the ‘Video’ file created and profile type which is uncompressed AVI. Then all the frames in M are written in the file using ‘writevideo’ command

ERROR FACED

use of the wrong syntax while opening and closing of video file while writing the frames in the file

Correction measures are taken by removing the apostrophe sign in open and close command syntax

LINK FOR THE ANIMATION VIDEO

https://drive.google.com/file/d/1xxiudJQrszpTbZOqgUQAkKdlQnjb6Fi_/view?usp=sharing

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.