Week 2- 2R Robotic Arm Challenge
% Matlab to simulate the forward kinematics of a 2R Robotic Arm
clear
close all
clc
% Assumed inputs
% origin points
x0 = 0;
y0 = 0;
% Length 1st and second arm
l1 = 1;
l2 = 1.3;
% angle of inclination
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
% Using for loop to plot and animate the 2R robotic arm
ct = 1;
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
plot([x0 x1], [y0 y1], [x1 x2], [y1 y2], 'linewidth',2)
axis ([-0.1 1.5 0 1.5])
pause(0.02);
M(ct) = getframe(gcf);
ct = ct+1;
end
end
% for creating a movie to upload in youtube
movie(M)
videofile = VideoWriter('forward_kinematics_2R_robotic_arm.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
EXPLANATION:
Assuming inputs such as origin point,length,angle of inclination
linspace command - we can get a inbetween values without changing the spacing inbetween values
using for loop i and j to get the values of x1 y1 x2 y2
and get that values in loop to demonstrate how the kinematic arm works.
Plot - to plot all the points we got
determining the axis
pausing command for each 0.2 seconds for the demonstration purpose
ct = ct+1 - we are adding 1+1 for every loop
For creating the movie:
creating a movie file using Video Writer command
naming the video, determing the format of the video
opening the video
writing what we need inside the video(in this case we need all the frames captured)
closing the video
REPORT:
Errors faced by me
- forgot to change the new variable THETA
- j = 1:lenght(theta2) undefined because spelling of length is wrong
- VideoWriter = v and w are not capitalized
- for and end are not aligned in for loop
VIDEO LINK IN YOUTUBE - https://youtu.be/4Vw5u5pQeY8