Challenge

Week 2- 2R Robotic Arm Challenge

Program for Challenge 2R Robotic Arm

% Challenge Program To Simulate the Forward Kinematics of a 2R Robotic Arm

% Inputs 
% Arm Lengths
arm1 = 5
arm2 = 3

% Both the arm position is define by angles 
% linspace command is used to have the range of position of arms
angle1 = linspace(0, 75, 10);
angle2 = linspace(0, 60, 10);

% Using 'For Loop' command to move the arm in respect to each other for
% given range of angles
ct = 1
for i = 1:length(angle1);
    ANGLE1 = angle1(i);
    for j = 1:length(angle2);
        ANGLE2 = angle2(j);

        % cordinates for locating the Arms in graph,

        x0 = 0
        y0 = 0

        x1 = arm1*cosd(ANGLE1);
        y1 = arm1*sind(ANGLE1);

        x2 = x1 + arm2*cosd(ANGLE2);
        y2 = y1 + arm2*sind(ANGLE2);

        % Ploting the arms on graph using plot command
        % here (x0, y0) and (x1,y1) are the cordinates for the arm1
        % also (x1, y1) and (x2, y2) are the cordinates for the arm2
        % we have used the plot, counter and pause to represent the arms
        % and its various postion in one single animation

        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2]);
        
        % giving a fix and proper limits to the axis
        axis([-5 10 -2 10]);
        pause(0.1);

        % getting all the individual frames in an arry called M
        % using getframe command to get current figure window
        M(ct) = getframe(gcf);
        % first svae the frame and then increment the counter
        ct = ct + 1;
    end
end
% to genreate a move using all the frame movie(m) command is used    
movie(M)
% creating a video file by using videoWriter
videofile = VideoWriter('two_r_robotics_arm.avi','Uncompressed AVI');
% the video file will be open and then it will be played and closed
open(videofile)
writeVideo(videofile,M)
close(videofile)

Youtube link is provided below

Challenge 2R Robotic Arm

Explanation :

The Program is written to simulate the forward kinematics of a 2R Robotic Arm

Step1 : Title is give to the program using comments 2R Robotic Arm

Step2 : The inputs variables are define that is the length of the arm and the angle of the arms, the 2 Arms are arm1 and arm2 and the angle is angle1 and angle2 respectively. The angle are in reference to the hoizontal axis. The angle are different for different position of the arm therefore the angle is define by the linspace command.

Step3 : The cordinates of the arms1 (x0, yo) and (x1, y1) and arm2 (x1, y1) and (x2, y2) here the common poin (x1, y1) act as joint for two arms.

Step4 : The graph is plot using the plot command the, line command and the hold on command will creat the n number of graph so that all commands are collectively represent in the plot command with the ct(counter), pause and "for loop" command.

Step5 : Modifing the for Loop command by giving repetation of arms movement with the number of intervals in the angle, the arm2 moves in a given range for all the interval of arm1 that is given by using for loop command in an for loop command. So for every arm1 interval the arm2 moves in all given postition.

Step6 : Now collecting all the frames in arry using getframe command

Step7 : Now increment the counter

Step8 : End the for loops

Step9 : To generate a movie using all the frame the movie(M) command is used

Step10 : Creating a Videofile using the VideoWriter('name.avi','Uncompressed AVI')

Step11 : now the commands open(videofile), writeVedio(videofile,M) and close(videofile) will open the created video file andplay the video file and then close the video files.

Step12 : You will find and "AVI" file in the respective matlab folder where you can check the animation of the 2R Robotic Arm

Problem :

1) The common cordinate x1 y1 was not added in the x2 y2 cordinate. Insteaded of x1 y1 i used to add arm1 length and arm2 length which use too eliminate my one interval evrytime in arm2 for each arm1 position.

For solution : I added the x1 y1 cordinates in the x2 y2

Thank You.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.