Matlab-C++ Interface for a Flexible Arm Manipulator Simulation using Multi-Language Techniques Maricela Gamiño
J. Carlos Pedraza
Centro Universitario Cerro de las Campanas, Querétaro, Qro., C.P. 76010, México
[email protected]
Centro de Ingeniería y Desarrollo Industrial, Av. Playa Pie de la Cuesta, No. 702, Col. Desarrollo San Pablo, Querétaro, Qro., C. P. 76130, México
[email protected]
Juan M. Ramos
Efrén Gorrostieta
Universidad Tecnológica de San Juan del Río, Av. La Palma 125, Col. Vista Hermosa, San Juan del Río, Qro., C. P. 76800, México
[email protected]
Instituto Tecnológico de Querétaro, Av. Tecnológico S/N esq. M. Escobedo, Col. Centro, Querétaro, Qro., C.P. 76000, México
[email protected]
Abstract In this paper a multi-language technique to simulate the behavior of a pneu-matic-driven flexible manipulator is proposed. The selected flexible manipulator has one degree of freedom. First, a way to interact between two programming languages is presented, by taking advantage of each language benefits in order to facilitate the development of a complex system simulation tool. Later, the ma-nipulator structure was developed using a CAD software, and then the VRML file was obtained and used as a description of the system. Next, Matlab perform the manipulator mechanism direct kinematics and C++ is used to show the re-sults with the help of the OpenGL graphic libraries.
1. Introduction Today, even the advances in computer technology had been made in a short period of time, in some cases a programming language by itself is not enough to solve real world complex or specialized problems associated with physical systems, and therefore generate a friendly user interface. Due to the fact that every programming language has its benefits and drawbacks, it is not easy to find a unique language that satisfies all the application requirements, therefore the programming interfaces using multiple languages has surge to cover the needs of solving complex applications. Such applications are implemented into scientific research, industrial controls, manufacturing, and some commercial applications. Moreover, the use of programming interfaces to the design of professional graphs, flexible databases, multitasking environments and real time control, can be integrated to form an efficient computer system that allows to solve diverse application challenges. However, the main difficulty to achieve such tasks is the lack of information about the way to make the different languages interact between them [1]. One common example of multiple interfaces or distributed software (middleware) is the Common Object Request Broker Architecture (CORBA) [2], which is one of the most common Multilanguage programs.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
Considering that the architecture of CORBA is independent of the maker, this software is one of the most used in computer applications to work in a network, because it can integrate diverse machines of different size that vary from mainframes to desktop computers and even embedded systems. One of its most frequent and important uses is in servers to handle a big number of clients with high reliability. CORBA works hidden in a lot of web sites, and probably some of them are used by you everyday. Due to the fact that some programs might be used in the simulation of a recent process, and were developed to cover a specific necessity like math analysis, graph plotting, information exchange via internet, and so on, it is difficult to develop a project using only one of them. By other hand, the specialized software that covers two or more of the above mentioned characteristics are very expensive because are sold in a modular form or have another restrictions, and if it tries to interact with another languages could give as a result that is a very complex process, therefore, it is necessary to search for more economic alternatives that be more easy to implement. As a simulation example applied to mechatronic systems, there is a path planning of a 5 DOF manipulator [3], where a similar process and methodology is carried out, as shown on figure 1. The process on figure 1 implies a direct interaction between two programming languages, Matlab and Visual C++. This is the kind of works where the idea of having a direct interaction between Matlab and C++ was originated. In the case of the flexible robot manipulator with pneumatic driven and 1 DOF, a direct interaction between the above mentioned languages is carried out. In this first approach, we only consider the mechanism kinematics. On figure 2 there is a photograph of a flexible manipulator built as a first approach, and on figure 3 it can be shown the robot implemented with OpenGL. It is important to notice that the behavior of a pneumatic driven actuator is complex due to the internal friction forces and the air compressibility [4]. Along this line, there are many works [5] [6] [7] that serve as the physical and mathematical development base for the simulation. Due to the application of complex numerical calculus like the nonlinear behavior of the air compressibility and the need of visualize the results in a graphical interface to visualize and analyze the final prototype, the handle of the math is leaved to Matlab and the graphical interface to C++. And OpenGL The simulation process requires a continuous interaction between C++ and Matlab considering the displacement of the pneumatic driven cylinder the main variable. C++ language handles the rod position changes of the cylinder to generate a Matlab routines callback to achieve the necessary calculus and give the information to simulate the movement in a graphical form. The problem can be solved completely using only one programming language as Matlab or C++, however one of the main ideas in this work is the use of the advantages of each language and create a common interface to optimize the solution, without the translation of one program coding to another. Having this problem in mind, we show the advantages of using a multiple interface programming techniques. Considering the above statements, an improved methodology to develop interfaces between the pro-gramming languages Matlab and C++ as a first approach is proposed.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
Figure 1. Block diagram of a Manipulator robot movements simulation to generate a trajectory.
Figure 2. Flexible manipulator prototype which has one degree of freedom and pneumatic driven.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
Figure 3. Flexible manipulator modeling in C++ and OpenGL.
2. Interface Methodology using Multiple Languages Figure 4 shows a block diagram of the proponed methodology to be used for the interface development between Matlab and C++. Here, we have to mention that many research works have been proposed in the past to establish interaction between C++, Matlab and Java separately. However, most of them just present a basic approach to do interaction between the mentioned languages. In our proposal, the main contribution is the application of a methodology to do interaction between the three languages and the information treatment like the management of the nonlinear behavior of the model in order to perform the simulation of the system. It is important to notice that on figure 4, the interaction with Java is leaved as a future work, and then we are concentrated only in working with two languages; C++ and Matlab. Some of the main charac-teristics of those languages are briefly described. C++: Simple, modern, object oriented, easy cycle and subroutine uses, and possibility of using OpenGL to handle graphics and visualize. Matlab: Intensive calculations from a numerical point of view, high level language base don vectors, arrays and matriz calculations, external application interfaces like C++, Java, COM and EXCEL components, and some application conversion from Matlab to C++ by using a compiler. An important part for the development of the simulation is the system kinematic modeling, which is described as follows.
Figure 4. Proposed methodology to work with C++ and Matlab for the problem solution. 2.1 Behavior description of the manipulator using inverse kinematics We take the CAD/CAM design as a support [5] to obtain a descriptive file in a VRML format [8], which is used to generate the figure 2 with the help of the OpenGL graphic libraries and programmed in C++. Figure 5 shows the geometric description of the system, and figure 6 shows the relationship between the angles that Matlab estimates and the system structure.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
l2
5 l3
4
θ6
l1
3
θ5
r4 r2
r1
θ4
r5
2 1
x
θ3
r3
(a) (b) Figure 5. (a) Geometry and mechanism parts utilized in the simulation. (b) Characteristic angles of the manipulator movements calculated using Matlab. On table 1 we can see the list of the parameters and variables showned on figures 5 and 6, also table 2 shows the meaning of the involved variables and table 3 indicates the assigned names to the most important parts of the mechanism. Table 1. Definition of the used parameters in the flexible arm system. r1 r2 r3 r4 r5 l1 l2 l3
Definition Distance from pívot to the bottom cylinder Rod longitud Difference in high between the cylinder and the crank Crank longitud Pivot distance between cylinder and crack Pivot distance between the crank and straight Straight bar longitud Couple bar longitud
Value (m) 0.042 0.357 0.108 0.074 0.450 0.041 0.043 0.099
Table 2. Definition of the used variables in the flexible arm system. X θ3 θ4 θ5 θ6
Definition Piston and rod displacement Pneumatic cylinder slope Crank inclination slope Couple bar slope Arm output angle
Table 3. Mechanism main parts. No. 1 2 3 4
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
Description Cylinder Piston Crank Couple bar
Unit M Degrees Degrees Degrees Degrees
5
Straight bar
Due to the displacement of the piston in X value, the force generated is applied at the join between the crank and the couple bar pushing the straight bar at the θ6 angle respect to horizontal plane. The equations (1) to (4) described the system kinematics obtained from [5]. Once the equations are described, we must solve them, using Matlab, as indicated at the introduction and methodology. 2
2
2
2 2 2 2 r6 = r1 + x + r2 , k1 = r6 − r3 − r4 − r5 , k2 = r4 − r6 − r5 − r3 2r6 2r4 2
C1 =
2
2
2
2
2
2
2
r − l3 + l2 + l1 , l − l1 − r4 − l3 l l1 , l C2 = 1 , C3 = 4 C4 = 1 , C5 = 2 r4 l2 2r4l2 l3 2r4 l3
2
D1 = cosθ 4 − C1 + C4 cosθ 4+C5 , D2 = −2 sin θ 4 , D3 = C1 + (C4 − 1) cos θ 4 + C5 D4 = cosθ 4 − C1 − C2 cosθ 4+C3 , D5 = C1 − (C2 + 1) cosθ 4 + C3 − D − D 2 − 4D D 2 2 1 3 2D1
θ 5 = 2tg −1
r − r2 −k 2 +r2 3 3 2 5 k2 − r5
θ 3 = 2tg −1
−r + r 2 −k 2 +r 2 3 3 1 5 k1 + r5
θ 4 = 2tg −1
(1)
(2)
− D − D 2 − 4D D 2 2 4 5 2 D4
θ 6 = 2tg −1
(3)
(4)
2.2 Equations solution using Matlab Matlab supply some interfaces to extern routines written in another programming language, like management shared data between routines, clients or server with communication through a Compo-nent Object Model (COM) or Dynamic Data Exchange (DDE), and peripheral devices to have a direct communication with Matlab. This interfaces formerly are called Application Program Interfaces (API) of Matlab [1]. In Matlab, there is a method (API) named shared DLL, which can be called from an environment like Visual C++. This is the used method to obtain a DLL library to perform the complex math calcula-tions which are assigned to Matlab. It is important to mention that as a first approach the movement generated by the equations 5 to 7 corresponds to a damper string mass system. µ=
λ=
c 2 − 4mk 2m
c 2m
x(t ) = e−λt ( A cos µt + Bsenµt )
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
(5) (6) (7)
Where X is the piston displacement. A control PID is applied at the plant represented by the mechanical system at figure 5, as a second approach. The figure 6 shows the control diagram used.
θp
+
PID
Actuator
Plant
θ
-
Figure 6. PID Control Scheme. The control variables are contained in a vector, as shown the equation (8). The equations (9), (10) and (11) represent the proportional, integral and derivative errors respectively; and equation (12) shown the control law used. u = [A1 , A2 , A3 ]
(8)
e= Xp −X
(9)
ei = ∑ e(Ti )
(10)
ed = e(Ti ) − e(Ti −1 )
(11)
A j = K p e + K i ei + K d ed
(12)
i
Through equation 12 the air flow is controlled into the pneumatic actuator, displacing an X distance to the piston. The X value is obtained with the simplified thermo-mechanical model [7], which must be solved using numerical methods used in state equations. Once X value is obtained, is necessary to compute the mechanical information, given by θ3, θ 4, θ 5 and θ 6 angles. Now we must to create the C++ interface. 2.3 C++ application C++ is the base language to develop the proposal interface, because C++ can call the Matlab DLL file, and to the OpenGL libraries. There are two main steps in C++: the call to DLL and descriptive libraries creation for the flexible manipulator robot with OpenGL. The functions that we must use to call the DLL file are: nomfilelibInitialize(); mlfNomfiledll(); nomfilelibTerminate(); Where mlfNomfiledll() is an interface function from the nomfiledll(), created by Matlab compiler while the compilation process is executed. Is not possible to call the DLL, only througth the interface function mlNomfiledll(). To get a functional interface successful, is necessary to initialize and clean the memory used by the interface, and the nomfilelibInitialize() and nomfilelibTerminate() functions must be used.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
Once the problem is defined, and results are obtained using the Matlab Interface, we can do a flexible manipulator simulation movement with the OpenGL libraries. 2.4 OpenGL Applying Mass-spring-damper equation. To test the Matlab and C++ interaction, a first experiment was used, which consist in the development of a pneumatic actuator with OpenGL. The Mass-spring-damped equation is applied to compute the dis-placement and then observe the displacement made by the piston movement. Is im-portant to use the minimum and maximum piston displacement values and send them to the Matlab DLL. The DLL file gives us the piston behavior, in a position vector, and C++ use the vector values to generate a simulation movement from the initial position to the extreme of piston. Two methods were used to get the necessary data for piston movement simulation: First, C++ calls the Matlab DLL and computes all points of movement, save in a file, that later C++ use to read the position data and do a simulation movement. Second, C++ calls the Matlab DLL and compute just one movement, do a graphic result, and compute the next position to graph again, and the process is repeated as much as necessary.
3. Testing the Interface Methodology 3.1 Mass-spring-damped simulation The simulation software use the Mass-spring-damped equation to move the piston, and there is not a considerable difference between the use of DLL file methods ex-plained before, maybe because the equation are easy. The piston displacement results in a graphic presentation with a start point in equilibrium are shown in figure 7, and are consistent for both methods because the computing parts are the same. 3.2 Simulation PID control Figure 8 shown the flexible manipulator robot output system behavior, with a PID control application. The next step is to do the full flexible manipulator robot simulation, using the in-verse kinematics model an x piston displacement is given from C++ and Matlab DLL file is executed. The DLL return the angle information consisting in θ1, θ2, θ3 and θ4 angles used to do a graphical movement of the mechanical parts including the robot arm, with the OpenGL libraries applications.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
Piston Displacement
Piston Displacement
5
0.08
4 0.07 3 0.06
X [m]
X [m]
2 1
0.05
0 0.04 -1 0.03
-2 -3 0
2
4
6
8
10
12
14
16
18
20
t [s]
Figure 7. System mass-spring-damped displacement graphic.
0.02 0
1
2
3
4
5
6
7
8
9
Fig. 8. PID control flexible manipulator robot.
4. Conclusions and Future Work A methodology has been presented to approach the major C++ and Matlab advan-tage, getting an interface for two different languages information exchange, with a direct interaction. This kind of methodology ha been used to develop a specific physical problem simu-lation and help to find a solution using distributed software. Once the interface methodology has been established it is relatively simple for a person with a basic knowledge of C++ and OpenGL to apply it in simulations of similar projects and moreover to some physical models with similar mathematical characteristics. As future work, we are planning to implement bigger mathematical complex algo-rithms, for example, neural networks and fuzzy logic. Another challenge is to ´perform a web interaction for graphic simulation on Internet using Java language.
5. References [1] Ying Bai; Applications Interface Programming Using Multiple Languages; 1st Edition; Prentice Hall; ISBN 013-100313-5; 2003. [2] www.omg.org/corba. 10-05-2006 [3] J. A. Soto Cajiga, J. E. Vargas Soto, J. C. Pedraza Ortega; Generación de trayec-torias para un robot manipulador utilizando procesamiento de imágenes y spli-nes; Segundo Congreso Internacional de Ingeniería; Marzo de 2006; Querétaro Qro. ISBN 968-845-296-3.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006
10
t [s]
[4] Moore P. y J. Pu; Progression of servo pneumatics toward advanced applications; Fluid Power Circuit, Component and System Design; K. Edge and C. Burrows, Eds. Boldock, U. K.: Research Studies Press; páginas 347 a 365; 1993. [5] Fernando Fco. Kiyama Miramontes; Modelado de un Robot Manipulador Flexi-ble; Trabajo de Tesis para obtener el grado de Doctor en Ingeniería Mecatrónica; Centro de Ingeniería y Desarrollo Industrial; 2005. [6] Kiyama F. y J. E. Vargas; Modelo Termo-Mecánico para un Manipulador tipo Dieléctrico; Información Tecnológica; volumen 15; número 5; páginas 23 a 31; 2004; ISSN 0716-8756. [7] Juan M. Ramos, José E. Vargas, Efrén Gorrostieta y Jesús C. Pedraza; Nuevo Modelo Polinomial del Comportamiento de un Cilindro Neumático; Revista In-ternacional Información Tecnológica; Vol. 17, no. 3; ISSN 0716-8756; 2006. [8] Andrea L. Ames, David R. Nadeau and John L. Moreland; VRML 2.0 source Book; Second Edition; Ed. John Wiley & Sons, Inc.; ISBN 0-471-16507-7; 1997.
Proceedings of the Fifth Mexican International Conference on Artificial Intelligence (MICAI'06) 0-7695-2722-1/06 $20.00 © 2006