Week 2- 2R Robotic Arm Challenge
write a code for forward kinematic 2-r robotic arm.
robot genrally have two length .i.e links and one of it a botom link and other is manipulator at the top.
we first provide the inputs for the length of robotic arm
as l1 and l2
now we require a particular range of angles for robotic arm rotaion
here range of angle (theta) given from 0-90 degree
for both the link of robotic arm.
using linspace command range of theta from 0-90 for getting 10 values
(ct) counter command used for different frame .
for the number of values and and the number of different frame of robaotic arm .i.e for creating loop for the animation using for loops.
for the bottom link use for loop as 'i' which cover the ; range from 1 to the length of theta 1 .i.e i= 1-10 values
for the top link ..i.e. manipulator use for loop as 'j' which cuver the ; range from 1 to the length of theta 2 .i.e i= 1-10 values
x0y0, x1y1, x2y2, are the coordinates for the robotic arm.
after this plotting the robotic arm using 'plot' command
plotting coordinates with linewidht 3
linewidth command use to change a thickness of line,curve,...etc
after this , axis limits given for the coordinates fo x and y by using the axis command
pause command used for slow-motion of robotic arm
now , creating a movie for the animation of the robotic arm as the name of m,
after this provide a name to file, videofile and under the videowriter command named a animation as forward_kinematic.avi
and after this close the videofile by using command close.
https://drive.google.com/file/d/1zRx5mifdn1Ih0Uctg25AGsTUXRnLG-US/view?usp=sharing
% program for forward kinematic 2R robotic arm
% inputs
% length
l1=1; %(bottom link of length)
l2=0.5; %(top link of length)
% Angle (angle given both link for rotaion)
theta1=linspace(0,90,10); %(angle for link 1 varry from 0-90 for 10 values)
theta2=linspace(0,90,10); %(angle for link 2 varry from 0-90 for 10 values)
ct=1; %(counter command for plotting)
for i = 1:length(theta1) %( this loop for the link L1 )
THETA1=theta1(i);
for j = 1:length(theta2) %( this loop for the link L2 )
THETA2=theta2(j);
x0=0; %( strting co-ordinates for x and y)
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]); %( axis limtes for x and y)
pause(0.003);
m(ct) = getframe(gcf);
ct=ct+1; %(increment in counter)
end
end
%(creating movie for the animation)
movie(m) %(genrating movie with all frame)
Videofile = VideoWriter('forward_kinematic.avi','Uncompressed avi'); %(file name)
open(Videofile)
writeVideo(Videofile,m)
close(Videofile);