Forward Kinematics of 2R Robotic Arm
%simulation
clear all
close all
clc
%inputs of lengths of arm and angle traversed by them
l1=2;
l2=1;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
ct=1;%a counter has been created to store each frame as per counter no. and then increament
for i=1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
x0=0;%this gives the starting postion about which link 1 rotates
y0=0;
x1=l1*cosd(THETA1);%this coordinate defines the postion of other end of link 1
y1=l1*sind(THETA1);%and the startingpoint of link 2
x2=x1+l2*cosd(THETA2);%this coordinate defines the other end of link 2
y2=y1+l2*sind(THETA2);
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis([-1 4 -4 3])
M(ct)=getframe(gcf) %it is used to store the frame to create a movie
ct=ct+1;
end
end
%to create a video
movie(M)
videofile=VideoWriter('arm_manipulator.avi','uncompressed avi')
open(videofile)
writeVideo(videofile,M)
close(videofile)
This program is used to show the workspace covered by robotic arm and angle traversed by it through a simulation.
We define the length of links and decide the limits of angle which both the links of robotic arm has to cover.
We define coordinates of end points of both the links using polar coordinates system
Using these coordinates we make a plot of robotic arm where we store every frame using 'M' and these frames help us to create a movie.
Using movie command we combine these various iterations frames of theta 1 and theta 2.
We give the name to the file and file format for the video.
Using open command we open the file, using writeVideocommand we write into the assigned file and ultimately close command to close the file.