Week 2- 2R Robotic Arm Challenge
Program of a Forward Kinematics of a 2R Robotic arm :
% robotic arm challenge
clear all
close all
clc
%inputs
l1= 1.2; %length of link1
l2= 0.8; %length of link2
%angles for arm from 0 to 90
theta1= linspace(0,90,20);
theta2= linspace(0,90,20);
ct= 1;
%for loop function
for i= 1:length(theta1)
THETA1= theta1(i);
for j= 1:length(theta2)
THETA2= theta2(j);
x0= 0; %starting co-ordinates for x-axis
y0= 0; %starting co=ordinates for y-axis
x1= l1*cosd(THETA1); %link1 co-ordinated for x-axis
y1= l1*sind(THETA1); %link1 co-ordinates for y-axis
x2= x1+l2*cosd(THETA2); %link2 co-ordinates for x-axis
y2= y1+l2*sind(THETA2); %link2 co-ordinates for y-axis
%plotting
plot([x0,x1],[y0,y1],[x1,x2],[y1,y2],'linewidth',3);
axis([-0.5 2.5 0 2.5])%plot values for x-axis and y-axis
pause(0.05) %pause time for each frame
xlabel('Along the X axis(m);'); ylabel('Along the Y axis(m)');
M(ct)= getframe(gcf);% frame for animation video
ct= ct+1; %increment for frame
end
end
movie(M)
vidfile= VideoWriter('forward_kinematics.avi');
open(vidfile)
writeVideo(vidfile,M)
close(vidfile)
Explanation:
l1= 1.2m [length of link1]
l2= 0.8m [length of link2]
theta1= 0 to 90 degrees [angle range for link1 with 20 intervals]
theta2= 0 to 90 degrees [angle range for link2 with 20 intervals]
linspace: This function generally linearly spaced vectors.
[x0,y0],[x1,y1],[x2,y2] are co-ordinates along the x-axis and y-axis for link1 and link2.
Forloop function: A forloop is arepetation control structure that allows you to efficiently write a loop that needs to execute a specific numbers of times.
M(ct) function is used to get the frame.
vidfile: It defines the name and formate of videos.
Link of the program:
https://drive.google.com/file/d/1a_WrwEfIYx9RjcGWkiBSCGvSA5-AlaXL/view?usp=drivesdk
* I did not faced any of the errors in this program.