Week 2- 2R Robotic Arm Challenge
clear all
close all
clc
%inputs
l1=2
l2=1
theta1=linspace(0,90,10)
theta2=linspace(0,90,10)
%logic using for loop
ct=1;
for i=1:length(theta1)
THETA1=theta1(i)
for j=1:length(theta2)
THETA2=theta2(j)
%defining the values of x and y cordinates each
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
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3)
axis([-1 3 0 3])
pause (0.1)
m(ct)=getframe(gcf);
ct=ct+1;
end
end
movie(m)
videofile=VideoWriter('robotic_arm_challange_4.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,m)
close(videofile)
EXPLANATION FOR THE CODE
FOR STIMULATING THE ROBOTIC ARM WE NEED TO UNDERSTAND THE KINAMATICS OF THE LINKS
SO AS WE SAID THE WORD LINKS LENGTH COMES UNDER CONSIDRATION AND FOR STIMULATION IN 2-DIRECTION WE NEED ANGLE MADE BY THE LINK THROUGH HORIZONTAL LINE .
1) first of all we need to define variables ,so here our variables are l1,l2 then angle made by link theta1 and theta 2
2)so basically for stimulating the arm we will need n numer of values for theta1 and theta 2 (considring n as intiger ) so for creating the n values we define array .
3) But just by creating the array its not sufficient for code to genrate loop of stimulation.
4)so for this purpose we use "for" loop which basically repeats your syntax in defined number of times
so in for loop we defined "i" which is called loop variable
5) Now, for link 1 we defined "for i=1:lentgth(theta1) here "i" is loop variable which repeats the set of value each time creating a different array .
so, as we say 1:length(theta1) the loop counter variable takes number of times the loop we have to create , as shown in code
after that we define the another variable say THETA1=theta1(i) which means the new variable will take valeus from theta1 and define the loop i times "as of now consider theta 1 has 10 values between 0 to 90
so the variable THETA1 will repeting the same action(or code ) for 0 ,10 to 90 diffrent times .
6) same goes for 2nd variable called theta2 ,here we are creating for loop under a foor loop so that it can show how many times theta2 can repeat for one value of theta1.
7) now as we are done defining for loop for each variable we will define
the coordinates x0,y0, x1,y1, x2,y2 as given in code
8) now for plotting the graph we are using the command plot so first we need to define x coordinate and then y coordinate as shown in code , still thats not enough to stimulate the graph
9) for stimulation of code for getiing all the graphs in one single frame we are using ct and after that creating the array for ct and incrimenting the value of it , so we can get all graphical representation in single run .
10)now we have to create the video using this frames we have created using ct and incrimanting the values by 1 so we use
movie(m)
videofile=VideoWriter('robotic_arm_challange_4.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,m)
close(videofile)
this command and run the code .
PROBLEMS FACED WHILE CREATING THE CODES
1) the most basic problems while creating the code were syntax of the codes if you forget any of the command or any important line in syntax the code starts showing error
2) creating logic while programming
OVERCOMMING THE CHALLANGES
while programming just be 100 % present because everything is case sensitive
and to create logic first create the chart that how are you going to create the logic
these were the two only problems i faced while programming.
Here is the link for the video : https://drive.google.com/file/d/13mrJoFaysED7SCGuL6v24KkWo_DN1FKd/view?usp=sharing