To Program in MATLAB to simulate the forward kinematic of 2R Robotic arm.
2R Robotic Arm
Aim: To Program in MATLAB to simulate the forward kinematic of 2R Robotic arm.
Derivation of equation:
Coordinate of x0, y0: -
As the base of the link one is fixed the coordinates are represented as (0,0)
Hence x0=0 and y0=0
Coordinates of x1, y1: -
The coordinates of x1 and y1 lies on the top end point of the link1
Hence the position of the points lies with respect to length of link1 (i.e.)
l1,
x1 of the link is cos (1) for length of link 1
x1= l1 x cos (1)
y1 of the link is sin (1) for the length of link 1
y1=l1 x sin (1)
Coordinates of x2, y2: -
The coordinates of x2 and y2 lies on the top end of the link2
Hence the position of the points lies with respect to the length of link2 (i.e.) l2 as well as position of the x1 and x2 as the base point of link2 is at the coordinates of x1, y1.
X2= x1 + (l2 x cos (2))
and y2
y2=y1 + (l2 x cos (2))
Objective of the project
- The main objective of this project is to simulate the movement of a two links robotic arm.
- This is achieved by plotting a line graph with different colors to represent the links and their movement.
- A set of angles turned by both the links are given as the input .
- Each frame of figures plotted for each combinations of the angles are combined from gcf to a movie AVI.
- This file is saved as animated file.
Body of content: -
This program will successfully simulate the animation video of the robotic arm.
Code: -
%kinematic analysis of robotic arm
close all
clear all
clc
%length of arms
l1=1; %length of fisrt arm l1
l2=0.5; %length of second arm l2
%Angles from 0 to 90 degree with 10 values
theta1=linspace(0,90,10); %varying angles between the base and the link1
theta2=linspace(0,90,10); %varying angles between horizon and the start of link2
%Counter variable with assigned initial value 1
ct=1
for i= 1:length(theta1) %Iterates i from 1 to 10 as length of theta1 is 10
%Each value of theta1 assigned to THETA1
THETA1=theta1(i);
for j= 1:length(theta2) %Iterates j from 1 to 10 as length of theta2 is 10
%Each value of theta2 assigned to THETA2
THETA2=theta2(j)
%Coordinates
x0=0; % x & y coordinates of the start of link one
y0=0;
x1=l1*cosd(THETA1); %x & y coordinates of the end of link1 and start of link2
y1=l2*sind(THETA1);
x2=x1+(l2*cosd(THETA2)); %x & y coordinates of the end of link 2
y2=y1+(l2*sind(THETA2));
%ploting of the graph with all three set of coordinate
%width of line is 3 and marker at the line end of shape o
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'marker','o','linewidth',3)
%providing the limits at both x and y axis in the plot graph
axis([-0.1 1.5 0 1.5])
%frezzing the change of figure of plot for every 0.002 sec thus cont
pause(0.002);
%getting each figure to variabme M with respect to continuous movement
M(ct)=getframe(gcf);
%Increment of Ct
ct=ct+1;
end
end
%Combine all the frames of M of ct as a continuous movie
movie(M)
%making vediofile variable as a empty disk to store the movie of AVI format
videofile = videoWriter('robot_kinematic.avi','Uncompressed AVI');
open(videofile)
%save the movie to the created videofile
writeVideo(videofile,M)
close(videofile)
Codes explanation: -
- First the code starts with the general commands close all, clear all, clc.
- Length of each link of the arm is assumed link1=1 m and link2=0.5 m.
- Linspace command is use to obtain 10 values for the angle turned at the nodes of the links from 0to 90 .
- These values are assigned to theta1 and theta2 as n 1D array of values
- For command is used to surf from 1 to 10(length of the theta1 array)
- Each time the for loop is executed the value of i is used to assign that particular index value of the theta1 array to the variable
- Another for loop is created inside this loop which repeats the same procedure to assign the value of theta2 to THETA2 using
- The coordinates and the formula are provided for x0, y0, x1, y1, x2, y2.
- All the coordinates values are plotted at one time and linewidth command and marker command is used to control the width and appearance of the line.
- Axis is used to limit the values that are displayed in the plot by providing axis([xstart xend ystart yend]).
- Each figure of the graph is saved to each index of variable M using ct which increases for each execution of the for loop.
- The sets of frames in M made as a movie by command movie.
- And the rest of the commands writes the movie as a video file of AVI format.
Output:-
Result Video:-
Conclusion: - From this we can conclude that MATLAB can to be used to design and alalysis the degree of freedom of robots which can be highly used in manufacturing sectors.
Errors:
1.
overcame by makinf the frist word (v) of 'Videowriter' to uppercase V
2.
over came by changing M of 'Movie' function to lowercase m
3.
instead of defineing 'Uncompressed AVI' ,i made a mistake by using ' Uncompressed.AVI'.