Simulation of Newton's pendulum using switched bond graphs
Krister Edstrom
Department of Electrical Engineering Linkoping University, S-581 83 Linkoping, Sweden
WWW: http://www.control.isy.liu.se
Email: edstrom@isy.liu.se
August 25, 1998
REGLERTEKNIK
AUTOMATIC CONTROL LINKÖPING
Report no.: LiTH-ISY-R-2048 Submitted to ICBGM'98
Technical reports from the Automatic Control group in Linkoping are available by anonymous ftp at the
address
ftp.control.isy.liu.se. This report is contained in the compressed postscript le
2048.ps.Z.
Simulation of Newton's pendulum using switched bond graphs
Krister Edstrom
(edstrom@isy.liu.se) Dept. of Electrical Engineering
Linkopings Universitet SE-581 83 Linkoping, Sweden
1 Introduction
The well know Newton's pendulum, shown in Figure 1, is in this paper modeled and simulated using switched bond graphs 5]. The pendulum is very dicult to model with classical bond graphs since the connection and disconnection of masses will cause causal changes in the model.
Figure 1: Newton's pendulum
When making a switched bond graph model, the level of details in the model can di er. The contact between the masses could be modeled with a spring and a damper to describe the elasticity and the dissipation respectively. In most mechanical literature, impacts between bodies are not modeled at such a detailed level
3]. The e ects of elasticity and dissipation are modeled as instantaneous, using the principle of momentum conservation and another relation describing the capacity of the bodies to recover from impact. Since the switch describes innitely fast changes in the system, this paper describes a model where the elasticity and momentum conservation are modeled within the switch.
Simulation of switched bond graphs has been discussed earlier in, e.g., 1, 4, 2]. In 1] it is shown how a switched bond graph can be simulated when the initializations are assumed to be trivial. In 4, 2] initialization using a generalization of momentum conservation is discussed. Problems where the switch models very fast are then dealt with. In this paper we discuss an approach for modeling very fast energy storage within the switch.
2 A switched bond graph model of the pendulum
To simplify the bond graph, we will assume that the ideal physical model (IPM) of Newton's pendulum is
the one shown in Figure 2.
Figure 2: An IPM of Newton's pendulum.
The switched bond graph model of the IPM in Figure 2 is depicted in Figure 3. In the bond graph the
ow variables are velocities and the e ort variables are forces. The extra 1 -junction is introduced to get an intuitive mathematical description. Together with the choices of positive energy ow directions, all velocities will be positive to the right.
0 1 0 1 0 1 0 1 0 1
C1 C2
I1 I2 I3 I4
Sw1 Sw2 Sw3 Sw4 Sw5
Figure 3: The switch bond graph model of Newton's pendulum.
With the assumption that all I -elements and all C -elements are linear, the bond graph model is complete except for the description of the switches. A switch will include conditions for changing states and, if necessary, an initialization rule consisting of an elasticity coecient .
2.1 The storage elements
The storage elements model the masses and the springs. We will assume that the masses weigh 100 g each and that the sti ness of each spring is k = 10 N=m . The assumption that the I - and C -elements are linear gives the following constitutive relations for the I -elements:
x _ = e (1)
f = x I = x
m = 10 x (2)
and for the C -elements:
x _ = f (3)
e = x
C = k x = 10 x (4)
2.2 The Sw-elements
The switches model two di erent phenomena the contact between a spring and a mass ( Sw
1and Sw
5),
and the contact between two masses ( Sw
2, Sw
3, and Sw
4). In the
Estate, where a switch acts as a zero e ort source, the e ort (force) between the elements is zero and there will be no contact. In the other state,
F
, where a switch acts as a zero ow source, the velocity di erence is zero, and hence the elements are connected.
Contact between a spring and a mass
In the rst case, when a switch models the contact between a mass and a spring, the modeling procedure
is straightforward. In the
F-mode, where the mass and the spring are connected, the e ort variable at the
bond next to the switch describes the force from the spring acting on the mass. The condition for loosing
contact is that this force becomes less than zero.
When the elements have no contact, i.e., when the switch is in the
E-mode, the change of modes appears when the mass reaches the spring.
The two transition conditions for switches Sw
1and Sw
5is hence:
g
FE= ( e < 0) (5)
g
EF= (
Z
fdt
C ) (6)
The integral
Rfdt describes the position of the mass relative to the position of the spring, and C is a constant, di erent for each switch, depending on the position where the mass reaches a spring.
The initialization of the new mode when one of the two switches Sw
1or Sw
5changes states will be trivial since the state variables are continuous is both switching directions. The new values of all states x = ( x
1::: x
6)
Tequal the old values x
0.
x = x
0(7)
Contact between two masses
When a switch models the contact between two masses, elasticity and damping have to be included in the switch model. This is done by introducing the elasticity coecient in an initialization rule belonging to the switch.
The condition for changing from
E-mode to
F-mode, i.e., detecting the collision, is the same as above:
(
Rfdt
C ). We will also include the condition ( f < 0) because energy is transferred between the masses only when the distance between them is zero, and they are moving towards each other. This gives the transition condition g
EF=(
Rfdt
C )
^( f < 0). To detect when the masses loose contact is trickier. The procedure for detection is the following:
When detecting a collision, the switch changes position from
Eto
F. The new mode will be initialized using one equation describing momentum conservation, and another equation describing the elasticity. The generation of the equation describing the momentum conservation is algorithmically found from the switched bond graph 2]. The ow variable f at the switch is the di erence in velocity between the two masses. Hence, the initialization equation describing elasticity is f =
;f
03], where f
0is the value of the ow before the collision.
This initialization procedure will give a value of f that is non-zero, assuming that
6= 0. This contradicts the constitutive relation for the switch, f
0. Therefore the mode is left immediately when entered. The system then returns to its previous mode with new values of the velocities of the masses.
The complete description of switches Sw
2, Sw
3, and Sw
4is:
g
FE= | (8)
g
EF= (
Z
fdt
C )
^( f < 0) (9)
= 1 (10)
There are two initialization rules that will be generated when one of the switches Sw
2to Sw
4changes state, depending on whether transition condition g
FEor g
EFis fullled. When the switch changes state from
Fto
E
, the state variables x are continuous:
x = x
0(11)
When switching in the other direction,
Eto
F, the initialization is more dicult. With the indeces a and b
for the two masses next to the switch changing states, the following initialization rule, describing momentum
conservation, will be generated when changing modes 2]:
x
a+ x
b= x
0a+ x
0b(12)
The initialization rule describing elasticity is:
f =
;f
0 )f
b;f
a=
;( f
b0;f
a0)
)1
I
bx
b;I 1
ax
a=
;( 1 I
bx
0b;I 1
ax
0a)
))
10 x
b;10 x
a=
;10 x
0b+ 10 x
0a )x
b;x
a= x
0a;x
0b(13) All other states, belonging to the masses not colliding, and to the springs, will be continuous:
x
r= x
0r(14)
When solving Equations (12) and (13) the following values of the initial states are found:
x
a= x
0b(15)
x
b= x
0a(16)
x
r= x
0r(17)
To conclude the complete model of the switch has to include a condition for detecting contact between the masses. The condition for leaving the mode is not necessary, since the mode is left due to a contradiction between the constitutive relation of the switch and the initial values of the new mode. Furthermore, the condition for leaving the mode cannot be described in terms of the force di erence between the masses, since the masses are rigidly connected.
The model of the switch also has to include an initialization rule. When describing a collision between two masses, the initialization rule is given by a parameter describing the elasticity. An initialization equation containing this parameter can then be derived from the bond graph.
3 Simulation
3.1 The simulation algorithm
The simulation algorithm consists of the following steps:
1. Start the simulation in the initial mode and continue until a transition condition is fullled or the stop time is reached. The continuous equations are found by rst replacing the switches with zero e ort or zero ow sources, depending on what states the switches are in, and then using a standard bond graph equation generation algorithm.
2. Generate the initial rules for the new mode as described in Section 2.2. If the initial values contradict the constitutive relation for the switch, go back to the previous mode with the new values of the states.
3. Check if any transition condition is fullled by the initial values. If so, go to step 2.
4. Simulate the new mode until a transition condition is fullled or the stop time is reached. If a transition condition is fullled go to step 2.
3.2 Modes visited during simulation
If we are starting in mode
EEEEE(all ve switches in
Eposition) with the leftmost mass moving to the left
with 1 m=s the mass will soon reach the spring. There will be contact between the mass and the spring,
mode
FEEEE, until the velocity is reversed and the force between them goes to zero, mode
EEEEE. We are then back in the starting mode with the same magnitude of velocity but with a di erent direction.
The next mode change occurs when the mass I
1will hit mass I
2, and the simulation will continue in mode
EFEEE
. The initialization rule for this mode will give a value of the relative velocity of the masses that contradicts the constitutive relation of the switch. Hence the mode is left before simulated and we are back in mode
EEEEE. The velocity of mass I
1is transfered to mass I
2. Immediately the transition condition for entering mode
EEFEEis fullled. When initializing this mode we will immediately end up un mode
EEEEE
etc.
The discrete state trajectory will be repetitive, and the modes visited in each repetition are shown in Table 1.
The mode number in the table are the switch states interpreted as binary numbers,
EFEEE)10111
)23.
Add 1 to get mode number 1 for the combination
FFFFF. Hence mode
EFEEEhas mode number 24.
step mode mode no step mode mode no
1
EEEEE32 simulated 11
EEEEE32 simulated
2
FEEEE16 simulated 12
EEEFE30 not simulated
3
EEEEE32 simulated 13
EEEEE32 not simulated
4
EFEEE24 not simulated 14
EEFEE28 not simulated
5
EEEEE32 not simulated 15
EEEEE32 not simulated
6
EEFEE28 not simulated 16
EFEEE24 not simulated
7
EEEEE32 not simulated 1
EEEEE32 simulated
8
EEEFE30 not simulated 2
FEEEE16 simulated
9
EEEEE32 simulated 3 ::: ::: :::
10
EEEEF31 simulated 4 ::: ::: :::
Table 1: Modes that are iterated when simulating the pendulum.
3.3 Generating a mathematical description
Since only three modes are simulated, only three mode equations have to be generated, and they are the equations for modes number 32, 31, and 16.
mode no 32 mode no 31 mode no 16
x _
1= 0 x _
1= 0 x _
1=
;x
5=C
5x _
2= 0 x _
2= 0 x _
2= 0
x _
3= 0 x _
3= 0 x _
3= 0
x _
4= 0 x _
4=
;x
6=C
6x _
4= 0
x
5= 0 x
5= 0 x _
5= x
1=I
1x
6= 0 x _
6= x
4=I
4x
6= 0
To exemplify how the initialization procedure works we will take a look at steps 3-6 in Table 1.
In step 3 the continuous equations are solved numerically. The solver also handles the transition conditions for changing modes. When detecting that transition g
EFfor switch Sw
2is fullled, the solver returns the current values of the continuous states and information about which switch the condition belongs to. This information will lead us to the new mode, which is initialized according to Equations (15), (16), and (17).
This is step 4 in the table.
The values of the continuous states when the condition is fullled are such that the ow at the switch, f
Sw0 2,
is non-zero. Since the ow after initialization is f
Sw2=
;f
Sw0 2, where = 1, we get f
Sw2 6= 0. Hence the
constitutive relation for the switch, f
Sw2= 0, is violated. The simulation therefore continues in the previous
mode, mode number 32, with the new values of the states.
The only di erences between step 5 and step 3 are that the second mass has velocity 1 m=s and the rst mass is in rest in step 5. Mode number 28 will therefore be initialized in exactly the same way as mode number 24.
3.4 A simulation run
If assuming that the radius of a mass is 0 : 01 m , that it is 0 : 03 m from the left spring to the center of the leftmost mass when all four masses have contact, and that it is 0 : 03 m from the right spring to the center of the rightmost mass when all four masses have contact, the result from a simulation run is shown in Figure 4.
The gure shows one iteration of steps 1 to 16 in Table 1.
0 0.5 1 1.5
−0.1
−0.08
−0.06
−0.04
−0.02 0 0.02 0.04 0.06 0.08 0.1
Time, s
State variable values, m/10 or kgm/s
x
I1
x
I
4
xC
1
xC
2
Position, m/10
0 0.5 1 1.5
−0.2 0 0.2 0.4 0.6 0.8 1 1.2 1.4
Time, s
p
I1
pI
4
p
C1
pC
2