Week 2- 2R Robotic Arm Challenge
To simulate the 2D robotic arm, first stated thetas values and some dimensions. the initial values are zero for x and y so to find the final value use theta1 to find x1and y1. Then we found the x2 and y2 values by using trigonometry and also adding the x1 and y1 value.
% A program to simulate the forward kinematics of a 2R Robotic Arm
clear all
close all
clc
%inputs
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct=1
l1 = 1;
l2 = 0.5;
x0 = 0;
y0 = 0;
%nested for loop
for i = 1:length(theta1)
for j = 1:length(theta2)
x1 = l1*cosd(theta1(i));
y1 = l1*sind(theta1(i));
x2 = x1+l2*cosd(theta2(j));
y2 = y1+l2*sind(theta2(j));
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'lineWidth',3);
axis ([0 2 0 2]);
M(ct) = getframe(gcf)
ct = ct+1
end
end
%movie writer
movie(M)
videofile = VideoWriter('robot_arm.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile);
after finding all the points we plotted the graph and made a movie for which to recognize every frame we used m(ct)and get frame command and used the movie writing format to complete the program.
https://drive.google.com/file/d/1QYftChB1Yd4OnUaZFATH5cSntnF3jPCp/view?usp=sharing