segway - inverse pendulum and what math tools you need to ... · motivation goals i we want to...
TRANSCRIPT
Segway - inverse pendulum
and what math tools you need to simulate it
January 9, 2019
Motivation
Segway
I A Segway PT - short for Segway Personal Transporter - is a two-wheeled,self-balancing personal transporter.
Source: http://de-de.segway.com/
I How does it balance itself?
Motivation
Goals
I We want to understand the function of the Segway by simulating the simplifiedmodel of an inverse pendulum on a moving platform:
I Throughout the presentation we will pay particular attention to the math toolsneeded for the derivation and simulation of the model.
Model
I The model, as depicted in Das Mathe-Praxis-Buch, J. Harterich, A. Rooch, 2014,Springer Verlag:
Source: Das Mathe-Praxis-Buch, p. 4, Abb. 1.1
I With M mass of the cart, m mass of the pendulum, l length of the pendulum, αangular displacement of the pendulum, g gravitional force, F force applied on thecart, x position of the cart, T disturbance (e.g. wind, pushing), Θ moment ofinertia.
Equations of motion
Derivation
I To obtain equations of motion for such a system we use Lagrangian mechanics.
I For our inverse pendulum we obtain:
x = −ml
M +mα2 sin(α) +
ml
M +mα cos(α) +
1
M +mF
α =3
4lx cos(α) +
3g
4lsin(α) +
3
4ml2T
I To reduce writing overhead we simplify:
x = c0α2 sin(α) + c1α cos(α) + c2F
α = c3x cos(α) + c4 sin(α) + c5T
I We obtain a system of coupled nonlinear ordinary differential equations ofsecond order.I ordinary differential equation - equation contains an entity u and its ordinary
derivatives e.g. u, ∂u∂x
I nonlinear - equation contains nonlinear expressions e.g. u2, sin(u)I second order - highest occuring derivativeI system - more than one equationI coupled - equation regarding u contains entities, that are not u or one of its derivatives
I Such an equation is in general not solveable by analytical means only.
Equations of motion
Partly decoupling
I By inserting equation 1 in equation 2 and vice versa we obain ”less” coupledequations:
x =(c0α
2 sin(α) + c1c4 sin(α) cos(α) + c2F + c1c5T)/(
1− c1c3 cos2(α))
α =(c0c3α
2 sin(α) cos(α) + c4 sin(α) + c2c3 cos(α)F + c5T)/(
1− c1c3 cos2(α))
I Now our system is more convenient but still highly nonlinear.
Linearization
I To simplify our model, we want to remove any nonlinear term. This procedure iscalled linearization.
I It relies heavily on approximation and therefor resulting systems only have alimited validity.
I We use Taylor’s theorem, more correct Taylor polynomials of first order, toapproximate the terms:
α2 ≈ 0
sin(α) ≈ αcos(α) ≈ 1
Equations of motion
Linearized
I After replacing nonlinear parts with linear approximations we obtain:
x =(c1c4α+ c2F + c1c5T
)/(1− c1c3
)α =
(c4α+ c2c3F + c5T
)/(1− c1c3
)I It is necessary to realize how small the margin is in which the approximation - and
therefor the linear model - holds.
I Now our system is linear but still of second order.I There are at least two reasons to reduce the order of the system of differential
equations:I We are interested in the position x of the cart as well as the angular displacement of
the pendulum α on it. So far the equations describe only the change of the velocity xof the cart and the change of the angular velocity α of the pendulum.
I We will later be able to apply iterative methods to solve the system numerically e.g. theclassical Runge-Kutta method.
System of differential equations
Reducing order
I The entities we want to observe are ~x =(x, x, α, α
)T. The time derivative is
~x =(x, x, α, α
)T.
I By appending the system with the equations
x = x, and α = α
we obtainxxαα
=
0 1 0 00 0 c1c4
1−c1c30
0 0 0 10 0 c4
1−c1c30
xxαα
+
0c2
1−c1c30
c2c31−c1c3
F +
0
c1c51−c1c3
0c5
1−c1c3
T
Keep in mind that F and T are scalars in this one-dimensional model problem.
I In matrix notation
~x = A~x+~b1F +~b2T
it is more visible that we now have a system of linear differential equations offirst order.
System of differential equations
Analytical solution
I When omitting F and T we restrict external influence T or a force F upon thecart. We then have the opportunity to solve the system
~x = A~x
by means of analytical methods.
I The solutions to the system will be a linear combination of
~xi(t) = eλit~vi,
where λi are the eigenvalues and ~vi are the eigenvectors of the systems matrixA.
I When A is diagonalizable, creating the solutions via linear combination is trivial.Unfortunately our A is not diagonalizable:I When the eigenvalues of A are complex we get real solutions via the real and the
imaginary part of the complex solutions.I When the eigenvalues of A are real, but their algebraic multiplicity differs from their
geometric multiplicity we have to find generalized eigenvectors to append oursolutions with.
Eigenvalues and Eigenvectors
Eigenvalues
I Eigenvalues are the roots of the characteristic polynomial of A, which iscomputed by the determinant:
det(A− λI) = P(λ).
I While the determinant of matrices up to the size 3× 3 can easily be obtained viathe rule of Sarrus, for higher-dimensional matrices we use Laplace’s formula.
I For (artificial) concrete values M = 0.5kg, m = 1.75kg, l = 0.5m andg = 10m/s2 we get λ1 = 0, λ2 = 0, λ3 = −6, λ4 = 6.
Eigenvectors
I Eigenvectors are the solutions to the homogeneous system of linear equations
(A− λiI)~vi = 0
I For λ3 and λ4 we find the related ~vi. For λ1,2 we additionally have to find ageneralized eigenvector ~w.
System of differential equations
Analytical solution
I The solution has the form:
~x(t) = d1~v1eλ1,2t + d2(t~v1 + ~w)eλ1,2t + d3~v3e
λ3t + d4~v4eλ4t
=
d1 − 7c4e−6t + 7d3e6t + d2(1 + t)
d2 + 42c4e−6t + 42d3e6t
−18d4e−6t + 18d3e6t
108d4e−6t + 108d3e6t
.
I Due to the natur of the e-function it is obvious that eλt will be unconstrained aslong as λ > 0 and tend to +∞, for growing t.
I It is necessary to find a way to control the eigenvalues of A.
Control
Control matrix
I We use a linear control approach F = −K~x with a matrix K, that is effectivelya vector - in our one-dimensional case - and get
~x = A~x+~b1F = A~x−~b1K~x
= (A−~b1K)~x = A′~x.
I By correct choice of K we can control the eigenvalues of A′. This procedure iscalled pole placement. In Matlab this method is provided in a function calledplace().
I If you are interested in how this method works have a look at Robust PoleAssignment in Linear State Feedback, J. Kautsky, N.K. Nichols, and P. VanDooren, International Journal of Control, 41 (1985), pp. 1129-1155.
Simulation
Iterative method
I There are many explicit and implicit iterative methods to solve systems of linearordinary differential equations of first order - and therefor single linear differentialequations of first order as well. The simplest is the Euler method.
I We use the classical Runge-Kutta method, due to its good properties in stabilityand stiffness:
~k1 = ~f(tn, ~yn),
~k2 = ~f(tn +1
2h, ~yn +
1
2h~k1),
~k3 = ~f(tn +1
2h, ~yn +
1
2h~k2),
~k4 = ~f(tn + h, ~yn + h~k3),
~yn+1 = ~yn +1
6h(~k1 + 2~k2 + 2~k3 + ~k4).
I Figuratively speaking, we obtain the new descent direction as a weighted averageof four different descent directions.
I The properties of such a method need to be proven mathematically.
Solution
Compare linear and nonlinear case
I We compare the numerical solutions of the linear (red) and the nonlinear (blue)case without control:
-0.02
0
0.02
0.04
x
Vergleich beider Modelle ohne Regulierung
0
50
100
150
200
-1
0
1
F
0.8 0.9 1 1.1 1.2 1.3 1.4
t
0
0.5
1
T
I We observe two characteristics:I Up until a value for α, there is barely a difference between the linear and nonlinear
cases - as we expected when we linearized the system.I The solution for the linear case tends to infinity - as we expected due to the positive
eigenvalue of A.
Solution
Compare linear and nonlinear case
I We compare the numerical solutions of the linear (red) and the nonlinear (blue)case with control:
-2
-1
0
x
Vergleich beider Modelle mit Regulierung
-20
0
20
-20
-10
0
10
F
0 1 2 3 4 5 6 7 8 9 10
t
0
0.5
1
T
I We observe only slight differences between the two cases that minimize over time,due to the control we applied.
Solution
Nonlinear case
I We review the numerical solution of the nonlinear (blue) case without control:
-0.05
0
0.05
0.1
x
Loesung mit nicht-linearem Modell ohne Regulierung
0
2000
4000
-1
0
1
F
0 1 2 3 4 5 6 7 8 9 10
t
0
0.5
1
T
I We observe that the momentum T we applied to the system reflects in the overallmovement of the cart over time.
Sources
I Das Mathe-Praxis-Buch, J. Harterich, A. Rooch, 2014, Springer Verlag
I http://de-de.segway.com/SegwayPortal/media/Segway/Productimages/i2-SE/360/i2 SE 03.png, 2019
I http://de-de.segway.com/SegwayPortal/media/Segway/Productimages/i2-SE/360/i2 SE 05.png, 2019
I Numerik gewohnlicher Differentialgleichungen, M. Eiermann, 2011, TUBAF
I The dynamics of a Mobile Inverted Pendulum (MIP), S. Ostovari, N. Morozovsky,T. Bewley, 2012, UCSD