Simulation of a 2R Robotic Arm using MATLAB
Aim of the Project:
To simulate the forward kinematics of a 2R Robotic Arm using MATLAB.
Objective:
The robot consists of two arms(2R). The arm of the robot is in a kinematic state which is about to move around an angle of 0degrees to 180degrees. Here, we consider that 0 degrees to 90 degrees.
Theory:
Robot Kinematics:
Robot kinematics applies geometry to the study of the movement of multi-degree of freedom kinematic chains that form the structure of robotic systems. The emphasis on geometry means that the links of the robot are modeled as rigid bodies and its joints are assumed to provide pure rotation or translation.
Robot kinematics studies the relationship between the dimensions and connectivity of kinematic chains and the position, velocity, and acceleration of each of the links in the robotic system, in order to plan and control movement and to compute actuator forces and torques.
Forward Kinematics:
Forward kinematics specifies the joint parameters and computes the configuration of the chain. For serial manipulators this is achieved by direct substitution of the joint parameters into the forward kinematics equations for the serial chain. For parallel manipulators substitution of the joint parameters into the kinematics equations requires the solution of a set of polynomial constraints to determine the set of possible end-effector locations.
Robotic Arm:
A robotic arm (not robotic hand) is a type of mechanical arm, usually programmable, with similar functions to a human arm; the arm may be the sum total of the mechanism or may be part of a more complex robot. The links of such a manipulator are connected by joints allowing either rotational motion (such as in an articulated robot) or translational (linear) displacement. The links of the manipulator can be considered to form a kinematic chain. The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.
Here we consider the robotic arm as shown in the above picture:
The links being link 1 and link 2. L1 and L2 being the lengths of the two links respectively. Considering the link 1 to be fixed to the horizontal plane and making an angle θ1 with the horizontal. Link 2 is connected to link 1 and the second joint making an angle θ2. Considering the start and end coordinates of link 1 to be (X0, Y0) and (X1, Y1) respectively. Similarly, the start and end coordinates of link 2 to be (X1, Y1) and (X2, Y2) respectively.
Where,
X0 = 0 Y0 = 0
X1 = L1. Cos (θ1) Y1=L1. Sin (θ1)
X2=X1+L2. Cos(θ2) Y2=Y1+L2. Sin(θ2)
MATLAB PROGRAM:
clear all
close all
clc
% Inputs for the program
ct=1;
% Angles
theta_1=linspace(0,90,10);
theta_2=linspace(0,90,10);
%lengths of the links Link 1 and Link 2 respectively are as follows
L_1=1;
L_2=0.5;
%Coordinates of the starting point of link 1
X_0=0;
Y_0=0;
for i=1:length(theta_1)
Theta_1=theta_1(i);
for j=1:length(theta_2)
Theta_2=theta_2(j);
X_1=L_1.*cosd(Theta_1);
Y_1=L_1.*sind(Theta_1);
X_2=X_1+L_2.*cosd(Theta_2);
Y_2=Y_1+L_2.*sind(Theta_2);
%plotting
plot([X_0 X_1], [Y_0 Y_1], [X_1 X_2], [Y_1 Y_2], 'linewidth',6)
axis([-0.1 1.5 0 1.5])
M(ct)=getframe(gcf);
ct=ct+1;
pause(0.1)
end
end
movie(M)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
PROGRAM EXPLANATION:
- Inputs: We give the inputs to both the angles theta1 and theta2 using linspace command to get 10 equally spaced values between 0 to 90-degree angle. Then we took link 1 and link 2 values as 1 and 0.5 respectively.
- Using for loop here: 'i' is called as loop counter which determines that how many times for loop is going to be executed.i is varying from 1 to length of theta1, and I assigning the THETA1 which is used to specify the value of theta. whenever the value of 'i' changes THETA1 value also gets changed. once again I am using for loop command for the theta2. for that, I am assigning j. it is varying from 1 to length of theta2. once the j value changes THETA2 value also gets changed.
- Plotting: Now I plot the graphs with all the coordinates and taking linewidth of 6mm and taking axis of -0.1 to 1.5 for x-axis and 0 to 1.5 for the y-axis.
- Pause command is used to pause the figures in the animation for 0.1 seconds.
- ct command is used to count the number of figures and also control the loop.
- movie(M) is used to create a movie for the program.
- We use videofile variable to name the video and to get the movie in avi file using VideoWriter function then we use the close function to close the videofile.
Screenshots of Output:
Output Animation Movie link:
Errors occurred during programming:
This error is due to the old version of Matlab. I was using the R2010a version where VideoWriter function was not included.
This error occurred because I used "videowriter" instead of "VideoWriter". The function is case sensitive.
Conclusion:
From the program, we can clearly determine the forward kinematics of the 2r robotic arm and we also determine the workspace of the robot.
References: