Week 2- 2R Robotic Arm Challenge
Aim:
To create a program for three arm robotic arm using MATLAB program.
General Procedure:
- Create a script file in MATLAB.
- Use basic commands to clear,close all variables and clear command box.
- Save the script file.
Procedure:
Inputs like robotic arm length,angle has to be given to get the postion of the arm i.e., coordinates of each arm and plot it to get various positions of the robotic arm
- Inputs given as robotic arm length(l1,l2,l3)
- Angle of the robotic arm given as `theta_1`,`theta_2`,`theta_3`
- Various angles are given using linspace command
- theta_1=linspace(0,90,10) for robotic arm-1
- theta_2=linspace(0,120,10) for robotic arm-2
- theta_3=linspace(0,45,10) for robotic arm-3
- Create a nested for loop for each of robotic arm.
- Calculate position of the robotic arm-1 i.e., coordinates (x1,y1) using arm length l1 and angle theta_1.
- Calculate position of the robotic arm-2 i.e., coordinates (x2,y2) using arm length l2 and angle theta_2 and arm length postion (x1,y1).
- Calculate position of the robotic arm-3 i.e., coordinates (x3,y3) using arm length l3 and angle theta_3 and arm length postion (x2,y2).
- Plot all the positions of robotic arm in graph.
- Use hold on command to overwritten of graph.
- Use pause command to create a motion of lines in graph.
- Use counter and getframe command to capture each and every postion of the robotic arm.
- Create a videofile from captured frames.
- Use VideoWriter command to create name of the videofile and format of the videofile.
- Use open,writeVideo & close commands to write a videofile.
CODING:
close all
clear all
clc
%robotic arm 3%
l1=2
l2=1
l3=0.5
theta1=linspace(0,90,10);
theta2=linspace(0,120,10);
theta3=linspace(0,45,10);
%coordinates%
x0=0
y0=0
ct=1;
for i=1:length(theta1)
THETA1=theta1(i)
for j=1:length(theta2)
THETA2=theta2(j)
for k=1:length(theta3)
THETA3=theta3(k)
x1=l1*cosd(THETA1);
y1=l1*sind(THETA1);
x2=x1+l2*cosd(THETA2);
y2=y1+l2*sind(THETA2);
x3=x2+l3*cosd(THETA3);
y3=y2+l3*sind(THETA3);
%plotting
plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],[x2 x3],[y2 y3],'linewidth',3)
axis([-0.5 4 0 4])
pause(0.1)
M(ct)=getframe(gcf);
ct=ct+1;
end
end
end
movie(M)
videofile=VideoWriter('robotic_arm_3.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)
Results
Graphs are plotted and videofile is created for robotic arm.
***Note***:Videofile is too big to upload nearly 1 gb
https://youtu.be/CHY7dDDBXmM