Week 2- 2R Robotic Arm Challenge
% Simulation of a Robotic Arm
clear all
close all
clc
%Inputs
%Length of the arms in meters
l1 = 1;
l2 = 0.5;
% Maximum angle of arms from x-axis
% Linespace command will generate matrix of numbers from 0 to 90 in 10 intervals
% e.g. numbers generated will be 0, 10, 20, 30, etc.
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
% variable for counting frames
ct=1;
% for loop to loop through the number of numbers in 'theta' matrix
% 'i' will loop throug 'theta' one and for every single number it will add that number to 'THETA1'
% 'j' will do the same as above but for 'THETA2'
for i = 1:length(theta1)
THETA1 = theta1(i);
for j = 1:length(theta2)
THETA2 = theta2(j);
% starting point for arm-1
x0 = 0;
y0 = 0;
% ending point of arm-1 and starting point of arm-2
x1 = l1*cosd(THETA1);
y1 = l1*sind(THETA1);
% end point of arm-2
x2 = x1 + l2*cosd(THETA2);
y2 = y1 + l2*sind(THETA2);
% Plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
% to display the graph to show the animation
axis([-0.1 1.5 0 1.5])
% to pause the process for 0.03 seconds
pause(0.03)
% To copy the frame shown on the plot window
M(ct) = getframe(gcf);
% add the number of frmaes to the variable 'ct'
ct=ct+1;
end
end
% To create the movie of animation of the above processes by running the frames copied in 'M(ct)
Movie(M)
% Creating a video file in '.avi' formate
videofile = VideoWrite('forward_kinematics.avi','Uncompressed AVI')
% open the video file created above
open(videofile)
% Wrte all the frames in this file
writeVideo(videofile,M)
% close this file
close(videofile)
YouTube video link fr simulation of robotic arm: https://youtu.be/v9ZRTHgNbd4
Errors made will creating this program:
1. Typo error wrong plots were displayed: I wrote 'thita1' and 'thita2' instead of writing 'THITA1' and 'THITA2'. The arms were ploted as a curve rather than a strate line. screen shot are attached below.
2. Typo error animation was not initialised: I forgot to type veriable for frame counter i.e. 'ct'. the error code was "'ct' variable is not defined' and the animation was not runing.screen short are attached below.
3. Typo error video not getting saved: I wrote 'VideoWrite' instead of typing 'VideoWriter' thus showing error 'unrecognised function or variable 'videowrite