To write a program in MATLAB/OCTAVE to simulate the forward kinematics of a 2R Robotic Arm.
AIM:
To write a program in MATLAB/OCTAVE to simulate the forward kinematics of a 2R Robotic Arm.
EQUATION/FORMULA USED:
`x0 = 0`
`y0 = 0`
`x1 = l1*cos(theta1)`
`y1 = l1*sin(theta1)`
`x2 = x1 + l2*cos(theta2)`
`y2 = y1 + l2*sin(theta2)`
OBJECTIVE:
- To understand the kinematics of linkages.
- To understand the movement of a robotic arm.
THEORY:
The kinematic equations of a robot which is used to compute the position of the end-effector from a specified value for the joint parameters, then the complete process is called forward kinematics.
Forward kinematics for a robotic arm calculates the Cartesian position and orientation of the end effector taking joint angles as input.
These type of robots have huge industry exposure and application. It is used especially for a sophisticated task like welding fitting moulding etc.
BODY:
- CODE:
% forward kinematics of a 2R robotic arm manipulator
clear all
close all
clc
%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
plot([x0 x1], [y0 y1], [x1 x2], [y1 y2], 'linewidth',3);
axis([-0.1 1.5 0 1.5]);
file_text = sprintf("armanimation%05d.png",ct)
saveas(gca, file_text)
pause(0.03);
ct = ct+1;
endfor
endfor
2. STEP-WISE EXPLANATION OF THE CODE:
- This program is written and executed using octave.
- Starting with all the general command e. clear all, close all & clc.
- Inputting all the code comment at all the required location starting with %
- Length of both the links is taken as l1 = 1 and l2 = 0.5 which is constant throughout.
- using linspace command 10 value between 0 to 90 is considered for both theta1 and theta2.
- For loop is taken for theta1 where i=1
- Inside for loop of theta1 and another for loop is taken for theta2 where j=1.
- Inside the for loop of theta2 equation is written for all the three-axis i.e. x0, y0, x1, y1, x2, y2.
- Thereafter plotting is done with linewidth 3.
- Note: Since the program is executed in octave therefore the process of stitching the images and saving the output video is little different than that in MATLAB.
- Thereafter, for loop of theta2 ends followed by theta1.
- ERROR FACED WHILE PROGRAMMING:
- Since the tutorial video was explained in MATLAB. The first error was that I was not knowing the process of stitching the image and saving the output in the form of video is different in case of the octave. Also in the video, I was not aware of this change.
- The second error was made while saving the file I was selecting a wrong file format due to a minor error in my code i.e. %05d screenshot is attached below.
- The third error was in CMD I could not able to change the directory.
- STEP TAKEN TO OVERCOME THOSE ERROR:
- The first error was rectified with the help of my instructor over a call.
- The second error was fixed by amending the code.
- The third error was rectified by adding cd before pasting my file location in CDM
- SCREENSHOT OF ERROR:
FIRST ERROR:
SECOND ERROR:
THIRD ERROR:
OUTPUT:
RESULT:
After rectifying all the error, we have got the video of the output plot.