Week 2- 2R Robotic Arm Challenge
%2R Robotic armclear allclose allclc%Step 1: Declaring length of two links of robotic arm as l1 and l2. Fixing l1=1 and l2=0.5. l1 =1;l2 =0.5;%Step 2: Declaring different values of theta1 and theta 2.theta1 = linspace(0,90,10);theta2 = linspace(0,90,10);%Step 3: Using for loop to process the function.ct=1;for theta1 = linspace(0,90,10) %Declaring start and end points of l1. x0=0 y0=0 x1= l1*cosd(theta1) y1= l1*sind(theta1) %Step 4: Declaring start and end points of l2. for theta2 = linspace(0,90,10) x2= x1+ l2*cosd(theta2) y2= y1+ l2*sind(theta2) % Step 5: Plotting plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3) axis([0 1.5 0 1.5]) pause(0.3) M(ct) = getframe(gcf); ct=ct+1 endendmovie(M)videofile = VideoWriter('Forward_kinematics.avi','Uncompressed AVI');open(videofile)writeVideo(videofile,M)close(videofile)
Project Report
Step 1: Declaring length of two links of robotic arm as l1 and l2. Fixing l1=1 and l2=0.5.
Step 2 : theta1 defines the rotaion of first link(l1) and theta2 defines the rotation of second link(l2). Declaring different values of thata1 by using 'linspace' command. By declaring "theta1 = linspace(0,90,10)", we get 10 values and of theta1 between 0 and 90 with a common difference of 10. Same command is used for declaring different values of thata2.
Step 3: For every value of variable theta 1, I am going to get 10 values of variable theta 2. Therefore, 'for loop' is used to execute this type of functions. By using "for theta1 = linspace(0,90,10)", I am initiating the loop from theta1=0. Inside this loop, I've declared the values of the variables x0,y0,x1 and Y1. xo,y0 is the starting point and x1,y1 is the ending point of l1. Assuming starting point as origin, I've declared x0=0 and y0=0. Then I've declared 'x1= l1*cosd(theta1) and y1= l1*sind(theta1) as the end points of l1 for different values of theta1. For theta1=0, I am going to have 10 values of theta 2. Similarly, for every value of theta1, I am going to have 10 values of theta2. Therefore I will use nested for loop for defining parameters for l2.
Step 4: By using "for theta2 = linspace(0,90,10)", inside the first 'for loop', I am initiating the second 'for loop' from theta2=0. Inside the second 'for loop', I've declared the values of the variables x1,y1,x2 and Y2. x1y1 is the starting point of l2 and ending point of l1. As I've defined x1y1 in the first 'for loop', I've declared only x2y2 in the second 'for loop'. As both the links are in continuation, I've declared x2= x1+ l2*cosd(theta2) and y2= y1+ l2*sind(theta2) as the end points of l2.
Step 5: For plotting, I've used the command "plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)". I've used the command "axis([0 1.5 0 1.5])" to get a proper plot between 0 and 1.5. Origin being (0,0) and '1.5' being the extreme values on X and Y axes.
For each value of theta1, the second 'for loop'(nested for loop) will be executed 10 times(for 10 different values of theta2). I've used the command "pause(0.3)" to pause the ploy animation after every 0.3 seconds. I've used the command "ct=ct+1" to everytime increase the for loop counter by 1. By using the command "M(ct) = getframe(gcf)", I've saved the current frame in the variable(M). After that, I generated a movie of the plot animation.
Errors faced while programming:
1) I did'nt used the 'hold on' command, therefore, I was able to see the plot of second link only.
2) Initially I did not used the the linspace command for declaring the values of theta 1 and theta2. I used the command "for theta1 = 0 : 90" due to which I was getting all the values of theta1 between 0 and 90.
Steps taken to resolve the error:
1) Watched the video again and got an idea to use the 'hold on' command.
2) Watched the video to understand the significance of 'linspace' command and then used it to get finite values of theta in order to get a proper output.
Output Screenshots:
Youtube link to the animation video: https://www.youtube.com/watch?v=c9Ez6xreA5Q