Challenge

Week 3.2 - 2R Robotic Arm Challenge

% inputs for values of l1 and l2
l1 = 1;
l2 = 0.5;
% inputs for values of theta 1 and 2
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
% iteration value as ct
ct = 1;
% looping for the value in array theta1 from value 1 to length of theta1
% iteration value i
for i = 1:length(theta1)
    % the evaluated value from the looping is assigned to the variable
    % THETA1
    THETA1 = theta1(i);
    % looping for theta2 as the same as for theta1
    for j = 1:length(theta2)
        % the evaluated value of theta2 assigned to variable THETA2
        THETA2 = theta2(j);
        % the inputs for x0 and y0  
        x0 = 0;
        y0 = 0; 
        % the calculated value of x1 and x2 ,y1 and y2
        x1 = l1*cosd(THETA1);
        y1 = l1*sind(THETA1);
        x2 = l2*cosd(THETA2);
        y2 = l2*sind(THETA2);
        % plotting with required axis and pause for animation
        plot([x0 x1],[y0 y1],[x1 x2],[y1,y2],'linewidth',3)
        axis([-0.1 1.5 0 1.5])
        pause(0.03)
        % the frames ct is stored in a array M 
        M(ct) = getframe(gcf);
        % increement
        ct = ct + 1;
    end
end
% movie generated by mathlab with the frames in array M
movie(M)
% video file is made with the file name 
videofile = VideoWriter('RoboticArm.avi','Uncompressed AVI');
% file opened
open(videofile)
% the file video is written
writeVideo(videofile,M)
% the file is closed
close(videofile)

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.