Simulation of Forward kinematics of a 2R Robotic Arm
AIM
To simulate the forward kinematics of a 2R Robotic Arm.
OBJECTIVES
- To simulate the forward kinematics of the 2R Robotic Arm and create an animation.
THEORYForward kinematics for a robot arm takes as input joint angles, and calculates the Cartesian position and orientation of the end effector.
This allows us to know about the reach of the arm within the workspace.
It is calculated by taking the co-ordinates of the starting and ending point of the links at different angles of the links with x-axis.
L1=Length of Link 1
L2=Length of Link 2
Θ1(theta1)=Angle made by Link 1 with x-axis
Θ2(theta2)=Angle made by Link 2 with x-axis
Points-
(X0,Y0)=starting point of Link 1
(X1,Y1)=ending point of Link 1 and starting point of Link 2
X1=L1*cosΘ1 ; Y1=L1*sinΘ1
(X2,Y2)=ending point of Link 2
X2=X1+L2*cosΘ2 ; Y2=Y1+L2*sinΘ2
INPUT DATA ASSUMED
(X0,Y0)=(0,0)
Length of first link, L1=1 m
Length of second link, L2=0.5 m
theta1 and theta2 vary from 0 to 90 degree in 10 values
CODE
Programming Language used- MATLAB
%Simulate the forward kinematics of 2R robotic arm
clear all
close all
clc
%Lengths of first link,l1 and second link,l2(in metres)
l1=1;
l2=0.5;
%Angles made by both links with respect to x-axis
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
%For creating animation of 2R robotic arm
ct=1;
for i=1:length(theta1)
THETA1=theta1(i);
for j=1:length(theta2)
THETA2=theta2(j);
%Starting co-ordinates for link 1
x0=0;
y0=0;
%Ending co-ordinates for link 1 and starting co-ordinates for link 2
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
%Ending co-ordinates for link 2
x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);
%Plotting of forward kinematics
plot([x0,x1],[y0,y1],'linewidth',4,'color','b',[x1,x2],[y1,y2],'linewidth',4,'color','r')
axis([0 1.5 0 1.5])
pause(0.1)
file_text=sprintf("robotic_arm_simulation%d.jpg",ct)
saveas(gca,file_text);
ct=ct+1;
endfor
endfor
OUTPUT
The animation file can be viewed from the following link-
https://drive.google.com/file/d/1C-OueqaVhVqgmU5RGUZCCkm27l-0Rqf5/view
EXPLANATION
Code-
Two for loops are used to calculate different coordinates for (X1,Y1) and (X2,Y2) for different values of theta1 and theta2.
As (X1,Y1) depends on ‘theta1’ so one for loop changes this coordinate by changing the value of ‘theta1’ and for each (X1,Y1) corresponding (X2,Y2) co-ordinates are calculated varying the value of ‘theta2’ using the second for loop.
A counter is used to save all the iterations. The value of counter is set to 1 which increases by 1 for every iteration of loop.
‘saveas’ and ‘sprintf’ commands are used to save each iteration.
Output-
The images obtained from the code are used together to make an animation using ImageMagick. The output shows the Simulation of Forward Kinematics of the 2R Robotic Arm.
ERRORS ENCOUNTERED
Syntax error-axis() used instead of axis([]) for defining axis limits.
CONCLUSION
From the simulation we can see how the Robotic arm moves in the workspace.