Challenge

Week 2- 2R Robotic Arm Challenge

  1. A) Write a program in MATLAB to simulate the forward kinematics of a 2R Robotic Arm

1)Aim: -

Simulating forward kinematics of 2R Robotic Arm

2) Objectives: -

  • Write a program in MATLAB to simulate the forward kinematics of a 2R Robotic Arm
  • Creating an animation from the plots obtained in the program. 3. Understand the movement of an 2R Robotic in 2D workspace.
  • Understand the movement of an 2R Robotic in 2D workshop

3) Theory

A wide variety of robot mechanisms can be described by categorizing their arrangement of joints and joint types. For the moment we will ignore the size and shape of links, and simply focus on broad categorization.

First, there are three typical joint types, each describing the form of relative transformations allowed between the two links to which it is attached:

  • Revolute: the attached links rotate about a common axis.
  • Prismatic: the attached links translate about a common axis.
  • Spherical: the attached links rotate about a point
  • Kinematics is the relationships between the positions, velocities and accelerations of the links of a manipulator.
  • A robotic arm is a type of mechanical arm, usually programmable, with similar functions to a human arm.
  • The forward kinematics is when the kinematical data are known for the joint coordinates.
  • the arm may be the sum total of the mechanism or may be part of a more complex robot.
  • The links of such a manipulator are connected by joints allowing either rotational motion or translational displacement.
  • The links of the manipulator can be considered to form a kinematic chain.
  • The terminus of the kinematic chain of the manipulator is called the end effector and it is analogous to the human hand.
  • Robotic arms are machines that are programmed to execute a specific task or job quickly, efficiently, and extremely accurately various industrial applications such as drilling, welding, metal cutting, painting.
  • The variables of the end effector in a given Cartesian space are to be computed.
  • A programmable robotic arm can be a complete machine in and of itself, or it can function as an individual robot part of a larger and more complex piece of equipment.
  • A robotic joint provides relative motion between two links of the robot. Each joint, or axis, provides a certain degree of-freedom (DOF) of motion.
  • In most cases, only one degree-of-freedom is associated with each joint.
  • The robot's complexity can be classified according to the total number of degrees-of-freedom they possess. Figure 1 shows the graphical representation and placement of frames/links and joints

Fig (1). Links arm showing 2R robot manipulator

The equation to find the formula for forward kinematic 2 links Robotic arm will be given below

Computes the position and orientation of an

end – effector in terms of the joint angles

Position

X

Y

Orientation

Fig (2) co- ordinate frames for two-link planar robot arm

4) Program: -

% Program for Forward kinematics 2R robotic arm written in MATLAB will be

% Simulate the forward kinematics of a 2r robotic arm

Clear all

Close all

Clc

%Initially inputs will be taken like this

% We have two links so we naming Link_1(L1) and Link_2(L2)

L1=1;

L2=.5;

% Dimensions in meters

% Link_1 will be Represent by different angles so we defined as (theta_1) in degrees

Theta_1=linspace (0,90,10);

% Link_2 will be Represent by different angles so we defined as (theta_2) in degrees

Theta_2=linspace (0,90,10);

% Initial coordination of link_1 will be

X_0=0;

Y_0=0;

Ct=1;

% For plotting the graph, we need continuous values so we used FOR loop

For I = 1: length(theta_1)

THETA_1=theta_1(i); % finding the initial values of link_1

For j =1: length(theta_2)

THETA_2=theta_2(j);

% to calculate the end point of link_1 will be

X_1=x_0+L1*cosd(THETA_1);

Y_1=y_0+L1*sind(THETA_1);

% To calculate the end point of link_2 will be

X_2=x_1+L2*cosd(THETA_2);

Y_2=y_1+L2*sind(THETA_2);

% to simulate the values in graph

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]);

% Plot will be Pause some seconds to visible clear and slowdown

Pause (0.02);

% collecting the current plot to combine

M(ct) = Getframe (gcf);

% so every values increment we need equation

Ct = Ct + 1;

End

End

% for making the graph like movie

Movie(m);

% to creating a video like movie file ‘.AVI’ format

Videofile = Videowriter (‘Forward_kinematics_of_2R_Robotics_arm.avi’ , ‘uncompressed.avi’);

Open(VideoFile)

% For writing video file

Writevideo (Videofile, M);

% to close the video file

Close (videofile);

(actually graphs and equations are not pasted so please follow the link below attached)

5) Explanation of the program

  • Lengths of both the links are taken as input. Length of link-1 (L1) is taken as 1m and length of link-2 (12) is taken as 0.5m.
  • Angles traced by both the links, for link-1 and for link-2 is taken as input.
  • The angles traced over a range to simulate the movement of the robotic arm.
  • Base position of link-1 (x0,y0 )is considered as origin (0,0).
  • Then we use double for loops are used to iterate 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.
  • For a particular value of theta1 and theta2, the end position of link-1 is calculated by these equations.
  • The end position of link-1 is also the start position of link two.
  • The end position for link-2 is calculated by these equations.
  • Then for each particular position of lin-1 and link-2, a plot is made which is then captured frame by frame to make a movie.
  • 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 thus created.

6) Code Explanation

  • Before writing the code, it's important to start with clear all, close all and clc commands
  • since Clear all-removes data from the workspace,
  • freeing up system memory Close all-deletes the current figure or the specified figure
  • clc- clears all input and output from the Command Window display, giving you a "clean screenNext step for the code is to define the inputs and its values.
  • Length of Link_1 and Link_ 2 were both defined.
  • both theta 1 and theta 2 were defined by using the linspace' command.
  • The function of the linspace generates linearly spaced vectors.
  • So in linspace(0,90,20) means that Matlab will generate a row vector of 20 points linearly spaced between and including 0 and 90The next step is to set up a counter.
  • A counter is a variable that counts an event in a loop.
  • A for loop was used for this. project,
  • for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
  • theta 1 and theta 2 will contain multiple values of the angle within the x-axis,
  • a new variable is needed inside the for loop for both x and y coordinates.
  • THETA 1 and THETA 2 are added to the code, for THETA 2 the variable j was added instead of i as this will give THETA 2 its own respective angle.
  • The formula for calculating x1, yl, x2 and y2
  • The next step is to plot the graph for all the x and y coordinates with axis
  • pause command was used for pausing the command for a certain time, for this project a pause of 0.02 s was used.
  • The M command was used to capture the current frame every time the for loop runs.
  • The final step of the loop is to add a +1 to the ct variable; increment the frame every time the for loop run.
  • End command was used for the plot and for the for loop to stop both from running.
  • The final step of the code is to create a movie of the animation of the robotic arm, so the movie command was used

7) errors faced while Programming

  • The first error I had in the code for this project in formule cos(theta_1) ;but my program never show the error but my accurate values not match graph will be different
  • I accidentally typed Movie' instead of 'movie' since Matlab is a case sensitive program language,
  • I enterd linewidth and Axis in caps so it shows invalid text character commands
  • Once I rewrote the command the code worked fine.
  • Error in finding initial values system fixing I so I changed and its work

8) Steps taken to overcome those errors

  • Before execute the program prepare your program in writing work.
  • Try to make errors to over come the right program to memorise the mistakes
  • of mistakes can you perfect when you the program writer.
  • When you execute the program be patio’s and cool with mind on keyboard
  • Prepare your own program for n no.of trails with n no .of errors with solutions

(actually graphs and equations are not pasted so please follow the link below attached)

Note:- i am always wriiting the program in word and that will copied and change some corrections in matlab

9) Animation video will be available in below given link

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

https://drive.google.com/file/d/1KsD-ffGQSqUM7jiszCwb3HFqzU6edqvF/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.

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.