Week 2- 2R Robotic Arm Challenge
program for the simulate the : 2R Robotic arm
this is also refere as forward kinematics
To start the 2R robotics arm program first thing to understand is kinematics of the linkage. it contain two link and two rotational joints so both link L1 and L2 will make some angle with respect to x axis.
let L1 = link 1
L2 = link 2
both link will make angle theta suppose
L1 make theta1 and L2 make theta2 with respect to x axis
so if the theta 1 and theta 2 are given then what is the final position of the manupulator we have to calculate through this program
(manupulator can be building tool or maching too)
Solution
To calculate the position of the link1 :
so the link1 have two points which is starting point and end point, the starting point is fix to the base of the robot and ending point is connected to the link2 . so the starting coordinats are (x0,y0) =(0,0) and ending point is (x1,y1)= (l1*cos(theta1),l1*sin(theta1))
To calculate the position of the link2 :
Here the coordinates of the link2 are like that ending points of the link1 is starting point of link2 hence (x1,y1) and second points are (x2,y2) = {(x1 + l2*cos(theta2)),(y1 + l2*sin(theta2))}
hence solution set is (x0,y0),(x1,y1),(x2,y2)
so the program is as bellow
Here are some multiple values of theta1 and thets2 so that we can visualize the plot easily and also set the animation for more clarification through program.
inputs for the program are
link1 = 1.1 m
link2 = 0.4 m
theta here are in the renge of 0 to 90 degree for the both theta.
pause = 0.1sec
linspace for the interval of the degree 0 to 90 and having the calculation of 15 values for more clearance.
% forward kinematics of a 2R Robotic arm manupulator
clear all
close all
clc
%Inputs
l1 = 1.1;
l2 = 0.4;
theta1 = linspace(0,90,15);
theta2 = linspace(0,90,15);
ct=1
for i = 1:length(theta2)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
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])
pause(0.1)
M(ct) = getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile = videowriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writevideo(videofile,M)
close(videofile)
here with this answer the the attachment includes the code for the forward kinematics of 2R robotics arm and plotting graph.