Challenge

Week 2- 2R Robotic Arm Challenge

% A program tp simulate the forward kinematics of a 2r robotic arm

clear all
close all
clc
 
% inputs
% length of link-1 and link-2 in meter
L1=1;
L2=0.5;

% angle tracked by link-1 and link-2
theta_1=linspace(0,90,11);
theta_2=linspace(0,90,21);

% initialising base coordinates of link-1
x_0=0;
y_0=0;

ct=1;

for i=1:length(theta_1)
    THETA_1=theta_1(i);
    for j=1:length(theta_2)
        THETA_2=theta_2(j);

        % calculating the coordinates of end point of link-1
        x_1=x_0+L1*cosd(THETA_1);
        y_1=y_0+L1*sind(THETA_1);

        % calculating coordinates of end point of link-2
        % End coordinates for link-1are the start coordinates for
        x_2=x_1+L2*cosd(THETA_2);
        y_2=y_1+L2*sind(THETA_2);

        plot([x_0 x_1],[y_0 y_1],[x_1 x_2],[y_1 y_2],"linewidth",3);
        axis([-0.1 1.5 0 1.5]);

        % pausing the current plot for a while before moving to the next
        % plot
        pause(0.03);
        title('kinematics of 2R robotic arm')
        xlabel('arm movement in x axis');
        ylabel('arm movement in y axis');
        
        
        % Incrementing ct so that each frame is captured in M 
        ct=ct+1;
       
    end
end

% making a movie from collected frames
movie(M);

% Creating a video file of '.avi' format to save the animation 
videofile=Videowriter('forwardkinematics_of_2r_robotic_arm.avi','uncompressed AVI');
open(videofile);

% writing the movie in the videofile created
writeVideo(videofile,M);
close(videofile);



        

Explanation:

1. length of the both links are taken as input.

Lenght of link-1 L1=1m

Length of link-2 L2=0.5

2.Angles traced by both the links,for link-1 and link-2 is taken as input.

theta1=linspace(0,90,11)

theta2=linspace(0,90,21)

by this,11 values for theta will be calculated,which is starting 0 upto 90 degrees.

3.Base position of link-1(x0,y0) is considered as origin(0,0).

4.Then two for loops are used to interate over the range of angles traced by both the links.For each particular angle of link-1,link-2 is moved over its entire range,to obtain different positions of end effector at that angle of link-1.

5.For a particular value of angle theta1 and theta2 the end position of link-1 is calculated by these equations

x1=x0+L1.cos(theta1)

x2=y0+L1.sin(theta1)

The end position of link-1 is also the start position of link-2.the end position for link-2 is calculated by these equations.

x2=x1+L2.cos(theta2)

y2=y1+L2.sin(theta2)

6.Then each position of link-1 and link-2,a plot is made which is then captured frame to make a movie.

7.A video file of '.avi' format is made to save the movie.The movie is then written into the videofile and the final animation is created.

Errors:

I had write 'y_2' in the space of 'y_1'.

And write that 'y_1' replaces 'y_2' to overcome that error.

OUTPUT:

https://youtu.be/hqUu7qjetI0

Conclusion:

A simulation of the forward kinematics of 2R robotic arm was created using MATLAB program.

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.