You are on page 1of 11

346 Introduction to Robotics

Appendix

B
Use of MATLAB
and RIDIM

In this appendix, steps to use the commercial software, MATLAB, and RIDIM
program developed by the author and his group of students are explained.

B.1 USE OF MATLAB

MATLAB is a commercial software by MathWorks Inc., USA. It has large number of


mathematical operators and commands that can perform wide range of analysis, e.g.
matrix operations, algebraic and differential equation solutions, optimisations,
control experiments, etc.

B.1.1 Initialise MATLAB


It is expected that MATLAB is installed in a computer where the user will be
performing computations. If an icon is available on the Desktop the user has to
double-click on it using the left button of the mouse connected to the computer.
Alternatively, the user can left-click, in sequence, on the button/menus that popup:
Start -> All Programs -> Matlab-> MATLAB.

B.1.2 How to Use MATLAB?


When MATLAB software starts, the MATLAB screen appears with “>>” prompt.
This window is called MATLAB command window. Some basic operations are

Print Area 28x48 pica


Trim Area 36x54 pica
Appendix B 347

shown here. For detailed description, one may refer to the books available on
MATLAB, e.g. Pratap (2002), and use the Demos and Help menu of the software.

B.1.2.1 Vectors in MATLAB


Any column vector or what is simply referred in this book as vector, say, a ∫
[a1 a2 a3]T, the following commands are used:
>> syms a1 a2 a3
>> av = [a1; a2; a3]
av =
[a1]
[a2]
[a3]
where ‘syms’ is a MATLAB command to define the variable as symbolic, instead of
numerical. Moreover, ‘av’ is a user defined variable name for the vector, a. In
contrast a row-vector, say, a ∫ [a1 a2 a3], can be generated as
>> syms a1 a2 a3
>> av = [a1 a2 a3]
av =
[a1, a2, a3]
If the elements of the row-vector are numbers, say, a ∫ [2 1 5], then
>> av = [2 1 5]
av =
2 1 5
Addition of two vectors, say, a ∫ [2 1 5]T and b ∫ [1 4 2]T, are obtained as
>> av = [2; 1; 3];
>> bv = [1; 4; 2];
>> cv = av + bv
cv =
3
5
5

Scalar product of the above two vectors, a and b, is obtained as


>> av = [2; 1; 3];
>> bv = [1; 4; 2];
>> av’*bv
ans =
12
Note above that if no variable is assigned on the left of the operation, it is given as
“ans.”

B.1.2.2 Matrices in MATLAB


Let two matrices, A and B, are given by
348 Introduction to Robotics

LM2 3 1 OP LM1 2 3 OP
A∫ 3 5 2 ; and B ∫ 2 3 5 (B.1)
MM5 6 PQ
P MM8 9PQ
P
N 1 N 2
Representation of the above matrices in MATLAB are as follows:
>> am = [2 3 1; 3 5 2; 5 1 6]
am =
2 3 1
3 5 2
5 1 6
>> bm = [1 2 3;2 3 5;8 2 9]
bm =
1 2 3
2 3 5
8 2 9
Addition of above two matrices, A + B, is obtained as
>> am+bm
ans =
3 5 4
5 8 7
13 3 15

whereas the multiplication of A and B, AB, is given by


>> am*bm
ans =
16 15 30
29 25 52
55 25 74

Besides algebraic operations, one can find the properties of the matrices as well,
e.g. determinant, eigenvalue, etc. For example, determinant of A is calculated as
>> det(am)
ans =
10

whereas eigenvalues of A are


>> eig(am)
ans =
9.2085
0.3121
3.4794

Moreover, the inverse of A can be evaluated as


>> inv(am)
ans =
2.8000 –1.7000 0.1000
–0.8000 0.7000 –0.1000
–2.2000 1.3000 0.1000
Appendix B 349

Finally, the solution of a set of algebraic equations written in the form of Ax = b,


is given by, x = A-1b. In MATLAB, vector x is obtained as
>> xv = am\bv
xv =
–3.8000
1.8000
3.2000
where vector b is the one used in Subsubsection B.1.2.1. One can now check the
multiplication of matrix A and vector x as
>> am*xv
ans =
1.0000
4.0000
2.0000
which is verified as vector b.
It is pointed out here that whatever has been done above in the MATLAB
command window can also be typed in a .m file, say, “soln.m” which can then be run
from MATLAB window or clicking “Debug->Run” in the file editor. Here, the
software may prompt for MATLAB path setting. The user should specify the one
where “soln.m” is saved. In either case the results will appear in the MATLAB
command window.

B.2 USE OF RIDIM

RIDM is the acronym for Recursive Inverse Dynamics for Industrial Manipulators.
Its VC++ interface program developed for the MS-Windows users to combine two
C++ programs, one to solve the inverse kinematics problem formulated in Marothiya
and Saha (2003) and the other one is the recursive inverse dynamics algorithm
proposed in Saha (1999). Both the aspects of inverse kinematics and inverse
dynamics are discussed in Chapters 6 and 9 of this book as well. The program
requires the following inputs:
• The Denavit and Hartenberg (DH) parameters of the robot manipulator de-
fined in Chapter 5. A file stores these DH parameters.
• The program then asks for the initial and the final configurations of the robot.
This input could be fed in joint level coordinates as well as in Cartesian coor-
dinates.
• Time of moving from initial to the final specified positions, and
• Number of steps.
Based on the above inputs, the program calculates the trajectory to be followed
and stores it in another file. Then, there is an option of performing the inverse
dynamics using RIDIM for the calculated trajectory, whose output (joint torques/
forces) is also stored in a file. The results stored in the files are available for plotting
or other analyses.
350 Introduction to Robotics

B.2.1 RIDIM Installation


To instal RIDIM download ‘ridim.zip’ from http://web.iitd.ac.in/saha or the book’s
Website. Note here that the user’s computer system must have following two files in
C:\windows\system
MFC42D.DLL
MSVCRTD.DLL

If the above files are not there in the system, then take them from
RIDIM\SYSTEM-FILES
folder of unzipped folders.
Next, to instal RIDIM follow the steps given below:
1. Unzip it in ‘C:\’ folder. That is, while unzipping ‘select different folder’ and
give/choose ‘C:\’ .
2. Go to ‘C:\’ folder. Right click on RIDIM folder. Click on ‘properties.’ Click on
‘read only’ (it will remove the tick mark, if any). Apply and close window.
3. Double click on ‘RIDIM’ to enter the folder. Click ‘select all.’ Take the cursor
arrow on any file icon. Right click. Click on ‘properties.’ Click ‘read only’ (it
will remove the tick mark, if any). Apply and close window.
4. Double click on Debug folder. Drag ‘proj’ file (application file where RIDIM
icon appears to the Desktop.
5. Double click the ‘RIDIM’ icon.
6. Enter the input as desired.
7. Plot using MS-EXCEL or MATLAB.
If the above things do not work, then most probably you do not have write access
on ‘C:’ drive. Ask the system administrator for permission, or send email to the
administrator of the book’s website.

B.2.2 How to Use RIDIM?


1. Double click the RIDIM icon (File name: proj1) on the desktop, one window
will come briefing about the software. Click ‘Next’ to proceed or ‘Cancel’ to
close the program.
A window will appear asking for number of degrees of freedom. Enter the
number of degrees of freedom. For example, DOF 6 ø
where, underlined quantities are to be specified by the users, and ø
means ‘Press Next’ or ‘Press Return Button’.
2. After this, depending on the user’s choice, the program asks for the DH param-
eters and the link properties. For example, DH parameters and the link param-
eters are given in Table B.1. Please refer to Chapters 5–9 for the meanings of
the terms.
All the above values are to be fed one after another link, beginning from link 1.
After all the data are entered, a window appears indicating the storage of the
parameters in a file ‘dhpara.r’. Click ‘Next’.
Appendix B 351

Table B.1 Sample data used by RIDIM (stored in ‘dhpara.r’)

No. Jt. ai bi a qI mi xcm ycm zcm Ixx Ixy Ixz Iyy Iyz Izz
1 R 1 0 –90 0 1 1 1 1 1 1 1 1 1 1
2 R 2 5 180 0 1 1 1 1 1 1 1 1 1 1
3 R 3 3 –90 0 1 1 1 1 1 1 1 1 1 1
4 R 0 7 90 0 1 1 1 1 1 1 1 1 1 1
5 R 0 0 90 0 1 1 1 1 1 1 1 1 1 1
6 R 1 2 90 0 1 1 1 1 1 1 1 1 1 1

3. For trajectory planning, it asks for 2 parameters


(a) Total time: For example,
Total time: 15 ø
(b) No. of Steps: This is for deciding the precision of calculations. The more
the no. of steps, the more the trajectory is planned precisely. This data is
important for calculating the results at various positions. For example,
No. of Steps: 30 ø
4. There appears one window, on which, the option ‘Run Ikin.cpp’ is to be
clicked for inverse kinematics and the trajectory planning. First of all, the pro-
gram will ask whether the user wants to enter the data in joint level coordinates
or the Cartesian level coordinates:
Please specify how would you like to enter the positions:
In joint level coordinates (Press 1)
Or in Cartesian coordinates (Press 2)? 1 ø
(i) If 1 is entered, it asks the joint angles in the following manner for both,
initial and the final positions:
Enter trajectory: Joint level (1) or Cartesian level (2) 1 ø
Enter initial and final joint coordinates
[Angle for revolute and Length for prismatic pair]
Initial value (degree or meter) for joint 1 : 10 ø
Initial value (degree or meter) for joint 2 : 60 ø
Initial value (degree or meter) for joint 3 : 45 ø
Initial value (degree or meter) for joint 4 : 30 ø
Initial value (degree or meter) for joint 5 : 90 ø
Initial value (degree or meter) for joint 6 : 100 ø
And similarly for the final configuration
(ii) If 2 is pressed, a window will appear where the following input should be
provided.
Asking initial configuration, e.g.
1. Enter position of the end effector
Enter (P1 P2 P3 ) 6 1 5 ø
352 Introduction to Robotics

2. Enter the rotation matrix for End Effector :(Q)


Enter Q11 12 13 : 0 1 0 ø
Enter Q21 22 23 : –1 0 0 ø
Enter Q31 32 33 : 0 0 1 ø
5. All possible inverse kinematic solutions are generated and shown, and the user
is asked a particular solution number to be used for calculations. If user is not
sure about which one to select, he/she may press any key. In this case, default
solution no. (currently it is 1) is chosen. For example
Enter the solution no. to check :(Press any key for default, i.e. 1) : 3 ø
Similar procedure is taken for getting final configuration.
(Please note that for 2-dof planar case, before asking the initial and the final
position, user would be asked whether he needs the lower or upper arm solu-
tion. The window will appear like:
You’d have lower arm solution (1), or the upper (2) ? 1 ø
6. After all the data are entered, inverse kinematic solutions are stored in a file.
Then
TYPE ‘ok’, THEN ENTER TO CONTINUE ok ø
7. A window appears indicating that the trajectory computations are done and the
data generated is stored in a file ‘ikin.r’ and asks to ‘RUN Idyn.cpp’. Press
‘ok’.
8. A window appears again with options ‘Ikin.cpp’ and ‘Idyn.cpp’. Click on the
second option.
9. A window for Idyn.cpp will appear asking for the gravity vector. For example,
Gravity vector in 1st frame (g_x g_y g_z)? 0 0 –1 ø
10. The inverse dynamics results are stored in a file and the program exits auto-
matically. There would appear, one more window indicating that the Joint
torque or the force values are stored in ‘Idyn.xls’ file in Ridim folder of C:
directory, which can be plotted.
11. To close the program, click “X” icon on the right of the screen.
In order to use the ‘forward kinematics’ module of RIDIM to verify the above
inverse kinematics results, following steps can be followed:
1. Double click on ‘forwardkin.exe’ in ‘C:\debug’ folder or on a window through
RIDIM icon.
2. One window appears asking whether the user wants to use the DH parameters
stored in ‘dhpara.r’ file, or does he/she want to enter new values, e.g.
DH parameter values
Do you want to read from file dhpara.r? (Press 1)
Or you want to create one? (Press 2) 2 ø
3. If 1 is entered, the values entered through RIDIM software is taken. If 2 is
pressed, it will ask first the degrees of freedom and then the link parameters,
e.g.
Enter the no. of degrees of freedom : 3 ø
Enter DH parameters:
Appendix B 353

Link length (a[i]) Offset length (b[i]) Twist angle in degrees(alpha[i]) :


link 1 1 2 90 ø
link 2 3 4 45 ø
link 3 1 1 0 ø
4. After entering the data, user is asked to choose whether he/she wants to check
the solutions stored in ‘ikinsoln.r’ or wants to enter new joint values (q).
You want to check joint values stored in ikindsoln.r (Press 1)
Or, you want to enter your own values (Press 2) 2 ø
5. If 1 is entered, forward kinematics of the stored solution is done. This follows
the procedure, exactly same as explained in point 3. If, otherwise, 2 is entered
then the individual theta values are asked, e.g.
Enter th[1] (degrees): 45 ø
Enter th[2] (degrees): 60 ø
Enter th[3] (degrees): 30 ø
6. Based on the input, the forward kinematic results, viz. end effector’s orienta-
tion matrix and the position are displayed, i.e.,
Rotation matrix is :
0.33968 –0.118764 0.933013
–0.16032 –0.984789 –0.0669873
0.926777 –0.126826 –0.353553
EE position is:
5.86889
–1.28797
5.1713
Press ok and enter ok ø

B.2.3 An Illustration with PUMA 560


The robot, PUMA 560, is shown in Fig. B.1, whose DH parameters are given next to
it.
To use the inverse kinematics program the following inputs are used:
Position of the end-effector,
p = [0.67837 0.24867 0.07662]T
Orientation of the end-effector,
Q = [-
0.84086 0.25393 0.47799; 0.54115 0.37712 0.75163; 0.01060 0.89067 –
0.4545]
The values of p and Q are taken from the output of a forward kinematics solution
when the joint angles are taken as
q = [5 30 10 45 90 60 ]T degrees
This means that one of the solutions from the inverse kinematics program should
match with the above values, which is true from the following output of the inverse
kinematics module of RIDIM:
354
Introduction to Robotics
Waist (Joint 1)

Upper arm Shoulder (Joint 2)

Shoulder Elbow Link a b a q


(Joint 3) k (m) (m) (deg) (deg)
1 0 0 –90 q1 (JV)
2 0.432 0.149 0 q2 (JV)
Wrist rotation
3 0.02 0 90 q3 (JV)
(Joint 4)
Wrist bend 4 0 0.432 –90 q4 (JV)
(Joint 5)
Trunk z Forearm 5 0 0 90 q5 (JV)
Flange 6 0 0.056 0 q6 (JV)
(Joint 6)
y

Wrist
x
Fig. B.1 PUMA 560 robot and its DH parameters
Appendix B 355

The solutions are:


Sol no.: 1 5 30 10 45 90.0002 60.0001
Sol no.: 2 –149.82 –132.601 10 –83.9618 24.3137 –19.1774
Sol no.: 3 5 –47.3984 164.698 77.6014 46.3851 –12.3228
Sol no.: 4 –149.82 150 164.698 –155.036 75.9605 70.9998
Sol no.: 5 5 30 10 –135 –90.0002 –120
Sol no.: 6 –149.82 –132.601 10 96.038 –24.3137 160.822
Sol no.: 7 5 –47.3984 164.698 –102.399 –46.3851 167.677
Sol no.: 8 –149.82 150 164.698 24.9645 –75.9605 –109
Enter the solution no. to check :(press any key for default, i.e., 1) :
Now, the user is asked to select a particular solution or a default is chosen. Note
that the solution number 1 (indicated above as ‘Sol no.: 1’) is the one that corresponds
to the input values. Next, to demonstrate the inverse dynamics module of RIDIM, the
position, velocity and acceleration trajectory are generated based on the inverse
kinematics solutions. For example, let us use the following values:
Initial conditions: qi (0) = 0; Final conditions: qi (T) = 180° for i = 1, º, 6; Time
duration, T = 10 sec
3.5
0.7
3
0.6
2.5 0.5
Joint velocity
Joint value

2 0.4
1.5 0.3
1 0.2
0.5 0.1
0 0
0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10
Time (sec) Time (sec)
(a) Position (b) Velocity
0.25
0.2
0.15
0.1
Joint acceleration

0.05
0
0 1 2 3 4 5 6 7 8 9 10
–0.05
–0.1
–0.15
–0.2
–0.25
Time (sec)
(c) Acceleration
Fig. B.2 Joint trajectory: (a) Position, (b) Velocity, and (c) Acceleration
356 Introduction to Robotics

The generated trajectories for each joint are shown in Fig. B.2(a–c). Inverse
dynamics results are then obtained for PUMA 560, which are plotted in Fig. B.3(a–
f.). The plots were generated using MS-Excel program.

8 100
6 80
4 60
40
Torque (Nm)

Torque (Nm)
2 20
0 0
0 1 2 3 4 5 6 7 8 9 10
–2 –20 0 1 2 3 4 5 6 7 8 9 10
–4 –40
–60
–6 –80
–8 –100
Time (sec) Time (sec)
(a) Joint 1 (b) Joint 2

30 0.5
0.4
20
0.3
Torque (Nm)

Torque (Nm)

10 0.2
0 0.1
0 1 2 3 4 5 6 7 8 9 10
0
–10 0 1 2 3 4 5 6 7 8 9 10
–0.1
–20 –0.2
–30 –0.3
Time (sec) Time (sec)
(c) Joint 3 (d) Joint 4
0.015
0.2
0.01
0.15
0.005
0.1
Torque (Nm)

Torque (Nm)

0
0.05 0 1 2 3 4 5 6 7 8 9 10
–0.005
0 –0.01
0 1 2 3 4 5 6 7 8 9 10
–0.05 –0.015
–0.1 –0.02
–0.15 –0.025
Time (sec) Time (sec)
(e) Joint 5 (f) Joint 6
Fig. B.3 Torque values at (a) Joint 1; (b) Joint 2; (c) Joint 3; (d) Joint 4; (e)
Joint 5; (f) Joint 6

SUMMARY
In this appendix, the use of MATLAB and RIDIM are explained. This will help the
reader to solve some of the examples and exercises given in the chapters on
kinematics and dynamics.

You might also like