Challenge

Week 2- 2R Robotic Arm Challenge

% A Program to calculate various positions of 2 link robotic arm mechanism

clear all           % to clear workspace 
close all           % to close all the windows like plot
clc                 % to clear the commands.

% inputs required for calculations
l1 = 1;                       % length of first link arm
l2 = 0.5;                       % length of second link ara
theta1 = linspace(0,90,10);         % various angle position of link 1
theta2 = linspace(0,90,10);         % various angle position of link 2
ct=1;
for i = 1:length(theta1)     % here we says that i varies from 1 to length of theta1
    THETA1 = theta1(i);      % the value of theta1 ar various positions of i nstored in new variable THETA1
    for j = 1:length(theta2)  % here we says that j varies from 1 to length of theta2
        THETA2 = theta2(j);   % the value of theta2 ar various positions of i nstored in new variable THETA2
        x0 = 0;               % initial value of x for link 1
        y0 = 0;               % initial value of y for link 1
        x1 = l1*cosd(THETA1);  % final value of x for link 1 & initial value of x for link 2
        y1 = l1*sind(THETA1);  % final value of y for link 1 & initial value of y for link 2
        x2 = x1+l2*cosd(THETA2);  % final value of x for link 2
        y2 = y1+l2*sind(THETA2);  % final value of y for link 2
        % plotting
        
        plot ([x0 x1], [y0 y1], [x1 x2], [y1 y2],'linewidth',3)
        axis([-0.1 1.5 -0.1 1.5])
        pause(0.08)                  % it shows the pause of graph after one for loop complete
       M(ct)=getframe(gcf);          % it is used to store each frame
       ct=ct+1;
      
    end
end
movie(M)                    % it stores all the frames got above
videofile= VideoWriter('robotic_arm_kinamatics.avi',"Uncompressed AVI")  % it is used to cread  video file & its type
open(videofile)             %  here we open the video files
writeVideo(videofile,M)     % here we write or merge all the frames to get a video
close(videofile)            % after cfreating we close the file

A REPORT ON 2R ROBOIC ARM CHALLENGE.

Aim :-

Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.

Governing equations :- L2 (x2,y2)

(x1,y1)

L1 2

1

(x0,y0)

Figure :- Robotic ARM Mechanism.

The above figure shows the inputs & outputs for various position of 2R link arm mechanism. It is used to calculate various positions with variation in theta (ɵ) for robotic arm in any industry so that we can get ease of using that arm.

X0 = 0

Y0 = 0

The above equation shows various co-ordinate points for x & y with respect to theta (ɵ).

Objective:-

To get a proper simulation of 2R-robotic arm.

Body of the project

Here we assume value for l1 and l2 and consider value of theta from 1 to 90 degree.

In this program we use nested ‘for loop’ to get desired result. Looking the-program it is clear that ‘I’ is the value of theta which ranges from 1 to length of theta1 & value of ‘j’ is the value of theta which ranges from 1 to length of theta. Here after 1st ‘for loop’ executed then next ‘for’ loop will be executed for all the values and this cycle continues.

We use sind & cosd rather than sin & cos. This is because our input values are in degree that’s why we have to use sind & cosd.

In plotting we use pause for our graph which says that after each for loop-executed we get a pause of 0.08 seconds.

Problems faced :-

1.

I continuously get this error while performing. After this I made changes in that line add brackets then I found that my program is continue after for loop without any enter.

2.

After using figure command. I get this messy result so avoid that.

3.

Without using “plot & hold on” command. I get this messy result and my lines get coloured randomly.

I remove the hold on command and add pause command there as directed in the videos.

4.

Initially I don’t get-animation, I used line command which shows me a lot of graph in different windows.

So, I use plot command and use all my co-ordinate points in one line.

Initially it’s hard to get video. But I saw the video them it is clear to me.

Final program :-

% A Program to calculate various positions of 2 link robotic arm mechanism

clear all % to clear workspace

close all % to close all the windows like plot

clc % to clear the commands.

% inputs required for calculations

l1 = 1; % length of first link arm

l2 = 0.5; % length of second link ara

theta1 = linspace(0,90,10); % various angle position of link 1

theta2 = linspace(0,90,10); % various angle position of link 2

ct=1;

for i = 1:length(theta1) % here we says that i varies from 1 to length of theta1

THETA1 = theta1(i); % the value of theta1 ar various positions of i nstored in new variable THETA1

for j = 1:length(theta2) % here we says that j varies from 1 to length of theta2

THETA2 = theta2(j); % the value of theta2 ar various positions of i nstored in new variable THETA2

x0 = 0; % initial value of x for link 1

y0 = 0; % initial value of y for link 1

x1 = l1*cosd(THETA1); % final value of x for link 1 & initial value of x for link 2

y1 = l1*sind(THETA1); % final value of y for link 1 & initial value of y for link 2

x2 = x1+l2*cosd(THETA2); % final value of x for link 2

y2 = y1+l2*sind(THETA2); % final value of y for link 2

% plotting

plot ([x0 x1], [y0 y1], [x1 x2], [y1 y2],'linewidth',3)

axis([-0.1 1.5 -0.1 1.5])

pause(0.08) % it shows the pause of graph after one for loop complete

M(ct)=getframe(gcf); % it is used to store each frame

ct=ct+1;

end

end

movie(M) % it stores all the frames got above

videofile= VideoWriter('robotic_arm_kinamatics.avi',"Uncompressed AVI") % it is used to cread video file & its type

open(videofile) % here we open the video files

writeVideo(videofile,M) % here we write or merge all the frames to get a video

close(videofile) % after cfreating we close the file

Conclusion:-

Hence, we get various co-ordinate points and get the desired result.

For video file we collect all then frame using get frame command and then we merge all those into a movie (M) using write video command.

The link of the videos is as follows: -

https://youtu.be/C_6kmtpHZi8

https://youtu.be/C_6kmtpHZi8

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.