Robotic arm simulator with the help of matlab
Objective :
1. To create a simulation of 2 arm robotic linkage with the help of matlab
Theory :
In this project we simulate a simple movement of two robotic arm , by this information we could able to find the reach of the robotic arm by this way we able to identify the workspace for the robotic arm this is very simple robotic arm simulator which will show the basic concept of simulation in matlab .
Matlab Code:
% forward_kinematics
close all
clear all
clc
% defining lenth of both link and angle
l1 = 1.5;
l2 = 0.75;
theta1 = linspace(0,90,10);
theta2 = linspace(0,180,10);
ct = 1;
%loop to create a movement of robotic arm
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);
pause(0.01)
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
axis([-1,3.5,-1,3.5])
M(ct) = getframe(gcf);
ct = ct + 1;
end
end
%creating and saving animation file
movie(M)
videofile = VideoWriter('kinematic_arm_simulator.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation :
from above code we first define the length of two arm we also could use input command to get the user input then user can input the length of the two arm.
then after we define THETA1 and THETA2 which is basically the represent the angular movement of link 1 and link 2 respectively .
now to create the angular movement of both link we use for loop here we are using two for loops so that every one angular movement of link 1 we get multiple angular movements of link 2 that's why we use 2 for loops .
so now that we could plot our results now we are plotting and pausing which means plot will pause at every set time interval so that we could see the movement of both link .
here, axis is defines to fix the axis coordinates .
x0, y0 = (0,0) intial postion of linkl1
(x1,y1)=(l1⋅cos(θ),l1⋅sin(θ)) postion of link1
(x2,y2)=(l2⋅cos(θ),l2⋅sin(θ)) position of link2
Result:
https://drive.google.com/drive/u/0/folders/1qjrcg8vi2Jb3gX79heLGQeIfnh1m3nc-
the above link is given to see the animation of the 2R robotic arm .