Robotic Arm Animation
- AIM :
- To write a program to simulate the forward kinematics of a 2R Robotic Arm using MATLAB.
- OBJECTIVE :
- The objective of this project is to plot graph of positions of a robotic arm with respect to change in angle of inclinations.
- This project helps us to determine the reach of the Robotic arm at different positions.
- BODY OF CONTENT :
- Inputs :
- The program initially starts with defining the lengths (L1 & L2) of two arms which are connected to each other.
- The angle between first arm and X-Axis is given as theta1 while angle between second arm and X-Axis is given as theta2. Both are defined using ‘linspace’ to get a specific range of 0° to 90° with a gap of 10°
b. Code :
- In order to iterate the code for 10 different positions of each arm, we need to use a ‘for loop’ for both arms separately.
- Inside the for loop we write our program starting by fixing the base point at [0,0] and the endpoint of first arm. The start point of second arm is same as the end point of first arm.The end point of second arm is also defined.
c. Plot :
- The plot command is used to plot the points ([x0 x1],[y0 y1],[x1 x2],[y1 y2]).The axis is defined and pause command is used to set up a proper speed of animation.
d. Movie :
- To make a video; we need to use a variable (ct) before the for loop and assign in a value of unity. Then we need to create an array M which collects all the frames and stores it. Then we need to increment the value of ct by 1 inside the for loop.
- We end the for loop. Create a movie using movie command.
- Create a videofile to save the file in .avi format uncompressed.
- Write commands to open, edit & close the videofile.
4. CODING :
clear all
close all
clc
% Inputs
% Length of Arms
l1 = 1;
l2 = 0.6;
% Angle of Inclination
theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);
ct = 1;
for i = 1:length(theta1)
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 2 0 2]);
grid on
pause(0.05);
M(ct) = getframe(gcf);
ct = ct + 1;
end
end
movie(M);
videofile=VideoWriter('Challenge3_Robotic_Arm.avi','Uncompressed AVI');
open(videofile);
writeVideo(videofile,M);
close(videofile)
Errors Faced :
Steps taken to overcome the error :
The Error was due to an incorrect entry of the command VideoWriter which was enterd as videowriter (case-sensitive).
4. OUTPUT :
https://drive.google.com/file/d/1vLqZmGsW1vVn4SI4L5gn60neDEFMKF0x/view?usp=sharing