Week 3.2 - 2R Robotic Arm Challenge
- Writing code for 2R Robotic arm Challenge.
Resultsclear all close all clc %definition of length of link 1 and 2 l1= 2 l2 =0.3 %definition of angles theta1= linspace(0,90,20); theta2= linspace(0,90,20); ct=1; %calculation of positions for i= 1:length(theta1) temp1 = theta1(i); for j= 1:length(theta2) temp2 =theta2(j); x0= 0; y0 =0; x1 =l1*cosd(temp1); y1 =l1*sind(temp1); figure(1) x2 =x1+2*cosd(temp2); y2 = y1+2*sind(temp2); plot([x0,x1],[y0,y1],[x1,x2],[y1,y2]); axis([0 3 0 3]) pause(0.001) M(ct)=getframe(gcf); ct=ct+1; end end movie(M) videofile =VideoWriter('ques5.avi','Uncompressed AVI') open(videofile) writeVideo(videofile,M) close(videofile) -
11 =
2
12 =0.3000
videofile =VideoWriter
General Properties:
Filename: 'ques5.avi'
Path: 'C:\Users\Shruti Jadhav\Documents\MATLAB'
FileFormat: 'avi'
Duration: 0Video Properties:
ColorChannels: 3
Height: []
Width: []
FrameCount: 0
FrameRate: 30
VideoBitsPerPixel: 24
VideoFormat: 'RGB24'
VideoCompressionMethod: 'None'Methods
>>
- Explaination
- input the given data by assigning suitable variables and here the we are using the "linspace" command to get the different values of theta1 and theta2 as per range mention in above code.
- After assigning the data, "for loop" command is used for assigning different values to theta1 as in THETA1 and similarly for theta2 as in THETA2.
- In next, input the coordinates for forward kinematic movement of 2R roboticarm.
- Then, using the "plot()" command plotting all the value of coordinates in graph.
- for better animation, using the "ctr=1...ct=ct+1" command for contouring frame.
- for making animation video, i'm using,
-
"M(ct)=getframe(gcf);ct=ct+1;movie(M)videofile= VideoWriter('ques5.avi','Uncompressed AVI');open(videofile)writeVideo(videofile,M)close" command.
- Here, the above code execute for creating the video(avi) file then with the use of "open(videofile)" command ,the video file open then using the command of "writeVideo(videofile,M)" above coding frame will be stored in video and using "close" command, closing the video file.
- So, this was the explanation about the above program.
You tube link-