Challenge

Week 2- 2R Robotic Arm Challenge

AIM: Show the mechanism of Robotic Arm moving in circular manner.

Program :

clear all
close all
clc

%Inputs
l1 =1;
l2 =0.5;

theta1 =linspace(0,90,10);
theta2 =linspace(0,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]);
        xlabel('X')
        ylabel('Y')
        legend('Link1', 'Link2')
        pause(0.3)
        M(ct)= getframe(gcf);
        ct=ct+1;
    end
end


movie(M)
videofile = VideoWriter('C:\Users\Saurabh\Desktop\code\Matlab\twoR_Robotic_Arm');
open(videofile)
writeVideo(videofile,M)
close(videofile)

Report:

  1. Code Explaination :
    1. First we have to give an inputs which will be lengths of "link1" and "link2" and an angles between links and surface.
    2. Initializing the length of "link1" is 1 and that of "link2" is 0.5.
    3. Providing the angle of each link i.e. theta1 and theta2 using "linspace" command starting from 0deg to 90deg with 10deg of increament.
    4. ct is counter commmand which stores every frame started from value 1.
    5. The command "for" is used to repeat the specified commands using variables. Here this command using "i" variablefor "link1" varies from 1 to length of theta1 i.e. 10 and for each value of "theta1", the value of "THETA1" will vary from 0 to 90 with increment of 10.
    6. Similarly for loop command is used for link2 theta2 will vary from 0 to 90 with increment of 10 by using "j" as a variable.As theta2 is increased the value of THETA2 also increases.
    7. Giving starting coordinates of link1 as x0 and y0 are (0,0).
    8. For ending coordinates of link1 and starting coordinates of link2 as (x1, y1).
      1. x1= l1*cosd(THETA1)
      2. y1= l1*sind(THETA1)... where THETA1 is the final values of angle of link1.
    9. For ending coordinates of link2 as (x2, y2).
      1. x2=x1+ l2* cosd(THETA2)
      2. y2=y1+ l2* sind(THETA2)... where THETA2 is the final values of angle of link2.
    10. Now to plot the graph starting and ending coordinates of link1 and link2.
      1. plot([x0 x1],[y0 y1],[x1 x2],[y1 y2], 'linewidth', 3)
    11. To give the limits to graph using axis command, ranging x-axis from -0.1 to 1.5 and y-axis from 0 to 1.5.
      1. axis([-0.1 1.5 0 1.5])
    12. Added x-label and y-label as "X" and "Y" to identify the names of the axes.
    13. Indicated blue line as "Link1" and red line as "Link2".
    14. Pause is used to pause the frame for that period of time. We are using the for it is "0.3 sec".
    15. Adding an array called M storing all the frames by using getframe command. In this command the current frame will be stored in an array called M.
      1. M(ct)= getframe(gcf)... gcf= get current frame
    16. Now the counter value will increase by 1 after storing the frame. This indicates the number of frame is increasing with increasing the value of counter.
    17. Ending "for"command of "j" variable the "for" command for will increase by 10 and the process will be repeated again and again.
    18. To make the animation of array M we initiate movie command.
    19. We are going to make the video file by videowriter command saving with the name of file and the profile of the file.
      1. videofile= VideoWriter('Robotic_Arm.avi','uncompressed AVI');
    20. To open that "videofile" and write an array M in it, we use open and writeVideo commands.
      1. open(videofile)
      2. writeVideo(videofile,M)
    21. And after this we will close the "videofile".
  2. Errors faced while programming:
    1. In the linspace command the I wrote sqaure brackets which was wrong and was not working also showing the error.
    2. Everytime I forgot to complete the statements with ";", which was also wrong and showing the error.
    3. I had written for "sind" and "cosd" angles with "theta" instead of "THETA", which was showing the different answer that not required. To overcome this problem I replace "theta" by "THETA".
    4. While plotting the graph I used "line" command for each link but in result it was showing me all the lines. So then I used "plot" command to get only two links in the graph using end points of each link.
    5. At the end of the program I forgot to write pause command which holds the frame for that specific time. The answer of this mistake was only the last links verticle in position. To recover this mistake I need to give the pause command with specific time which will hold the frame for that much of time.

Result: After running the program we get the following result.

https://drive.google.com/file/d/11m4R2To61cdAIvr4CTo0W7t77SVDqevd/view?usp=sharing

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.