Week 2- 2R Robotic Arm Challenge
Aim- to write a code that displays pos of a robotic arm at different angles.
Governing equation- 1)- x0=0,y0=0(fixed coordinates of first link) l1=1,l2=1 theta1, theta2(length of arms given theta1 and2 given)
2)- x1=l1cos(theta1)
3)-y1=l1sin(theta1)
objective- 1) to simulate a robotic arm having 2 linkage at diff angles.
Code-
close all
clc
clear all
%l1& l2 is the length of 1and 2nd arm
%x0 and y0 are coordinates of 1st arm linkage
l1=1;
l2=1;
x0=0;
y0=0;
%theta1 and theta 2 are angles made by arm1 and amr 2 respectively
theta1 = linspace(0,90,20);
theta2 = linspace(0,90,20);
counter=1;
%counter wil be used to store value of frames
%for loop is used to get multiple values of x1 and x2 at diff angles
for i=1:length(theta1)
Theta1=theta1(i);
x1= l1*cosd(Theta1);
y1= l1*sind(Theta1);
%another for loop so for 1 value of theta1 we can have multiple
%values of x2 y2 for diff values of theta2
for j=1:length(theta2);
Theta2=theta2(j);
x2= x1+l2*cosd(Theta2);
y2= y1+l2*sind(Theta2);
%to plot arm1 and arm2
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
%to define max and min limit of x axis and y axis
axis([0 2 0 2])
%to pause the program for req time
pause(0.03)
%to store each frame in a matrix
M(counter)=getframe(gcf);
counter=counter+1;
end
end
movie(M)
%to create a video file
videofile= VideoWriter("roboticarm.avi","uncompressed AVI")
open(videofile)
%to write data in the video file created
writeVideo(videofile,M)
close(videofile)
results- motion of robotic arm with two arm has been visualized click the below link to access file
https://drive.google.com/file/d/1R02l1US3VNHRo4biNioayM0RASg0uB4H/view?usp=sharing
issues faced- error1- array indices must be positive