Challenge

Week 3.2 - 2R Robotic Arm Challenge

https://drive.google.com/file/d/1drcmeY_uKlatUeZigFZGP1WkBAQ45qZ2/view?usp=sharing

clc
clear all
close all
% 2R robotic arm challenge
%defining a input
%let l1 be the link 1st & l2 be the 2nd
%length of the links is
l1=1;
l2=0.5;
%calculate the position of the links
%theta1 is the angle between 1st link and X axis
%theta2 is the angle between 2nd link and y axis
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
%counter
ct=1;
%using a for loop for contineous change of link position
for i=1:length(theta1)
THETA1=theta1(i); % for the 1st link theta change to length of theta1
for j=1:length(theta2) % for the 2nd link theta change to length of 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);
%using a single plot
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
% giving axis limits
axis([-0.1 1.5 0 1.5])
%giving a pause between changing position
pause(0.03)
% for creating a movie using command frame
M(ct) = getframe(gcf);
% incremenat counter
ct=ct+1;
end
end
%create a movie file
movie(M)
videofile = VideoWriter('robotic_arm.avi','Uncompressed AVI');
%opening a video file
open(videofile)
%writing a video into file
writeVideo(videofile,M)
%close video
close(videofile)
% Output giving in attached link
https://drive.google.com/file/d/1drcmeY_uKlatUeZigFZGP1WkBAQ45qZ2/view?usp=sharing
clc
clear all
close all
% 2R robotic arm challenge
%defining a input 
%let l1 be the link 1st & l2 be the 2nd
%length of the links is
l1=1;
l2=0.5;
%calculate the position of the links
%theta1 is the angle between 1st link and X axis
%theta2 is the angle between 2nd link and y axis
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

%counter 
ct=1;

%using a for loop for contineous change of link position
for i=1:length(theta1)
    THETA1=theta1(i); % for the 1st link theta change to length of theta1 

    for j=1:length(theta2) % for the 2nd link theta change to length of 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);

        %using a single plot 
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
        % giving axis limits
        axis([-0.1 1.5 0 1.5])
        %giving a pause between changing position
        pause(0.03)
        % for creating a movie using command frame 
        M(ct) = getframe(gcf);
        % incremenat counter
        ct=ct+1;

    end
end
%create a movie file    
movie(M)
videofile = VideoWriter('robotic_arm.avi','Uncompressed AVI');
%opening a video file
open(videofile)
%writing a video into file
writeVideo(videofile,M)
%close video
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.