Challenge

Week 2- 2R Robotic Arm Challenge

%2R ROBOTIC ARM

clear all
close all
clc


l1 = 2;
l2 = 1;
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);

         plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
         axis([-1 3 0 3])
         pause(0.03)
         M(ct) = getframe(gcf);
         ct=ct+1;

    end
end
movie(M)
videofile = VideoWriter('robotic arm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

clear all, close all,clc is used for clearing workspace, closing all graphical tabs, and clearing the command window.

STEP 1: Assigning the length and angular parameter of the robotic arm (ie.l1,l2,theta1,theta2).As the angular parameter will keep on changing so it should be an array and with the help of 'linspace' command, we can assign the start and end of a range along with the number of quantities required, which will be at uniform intervals from each other.

STEP 2: Assigning the coordinates of the arm (ie. x0,y0,x1,y1,x2,y2). which can be done by formulating the above length and angular parameters

STEP 3: Plotting the graph and animating it, to do so we have to put the angular and plot parameters into a loop and this can be done using 'for' command, by assigning a variable 'i' and giving it a range using length of theta1 the number of theta1 can be assigned to THETA1 similarly for theta2 'for' command can be used but with a different variable 'j' so that they have two assigned value, As the angular values are in the loop they have to be assigned to the formulated coordinate, so those parameters are to be included in the loop. next for the plotting 'plot' command is used with the coordinates assigned."axis' command is used to fix the axis so that uniformity can be seen in the animation when the arm moves."pause' command is used to reduce the interval so that a smooth animation can be attained,'end' command is use to close the loop.

STEP 4: movie making. To make the animating video, frames are to be captured of the above graphical plot and to do so counter is assigned to a variable 'M' and it is incremented at the end of the loop so that it can be stored at the end of every loop , to capture the frame 'getframe' command is used.After this 'movie' command is used with the counter frame stored variable 'M', it is then assigned with file name and type with the help of 'videowriter' command.'open' command is used to open the assigned file and with 'writevideo' command frame is been stored in the file the 'close' command is use to save and close the file.

ERRORS FACED

improper variable assigning during formulation, to avoid this avoid using similar variables capitalized.

2R ROBOTIC ARM ANIMATION

https://drive.google.com/file/d/1pHaLnsRmy4Cvu7lBjruhb7SSrx1FJC87/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.