Challenge

Week 2- 2R Robotic Arm Challenge

Aim :

Simulation of forward kinematics of a 2r robotic arm using Matlab.

Objective :

To write a code inorder to find the simulation of forward kinematics of 2r robotic arm and make a video file of the animation of the robotic arm in the plot. Upload the video in the youtube and paste the link.

Theory :

A robotic arm is a mechanical where it contains mechanical linkages with one arm fixed on a fixed point and forms an angle with the base line while moving. From the linkage 1 it is connected to another linkage which moves accordingly. Here we consider a robotic arm which contains two movable linkages and each arm moves 90 degree with respect to the horizontal line. Robotic arm are used for various industrial purposes such as painting, welding etc.

Equations :

  • Equation for finding the end points of linkage 1 of angle theta1,

`x1 = x0 + L1.cosd(theta1)`

`y1 = y0 + L1.sind(theta1)`

Equation for finding the end points of linkage 2 of angle theta2,

`x2 = x1 + L2.cosd(theta2)`

`y2 = y1 + L2.sind(theta2)`

Code :

close all
clear all 
clc
l1=10; %length of linkage 1
l2=5;  %length of linkage 2

theta1=linspace(0,90,20);  % angle formed by moving linkage 1
theta2=linspace(0,90,20);  % angle formed by moving linkage 2
  
ct=1; 
% iterating each values for theta1 and theta2
for i=1:length(theta1)
    THETA1=theta1(i);
    for j=1:length(theta2)
        THETA2=theta2(j);
        % fixing the base points
        x0=0; 
        y0=0;
        % finding the end points of linkage 1
        x1=l1*cosd(THETA1);
        y1=l1*sind(THETA1);
        % finding the end points of linkage 2
        x2=x1+l2*cosd(THETA2);
        y2=y1+l2*sind(THETA2);
        % plotting all values of end points of linkage 1 and linkage 2
        plot([x0 x1],[y0 y1],[x1 x2],[y1 y2],'linewidth',3)
        % fixing the end points for the plot
        axis([-1 15 0 15]);
        % pause time in seconds while playing each frames
        pause(0.2)
        % Capturing the current plot
        M(ct)= getframe(gcf);
        % increasing each frame after each frame is captured
        ct=ct+1;
    end
end

% creating a movie from all the frames collected above
movie(M);
% creating a videofile in '.mp4' format
videofile = VideoWriter('Forward_kinematics_of_robotic_arm.mp4','MPEG-4');
open(videofile);
% writing the above movie into a video file
writeVideo(videofile,M);
close(videofile);


Procedure :

  • First of all using clear all, close all and clc commands for clearing all datas in workspace, figures and plots and command window respectively.
  • Assigning the length values for linkage 1 and linkage 2.
  • Using the linspace command the range angle traced by linkages are taken as input.
  • Base points are fixed at origin(0,0).
  • For loops are used for iterating the values of angles and end points are calculated using that angles and the equations mentioned in theory part.
  • The end points of linkage 1 and linkage 2 is calculated at each angles formed by iterating.
  • Using plot command, plot of these ends are made.
  • Frames are captured after plotting the graph.
  • Then a movie is made from all frames colleced.
  • For saving the video, a video file is created in '.mp4' format.
  • Finally we will write the movie into the video file created.

Conclusion :

Simulation of the forward kinematics of 2r robotic arm is made and the values are plotted in the graph. Plotting of each frames are captured and created a video file. The video is uploaded to the youtube and the link is given below

Youtube link:

https://youtu.be/9tbVq8O9GvY

Error :

No major errors were found.

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.