Challenge

Week 3.2 - 2R Robotic Arm Challenge

You tube link:

https://youtu.be/CoxQb_3jh-I

Google Drive link:

https://drive.google.com/file/d/1awjdGypbdZPh5YA_-Lk7SkZlqzfJk_29/view?usp=sharing

* Note: no error encountered during programming

clear 
close all
clc
% defining the length of two connecting rods
l1=1.5;
l2=0.5;
% defining the angle sugjected to move by the two connecting rods
theta1=linspace(0,90,10);
theta2=linspace(0,90,10);
% defining the variable to store the figure of each frame to make it as
% video file
ctr=1;
for i=1:length(theta1) % defining the for loop for the movement of l1 connecting rod from 0 to 90 degree
    THETA1=theta1(i);
    for j=1:length(theta2) % defining the for loop for the movement of l2 connecting rod from 0 to 90 degree
        THETA2=theta2(j);
        x0=0;% intializing the x axis co-ordinate
        y0=0;% intializing the y axis co-ordinate
        x1=l1*cosd(THETA1);% intializing the x axis co-ordinates subjected to moved by the l1 connecting rod acorss theta1
        y1=l1*sind(THETA1);% intializing the y axis co-ordinates subjected to moved by the l1 connecting rod acorss theta1
        x2= x1 + l2*cosd(THETA2); % intializing the x axis co-ordinates subjected to moved together by the l1 & l2 connecting rods acorss theta2
        y2= y1 +l2*sind(THETA2); % intializing the y axis co-ordinates subjected to moved together by the l1 & l2 connecting rods acorss theta2
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],LineWidth=3) % plotting the co-ordinates x0, y0, x1, y1, x2, y2 moved by the two connecting rods
        axis([-0.5 4 -0.5 4]) % defining the axis
        pause(0.3) % pausing the inteval of time to 0.3 seconds to get the frame of each movement recorded in plot
        M(ctr)=getframe(gcf); % storing each frame movement in array called M
        ctr=ctr+1;% vraiable to get the next frame movement of l1 & l2 connecting rods
    end
end
movie(M) %  To create a movie frame from the current figure or axes i.e., getting it from an array called 'M'
video_file= VideoWriter('forward_kinematics.avi','Uncompressed AVI');% creates a VideoWriter object to write video data to an AVI file with Motion Uncompressed AVI compression.
open(video_file) % open the video file
writeVideo(video_file,M)% writes one or more movie frames typically returned by the getframe function.
close(video_file) % closing the video file and storing it in relevant folder

Line 1 ,2 & 3 - clear the variable in the workspace

Line 5 & 6 - defining the length of two connecting rods

Line 8 & 9 - defining the angle subjected to move by the two connecting rods

Line 12 - defining the variable to store the figure of each frame to make it as video file

Line 13 & 14 - defining the for loop for the movement of l1 connecting rod from 0 to 90 degree

Line 15 & 16 - defining the for loop for the movement of l2 connecting rod from 0 to 90 degree

Line 17 - initializing the x axis co-ordinate

Line 18 - initializing the y axis co-ordinate

Line 19 - initializing the x axis co-ordinates subjected to movement of the l1 connecting rod across theta1

Line 20 - initializing the y axis co-ordinates subjected to movement of the l1 connecting rod across theta1

Line 21 - initializing the x axis co-ordinates subjected to moved together by the l2 connecting rods across theta2

Line 22 - initializing the y axis co-ordinates subjected to moved together by the l2 connecting rods across theta2

Line 23 - plotting the co-ordinates x0, y0, x1, y1, x2, y2 moved by the two connecting rods

Line 24 - defining the axis for the plot

Line 25- pausing the interval of time to 0.3 seconds to get the frame of each movement recorded in a plot

Line 26 - storing each frame movement in array called M

Line 27 - variable to get the next frame movement of l1 & l2 connecting rods

Line 30 - To create a movie frame from the current figure or axes i.e., getting it from an array called 'M'

Line 31 - creates a VideoWriter object to write video data to an AVI file with Motion Uncompressed AVI compression.

Line 32 - open the video file

Line 33 - writes one or more movie frames typically returned by the getframe function.

Line 34 - closing the video file and storing it in relevant folder

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.