Week 2- 2R Robotic Arm Challenge
1.Simulation of forward kinamatics of 2R ROBOTICS arm using matlab.https://youtu.be/K5-bcOuGmZ01
Ans: To get 2R robotics arm,it has 2 rods with 2 linkages theta 1 and theta 2.
INPUTS: lenght of rods is given as l1=1 and l2=0.5 in meters.
theta1 = linspace(1,90,10), linspace is command is used here to get 10 different theta values between 1 to 90 for different possisions of arm 1. same for theta2.
ct is a counter command to give values one by one to execute forloop.
forloop is opened to execute the command one by one to simulate a first arm motion.
i = 1:length(theta1) is a command used to run i values one by one till the end value.
THETA1 = theta1(i) is used to store theta i values
one more forloop is opened to simulate 2nd arm motion.
j = 1:length(theta2) is a command used to run j values one by one till end value.
THETA2 = theta2(j) is used to store theta i values
COORDINATES: coordinates given x0 = 0,y0 = 0
x1 = l1*cosd(THETA1) ,y1 = l2*sind(THETA1)
x2 = x1+l1*cosd(THETA2), y2 = y1+l2*sind(THETA2)
PLOTTING:plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3) here plot command is used to plot the values x0,y0,x1,y1,x2,y2. linewidth command is used to give the width of the plot line.
axis([-0.1 1.5 0 1.5]) command used to give the plot range of x and y axis.
pause(0.03) is used to give time gap for each line ploted.
M(ct) = getframe(gcf) command used to store the values of each plot.
end command is used to close forloop.
To get a movie of each plot stored in M used command movie(M).
Videofile = VideoWriter('forward_kinamatics.avi','uncompressed AVI') is used give the file name which is running.
open(Videofile) is used to open the file.
writeVideo(Videofile,M) is used to save every plot to video file.
close(Videofile) is used to close the command to secure from other data.
OUTPUT:created a movie of forward kinamatics of a 2R ROBOTICS arm and uploaded in youtube https://youtu.be/K5-bcOuGmZ01.
commands and workspace screenshots are provided in comment box.
clc
clear all
close all
%inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(1,90,10);
theta2 = linspace(1,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])
pause(0.03)
M(ct) = getframe(gcf);
ct = ct+1;
end
end
movie(M)
Videofile = VideoWriter('forward_kinamatics.avi','uncompressed AVI');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)