Week 2- 2R Robotic Arm Challenge
yutube link of output:
https://www.youtube.com/watch?v=Ogs0XOVoBIM
simulate the forward kinematics of a 2R Robotic Arm
%simulation the forward kinematics of a 2R Robotic Arm
close all
clear all
clc
%lets assume lenghth of base arm L1 as 1meter
L1=1;
%lets assume lenghth of second arm L2 as 0.5meter
L2=0.5;
%lets assume base cordinate of base arm (x0,y0) be origin(0,0)
x0=0;
y0=0;
%ct is the frame to hold the plots
ct=1;
%assume the end point of base arm be at (x1,y1)
%also note that the end point of base arm is starting point of second arm
%end point of second arm be at cordinate (x2,y2)manupulator is attached.
%the angle made by base arm with respect to horizontal baseline be theeta1
%the angle made by second arm with respect to the base line be theeta2
%angle theeta1 be 0 to 90 degree with 20 equal spaceing
theeta1=linspace(0,90,20);
%angle theeta2 be 0 to 90 degree with 20 equal spaceing
theeta2=linspace(0,90,20);
%now we can express (x1,y1) in terms trignometric function,
%consider right triangle with origin(0,0)hypotnus L1 and angle theeta1
%x1 is L1*(cosd(theeta1)) & y1 is L1*(sind(theeta1))
%to calculate (x1,y1) for angle 0 to 90 with equal interval
%create temprory arry Theeta1 that holds value of angle from theeta1
for Theeta1=theeta1
x1=L1*cosd(Theeta1);
y1=L1*sind(Theeta1);
%now we can express (x2,y2) in terms trignometric function,
%consider right triangle with starting(x1,y1)hypotnus L2 and angle theeta2
%x2 is L2*(cosd(theeta2))+x1 & y2 is L2*(sind(theeta2))+y1
%second for loop provide set of data with respect to individual angle of l1
%to calculate (x2,y2) for angle 0 to 90 with equal interval
%create temprory arry Theeta2 that holds value of angle from theeta2
for Theeta2=theeta2
x2=x1+L2*cosd(Theeta2);
y2=y1+L2*sind(Theeta2);
%plot positon of basearm and second arm with a linewith of 3mm
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3 );
% insert grid and label x and y axis
grid on
xlabel("x axis")
ylabel("y axis")
%to fix the orgin point to the axis
axis([-0.1 1.5 0 1.5])
pause(0.01)
%assigning each ploted graph to M(ct) which stores individual frames and
%frame value is incrimented by 1 each loop
M(ct)=getframe(gcf);
ct=ct+1;
end
end
% to create a video file of the animation
%use function movie() to process the data from M(ct)
movie(M)
%create new video file with video name and format uncompressed avi
videofile=VideoWriter("forwardkinamaticschallenge1.avi","Uncompressed AVI")
%command to open the video file
open(videofile)
%write the plots/frames to video file
writeVideo(videofile,M)
%close the videofile and save
close(videofile)
note:
output screenshot , link has been atached and code explanation has been commented .
final output provides us with a video file with an animation of the 2 arm base arm bluecolour and second arm red colour in uncompressed avi format.
it shows us the possible positions of the movment of arm while assuming the min to max angle of both arm is 0 to 90 degree from base or xaxis