Week 3.2 - 2R Robotic Arm Challenge
Aim: To create an animation file of the plot.
To upload an animation on You tube and provide the You tube link for an animation in your report.
Governing Equatin:
To calculate the end co-ordinates of the first arm we are using,
x1 = l1*cosd(theta1)
y1 = l1*sind(theta1)
where 'l1' is the length of the first arm and theta1 is the angle made by the arm with x-axis.
To calculate the end co-ordinates of the second arm we are using,
x2 = l2*cosd(theta2)
y2 = l2*sind(theta2)
where 'l2' is the length of the first arm and theta2 is the angle made by the arm with x-axis.
The X component of a given vector is calculated by the cosine ratio and the Y component of a given vector is calculated by the sine ratio.
Main Objective:
To simulate the movement of a robotic arm.
Programme:
clear
close all
clc
%Inputs
l1 = 2;
l2 = 1;
theta1 = linspace(360,270,10);
theta2 = linspace(360,270,10);
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% Co-ordinates
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',4)
axis([-0.5 3.5 -3.5 2])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
movie(M)
videofile = VideoWriter('Forward_kinematics.avi','Uncompressed Avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Explanation:
The theta angle range is taken from industrial observations.
Considering the length of the Arms,
l1 = 2
l2 = 1
The values of theta1 for first arm range from 360 degrees to 270 degrees for 10 values respectively.
theta1 = linspace(360,270,10);
The values of theta2 for second arm range from 360 degrees to 270 degrees for 10 values respectively.
theta2 = linspace(360,270,10);
The counter starts atthe first value and is then incremented.
For loop is used so we can get different position of second arm for a particular position of the first arm.
Here (i) is the variable which is used to define different values of theta1.
THETA1 is a variable for the corresponding value of (i).
for i = 1:length(theta1)
THETA1 = theta1(i);
Here (j) is the variable which is used to define different values of theta2.
THETA2 is a variable for the corresponding value of (j).
for j = 1:length(theta2)
THETA2 = theta1(j);
Keepinf the co-ordinates of x0 and y0 at origin and calculating the co-ordinates for x1,y1 and x2,y2
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
Plotting the graph for the movement of the robotic arm.
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',4)
axis([-0.5 3.5 -3.5 2])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
Making a movie file for the graph plotted.
movie(M)
videofile = VideoWriter('Forward_kinematics.avi','Uncompressed Avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Results:
The link for the aniation obtained from the above programme.
https://drive.google.com/file/d/1tq0q6rn2aTnsQsyx6ljSY1fnz3JYrkCB/view?usp=sharing
Conclusion:
Hence the graph was ploted and animation was created for the forward kinematics of 2R robotic arm.