hybrid bond graphs

13
35 HYBRSIM—a modelling and simulation environment for hybrid bond graphs SPECIAL ISSUE PAPER P J Mosterman Institute of Robotics and Mechatronics, DLR OberpfaVenhofen, D-82230 Wessling, Germany Abstract: Bond graphs are a powerful formalism to model continuous dynamics of physical systems. Hybrid bond graphs introduce an ideal switching element, the controlled junction, to approximate continuous behaviour that is too complex for numerical analysis (e.g. because of non-linearities or steep gradients). HyBrSim is a tool for hybrid bond graph modelling and simulation implemented in Java and is documented in this paper. It performs event detection and location based on a bisec- tional search, handles run-time causality changes, including derivative causality, performs physically consistent (re-)initialization and supports two types of event iteration because of dynamic coupling. It exports hybrid bond graph models in Java and C/C++ code that includes discontinuities as switched equations (i.e. pre-enumeration is not required). Keywords: hybrid systems, physical system modelling, bond graphs, hybrid bond graphs, hydraulic actuators NOTATION 1.1 StiV systems Continuous physical system models may contain non- C storage of generalized displacement linearities and steep gradients that complicate numerical e eVort simulation. Integration methods such as the backward f ow diVerence formula (BDF) [ 3, 4 ] address these problems GY gyrator by reducing the simulation step size, at the cost of I storage of generalized momentum increased computational complexity. p generalized momentum To illustrate, consider the hydraulic cylinder in Fig. 1. q generalized displacement To move the piston with inertia m p , the intake valve with R dissipation uid inertia I in and ow resistance R in is adjusted to Se eVort source control oil ow into the cylinder. The elasticity C oil and Sf ow source viscosity R oil of the oil in the chamber generate a pressure TF transformer that opens a relief valve with inertia and resistance, 0 generalized KirchhoV current law I rel and R rel respectively, when the pressure exceeds a 1 generalized KirchhoV voltage law prede ned safety threshold. Initially, the relief valve may be closed and when the 1 INTRODUCTION Physical systems can be modelled by sets of ordinary diVerential equations (ODEs) possibly supplemented by algebraic constraints [diVerential and algebraic equa- tions (DAEs)]. Often these are composed from local con- stituent equations of primitive elements and constraints imposed by a network structure that connects them [ 1, 2 ]. The MS was received on 7 December 2000 and was accepted after revision for publication on 15 May 2001. Fig. 1 Hydraulic cylinder with relief valve I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Upload: api-26493464

Post on 11-Apr-2015

301 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Hybrid Bond Graphs

35

HYBRSIM—a modelling and simulation environmentfor hybrid bond graphs

SPECIAL ISSUE PAPER

P J MostermanInstitute of Robotics and Mechatronics, DLR OberpfaVenhofen, D-82230 Wessling, Germany

Abstract: Bond graphs are a powerful formalism to model continuous dynamics of physical systems.Hybrid bond graphs introduce an ideal switching element, the controlled junction, to approximatecontinuous behaviour that is too complex for numerical analysis (e.g. because of non-linearities orsteep gradients). HyBrSim is a tool for hybrid bond graph modelling and simulation implementedin Java and is documented in this paper. It performs event detection and location based on a bisec-tional search, handles run-time causality changes, including derivative causality, performs physicallyconsistent (re-)initialization and supports two types of event iteration because of dynamic coupling.It exports hybrid bond graph models in Java and C/C++ code that includes discontinuities asswitched equations (i.e. pre-enumeration is not required).

Keywords: hybrid systems, physical system modelling, bond graphs, hybrid bond graphs, hydraulicactuators

NOTATION 1.1 StiV systems

Continuous physical system models may contain non-C storage of generalized displacement

linearities and steep gradients that complicate numericale eVort

simulation. Integration methods such as the backwardf � ow

diVerence formula (BDF) [3, 4 ] address these problemsGY gyrator

by reducing the simulation step size, at the cost ofI storage of generalized momentum

increased computational complexity.p generalized momentum

To illustrate, consider the hydraulic cylinder in Fig. 1.q generalized displacement

To move the piston with inertia mp, the intake valve with

R dissipation� uid inertia I

inand � ow resistance R

inis adjusted to

Se eVort sourcecontrol oil � ow into the cylinder. The elasticity Coil and

Sf � ow sourceviscosity Roil of the oil in the chamber generate a pressure

TF transformerthat opens a relief valve with inertia and resistance,

0 generalized KirchhoV current lawIrel and Rrel respectively, when the pressure exceeds a

1 generalized KirchhoV voltage lawprede� ned safety threshold.

Initially, the relief valve may be closed and when the

1 INTRODUCTION

Physical systems can be modelled by sets of ordinarydiVerential equations (ODEs) possibly supplemented byalgebraic constraints [diVerential and algebraic equa-tions (DAEs)]. Often these are composed from local con-stituent equations of primitive elements and constraintsimposed by a network structure that connects them[1, 2 ].

The MS was received on 7 December 2000 and was accepted afterrevision for publication on 15 May 2001. Fig. 1 Hydraulic cylinder with relief valve

I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 2: Hybrid Bond Graphs

36 P J MOSTERMAN

intake valve closes completely, there is no � ow of oil model topology at each evaluation, i.e. it is interpretive.The advantage of the interpretive approach lies in theinto the chamber, causing the piston velocity to become

zero quickly. In a continuous model, a small leakage � exible treatment of variable structure, i.e. hybrid,models for which HyBrSim has been developed speci� -� ow of the valve interacts with the fast dynamics induced

by Coil and Roil , which leads to high-frequency low- cally [6 ]. It does not focus on sophisticated handling ofpure continuous and discrete behaviours.amplitude oscillations requiring a small simulation step

size for a considerable time interval. Section 2 reviews the bond graph modelling and simu-lation approach and identi� es the support provided byFor the particular problem, eYcient variable step-size

numerical integration may not be possible or such sol- HyBrSim. Section 3 discusses the hybrid bond graphmodelling approach, general hybrid dynamic systemsvers may not be available or suitable for the task at hand

(e.g. real-time simulation). eVects and how these are facilitated by HyBrSim.Section 4 describes the export � lter to C/C++ and Javaand Section 5 presents conclusions and future work.

1.2 Discontinuities

StiV systems because of steep gradients can be simpli� ed2 BOND GRAPH MODELLING ANDby abstracting the fast continuous transients into dis-

SIMULATIONcontinuous changes and the models assume a mixedcontinuous–discrete hybrid nature [5 ]. Hybrid systems

In HyBrSim, dynamic behaviour of physical systems istypically operate in piecewise continuous modes, mod-modelled by bond graphs [7, 8 ].elled by ODEs and DAEs. Mode changes are most con-

veniently modelled by activating and deactivatingconstituent equations of model components which maychange computational causality. For example, when the 2.1 Bond graph modelling with HYBRSIMintake valve in Fig. 1 closes, its constituent equation

Bond graphs model the exchange of energy, power,changes from enforcing a zero pressure drop across it tobetween idealized physical processes, which allows forenforcing zero � ow. These causal changes may result inmulti-domain modelling (e.g. electrical, mechanical anddynamic (i.e. run-time) changes in the state vector.hydraulic).Two situations can be classi� ed:

1. State variables become dependent on exogeneous 2.1.1 The power domainvariables.

2. State variables become algebraically related. Each power connection, bond, contains two conjugatevariables, eVort e and � ow f, the product of which con-In Fig. 1, when the intake valve closes and the reliefstitutes power, that correspond to an intensive variable

valve is closed as well, if the oil elasticity and viscosity(e.g. pressure and voltage) and rate of change in anare abstracted away, the piston velocity is forced to zero,extensive variable (e.g. volume and charge) respectivelyand, therefore, its momentum is no longer a state vari-[9 ]. There are nine primitive bond graph elements, listedable (� rst issue). In this mode, the required pressurein Table 1, that represent lumped ideal behaviour andbuild-up in the cylinder may be such that the relief valveexchange energy through ports.

opens. Now, the state variables that correspond to Ireland mp , i.e. the � uid momentum prel and the momentum

Irreversible processes. The ideal irreversible processespp, become dependent (algebraically related) and the

R dissipate energy and generate entropy. For example,initial piston momentum has to be distributed so that

in Fig. 1 the intake valve is modelled to have a dissipativetheir values are mutually consistent (second issue).

eVect, Rin. If the generated entropy does not aVectThe closing of the intake valve and the opening of the

dynamic behaviour, this port (at present not supportedrelief valve follow each other with no continuous

by HyBrSim) is not shown.diVerential-equation behaviour in between. In general,(de)activating blocks of equations may result in a Reversible processes. The ideal reversible processes Csequence of consecutive mode changes that has to con- and I store energy without dissipation and indicate stor-verge before continuous behaviour resumes [5 ]. age of � ow and eVort respectively, with initial values of

generalized displacement q0 (=Ce0) and generalized1.3 HYBRSIMmomentum p

0(=If

0). For example, in Fig. 1 the oil elas-

ticity Coil

stores oil compression. These variables captureHybrid bond graph simulator HyBrSim is a modellingand simulation environment to handle hybrid behav- the state of the system. In general, one storage element

can communicate energy to many diVerent domains;iours, implemented in Java. Instead of generating aglobal system of equations, HyBrSim attempts to propa- however, at present, HyBrSim supports only one-port

storage.gate known variable values (input and state) through the

I08800 © IMechE 2002Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 3: Hybrid Bond Graphs

37HyBrSim—A MODELLING AND SIMULATION ENVIRONMENT FOR HYBRID BOND GRAPHS

Table 1 Bond graph elements example, in Fig. 1 the oil pressure in the chamber is thesame on the intake path, relief path and the piston and

Process Identi� cation Properties Relationcan therefore be modelled by a 0-junction.

Irreversible R Resistance R e=Rf The weighted distribution elements are of TF, thetransformer type and GY, the gyrator type. The intake

Reversible C Capacitance C f =Cde

dt valve in Fig. 1 can be modelled by a TF element tomodulate the hydraulic power supplied to the cylinder.

Initial value q0 e=1

C P f dt+q0C

Graphical appearance. A HyBrSim bond graph modelof the cylinder in Fig. 1 is shown in Fig. 2. The bondI Inertia I e=I

df

dt graph elements are rectangles with the element type onthe left and their name on the right [10 ]. Power bondsInitial value p0 f =

1

I P e dt+p0I (depicted by a harpoon) connect elements that exchange

energy, e.g. in Fig. 2 the connection between the SeContext Se Amplitude E e=F

element and the TF element. In addition, bond graphSf Amplitude F f =Fmodels may contain modulation eVects based on connec-Normal 0 e

i=e

0 tions that carry no energy. Such a connection may corre-distribution åi

fi=01 fi= f0 spond to an individual eVort or � ow variable that is

åiei=0 tapped from a power bond by an active bond (depicted

Weighted TF Transformation ein=neout by an arrow). In Fig. 2 an active bond taps the velocitydistribution ratio n fin=nfout of the piston, mp, and feeds its value into the displace-GY transformation eout=rfin ment element that is part of the signal domain.ratio r ein=rfout

2.1.2 The signal domainThe context. The dynamics of the system environment

A number of mathematical operations are available thatare not modelled. Instead, interaction is modelled byoperate on signals, i.e. connections that carry no powerideal sources that can be of eVort and � ow type, i.e. Se(of which active bonds are a subset). In HyBrSim, theand Sf respectively. In Fig. 1, the interaction is by thesignal part of a model is shown in blue (grey inhydraulic pressure p

inand sump pressure p

smp, both of

monochrome depiction).Se type.In Fig. 2 the signal part is used to model a PID control

law for the piston displacement. This is a geometric stateThe junction structure. A junction structure that con-sists of normal and weighted elements distributes power. that is used as input to the control part, together with a

desired set point. The error between the two is integratedThe normal elements are of common eVort type (e.g. theKirchhoV current law), 0-junctions, or common � ow once to implement integral control and the velocity is

used directly to add a derivative component. A set oftype (e.g. the KirchhoV voltage law), 1-junctions. For

Fig. 2 Bond graph of cylinder with proportional–integral–derivative (PID) controller without the valvesbeing modelled

I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 4: Hybrid Bond Graphs

38 P J MOSTERMAN

proportional, integral and derivative gains, Kp, K

iand 2.2.1 The method

Kd) respectively, computes the controller output used toFirstly, causality is assigned to the power elements basedmodulate the physical process, in this case the hydraulicon a sequential causality assignment procedure (SCAP)power supplied to the cylinder. These block diagramalgorithm [12 ]. Next, an execution order is determinedelements allow multiple-input si and multiple-output so such that, at a given evaluation k, all input values of ansignals. Their functionality is given in Table 2.element are known when it is called to compute itsoutput. Modulated elements are handled by introducing2.1.3 User interfacepseudo-state behaviour, i.e. the modulation factor is one

The HyBrSim user interface consists of a work space evaluation (during continuous integration this equalsand a bond graph and block diagram toolbox. one integration step) delayed. The initial value is userConnections are made by � rst clicking the source and speci� ed.then the destination element. The source element deter- The execution order is determined by � rstly propagat-mines the type of connection. If it is a bond graph ing the values of all clock elements so that time modu-element, a power connection is made. If it is a block lation is not delayed. Next, the values of sources anddiagram element, a signal connection is made. A connec- storage elements in integral causality are propagated.tion from a block diagram to a bond graph element is The values of sources are user provided or, in the caseallowed in the case of a modulated element, Se, Sf, TF of modulation, given by the pseudo-state value. Theand GY, and automatically interpreted as such. values of storage elements in integral causality are com-

Right clicking on an element brings up a pop-up menu puted from their state. Storage elements in derivativewith entries that include the element name and its causality have no propagation roots and compute aproperties. In most cases, element properties include a numerical diVerence approximation of the time deriva-parameter p and initial value x0 (Tables 1 and 2). For tive variables, (1/p) [(x

k­ x

k Õ 1)/¢T ], where p is the

the summing element it contains a drop-down list with parameter and xk

the state with x0 as its initial value.all ingoing signals and their sign, p

i, i.e. whether they Note that this implies that the � rst time step is oV.

are to be added or subtracted. Furthermore, zero-order causal paths between resist-ances cannot be handled. These issues are addressed bya recently implemented approach that is beyond the

2.2 Simulation with HYBRSIM scope of this paper.After all eVort and � ow variables have assigned

Continuous simulation applies a distributed token pass-values, these are propagated into the block diagram

ing approach and is based on the forward Euler method,model part via active bonds. Together with the integrator

x(tk+ 1

)=x(tk)+xÁ (t

k) ¢T, where x(t

k) is the state at time

elements that propagate their stored value and the valuestk, xÁ (t

k) its time derivative and ¢T the integration step

of clock elements, all block diagram variable values aresize. Each port of a bond graph and block diagram

computed.element has an attribute that contains the current valueof the token at that port [11 ]. Note that focus of 2.2.2 Derivative causalityHyBrSim is on the interaction between continuous and

In the case of derivative causality, there is dependencediscrete models and, therefore, although simple, the for-between storage elements and sources and straight-ward Euler integration method is chosen as an initialforward propagation of their values does not apply.means to generate continuous behaviours.Instead, algebraic constraints on state variables deter-mine their values. In the case of dependence on sources

Table 2 Bond diagram elements only, the stored energy can be computed directly. Ifdependence on other storage elements exists, state values

Element ID Properties Relationhave to be found that are consistent with the algebraic

Clock t p, x0 If time<p, then so=x0 ; constraints. Two critical issues must be solved:else s0=time+x0 ­ p

1. A given set of values has to be made consistent withIntegrator int p, x0 so=p á åisidt

the algebraic constraints.Step ­ p, x0 If åisi>p, then so=1;

2. It must be ensured that one integration step ofelse s0=x0Sum + pi so= åipisi dynamic behaviour remains consistent with the

Multiplier 1 p so=p 1 Õipisi algebraic constraints.

Inverter inv p so=1

p 1 åisi

To achieve issue 1, HyBrSim implements theconservation-of-stat e principle [13 ] as an iteration pro-Square root sqrt p so= ã |p 1 å

isi | cess between algebraically related storage elements. This

sin sin p so=p 1 sin(åisi)

circumvents the need to generate the conservation equa-cos cos p s0=p 1 cos(å

isi) tions from a bond graph [13 ] and to solve these

I08800 © IMechE 2002Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 5: Hybrid Bond Graphs

39HyBrSim—A MODELLING AND SIMULATION ENVIRONMENT FOR HYBRID BOND GRAPHS

explicitly, either numerically or symbolically, as required C elements, standard simulation packages allow theinitialization of only one of them and, depending on thein other work [14, 15 ]. HyBrSim does facilitate equation

generation (for a class of bond graphs even in explicit value of E, the state of the other is computed whileneglecting to take into account the constraint that onlysolved form) but the direct implemention of the conser-

vation principle by balancing the exchange of extensity displacement can be added to one if it is taken out ofthe other.between storage elements seamlessly � ts the token

propagation simulation approach. Once consistent values are found, it has to be ensuredthat future behaviour remains consistent, i.e. for theFigure 3 illustrates the iterative process. Here, I2 is in

derivative causality* because of the algebraic depen- model in Fig. 3 that equation (1) remains satis� ed. Inan equation-based system, this is achieved by computingdence between I1 and I2 through their common � ow.

Therefore the stored momentum p1 and p2 has to be the gradient of behaviour while accounting for thedependence. From equation (1) andconsistent with

p1I1

=p2I2

(1) pÁ 1=E ­ pÁ 2 ­p1I1

R (2)

it follows, after diVerentiation of equation (1), thatSuppose that at a point in time, tk, p1=2 and p2=1.

These values may be user speci� ed if tk

is the simulation pÁ 1= [1/(I1+I2)] (I1E ­ Rp1)=­ 3.25 and one ¢T=0.1time step gives p (t

k+ 1)=p1(t

k)+pÁ 1(t

k) ¢T=1.175.start time or the result of a mode switch at t

kin the case

of a hybrid model. For I1=I2=1, this is inconsistent HyBrSim takes a two-step approach. Firstly, a gradi-ent is allowed that results in state values that are incon-with equation (1) and iteration � rst takes part of the

stored momentum out of I1, determined by a conver- sistent with the algebraic constraints. Secondly, the

iteration approach is applied to � nd consistent valuesgence factor è=0.4, and transfers it into I2 . This leadsto p1=1.6 and p2=1.4 (Table 3). For these momentum again. For the two inertias, after consistent values p1=

p2=1.5 are found, the gradient of p1 is determined whilevalues, equation (1) is still not satis� ed, and again a(now smaller) part of stored momentum is transferred disregarding the in� uence of I2 , i.e. e2=0, which yields

e1=­ 6.5, and one simulation step ¢T=0.1 is takenfrom I

1to I

2. This results in p

1=1.52 and p2=1.48.

This process continues until f1= f2 , within some preset that only updates the state of I1 , p1=0.85. This resultsin values for p1 and p2 that violate the algebraic con-numerical margin.

An important observation is that this allows all stor- straint in equation (1) and iteration computes p1=p2=1.175 as well.age elements to be initialized. Other simulation tools

typically allow only initialization of the reduced state,2.2.3 User interfacewhich may lead to diVerences in the simulation results.

For example, if the I elements in Fig. 3 are replaced byEVort, � ow and signal values can be plotted after simu-lation. These variables are coded by colouring the eVortstroke, the � ow circle and the � ll colour of the signalarrowhead, corresponding to the colours of the traces ina plot. This plot has a small set of rudimentary displayfeatures such as data points on–oV, autoscale, user-selected maxima and minima for x and y axes separatelyand a mouse-driven zooming feature. To allow the useof sophisticated plotting features such as those providedby Matlab [16 ], data can be written to a � le in standardASCII format, which includes the evaluation step k andthe time stamp t

kfor each of the sets of data points†.

Fig. 3 Bond graph with derivative causality In addition, power along each bond can be animated( logarithmic or linear) with positive power based at the

Table 3 Conservation-of-state iteration, è=0.4 harpoon destination and negative power at the source.Figure 4 shows the power distribution in the hydraulic

Iteration p1 p+2 p2 è( p+2 ­ p2)actuator in Fig. 1 at t=0.2 s. The relief valve is con-

0 2 2 1 0.4 sidered to be closed and, therefore, not shown and the1 1.6 1.6 1.4 0.08 PID control part is not shown because it does not distrib-2 1.52 1.52 1.48 0.016

ute power. At the point in time represented by Fig. 4, a3 1.504 1.504 1.496 0.00324 1.5008 1.5008 1.4992 0.000 64 small fraction of the power supplied by the pin source is

dissipated and some is returned by Iin

(power is based* Note that the eVort causality is indicated by a perpendicular strokeat the end of a power bond and � ow causality by a circle at theother end. † All plots in this paper are generated by MATLAB.

I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 6: Hybrid Bond Graphs

40 P J MOSTERMAN

when the junction changes its state. Computationally,this is similar to the use of a speci� c switching elementand, therefore, the HyBrSim implementation to handlehybrid phenomena also applies to switched bond graphs[23 ]. Note that dissipation may still occur when junc-tions change their state, e.g. in the case of a perfectlynon-elastic collision.

In the bond graph model in Fig. 2, if the valvesare modelled as ideal switches, the corresponding1-junctions (in and relief ) become controlled junctionswith inertial and dissipative eVects explicitly modelled.

3.1.2 The discrete event model

The discrete event model part is implemented by localFSMs, one for each controlled junction, that map each

Fig. 4 Logarithmic power distribution at t=0.2 s of their states on to the on and oV states. The graphicalrepresentation is a state transition diagram that is associ-ated with the junction property. For example, Fig. 6at the harpoon source and, therefore, negative). The oilshows the FSM for the relief valve mechanism in Fig. 1.dynamics represented by R

oiland C

oilhave almost

When the net pressure pnet crosses a threshold value pth ,reached steady state and hardly aVect the power balancepnet=pcyl ­ pth<0.0 the relief valve opens, i.e. the corre-(recall the logarithmic scale). After the initial transient,sponding controlled junction comes on. Note that thethe oil dynamics reach an internal steady state, and thethreshold value can also be modelled in the FSM. Forparameters Roil and Coil do not consume any moreexample, the relief valve closes again when the pressurepower. Therefore, to investigate low-frequency behav-has subsided and crosses another threshold ( pnet>25.0).iour these elements can be removed, e.g. by a singular

This leads to the behaviour in Fig. 7. During a controlperturbation related approach for bond graphs [17 ]. Inmanoeuvre, the intake valve closes inadvertently at t=general, such power analyses can be used to aid in model0.2 s. Shortly thereafter, the oil parameters have builtreduction by removing elements with low power con-up a pressure in the cylinder chamber that exceeds thesumption [18 ]. Animation can be paused, restarted andsafety threshold. Consequently, the relief valve opens forcontinued from � nal values when the simulation enda short duration (see Fig. 7b) until the pressure has sub-time was reached.sided and then closes again. This leads again to too higha pressure in the cylinder and the same procedurerepeats, after which the piston velocity has reduced to a3 HYBRID BOND GRAPHSvalue that can safely decay to zero. This ‘stuttering’ istypical of relief valve behaviour.Piecewise linearization of non-linearities and removal of

Each FSM associated with a controlled junction hassteep gradients may lead to hybrid models with continu-an initial state, indicated by a shaded background, andous behaviour that is interspersed with discrete modean active state that is highlighted. States can be addedchanges [19 ].and removed but are always of the on and oV type.

Because FSM switching eVects are included locally,no global analysis of the modes of behaviour is required.3.1 Hybrid bond graph modellingAlthough this avoids pre-enumeration (which can beprohibitively complex because of the state explosion) , itHybrid bond graphs endow the bond graph modelling

formalism with a � nite state machine (FSM) model part requires run-time facilities to determine the new globalmode dynamically. This includes causal analysis whichthat communicates by means of a controlled junction

[20 ]. may lead to run-time changes in the complexity of theunderlying system of equations (i.e. derivative causality

3.1.1 From discrete to continuous may emerge).

The controlled junction operates in one of two states to 3.1.3 From continuous to discretemodel switching behaviour systematically. When it is on,it acts as a normal junction and, when it is oV, a Block diagram signals and active bonds that may cause

a controlled junction to change its state are connected0-junction acts as a zero-value eVort source and a1-junction as a zero-value � ow source (Fig. 5). This to this junction and show up in the state transition dia-

gram as signal ports. Signal ports constitute crossingimplements ideal switching behaviour (see, for example,references [20 ] to [22 ]) and changes causality on one port functions that compare the value of the corresponding

I08800 © IMechE 2002Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 7: Hybrid Bond Graphs

41HyBrSim—A MODELLING AND SIMULATION ENVIRONMENT FOR HYBRID BOND GRAPHS

Fig. 5 The controlled junction types

Fig. 6 Hybrid bond graph model of actuator with the valves modelled by controlled junctions

Fig. 7 Simulation of the model in Fig. 6

variable in the bond graph, x, with a threshold ä. Two option is used to � nd the new state of all controlledjunctions and the second to halt continuous simulationinquiries are allowed: (a) the new truth value of the cross-

ing function can be requested and (b) it can be queried when a discrete event is generated.The comparison can be of the types listed in Table 4whether a crossing or change in the sign of the crossing

function z (­ 1, 0 and 1 for below, at and above the and results in a Boolean output (true and false) that canbe connected to transitions between states. Several signalthreshold respectively), takes place, indicated by setting

the inquiry Boolean variable cross to true. The � rst ports may be connected to one transition to form a

I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 8: Hybrid Bond Graphs

42 P J MOSTERMAN

Table 4 Crossing variable x and its the case of dynamic coupling, when a discrete statethreshold ä comparisons change causes a junction to switch between its on and

oV state (not each state change is necessarily one betweenRequest Return value

on and off ), eVort and � ow variables in the bond graphx<ä x<ä ­ å m ("cross l z>­ 1) may change their values and, when these values arex å ä x å ä+å m ("cross l z>0) propagated into the signal ports, they may enable furtherx=ä (cross m z>0 m x å ä+å) l

state transitions. Therefore, before continuous simu-(cross m z<0 m x " ä ­ å) l("cross m |x ­ ä | å å) lation can resume, iteration between the discrete model

x " ä x " ä ­ å m ("cross l z<0) parts and between the discrete and continuous modelx>ä x>ä+å m ("cross l z<1)

parts is necessary to � nd � rst a consistent, stable,continuous and discrete state.

A priori and a posteriori values. Algebraic constraintslogical conjunction. A signal port with output true gener-may be activated and deactivated during one sequenceates a discrete event that may enable a transition and,of discrete state changes and change the state values ofwhen it does, force it to occur immediately (i.e. the FSMstorage elements. In the bond graph model it may orimplements ‘must � re’ semantics) .may not be desired to return to the original values beforethe discrete state changes [5 ]. A check box speci� eswhether a signal port generates events based on a priori3.2 Hybrid bond graph simulationor a posteriori values of x around a discontinuity, shownby a ­ or + sign respectively on the left in the signalSimulation of hybrid systems has to deal with a numberport (see the relief FSM in Fig. 6). In case of a posterioriof idiosyncrasies [6 ].conditions, the new model variable values computed as

3.2.1 Event detection and location described in Section 2.2.1* are adopted by the signalport. In the case of a priori switching conditions, the

When continuous variables exceed threshold values, as values are only adopted after the system state is updatedspeci� ed in the signal ports, HyBrSim uses a bisectional and so discontinuous changes are eVected. The appli-search to � nd when the � rst event (in general there are cation of this is illustrated next.multiple events) in the ¢T interval occurs. If an event isdetected, the step size is reduced from ¢T to ät

m, where Mythical modes. Consider the situation where the

ätm

is computed on the basis of whether an event occurs, intake valve closes while vp>0, as discussed previously.ó=1, or not, ó=0, in the interval ät

ias follows: The oil viscosity R

oilimmediately causes a large pressure

in the cylinder chamber and this may cause the reliefvalve to open without any noticeable change in piston

äti+ 1=ät

i+¢t

i(1 ­ ó)

¢ti+ 1=1

2¢t

i velocity. If the oil viscosity Roil and elasticity Coil are(3) abstracted away (simply removed from the bond graph

in Fig. 6), the piston velocity becomes zero in the modeThe initial values for this iteration are ät0=0 and ¢t0=where both valves are closed. If the required (now in� -¢T, and the iteration terminates after a � xed number ofnitely) large pressure causes the relief valve to open, thea priori prescribed steps, m. This method is robust andvelocity would remain at zero, which diVers from theguaranteed to � nd the � rst event with a pre-speci� edbehaviour of the more detailed model. Instead, the stateaccuracy, provided that the crossing function does notvalues before the sequence of switches started by closinghave an even number of roots on the ät

iintervals.

the intake valve should be transferred to the mode whereBecause HyBrSim requires the user to determine the stepthe relief valve is opened. The intermediate mode wheresize of the Euler method, ¢T, this is the user’sboth valves are closed is called a mythical mode [5, 24 ].responsibility.In this example, if the opening of the relief valve is basedon a posteriori values, the state vector is not updated yet3.2.2 Reinitializationwhen it is inferred that the valve opens and, therefore,

During event iteration, algebraic dependences of storage the state is transferred correctly.elements may arise that discontinuously change the statevalues using the iteration procedure in Section 2.2.2. Pinnacles. When the intake valve closes, the viscous

pressure may not suYce to open the relief valve. Instead,3.2.3 Event iteration the elasticity may further build up pressure and there is

When an event occurs and a FSM changes its state, afurther transition from this new state may be immedi-

* If two consecutive evaluations occur at the same point in time, i.e.ately enabled, requiring a new evaluation of the FSM t

k=t

k Õ 1, the diVerence approximation to compute eVorts and � ows

of elements in derivative causality is formed by using êH ¢T.and causing a discrete iteration phase. Furthermore, in

I08800 © IMechE 2002Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 9: Hybrid Bond Graphs

43HyBrSim—A MODELLING AND SIMULATION ENVIRONMENT FOR HYBRID BOND GRAPHS

Fig. 8 Actuator with explicit state jump

a signi� cant change in elevator velocity before the relief there is a shorter time step to reach t=0.2 s, because ofroot � nding, described in Section 3.2.1.valve opens (see Fig. 7b). If the oil parameters are

abstracted away, a coeYcient of restitution, å, is usedthat depends on the dissipation of the original param- 3.2.4 Impulse comparisoneters, to compute the change in elevator velocity,vp=åvÕp , where vÕp is the value immediately before In the model of the hydraulic cylinder in Fig. 8, whenswitching started. In Fig. 8 this is implemented by the both valves are closed and the piston has non-zeroSf element with å=0.6.* velocity, a pressure spike occurs that takes the form of

The algebraic equation is activated using a posteriori a Dirac pulse and has an in� nite magnitude. Therefore,values and deactivated using a priori values. The relief the threshold pressure is always exceeded, regardlessvalve is opened on the basis of a priori values to ensure of the piston velocity. In the more detailed modelthat the computed velocity change is eVected. The stutt- whether the pressure threshold is exceeded depends onering behaviour shown in Fig. 7 now occurs instan- the piston velocity [19 ]. This can be included in a � rst-taneously at the same point in time, because the oil order approximation by comparing impulse areas, i.e.parameters are not present any longer. A sequence of the change in piston velocity.activations of the algebraic restitution constraint and HyBrSim explicitly compares impulsive variablesopening of the relief valve reduces the piston velocity based on their areas. The threshold values as speci� edbefore it can be safely set to zero, shown in Fig. 9 by in the signal ports are interpreted as areas as well.the data points with decreasing velocity at the switching Therefore, in the cylinder model in Fig. 8, because thetime. Note that the mode where both valves are closed pressure threshold is given in the signal port, the impulsehas a mythical incarnation; otherwise, the velocity trans- area is tested. If, however, the threshold is given by useferred to the mode where pinnacle is on is zero, and no of a constant value on the work space, this is interpretedstuttering behaviour takes place. as a normal non-impulsive variable and, therefore, dis-

Also note that in Fig. 9b the data points are evenly regarded when impulses occur. In Fig. 8 the int elementspaced during continuous integration (distance ¢T ), but is used for the continuous behaviour threshold and the

threshold value in the signal port for the impulse areacomparison. Therefore, if the instantaneous change invelocity is less than ­ 0.25, the relief valve opens and,* Note the unique labels of connections and that causal con� icts

between sources and junctions that are oV are not terminal. when during continuous behaviour the pressure falls

I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 10: Hybrid Bond Graphs

44 P J MOSTERMAN

Fig. 9 Simulation of the model in Fig. 8

change may be induced by an intermediate value andthis intermediate value should be transferred to the newmode instead. This can be implemented by, for example,a bisectional algorithm.

4 EXPORT FILTERSFig. 10 Chattering behaviour

HyBrSim can export a hybrid bond graph model as anbelow the combined threshold value of ­ 95.25, the relief explicit ODE or implicit DAE in Java or C/C++ tovalve opens as well. generate model behaviours using sophisticated numeri-

cal solvers.3.2.5 Further issues

Other phenomena in hybrid dynamic systems behaviour4.1 Explicit equationsthat at present cannot be handled by HyBrSim are

(a) chattering and (b) aborted projections.Explicit equations take the form xÁ = f (x, u, t), with xthe state variables, u input and t time and are generatedChattering. In hybrid dynamic system behaviour, afterby a straightforward graph traversal procedure after thea mode switch from an initial mode is completed and aexecution order of the bond graph model is established,stable and converged new discrete and continuous stateprovided that no derivative causality exists. Otherwise,is found, an in� nitesimal small time step may lead to athe iteration procedure described in Section 2.2.2 ismode change back to the initial mode.* The next in� ni-included as an additional method, executed after thetesimal time step may again switch to the mode reachedsystem of equations is evaluated. For example, for thefrom the initial one. This means the system has reachedmodel in Fig. 3, the variables I1.f and I2.f area switching surface in phase space where the gradientsalgebraically related as I1.f=I2.f. To facilitate theof behaviour point towards the surface in both modesiteration process, this is generated as a � xed point con-(Fig. 10). If this occurs, simulation reduces the step sizestraint where the new value of I2.f, namely I2.nf,to its smallest possible value repeatedly and, therefore,has to equal I1.f. Applying the conservation con-simulation becomes (many times prohibitively) slow. Atstraint leads to the changes I1.df and I2.df ofpresent, in HyBrSim this can only be circumvented byI1.f and I2.f respectively, and the iteration isdisabling root � nding, which causes a larger error. Arepeated until these changes are within some presetmore sophisticated algorithm has been developed innumerical margin. The generated method for the modelother work [25 ].in Fig. 3 is

Aborted projections. The dependence of a storagevoid 2i::iterate() {

element may cause a discontinuous change in its statedouble I2.nf = I1.f;

variable. Before this change is completed, a further modeI1.df = ( I2.I 1 (I2.nf ­ I2.f)) /I1.I;* Note that this diVers from an immediate switch back, in which case

no stable discrete state exists. I2.df = I2n ­ I2.f;

I08800 © IMechE 2002Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 11: Hybrid Bond Graphs

45HyBrSim—A MODELLING AND SIMULATION ENVIRONMENT FOR HYBRID BOND GRAPHS

and iteration conforms to Table 3, with the convergence withfactor being set by the calling method.

The drawback of an explicit solution is that it is modeu= [E.in], x=CI1. f

I2. f

f .f D, f =CI1.res

I2.res

f .resD (6)dependent because the change in state of a controlledjunction may aVect the computational causality.Therefore, the system of equations, fá , has to be derived

and derf the time derivative of the variable f. Thefor each global mode á. At present, a global causalrequired initial values can be computed by (a) using aanalysis is performed for permutations of up to threededicated routine explicitly generated by HyBrSim butcontrolled junction states.which suVers from the combinatorial restriction (thecomputations diVer per mode) and (b) using a moregeneral (and computationally more expensive) decompo-4.2 Implicit equationssition method that relies on the Weierstrass normal

A DAE system with equations of the form 0= form [27 ].f (xÁ , x, u, t ) is more � exible. Numerical solvers such asthe diVerential–algebraic system solver (DASSL) [4 ]provide the xÁ , x, u and t arguments and require a vector 5 CONCLUSIONSf of return values.

In this form, modulation need not be treated as a Bond graphs are a powerful formalism to model thepseudo-state and the iteration process is not required continuous behaviour of physical systems in diVerentbecause the algebraic constraints can be included in the domains. In many cases the dynamics contain non-implicit formulation. Although this means that the linearities or steep gradients that may be best handledsystem of equations becomes more diYcult to handle, by a discontinuous approximation. Hybrid bond graphsi.e. it is of a higher index [26 ], solvers such as DASSL facilitate this by supporting a junction that is controlledare typically able to handle this complexity provided that by a � nite state machine to operate as either a normalconsistent initial values are available. junction or a zero value source.

An additional advantage of the implicit formulation HyBrSim is a hybrid bond graph modelling and simu-is that controlled junction state changes can be included lation tool that is speci� cally developed to handle phen-by switched equations and, therefore, global analysis omena in the mixed continuous–discrete systems realm.is not required. To this end, the equations for each It performs event detection and location based on acontrolled 0-junction are formulated as follows: bisectional search, handles run-time causality changes,

including derivative causality, performs physically con-0=L æi

pifi+(1 ­ L)e (4)

sistent (re-)initialization and supports two types of eventiteration because of dynamic coupling. Continuouswhere Lµ{0, 1} is a mode selection variable that is 1 ifbehaviour is handled by a simple forward Euler inte-the junction is on and 0 if it is oV. The variablesgration scheme. Therefore, hybrid bond graph modelsp

iµ{ ­ 1, 1} indicate the orientation of each power

can be exported as Java and C/C++ code to be usedbond. Furthermore, equationsby sophisticated numerical solvers where discontinuities

0=ei­ e (5) are included as switched equations (i.e. pre-enumeration

is not required).are added for each power port i. In the case whenL=1, the standard equations for a 0-junction in implicitform are active. When L=0, equation (4) results in

ACKNOWLEDGEMENTSe=0 and, combined with equation (5), the eVorts on allports are zero. The formulation for controlled

The graphical appearance of the HyBrSim elements1-junctions is the dual of this.is based on a bond graph simulator by Robert BajzatFor the model in Fig.3, with a switch to turn the[28 ]. The author is supported by a grant from1-junction oV when the eVort of R exceeds 0.5, thethe Deutsche Forschungsgemeinschaft Schwerpunkt-equations areprogramm KONDISK.

E.e=E.in;f.L=(f.state ==True) ? 1.0 : 0.0;I1.res=­ I1.f + f.f; REFERENCESI1.e=I1.derf * I1.I;R.f= f.f; 1 Andersson, M. Object-oriented modeling and simulation ofR.e=R.f *R.R; hybrid systems. PhD thesis, Department of AutomaticI2.res=­ I2.f + f.f; Control, Lund Institute of Technology, Lund, Sweden,I2.e=I2.derf * I2.I; 1994.

2 Cellier, F. E., Elmqvist, H. and Otter, M. Modelling fromf.res=(­ E.e+I1.e+R.e+I2.e) * f.L+(f.L ­ 1) * f.f;

I08800 © IMechE 2002 Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 12: Hybrid Bond Graphs

46 P J MOSTERMAN

physical principles. In The Control Handbook (Ed. W. S. R262-98, Institute of Robotics and System Dynamics, DLROberpfaVenhofen, Wessling, Germany, 1998.Levine), 1996, pp. 99–107 (CRC Press, Boca Raton,

16 MATLAB, The Language of Technical Computing, MayFlorida).1997 (The MathWorks, Natick, Massachusetts).3 Bujakiewicz, P. Maximum weighted matching for high

17 Dauphin-Tanguy , G., Borne, P. and Lebrun, M. Orderindex diVerential algebraic equations. PhD thesis,reduction of multi-time scale systems using bond graphs,Technische Universiteit te Delft, Delft, The Netherlands,the reciprocal system and the singular perturbation method.1994.J. Franklin Inst., 1985, 319(1–2), 157–171.4 Petzold, L. R. A description of DASSL: a diVerential/

18 Minten, W., Vranckx, S., De Moor, B. and Vandewalle, J.algebraic system solver. Technical Report SAND82-8637,Bondlab, a MATLAB based GUI for bond graph model-Sandia National Laboratories, Livermore, California,ling. J. A, 1997, 38 (3), 11–15.1982.

19 Mosterman, P. J. and Biswas, G. Towards procedures for5 Mosterman, P. J. Hybrid dynamic systems: a hybrid bondsystematically deriving hybrid models of complex systems.graph modelling paradigm and its application in diagnosis.In Hybrid Systems: Computation and Control, Lecture

PhD thesis, Vanderbilt University, Nashville, Tennessee,Notes in Computer Science (Eds N. Lynch and B. Krogh),

1997.2000, pp. 324–337 (Springer-Verlag, Berlin).

6 Mosterman, P. J. An overview of hybrid simulation phen- 20 Mosterman, P. J. and Biswas, G. A theory of discontinuitiesomena and their support by simulation packages. In Hybrid in dynamic physical systems. J. Franklin Inst., JanuarySystems: Computation and Control, Lecture Notes in 1998, 335B (3), 401–439.Computer Science, Vol. 1569 (Eds F. W. Vaandrager and 21 Kassakian, J. G., Schlecht, M. F. and Verghese, G. C.J. H. van Schuppen), March 1999, pp. 164–177 (Springer- Principles of Power Electronics, 1991 (Addison-Wesley,Verlag, Berlin). Reading, Massachusetts).

7 Karnopp, D. C., Margolis, D. L. and Rosenberg, R. C. 22 Stromberg, J.-E., Top, J. and Soderman, U. Variable caus-Systems Dynamics: A Uni� ed Approach, 2nd edition, 1990 ality in bond graphs caused by discrete eVects. In(John Wiley, New York). Proceedings of the International Conference on Bond Graph

8 Paynter, H. M. Analysis and Design of Engineering Systems, Modeling and Simulation (ICBGM’93), Simulation Series,1961 (MIT Press, Cambridge, Massachusetts). Vol. 25, La Jolla, California, January 1993, pp. 115–119

9 Falk, G. and Ruppel, W. Energie und Entropie: Eine (Society for Computer Simulation, San Diego, California).23 Soderman, U. and Stromberg, J.-E. Switched bond graphs:Einfuhrung in die Thermodynamik, 1976 (Springer-Verlag,

towards systematic composition of computational models.Berlin).In Proceedings of the 1995 International Conference on10 Bajzat, R. Building geometric information into and gettingBond Graph Modeling and Simulation (ICBGM’95),out of mechanical systems described by bond graphs. InSimulation Series, Vol. 27, No. 1, Las Vegas, Nevada,MicroCAD’96, University of Miskolc, 1996.January 1995, pp. 73–79 (Society for Computer11 Mosterman, P. J. and Biswas, G. A Java implementationSimulation, San Diego, California).of an environment for hybrid modelling and simulation of

24 Nishida, T. and Doshita, S. Reasoning about discontinuousphysical systems. In Proceedings of the Internationalchange. In Proceedings of AAAI-87, Seattle, Washington,Conference on Bond Graph Modeling and Simulation1987, pp. 643–648.(ICBGM’99), Simulation Series, Vol. 31, San Francisco,

25 Mosterman, P. J., Zhao, F. and Biswas, G. Sliding modeCalifornia, January 1999, pp. 157–162 (Society formodel semantics and simulation for hybrid systems. In

Computer Simulation, San Diego, California).Hybrid Systems V, Lecture Notes in Computer Science (Eds

12 van Dijk, J. On the role of bond graph causality in model- P. Antsaklis, W. Kohn, M. Lemmon, A. Nerode andling mechatronic systems. PhD dissertation, University of S. Sastry), 1999, pp. 218–237 (Springer-Verlag, Berlin).Twente, The Netherlands, 1994. 26 Gear, C. W. DiVerential–algebraic equation index trans-

13 Mosterman, P. J. and Biswas, G. Formal speci� cations from formations. SIAM J. Scient. Statist. Computing, 1988,hybrid bond graph models. In Qualitative Reasoning 9(1), 39–47.Workshop, Cortona, Italy, June 1997, pp. 131–142. 27 Mosterman, P. J. Implicit modeling and simulation of dis-

14 Edstrom, K. Switched bond graphs: simulation and continuities in physical system models. In Proceedings ofanalysis. PhD thesis, Linkoping University, Linkoping, the 4th International Conference on Automation of MixedSweden, 1999. Processes: Hybrid Dynamic Systems (Eds S. Engell,

15 Mosterman, P. J. State space projection onto linear DAE S. Kowalewski and J. Zaytoon), 2000, pp. 35–40.28 Bajzat, R. http.//gold.uni-miskolc.hu/˜ iitbajzi/bond/.manifolds using conservation principles. Technical Report

I08800 © IMechE 2002Proc Instn Mech Engrs Vol 216 Part I: J Systems and Control Engineering

Page 13: Hybrid Bond Graphs