Week 2- 2R Robotic Arm Challenge
Robotic Arm- Forward Kinematics
In this, the length of the robotic arms are taken as 1m and 0.5m respectively.
1st arm and 2nd arm is provided with movement of 90degree and 180 degree.
PROGRAM CODE
clear all
close all
clc
% inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,90,10);
theta2 = linspace(0,180,10);
ct=1;
for i=1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% cordinates
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)
xlabel('x-cordinates')
ylabel('y-cordinates')
axis([-0.5 1.5 0 1.5])
pause(0.1)
M(ct)= getframe(gcf);
ct=ct+1;
end
end
movie(M)
videofile=VideoWriter('forwardkinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
EXPLANATION OF PROGRAM CODE
1st 3 line
clear all
close all
clc
This will help us to clear all the previous data and starts it as a fresh page
Line 5 & 6
Inputs are given for the length of the arms
Line 7 & 8
The degree of movement of the arms are given , Instead of giving 90 degree and 180 degree Linspace command is used with an interval of 10 values in between 0 & 90, 0 & 180.
Line 10 to 13
With the help of a for loop we can change the values of theta and the movement of the arms are possiblie.
Loop counters are given for respective arms like 'i' and 'j'.
Line 9
Counter commad is given before and after the for loop, as the interval between the theta is 10 and the it will be showing totally 100 value one by one till the for loop runs in the condition provided.
Line 15 to 20
Input data of the cordinate position of the arms
Line 22
Plotting command is given , as it visualize the arms postions
Line 23 & 24
xlabel and ylabel are provided for giving respective names for x axis and y axis
Line 25
The axis are given to fix the axis of rotation of the arms, if not provided the axis will continously changing.
Line 26
Pause command is given for adjusting the speed of movement of the arms in the plot.
Line 29 & 30 - for loop is a closed loop, as end are provided in these lines Two for loops are considered for respective arms.
Line 31 to 35 - These command are used to convert the animated plot into videofile and is saved automatically , this can be viwed when ever it is required.
OUPUT IS OBTAINED
ERROR FACED
In line 33 instead of open(videofile) , open('videofile') is given. But the animated output was obtained but showing error after that.
It was rectified by the technical support team.
Video Link https://youtu.be/vWt4bcC_u58