Week 2- 2R Robotic Arm Challenge
TITLE:-FORWARD KINEMATIC 2R ROBOTIC ARM
AIM-To calculate position of robotic arm for different angle
PROGRAMME
%Forward_kinematic 2R robotic arm
clear all
close all
clc
%Input
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,80,5);
theta2 = linspace(0,80,5);
ct = 1
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
%co-ordinate
x0 = 0;
y0 = 0;
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
%plottong
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3);
axis(-0.1 1.5 -0.1 1.5)];
pause(0.3);
M(ct) = getframe(gcf);
ct = ct+1;
end
end
movie(M)
videofile = VideoWriter('forward_kinematic.avi','Uncompressed AVI');
open(videofile);
WriteVideo(videofile,M);
close(videofile)
then run this program result will be animated video file for two arm robotic positional plot
Programme description
We are starting programme with programme statement-
e.g %Forward_kinematic 2R robotic arm
then with
clear all
close all
clc
Let say arm 1 has length l1 of 1meter & other arm has length l2 of 0.5 meter
We have 5 angles for both arms
Θ1=0° , 20°, 40°, 60° & 80° for that we have used linspace command for this range of 0 degree to 80 degree with 5 interval between
Same for θ2 = 0° , 20°, 40°, 60° & 80°
theta1 = linspace(0,80,5);
theta2 = (linspace(0,80,5);
ct = 1 (which is contour)
For this array of different angles we have used ‘for’ loop command
Here, we have two arms with two different angles we are using 2 for loops as below
For i = 1:length(theta1)
THETA1 = theta1(i);
For j = 1:length(theta2)
THETA2 = theta2(j);
Arm Positions with co-ordinates- inputs
x0 = 0 , y0 = 0
x1, y1 are the end of 1st link & start of 2nd link
Where as, x2, y2 is end of 2nd link
Thus with trigonometry we have equations for arm positions
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
%plotting-in this section we are giving input to programme i.e what to plot in plot command
So, plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],’linewidth’,3);
Axis range values mentioned in programme code
So, axis([-0.1 1,5 0 1.5])
Pause(0.03) which is tie interval between each plot while performing animation
To create animation for number of plots(figures) we are using below command
M(ct) = getframe(gcf); (gcf is get current frame)
Ct = ct+1;
End
End
ERRORS & IT'S OVERCOME ACTIONS
- Filename was wrong-corrected & saved as new programme with new name to run the programme
- Axis scale given in single colon-colon removed within the brackets
- Axis scale bracket missing-corrected by providing square bracket
- While creating animation with M(ct)command getframe(gcf) was written as
M(ct) = ct+1
Corrected as M(ct) = getframe(gcf);
errors screenshots attached as per it's error number
please check belowlink foranimation video
https://1drv.ms/v/s!ApWbfqb7PQOJjQ85_bLR_1E188EN?e=dxpkA0
Thanks