FORWARD KINEMATICS OF A ROBOTIC ARM
FORWARD KINEMATICS OF A ROBOTIC ARM
AIM - To simulate forward kinematics of a 2-R robotic arm using MATLAB
OBJECTIVE
- Write a program to simulate the forward kinematics of robotic arm.
- Learn how to create a animation video in MATLAB.
GOVERNING EQUATIONS
(x0,y0) = Position of the base
Position of Link-1 (x1,y1)
x1= l1cosθ1
y1 = l1sinθ1
Position of Link-2 (x2,y2)
x2 = x1+l2cosθ2
y2 = y1+ l2sinθ2
PROGRAM CODE
EXPLAINATION
- First we put the input values i.e; length of both links
L1 = 1m
L2 = 0.5m
- Then we provide the theta values using the “linspace” command.
- Then we write the “For Loop” function so that for every value of 1 , rotates complete 90 degree.
- The loop repeats for all the 10 values of and plots a graph for each time.
- We provide the x and y axes limits .
- By using the “getframe” command we capture the graphs of each time and convert them into a single animation.
- Then we put the “movie(M)” command to convert the animation into a video file and then save it .
The saved video file extension also has to be specified ,in this case its”.avi”.s
% Program to show the forward kinematics of a 2-R Robotic Arm
% Inputs
l1=1;
l2= 0.5;
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
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 the arms of Robot
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',5)
axis([-0.1,1.5,0,1.5])
pause(0.03)
M(ct)= getframe(gcf);
ct = ct+1;
end
end
% Code for converting the plots into a video
movie(M)
videofile = VideoWriter('forward_kinematics.avi', 'Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
ERRORS –
- Incorrect spelling of command “movie” and “VideoWriter”
- The Error was rectified by rewriting the correct spelling of the commands.
- Incorrect syntax of command
The error was rectified by changing the spelling of gct to gcf and then re-running the program.
-
OUTPUTS- The following graphs represent the position of the links at different values of theta.
CONCLUSION- Hence, the simulation of the Robotic Arm is completed and the link is given below.