Challenge

Week 2- 2R Robotic Arm Challenge

AIM: To Write a program in Matlab to simulate the forward kinematics of a 2R Robotic Arm

OBJECTIVES:

  1. To simulate the forward kinematics of a 2R robotic arm
  2. To produce animation of a robotic arm movements.

DIAGRAM OF FORWARD KINEMATICS ROBOTIC ARM:

  • Above diagram represents forward kinematics robotic arm consist of link 1 and link2

where,

`x0=0`

`y0=0`

`x1 = l1*cos(theta1)`

`y1 = l1*sin(theta1)`

`x2 = x1 + l2*cos(theta2)`

`y2 = y1 + l2*sin(theta2)`

Link1 = `l1`

Link2 = `l2`

PROGRAM TO SIMULATE FORWARD KINEMATICS OF 2R ROBOTIC ARM:

%program to make 2d arm movie

clear all
close all
clc

%inputs
l1 = 1;
l2 = 0.5;

theta1 = linspace(0,90,10);
theta2 = linspace(0,90,10);

ct = 1;
for i =1:length(theta1)
    THETA1 = theta1(i);
    for j = 1:length(theta2)
        THETA2 = theta2(j);
        x0 = 0;
        y0 = 0;

        x1 = l1*cosd(THETA1);
        y1 = l1*sind(THETA1);

        x2 = x1 + l2*cosd(THETA2);
        y2 = y1 + l2*sind(THETA2);

        %plotting
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        axis([-0.1 1.5 0 1.5])
        pause(0.03)
        m(ct) = getframe(gcf);
        ct = ct+1;
    end
end

movie(m)
videofile = VideoWriter('forward_kinematics.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,m)
close(videofile)

EXPLANATION:

  1. Program start with clear all,close all,clc
  2. Inputs taken for link 1(l1),link (l2) and `theta1` and `theta2`
  3. linspace command use in `theta1` and `theta2`. Linspace command generate n number of equally spaced elements between given inputs.
  4. before for loop counter (ct) use with starting value as 1
  5. Nested for loop use to program link 1 and link 2 angular movements. Primary for loop function for `theta1` and nested for loop function for `theta2`
  6. In nested for loop function all the cordinates define. Here, to get angular values in degree [cosd(x)] use and to avoid in radian
  7. ploting coordinates
  8. pause(n) to stop execution for n seconds
  9. To capture frames for movie getframe function use
  10. All figures assigned to variable m one by one using ct
  11. Termination of primary and nested for loop functions
  12. movie(m) plays frames in array m.
  13. videowriter function use to write data to avi file
  14. call open(videofile)
  15. writevideo function use to write all frames
  16. video file close by using close function

WORKSPACE:

ANIMATION OF 2R ROBOTIC ARM:

CONCLUSION: Practical and realastic experience of forward kinematics 2R robotic arm movements done by simulation in Matlab.

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.