Challenge

Week 2- 2R Robotic Arm Challenge

% Forward kinematics of a 2R robotic arm 
clear all
close all
clc

% Inputs
l1 = 1;
l2 = 0.5;
theta1 = linspace(0,110,15);
theta2 = linspace(0,110,15);


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([-1 2 -1 2])
        pause(0.1)
        M(ct) = getframe(gcf);
        ct = ct+1;
    end
end    

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

YOUTUBE VIDEO LINK

https://youtu.be/Xq_QxOUbeu4

Starting from inputs

l1 and l2 are the lengths of arm1 and arm2 respectively

theta1 and theta2 are the angles formed by the arm1 and arm2 with respect to x-axis

For getting multiple values of theta1 and theta2 we are using linspace command 'linspace(0,110,15)' in which '0' is the starting point, '110' is the end point and '15' is the number values between '0' to '110'

As we are taking multiple values for theta1 and theta2 we need to change the values through programming for which we are using 'for loop' command so that our calculation will be repeated for multiple values

After that we had assigned three points

1) (x0,y0) which is the starting point of arm1

2) (x1,y1) which is the end point of arm1 and starting point of arm2

3) (x2,y2) which is the end point of arm2

As starting point of arm1 is fixed at the origin so the value of (x0,y0) is (0,0) and the formula to calculate (x1,y1) and (x2,y2) is provided

After this complete calculation part now comes the plotting part

So for plotting we use plot command and we assign the co-ordinates to be plotted

we had used the 'linewidth' command to customise the line width according to us after that 'axis' command is used to define the axis we want

the next is 'pause' command used to pause the plot for certain time before it changes to next assigned values

After that 'getframe' command is used to record the axes

After ending for loop using 'movie' command movie of array 'M' is recorded

Using 'VideoWriter' command video of the output is made

One error was occured during this program i had use colon operator instead of coma in 'linspace' command screenshot of same is attached below

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.