Challenge

Week 2- 2R Robotic Arm Challenge

% Challenge 4 - MATLAB Code for Froward Kinematics of 2R robotic arm 
% Inputs taken 
% Arm length in m
arm1 = 1
arm2 = 0.5
% Arm angle in degrees
angle1 = linspace(0,90,10);
angle2 = linspace(0,90,10);
% Counter for the program
ct = 1
%Operating Conditions for the Robotic Arm
for i = 1:length(angle1)
    ANGLE1 = angle1(i);
    for j = 1:length(angle2)
        ANGLE2 = angle2(j);
        x0 = 0;
        y0 = 0;
        x1 = arm1*cosd(ANGLE1);
        y1 = arm1*sind(ANGLE1);
        x2 = arm1 + arm2*cosd(ANGLE2);
        y2 = arm1 + arm2*sind(ANGLE2);
        % Plotting of Robotic Arm
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 1.5 0 1.5])
        pause(0.2)
        M(ct) = getframe(gcf);
        %Counter incremented for each execution of the "For"loop
        ct = ct+1;
    end
end
movie(M)
videofile = VideoWriter ('Forward_Kinematics_2R.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

PROCEDURE TO CODE THE SIMULATION OF FORWARD KINETICS OF 2R ROBOTIC ARM :

  1. Enter the inputs of arm 1 and arm 2 required to simulate the forward kinetics of 2R robotic arm.
  2. Give the range of the angles that the arm would have to be simulated for along with the interval, by using 'linspace' command.
  3. Initiate the counter for the program by entering 'ct=1'.
  4. Initiate the 'for' loop and give the operating conditions for the robotic arm.
  5. Enter the initial x and y coordinates, (x0,y0) as 0.
  6. Give the transformations for the coordinates (x1,y1) and (x2,y2).
  7. By using 'plot' command, create a plot by using the obtained coordinates, giving a linewidth of 3.
  8. Enter the range of the axes and give a pause time of 0.2 .
  9. Use the 'getframe' command and name it as the variable 'M(ct)'.
  10. Increment the counter for each execution of the 'for' loop.
  11. End the 'for' loops.
  12. Use the 'movie' command to initialize the creation of the animation of the obtained frames.
  13. Use the 'VideoWriter' command to initialize the writing the video. Give the name of the written video and the format of the video.
  14. By using 'open', 'writeVideo', 'close' commands to open, write and close the video respectively.

ERRORS ENCOUNTERED: - None

Video file of 2R Robotic Arm Animation

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.