Sei sulla pagina 1di 11

2R- Robotic

Arm Challenge

NOVEMBER 8

Skill-Lync Masters in Hybrid and Electric Vehicle


Authored by: Haseeb Ahmad

1
Code

clear all
close all
clc

l1=10;
l2=5;
x0=0;
y0=0;

alpha=linspace(0,90,10);
beta=linspace(0,90,10);
a=1;
for i=1:length(alpha);
Alpha=alpha(i);
x1=x0+l1*cosd(Alpha);
y1=y0+l1*sind(Alpha);
for j=1:length(beta);

Beta=beta(j);
x2=x1+l2*cosd(Beta);
y2=y1+l2*sind(Beta);

plot([x0 x1],[y0 y1],[x1 x2],[y1


y2],'linewidth',3);
axis([0 15 0 15]);
pause(0.03);
M(a)=getframe(gcf)
a=a+1;

2
end
end
movie(M)
Videofile=VideoWriter('forward_kinematics_challenge.mp4'
,'MPEG-4');
open(Videofile)
writeVideo(Videofile,M)
close(Videofile)

Link to video:-
This is the link to the video https://youtu.be/lcej2NxUA5s

Code Explanation
• Link sizes
• Starting coordinates
• Angle of link #1 "l1" with the base line(y-axis) is alpha
• Angle of link #2 "l2" with the base line(y-axis) is beta

• “For” loop changing indexes for angle alpha


• Nominating a singular array "Alpha" to store a single value from "alpha" row
vector containing multiple values
• “For” loop changing indexes for angle beta
• Nominating a singular array "Beta" to store a single value from a "beta" row
vector containing multiple values
• Plotting and axis definition
• Using “a” as counter variable for saving frames in matrix M
• Movie making

3
4
Errors Explanation & Correction
1-

5
• Plotting not done as expected So after getting to know the errors I figured
out that a variable must be named differently to refer to angles alpha and
beta because MATLAB had only recognized alpha and beta as arrays.

6
7
2-

• Respective indexes “I” and “j” were written on the line other then the “for”
loop. It was corrected by starting the indexes from the same line.

8
3-

• Plotting was being done after all the loops were done. Therefore, it was
corrected using plot in the nested “for” loop.

9
4-

• Staring letter of movie command was capitalized. It was corrected by making


it small.

10
5-

• Video was not being written because format of the “open” for opening the
desired file was not right. Equal “=” sign was removed and replaced by the
parenthesis to rectify the error.

11

Potrebbero piacerti anche