Challenge

Week 2- 2R Robotic Arm Challenge

Forward Kinematic 2R Robotic MANUPLATOR

Explanation of MATLAB code for roboticarm.m

% inputs

l1 = 1;

l2 = 0.5;

l1 and l2 are the length of the links and are in Meter.

theta1= 45;

theta2= 90;

theta1 and theta2 are the angles that are made by the links with the X axis. Both values are in degree.

https://drive.google.com/file/d/199OMryUKcFb_DTxBzSAJcmY3PbUnMBqJ/view?usp=sharing

% coordinates

Coordinates are used to determine the location of robot and the area of working space.

x0= 0;

y0=0;

x0 and y0 defines the origin that is the base of the robot.

x1=l1*cosd(theta1);

y1=l1*sind(theta1);

x1 and y1 are the coordinates of the ending of first link and beginning of second link. Here we use cosd and sind instead of cos and sin because theta is specified in degrees.

x2= x1+l2*cosd(theta2);

y2= y1+l2*sind(theta2);

X2 and y2 are the coordinates of the ending of link 2 where the manipulator is located.

% plotting

line([x0 x1],[y0 y1],'linewidth',3,'color','r');

line([x1 x2],[y1 y2],'linewidth',3,'color','g');

Here we used the line command to plot the links of the robot where (xo x1 y0 y1 ) and (x1 x2 y1 y2) are the coordinates of the robot and linewidth is the command to give thickness to the line plots and colour is used to give specific colour to the lines.

We get the following result

Here red line shows the link one that makes angle theta1 and green line shows the link two that makes angle theta 2.

Explanation for MATLAB code roboticarmmotion.m

close all

clear all

clc

% inputs

l1 = 1;

l2 = 0.5;

Same explanation for the length as explained above for previous MATLAB file.

theta1= linspace(0,90,10);

theta2= linspace(0,90,10);

ct=1;

Here theta1 and theta2 are the angles that links make with the x axis but here we used the linspace command because we want to see the position at different angles.

Linspace command helps us to generate linearly spaced values/vectors between the starting point and ending point. Here starting degree is 0 and ending degree is 90 and is the 10 is the number of points it is going to take.

Here we used for command to because we want to test/check the position of links at different values to theta. As there are two values to theta that’s why we tool for loop twice that is one for theta1 and other for theta2.

for i=1:length(theta1)

Theta1= theta1(i);

for j= 1:length(theta2)

Theta2=theta2(j);

x0= 0;

y0=0;

Now the values for x1 and y1 will change according to Theta1 as different values will be considered between 0 to 90 degrees.

x1=l1*cosd(Theta1);

y1=l1*sind(Theta1);

As stated above values to x2 and y2 will also change according to Theta2.

x2= x1+l2*cosd(Theta2);

y2= y1+l2*sind(Theta2);

% plotting

Under plotting we used different commands. we can use command such as plot, hold on. We used command axis so that we can create our own axis so that graph/diagram clearer and sharper. -1 1 0 1.5 shows the axis.

axis([-1 1 0 1.5])

Plot command is used to plot all the values with the line width 3.

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

pause(0.03)

M(ct)= getframe(gcf);

ct=ct+1;

counter command is used for the increment of varibales.

end

end

movie(M)

videofile= VideoWriter('forwardkinematic.avi','uncompressed AVI');

open(videofile)

writeVideo(videofile,M)

close(videofile)

movie command helps us to save the plots as a movie. So different commands are used.

I got an error while writing the code but was able to find the error and rectify it

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.