SimMechanics, MapleSim and Dymola: a first look on three multibody packages
J.J.P. van Boekel DCT 2009.060
Bachelor Final Project report
Coach(es): dr. ir. I.J.M. Besselink
Supervisor: prof. dr. H. Nijmeijer
Technische Universiteit Eindhoven Department Mechanical Engineering Dynamics and Control Technology Group
Eindhoven, June 2009
Contents
Abstract4
Introduction5
1 Building a half-car multibody model7 1.1 Construction of a half-car model...... 8 1.2 Simulation performance...... 14
2 Verification & error handling 16 2.1 Testcase 1: absent connection between joint and car-body.... 16 2.2 Testcase 2: mass not specified, equal to zero...... 18
3 Numerical accuracy 20 3.1 Analytical model...... 20 3.2 Simulated model...... 22 3.3 Comparison...... 25
4 Visualisation of multibody models 27
5 Parametrisation of model variables 30 5.1 Specifying global parameters in Simulink/SimMechanics..... 30 5.2 Specifying global parameters in MapleSim...... 31 5.3 Specifying global parameters in Dymola...... 32 5.4 Dymola’s ’Experimentation Package’...... 32
6 Exporting and interchangeability 35 6.1 MapleSim...... 35 6.2 Dymola...... 36
7 Closed-loop systems behaviour 38
2 CONTENTS 3
8 Dymola Vehicle Dynamics Library 43 8.1 Introduction...... 43 8.2 Adaptability...... 43 8.3 Visualization...... 47 8.4 Performance...... 48
9 Conclusion 50
References 53
A SimMechanics windows 54
B MapleSim windows 56
C Dymola windows 59
D MapleSim C-code 65 Abstract
In this report, an comparison between three multibody packages (Simulink/Sim- Mechanics, MapleSim and Dymola) is made in order to check whether or not MapleSim or Dymola would be an suitable alternative to the now used multi- body software SimMechanics. Some important aspects are investigated by us- ing some simple models. A half-car is constructed and analysed from which is concluded that no big differences in simulation speed are present, but this is mainly due to the simplicity of the investigated models. Based on two testcases, an opinion regarding verification and error handling is given. By using a double pendulum system, a comparison is made based upon the accuracy of all three packages. This is done by comparing the results that the software gives with the results of an analytical derived equation of motion. Both MapleSim and Dymola are offering build-in functionalities for parametrization of model vari- ables which are investigated in this report. It is concluded that most of these functions could also be accomplished by making a few lines of code in MAT- LAB. The interchangeability functionalities are also investigated. In MapleSim, C-code can be exported use in for example MATLAB/Simulink. Dymola offers a functionality called the ’DymolaBlock’. This block can be used in a Simulink environment to load a model made in Dymola directly into the Simulink model. Closed-loop behaviour is checked by means of deliberately miss-aligning two component of a closed-loop system. It is checked how the software reacts to this and if and how the error is reported. Finally, the ’Vehicle Dynamics Library’ from Dymola is studied. An example model is investigated and a conclusion is made regarding adaptability of models. Also, visualization and performance aspects are discussed.
4 Introduction
Because of the continuous increase of computer power, the use of simulation tools is still growing. Multibody software for vehicle dynamics has been gaining popularity thanks to advantages the use of this type of software brings. Nowa- days many companies produce multibody software tools and thanks to this, the software is still getting better, faster and more reliable. Until now, Eindhoven University of Technology (TU/e) has primarily been using the multibody software called ’SimMechanics’ which is part of MAT- LAB/Simulink. This product is very widely used and has a great number of users around the world. One drawback of SimMechanics is the limited process- ing speed which makes it nearly impossible to perform real-time simulations. Another drawback is the lack of modern and fast visualization possibilities. An overall view concerning SimMechanics is that it lacks development pace over the past years. TU/e is exploring alternatives concerning multibody packages that can perform at least the same tasks as SimMechanics and should be faster regarding com- putation speeds and offers better possibilities to create code which is used for real-time capable models. In order to find a possible substitute for SimMechan- ics, two new multibody packages have been examined. The first package that is examined and compared to SimMechanics is called ’MapleSim’ (version 1.0). This package is created by the company ’MapleSoft’ and runs on the mathematical engine from Maple (version 12.02). The second package is called ’Dymola’ (version 7.1) and is created by the company ’Dynasim AB’. In chapter 1, a simple half-car model is build in all three packages, so that user friendliness of the software can be examined. Also, different aspects of building and analyzing a model are treated in this chapter. In chapter 2, the same half- car model is used to investigate how the packages deal with modelling errors and how they do inform the user. After this, in chapter 3 a double pendulum model is constructed. By means of this model, the numerical accuracy of all three packages is studied. In chapter 4, the visualization possibilities of the three multibody packages is explored. Chapter 5 deals with the parametrisation aspect of multibody models. By parametrize specific model variables, a model can be evaluated by varying some pre-defined model-properties. In chapter 6, interchangeability is discussed. By exporting models to C-code, this fast and efficient code can be used to perform for example ’Hardware In the Loop’ (HIL) simulations. Chapter 7 deals with a special but common kind of multibody
5 CONTENTS 6 systems, so called ’closed-loop systems’. In this chapter we investigate how the packages deal when components are not fully aligned to each other. Chapter 8 of this report handles the Dymola Vehicle Dynamics Library. Different aspects of this library are discussed and explained.
Acknowlegments
First of all, special thanks goes to my supervisor Igo Besselink for the help with the project and creating the report. Furthermore, I want to thank Gosé Fis- cher of CANdiensten, for providing MapleSim and helping me with problems or questions about MapleSim. Also I want to thank Mike Dempsey of Claytex Ser- vices Limited for providing Dymola and helping me with problems or questions concerning Dymola and the Vehicle Dynamics Library.
Disclaimer
This report is the work of a Bachelor student and does not necessarily reflect the opinion of the Eindhoven University of Technology in gen- eral. The student has previous experience with MATLAB/Simulink, but no experience with SimMechanics, MapleSim or Dymola at the start of the project. The student has spent about 15 weeks to study the different packages and to do the analysis described in this report. Chapter 1
Building a half-car multibody model
In this chapter we will consider how models are constructed in both Simulink/Sim- Mechanics, MapleSim and Dymola. In the first section of this chapter, the Modelica Language is discussed. This language is used to construct models in both MapleSim and Dymola. In order to give an objective view of all three packages, in the second section a relative simple half-car model is modeled. Dif- ferent aspect regarding usability of the software and construction of models are discussed.
The Modelica Language
Both Dymola and MapleSim make use of the Modelica language. Modelica is a free object-oriented modeling language with a textual definition to describe physical systems in a convenient way by differential, algebraic and discrete equa- tions. An example such a textual representation of a model is showed in figure 1.1. The text in this figure represents a parallel spring-damper component. In the top of the screen some parameters and input files are stated after which the actual equation of motion (f = c(s − s_unstretched) + ds˙) is introduced. One can easily identify s as being the prolongation of the spring and c and d as being the stiffness and damping-coefficient of respectively the spring and the damper. der(s) means the derivative of s, the elongation of the spring. The Modelica language is suited for multi-domain modeling and involves for example mechanical, electrical or hydraulic applications. In order to guarantee the interoperability of the modeling language, a free ’Modelica Standard Library’ is available. Furthermore, more both free and commercial Modelica libraries are available. An elaborate description of the Modelica language and a user manual/handbook can be found in [4].
7 CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 8
Figure 1.1: An textual representation of a parallel spring-damper component
1.1 Construction of a half-car model
In order to give an opinion about the user friendliness of all three packages, a half-car model (illustrated in figure 1.2) is constructed. The model consists of a sprung car-body mass and two unsprung masses that represents the suspension- and wheel-masses. Two spring-damper components represents the suspension of the half-car. Tyre-stiffness is introduced by means of a spring between the road-profile and the unsprung masses. CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 9
The numerical values of the model parameters are:
m_sprung = 700 [kg] I_z = 1000 [kgm2] k_rear = 25000 [N/m] k_front = 18000 [N/m] d_rear = 1800 [Ns/m] d_front = 1500 [Ns/m] m_unsprung_rear = 45 [kg] m_unsprung_front = 40 [kg] k_tyre = 2e5 [N/m]
Because a variable road height profile is used as an input to simulate the re- sponse of the half-car, the vertical tyre force is dependent from both the vertical position of the unsprung mass as from the height of the road-surface. Therefore, the vertical tyre force is calculated as the distance between the road and the unsprung mass multiplied with the vertical tyre stiffness. The resulting signal is applied to the unsprung mass as a force which is acting in vertical direction.
m_sprung I_z Sprung mass
k_rear k_front d_rear Spring/damper d_front
m_unsprung_rear Unsprung mass m_unsprung_front
k_tyre Tyre spring k_tyre
Road profile
Figure 1.2: A graphical representation of a half-car model
SimMechanics
In SimMechanics, models are constructed by dragging components from the ’Simulink Library Browser’ into the modeling window. The SimMechanics model of a half-car is showed in figure 1.3. By clicking a specific component, parameters and settings can be changed (see figure A.1 in Appendix A for CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 10 the car-mass block). In SimMechanics, coordinate frames are attached to the body. Subsequently, joints are attached between these coordinate frames. A ’planar’-joint is placed between the car-body and the ground-frame to enable a 2D-motion of the model. The spring and damper are accounted for by attaching a so-called ’Joint Spring & Damper’ to a prismatic joint between the unsprung mass and the car-body. By attaching a ’Body-Sensor’ to a coordinate frame port of the unsprung mass body, the height of the body can be measured and again be used as a input signal. Since this component measures the position of the body in all three directions, the easiest way is to use a so called ’demux’-block. Using this block, we can specify which components of the signals to use. The number next to the line between the ’Body-Sensor’ and the ’demux’-block indicates that we are dealing with 3 signals. From the ’demux’-block it is unclear which signals we selected, so this has to be determined by experimentation. The road-profile is introduced by specifying a road-height signal (as a function of the horizontal coordinate) in a 1D look-up-table. Depending on the horizontal position of the unsprung mass, a road-height is calculated, which is subtracted from the vertical position of the mass. By multiplying this signal with a constant (tyre-stiffness), a vertical spring-force is obtained. This force is applied to the unsprung mass using a ’Body-Actuator’ that is connected to the desired coordinate-system of the body.
Figure 1.3: The half-car model in SimMechanics CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 11
Results can be loaded into the MATLAB Workspace by connecting a ’To Workspace’- block to a specific signal obtained from e.g. a ’Body-Sensor’. During simulation, signals can be graphically presented using a ’scope’ (see figure A.2 which repre- sents the vertical position of the unsprung mass). This ’scope’ can be attached directly to a signal-line and is showed automatically when simulating the model. When double-clicking a specific component, the parameters-window appears where also a brief description of the component is found. When right-clicking a model and choose ’Help’ a more elaborate description of the specific model is showed in a separate screen.
MapleSim
Just like with SimMechanics, components are dragged from the ’Library Browser’ into the modeling screen. As can be seen in figure 1.4 just like SimMechanics, the model consists of a sprung mass, two unsprung masses, a world frame and other components needed for simulating the tyre-force. The main difference with SimMechanics is the construction of coordinate frames. In contrary to SimMe- chanics where these frames were specified within the body block, in MapleSim extra frames are constructed by adding so-called ’Rigid Body Frames’. These blocks can be used to construct a fixed translation and rotation with respect to another coordinate frame. Another difference with respect to SimMechanics is how the spring-damper is constructed. Whereas SimMechanics requires the use of an extra ’Joint Spring & Damper’-block, MapleSim has an option to specify stiffness and damping directly within the ’Prismatic Joint’-block. Tire stiffness is accounted for in basically the same way as was done in SimMechanics, again the ’demux’-block does not specify which signal is extracted. By clicking a com- ponent, the ’Parameters’ window on the right of the screen displays the possible parameters that are applicable for the concerning component. An example of such a screen is given in figure B.1 for one of the unsprung masses. As can be seen, for this component, mass-properties can be specified as well as some initial position and orientation properties. A nice feature of MapleSim is the ’Components’-window (see figure B.2). In this window, a hierarchic view of the model is given. Using this window, all components that are present in the model can be seen at a glance. When selecting a component, the connection-ports of that specific part are displayed. After right-clicking a component and selecting the ’Help on ...’ line, elaborate information about the specific component is showed in a separate help-window. As can be seen in figure 1.4, for some specific components MapleSim uses differ- ent colors for connection-lines and different connection-port-symbols. By doing this, it’s easy to make a distinction between different sort of signals such as multibody-signals, 1D-mechanical-signals or normal signal lines and between inputs or outputs. A elaborate explanation about all signals and symbols are found in the MapleSim user-manual. Results can be plotted by attaching probes to the connection lines of the model. In contrast to the probes in SimMechanics, MapleSim cannot ’live-visualize’ sig- nals. When attaching a probe, a screen appears in which the desired output signal(s) can be chosen (see figure B.3). After attaching probes and specify- CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 12
Figure 1.4: The half-car model in MapleSim ing signals, x- and y-axis variables have to be chosen (see figure B.4). After simulating, a ’Plot Window’ appears (see figure B.5). In this window, line and axis properties can be changed. Also, graph can be exported to various type of image-formats.
Dymola
In Dymola, the half-car model is constructed in basically the same way as was done in MapleSim (see figure 1.5). Again, components are dragged from the li- brary into the modeling-window. The car-body is modeled as a ’bodyShape’ which can be interpreted as being a mass with two coordinate-frames, just like what was done in MapleSim using a body block with two ’Rigid Body Frames’. By using an ’Absolute Position’-block, we can extract the horizontal and vertical position signal of the body. Here, we don’t need an ’demux’-block because Dymola directly asks which signal to use when dragging a line from the ’Absolute-Position’-block (see figure C.1). Parameters can be changed by double-clicking a component, an example of the ’parameter-window’ is showed in figure C.2 for the car-body. Other than MapleSim and SimMechanics, Dy- mola shows some parameters such as mass and stiffness/damping directly into the top-view which is particularly handy when checking the model. By clicking CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 13
’Info’ in the ’parameters’-window, an elaborate description of the selected com- ponent appears in a new help-window. Like MapleSim, Dymola uses different colors for connection lines specifying the signal-type. Similar to MapleSim, Dymola also offers a ’Component-Browser’, showed in figure C.3. Like MapleSim, the browser represents a hierarchic view of the components that are present in the model, as well as the connection-ports of a specific component. By right-clicking a component in the browser and choose for ’Info’, a similar information-window as discussed above will appear.
Figure 1.5: The half-car model in Dymola
An advantage of Dymola with respect to MapleSim and SimMechanics is that all input and output signals can be plotted after the model has been simulated. Therefore, in Dymola no probes have to be attached to the model and no axis- properties have to be specified before simulating a model. If needed, adjusting the plot characteristics can be done after simulating the model, using the ’plot- setup’-window (see figure C.4). CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 14
1.2 Simulation performance
As will be discussed in more detail in section 3.3, when using default simulation settings, big differences in accuracy can occur. Inevitable, this also influences the performance and speed of a simulation. Therefore, the same simulation settings as described in section 3.3 are used, because these settings give basically the same results with respect to accuracy. By using these simulation settings, a global indication regarding simulation-speed can be given. To check performance, the half-car-model is used again. The half-car model is simulated for 10 seconds. The numerical integrator settings (error tolerances and algorithms) are adjusted so that they are identical (as far as possible) in all three packages. The simulations are done with the same 1.86 GHz processor laptop that is freshly started every simulation to guarantee identical circumstances. Nevertheless, no ’strict’ conclusions concerning simulation-speed can be made because of the relative simplicity of the half-car model and because of structural difference between the investigated multi-body packages. An example of this can be given when we look at the way results are presented; in Dymola all signals can be accessed after simulation, in SimMechanics and MapleSim distinctive result-signals have to be chosen prior to simulation. In SimMechanics, the total simulating time for the half-car model is about 22 seconds. No additional information regarding the time needed for compiling the model equations and solving the equations is available. Simulating the half-car model in MapleSim takes approximately 19 seconds in total from which, according to the status-window, about 7 seconds in used for compiling the model equations and about 12 seconds is needed for solving the equations and make data plots. When we, under similar conditions, simulate the half-car model in Dymola, we can see that Dymola requires about 13 seconds simulation time. The time needed for translating the model is about 10 seconds, the residual 3 seconds are used to integrate the model-equations and process the data. Another aspect of software-performance that has to be mentioned is startup- time. When we look at MapleSim, the software itself is ready-to-use in about 20 seconds and the half-car model is loaded in about 2 seconds. Dymola requires 10 seconds for initializing and a model is opened in approximately 5 seconds. Because the slow-loading MATLAB software is needed to use Simulink/SimMe- chanics, starting-up SimMechanics requires significant more loading-time com- pared to MapleSim and Dymola. SimMechics is ready-to-use after about 80 seconds (which includes starting MATLAB and Simulink). Opening a model takes another 8 seconds. From the preceding experience, we can conclude that Dymola is the fastest with simulating the half-car model, but the differences with MapleSim and Sim- Mechanics are not significant. Nevertheless, the results give a first indication regarding the simulation speeds. However, this simple half-car model does not represent the practical use of a multibody package where much more complicated models will be created. When we really want to check if major differences in simulation time would occur, three extensive identical models should be build CHAPTER 1. BUILDING A HALF-CAR MULTIBODY MODEL 15 in all three packages. What we can conclude regarding start-up time is that Simulink/SimMechanics needs significantly more time to start than MapleSim and Dymola. The start-up time differences between MapleSim and Dymola are in the order of seconds, in favour of Dymola. Chapter 2
Verification & error handling
When constructing complex models, it’s important that possible modelling er- rors can be traced efficiently. Therefore, error-messages given by the software should be clarifying in order to localize the error. In order to check error-messages and verification, two half-car model (see chapter 1) test-cases are examined in which we deliberately cause an error. In the first case, we ’forget’ to attach one of the prismatic joints to the car-body. In the second case, we don’t specify a mass-value to the car body. In both cases we investigate how the three packages react and how they report the error. The question ’can we efficiently trace the fault by looking to the error-message?’ is answered after that.
2.1 Testcase 1: absent connection between joint and car-body
SimMechanics
When performing testcase 1 to the SimMechanics model, an error-message as showed in figure 2.1 appears. The message is not directly indicating where the fault occurs in the model, but from the fact that there is, however, a ’Ground- block’ present in the model we can conclude that somewhere, the rest of the model is not connected to it.
MapleSim
If we look at the error-message which is produced in MapleSim (see figure 2.2) we see a error-message which is explained by means of an error in the mathematic calculation. From this message we haven’t got a clue where to find the fault and what causes it. Because of these ’cryptic’ error messages, in practice it’s very hard to construct a model for the first time because no clear information about
16 CHAPTER 2. VERIFICATION & ERROR HANDLING 17
Figure 2.1: SimMechanics error message belonging to testcase 1 the location and characteristic of the fault is given when the model contains an error.
Figure 2.2: MapleSim error message belonging to testcase 1
Dymola
When performing the same testcase in Dymola, an error-message like figure 2.3 appears. From the sentences "Connector frame-b of joint object is not con- nected" and "Connector frame-b of line force object is not connected" it becomes very clear what was done wrong and where the fault is located in the model. CHAPTER 2. VERIFICATION & ERROR HANDLING 18
Figure 2.3: Dymola error message belonging to testcase 1
2.2 Testcase 2: mass not specified, equal to zero
SimMechanics
When looking at the error-message produced by SimMechanics (see figure 2.4), from just reading the message that the mass of the car body is not specified.
Figure 2.4: SymMechanics error message belonging to testcase 2
MapleSim
In MapleSim, a value which is obliged (such as the mass of a body) cannot be deleted. When trying to escape the default value, it is changed into a value of 1 [kg].
Dymola
When in Dymola deliberately a mass-value is not specified, the program does not produces an error-message. Apparently, a default value is chosen if no value is specified. When we look at the plots to check this, we indeed can see that Dymola uses a default value of 1 [kg] for the mass of the car-body, without informing the user. This can be a bit tricky, because the behavior of the half-car CHAPTER 2. VERIFICATION & ERROR HANDLING 19 becomes completely different. What we do see is that the mass-value indicated in the top-screen of the model is changed into m which indicates that no numeric value for the mass of the car-body has been chosen. Chapter 3
Numerical accuracy
In order to check the numerical accuracy of all three packages a relative simple 2D double pendulum model is modeled. By comparing the resulting motion induced by two initial conditions (for both θ1 and θ2) with an analytical derived equation, the software accuracy can be checked. A schematic drawing of the analysed double pendulum is showed in figure 3.1. The masses m1, m2 and also the length l1 and l2 of the pendulum are kept constant in all simulations. The pi initial condition are also kept constant and will be θ1 = 4 and θ2 = 0.
l _
1
θ1
m_1
l_ θ2 2
m_2
Figure 3.1: The double pendulum reference model
3.1 Analytical model
The double pendulum system will be analysed by hand using the Langrangian method (3.1).
20 CHAPTER 3. NUMERICAL ACCURACY 21
d T, − T, + V, = (Qnc)T (3.1) dt ˙q q q Where the generalized coordinates are chosen to be:
q θ q = 1 = 1 (3.2) q2 θ2 and the kinetic energy:
1 T = ˙qT M ˙q (3.3) 2 with M the mass-matrix of the system:
n X T M = mi(ri,q) ri,q (3.4) i=1 where ri,q represents the derivative of the position vector of mass mi with respect to the generalized coordinates (3.2). The mass-matrix becomes:
2 (m1 + m2)l1 m2l1l2(cosθ1cosθ2 + sinθ1sinθ2) M = 2 m2l1l2(cosθ1cosθ2 + sinθ1sinθ2) m2l2 (3.5) and using this result the kinetic energy T becomes:
1 2 1 2 T = m l θ˙ + m (l2θ˙ + l2θ˙ + 2l l θ˙ θ˙ cos(θ − θ )) (3.6) 2 1 1 1 2 2 1 1 2 2 1 2 1 2 1 2 Because no springs are involved in the system the potential energy becomes:
V = U in(q) + V ex(q) = V ex(q) (3.7) and thus becomes:
V = −m1gl1cosθ1 − m2g(l1cosθ1 + l2cosθ2) (3.8)
And because no non-conservative forces are involved:
Qnc = 0 (3.9)
When vector equation (3.1) is evaluated and then rewritten to θ¨1 and θ¨2 as a function of θ˙1, θ˙2, θ1 and θ2 (angles and angular-velocity of both generalized coördinates), two second order differential equations of motion are obtained: CHAPTER 3. NUMERICAL ACCURACY 22