Challenge

Week 2- 2R Robotic Arm Challenge

https://drive.google.com/file/d/1q_xWJeQT1NM4M1ct57c6SsfIfrFMe4SP/view?usp=sharing

Aim - To create a program to simulate 2R Robotic Arm using forward kinematics.

Definitions -

2R Robotic Arm

Robotic Arm is a machine which helps to move the objects from one place to another and to assemble parts in industries.

Kinematics -

Its the branch of mechanics that deals with the motion of object without concerned about the force that causes the motion.

Types

  1. Forward kinematics
  2. Inverse kinematics

Forward kinematics -

  • It refers to the kinematic equation which is used to find the position of end effector from the known joint parameter.

Objective -

  • To write a matlab code in order to simulate 2R robotic arm for the changing angles for link 1 and link 2 using forward kinematics.
  • To make a animation of robotic arm simulation.

Procedure -

  • While we start any program,we use three commands to close all windows and erase previous calculation.

  1. clear all - This command clear all the previously data stored in the work space.
  2. close all- this command close all the previous figure and plot windows.
  3. clc- This command clear the command window.
  • Now, The input variable which is required to calculate the position of end effector from the known joint parameter are as follows.

l1= 1;

l2= 0.5;

theta1= linspace(0,90,10);

theta2= linspace(0,90,10);

  • Here we use linspace function to generate linearly spaced vectors.
  • Here we use (;) to terminate a line and suppress the result to display on command window.

  • In code we use c(t) command which is a counter variable which helps in proper indexing in which the captured frame will be indexed sequentially.
  • Here, we use nested loops to run a code for pre-determine number of times containing one loop chained with other.
  • In loop we use for command to run the loop for pre-determined number of times.

As per the trignometric relations

x0=0, y0=0

x1= licosd(theta1)

y1= l1sind(theta1)

x2= x1+l2cosd(theta2)

y2= y1+l2sind(theta2)

Plotting -

  • Now, we use plot command to plotting graph from the known joint parameter.
  • A particular axis is given to the graph.
  • Next we use pause command to run video as per requirement.
  • We use get frame command which captures the figure as a frame.
  • get: refers to the current figure handle in matlab where it captures and in turn give the current figure to capture it as a frame for movies creation.
  • Now, we end the loop using end command.

Making animation of robotic arm simulation

Now, we start video writing in matlab.

  • movie(M) - Plays the movie frames in array 'M' once.
  • VideoWriter - This command will create a video file of specified name and format.
  • open - Opens the specified file (video file)
  • writeVideo - writes the created video file with the frames captured in the 'M' array.
  • close - Closes the specified file.

And finally the video file will be saved in the program path.

Code -

% To Create a Program to Simulate 2R Robotic Arm using forward kinematics
clear all
close all 
clc

% Input
% defining link
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);

 % trignometric relation
 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('robotic_arm.avi','Uncompressed Avi');
open(videofile)
writeVideo(videofile,M)
close(videofile)
    

Movie

https://drive.google.com/file/d/1q_xWJeQT1NM4M1ct57c6SsfIfrFMe4SP/view?usp=sharing

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.