Challenge

Week 3.2 - 2R Robotic Arm Challenge


Aim:
1. Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm, as shown in the video.
2.Create an animation file of the plot.
3.Upload an animation on You tube and provide the You tube link for an animation in the report.

Objective:
1.watch the full vedio.
2.write the code script for making robotic arm and movement of the links.
3.Learning the concept of making plots.
4.learning the concept of creating animation vedio by the help of codescript.
Body of the project:
INSERT SAMPLE CODE:
close all
clear all
clc
%inputs
l1= 1;
l2 = 0.5;
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);
%plotting
plot([x0 x1],[y0 y1],[x1,x2],[y1,y2],'linewidth', 3)
axis([-0.5 1.5 0 1.5])
pause(0.03)
M(ct) = getframe(gcf);
ct =ct+1;
end
end
movie(M);
Videofile = VideoWriter('forward_kinematics.avi');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)
Explanation:

Clear all is used to clear previous variables, values, size arrays from the workspace

Close all is used to close all the previous program.

Clc is used to clear all the values from the command window.

As per the video for making the robotic arm we need link. Here I am taking 2 link .
I am assuming the size of the link1 is 1 and link2 is 0.5. If i assume that
link1 and link2 connected with each other with rotational joint and the link 1 is joined

with base with rotational joints.

step 1 - will be finding the position of link 1.

step-2- will be finding the position of link 2.

we need calculate the co-ordinate of the starting value


for rotating them we need theta as degree. for getting the rotation rotation
we need different values of theta to rotate.

theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
for getting iteration for different value of theta we have to use for loop.

if in 2d plot if there two graph x and y then we can divide them in a component method where we can get the position of the

liks. So, there are three co-ordinates.

so, we start from 'zero' which is the base of the robot.

x0 = 0;
y0 = 0;
then the position of the link 1, which get from the co-ordinate
x1=l1*cosd(THETA1);
y1=l1*sind( THETA1);
then the position of the link 2,
x2= x1 + l2*cosd(THETA2);
y2= y1 + l2*sind(THETA2);

initialy i start the value of the 'ct' as 1 and after first iteration it will go to second iteration and it will runs automatically untill the last itteration.ct= 1;
here, i am taking the varriable M as an array and for getting the iteration of 10 times .
i want an increment the ct as each and everytime forloop get executes. thatswhy i am writing ,'ct =ct+1'
after that i am ending the two for loops so that code get complete the iteration as per the equation inside the for loop and get
different positioned plot which is used to make the video.

for fixing the axis of the links,

axis([-0.5 1.5 0 1.5]) - command is used.

For getting the visualise the animation for particular time i will use

pause(' write required time')

For making movie I am using movie(M) command.
for naming the Videofile = VideoWriter('forward_kinematics.avi'); command is used
for open the vedio file open(videofile) command is used.
to write the vedio 'writeVideo(Videofile,M)' command is used.
for closing the vediofile 'close(Videofile)' command is used.

after running the whole code matlav succesfully created a vedio by using the plot.

Note: I am attaching the vedio file link which i uploaded on the youtuube :-https://youtu.be/oriy7oy30mk
Conclusion:
1.From this challenge i learned how to create robotic arm by using link.
2.How to get frame or plots one by one as per the iteration,
3.How to use movie command to create vedio, save vediofile with the proper name.
Note: All the output is attached below, video also attached below.
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.