Challenge

Week 2- 2R Robotic Arm Challenge

% Forward kinematics of a 2R robotic arm manipulator


%inputs
l1=1;
l2=0.5;

theta1=45;
theta2=40;


%coordinates
x=0;
y=0;

>>command error for not executing exact x,y coordinates.It got rectified by executing x0,y0 coordinates properly;;

x0=0

y0=0

%calculating the position of an link1 & link2 mechanism

x1=l1*cosd(theta1);
y1=l1*sind(theta1);

x2=x1+l2*cosd(theta2);
y2=y1+l2*sind(theta2);

>> By changing THETA values we can change plot by different angles;;

%plotting

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

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

>>Executing an 2R arm manipulator movement plot::

% inputs
l1=1;
l2=0.5;

>> linspace command: makes an interval is constant;

theta1=linspace(0,90,10);
theta2=linspace(0,90,10);

>>ct command: increases  an figure and represents each and every frame and for loop by entering ct=ct+1;;

ct=1;

>> For Loop command reperates the command for (i) times;;


for i=1:length(theta1)
Theta1=theta1(i);

for k=1:length(theta2)
Theta2=theta2(k);

%coordinates


x0=0;
y0=0;

>>cosd&sind executes exact 90degress angle;;

x1=l1*cosd(Theta1);
y1=l1*sind(Theta1);

x2=x1+l2*cosd(Theta2);
y2=y1+l2*sind(Theta2);

%plotting[x1,x2],[y1,y2]

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

>> command error because of not executing the x,y coordinates in proper order;;

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

>> By placing axis we can fix proper position of x&y coordinates;if not x&y coordinates varies from each other;

>> hold on command executes the plot to don't get overlap;

>>pause command executes where THETA value changes;

axis([-0.1 1.5 0 1.5]);
pause(0.03)
ct=ct+1;

>>'m' for creating an animation video

>>getfram for getting different frames of an arm movement which varies by x&y,THETA variables


m(ct)=getframe(gcf);

end
end

>>end command used for an end of programm;

>>movie(m): creating an animation profile;

>>videofile : where file can be saved;

>>videowriter: file name was executed;

>>writevideo: writes the video and saves the video.

%output of the program

movie(m)
videofile=VideoWriter('robotic_arm_animation.avi','Uncompressed AVI')
open(videofile);
writeVideo(videofile,m);
close(videofile);

 >> INSERT CODE


%inputs
l1=1;
l2=0.5;
function[c]=robotic_arm_animation(l1,l2,theta1,theta2)

theta1=45;
theta2=30;


%coordinates
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.1 1.5 0 1.5];
ct=ct+1;
end

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.