Modelling Ball On Beam Control
Modelling Ball On Beam Control
Beam" System
In this document a mathematical model of the "ball-on-beam" system illustrated below is derived and expressed
in form of nonlinear state equations. To this end, Lagrange's approach for modelling mechanical systems is
applied. Later different methods to control this model to balance the ball on the beam is applied.
1
In particular, the figure introduces the fixed Cartesian reference frame and the beam-fixed coordinate
system which is rotated by the beam angle with respect to the reference frame. The beam
is pivot-mounted at the common origin of these coordinate systems such that it can freely rotate around the
z-axis. By means of an electric motor, which is of no further interest, the torque can be applied to the
beam, i.e. represents the control input . A force acting on the ball must be taken into account
as disturbance input . It is assumed that the ball rolls on the beam without slipping at all times. All other
friction forces and/or torques are neglected. The measured variables are the beam angle and the ball
position on the beam , which corresponds to the x-value of the ball's center of mass in beam-coordinates.
The meaning of some other parameters and quantities of interest is described by the comments in the following
variable declaration.
x_ball = q1
x_ball(t) =
beta_beam = q2
beta_beam(t) =
2
The overall motion of the ball is rather complex, since it simultaneously performs a rotational and a translational
movement. With respect to its center of mass, however, the kinetic energy of any rigid body can still be stated
as a simple sum of a purely translational and a purely rotational movement in relation to a fixed and non-moving
reference coordinate system. Thus, the total kinetic energy of the ball can be calculated as
with
: absolute value of angular ball speed around its center of mass with respect to fixed reference coordinate
system
: absolute value of translational speed at center of mass with respect to fixed reference coordinate system
Position of the ball's center of mass in the fixed Cartesian reference frame as a function of the generalized
coordinates:
xref_ball(t) =
yref_ball(t) =
Absolute value of translational ball speed as a function of and with respect to the fixed reference
coordinate system:
vref_ball(t) = simplify(sqrt(diff(xref_ball(t),t)^2+diff(yref_ball(t),t)^2))
vref_ball(t) =
Applying the summation rule for angular velocities (see e.g. [1]), the total angular speed of the ball can
be stated as the sum of the angular speed of the ball with respect to the beam and the angular speed of
the beam with respect to the fixed reference coordinate sytem , i.e. . Since in case
of the "ball-on-beam" system all angular speed vectors are parallel to the z-axis, this vector equation can be
simplified to the scalar relationship where
omegaref_beam(t) = diff(q2(t),t)
omegaref_beam(t) =
3
and follows from the ideal rolling conditions as
omegabeam_ball(t) = -diff(x_ball,t)/r_Ball
omegabeam_ball(t) =
Note that there is a negative sign in the later equation. It is caused by the fact that a negative rotation of the
ball against the "right-hand-rule" is needed to move the system into positive direction (see definition of
coordinate systems and counting direction in the figure above).
omegaref_ball(t) =
T_ball(t) = simplify(1/2*m_Ball*vref_ball(t)^2+1/2*J_Ball*omegaref_ball(t)^2)
T_ball(t) =
T_beam(t) = 1/2*J_Beam*omegaref_beam^2
T_beam(t) =
4
The total kinetic energy of the system results from the sum of the kinetic energy of the ball and of the beam as
T(t) =
V(t) = G*m_Ball*yref_ball(t)
V(t) =
Lagrangian
The Lagrangian
L(t) =
5
Non-conservative Generalized Forces
In general, the non-conservative generalized forces of a system with N degrees of freedom are given as [1]
and torque vectors acting on the system and , , as well as , , are the speed and
angular speed vectors of the corresponding contact points.
Applied to the "ball-and-beam" system, the number of degrees of freedom is and the external force
as well as the motor torque (see figure above) represent the only non-conservative quantities acting on the
mechanics. Thus, expressed in reference coordinates the formula above simplifies to the two non-conservative
generalized force terms
Force vector and corresponding speed vector of the contact point in reference coordinates
In beam coordinates the force acts in positive x-direction. Consequently, with respect to the fixed reference
coordinate system, the force vector can be expressed as
Fref_vec(t) = F(t)*[cos(q2);sin(q2);0]
Fref_vec(t) =
The position of the corresponding contact point C (see figure) of the force in beam coordinates is
xbeam_C(t) = x_ball(t)-r_Ball
xbeam_C(t) =
ybeam_C = r_Ball
ybeam_C =
Transformed into the fixed Cartesian reference frame, the contact point C is described by
xref_C(t) = xbeam_C(t)*cos(beta_beam(t))-r_Ball*sin(beta_beam(t))
6
xref_C(t) =
yref_C(t) = xbeam_C(t)*sin(beta_beam(t))+r_Ball*cos(beta_beam(t))
yref_C(t) =
Calculating the time derivative yields the speed vector of the contact point C in reference coordinates:
vref_Cvec(t)=[simplify(diff(xref_C(t),t));simplify(diff(yref_C(t),t));0]
vref_Cvec(t) =
The motor torque acts around the z-axis which represents the fixed axis of rotation for the beam. Thus, we
can state the associated torque vector according to
Mref_vec(t) = M(t)*[0;0;1]
Mref_vec(t) =
omegaref_beamvec(t) = omegaref_beam(t)*[0;0;1]
omegaref_beamvec(t) =
with respect to the Cartesian reference frame and considering the counting directions specified in the figure
above.
7
results in
Q1_nc(t) = simplify(transpose(Fref_vec(t))*(diff(vref_Cvec(t),diff(q1(t),t)))+transpose(Mref_ve
Q1_nc(t) =
results in
Q2_nc(t) = simplify(transpose(Fref_vec(t))*(diff(vref_Cvec(t),diff(q2(t),t)))+transpose(Mref_ve
Q2_nc(t) =
Applied to the "ball-on-beam" system with two degrees of freedom ( ), the evaluation of
deq1 =
deq2 =
8
Derive (Nonlinear) State Equations
Define state variables
In order to obtain a state space description of the "ball-on-beam" system from the equations of motion, the
generalized coordinates and their first-order time derivatives are introduced as state variables:
x1_def =
x2_def =
x3_def =
x4_def =
x1dot_def(t) =
x2dot_def =
9
x3dot_def = x4 == x3dot % x3_dot --> x4
x3dot_def(t) =
x4dot_def =
udef =
zdef =
10
deq1_in_xuz = subs(deq1_in_xuz,lhs(x4_def),rhs(x4_def));
deq2_in_xuz = subs(deq2_in_xuz,lhs(x4_def),rhs(x4_def));
% substitute q2 --> x3
deq1_in_xuz = subs(deq1_in_xuz,lhs(x3_def),rhs(x3_def));
deq2_in_xuz = subs(deq2_in_xuz,lhs(x3_def),rhs(x3_def));
% Substitute control input
deq1_in_xuz = subs(deq1_in_xuz,lhs(udef),rhs(udef));
deq2_in_xuz = subs(deq2_in_xuz,lhs(udef),rhs(udef));
% Substitute disturbance input
deq1_in_xuz = subs(deq1_in_xuz,lhs(zdef),rhs(zdef));
deq2_in_xuz = subs(deq2_in_xuz,lhs(zdef),rhs(zdef));
deq1_in_xuz
deq1_in_xuz =
deq2_in_xuz
deq2_in_xuz =
Solve for time derivatives of the states and determine state differential equation
These two resulting equations of motion and the two trivial state differential equations
together form a system of four equations. Solving this system of equations for the time derivatives
and results in the vector function which defines the right-hand side of the state differential equation
:
f =
11
Define measured signals as output variables
The ball position on the beam and the beam angle are measured such that these two signals are
specified as outputs and of the system. Since the states and are defined according to
h = [x1(t);x3(t)]
h =
12
displayFormula('y(t)==h')
f_wo_t =
h_wo_t = subs(h,[x1(t),x2(t),x3(t),x4(t),u(t),z(t)],[x1_,x2_,x3_,x4_,u_,z_])
h_wo_t =
13
% open_system('ball_on_beam_nonlinear_model_reference')
% matlabFunctionBlock('ball_on_beam_nonlinear_model_reference/actual_model_x_ball',f_wo_t,'vars
%
% matlabFunctionBlock('ball_on_beam_nonlinear_model_reference/actual_model_beta_beam',h_wo_t,..
% 'vars',{'x1_','x2_','x3_','x4_','u_','z_','r_ball','J_ball','m_ball','g',
r_ball = 0.0125
J_ball = 4*10^-6
J_ball = 4.0000e-06
m_ball = 0.064
m_ball = 0.0640
g = 9.81
g = 9.8100
J_beam = 2.9*10^-3
J_beam = 0.0029
(x = 0, u = 0, z = 0)
represents an equilibrium point of the system
% Define equilibrium point with time functions:
op = [x1; x2; x3; x4; u; z] == [0; 0; 0; 0; 0; 0];
f_op =
14
Linearize the system around the equilibrium point
A = simplify( subs( jacobian(f_wo_t,[x1_,x2_,x3_,x4_]), lhs(op_wo_t),rhs(op_wo_t) ) )
A =
b_u =
b_z =
C =
A_num = 4×4
0 1.0000 0 0
-2.7062 0 -7.0071 0
0 0 0 1.0000
-216.4966 0 0 0
15
b_u_num=double(subs(b_u,[r_Ball,J_Ball,m_Ball,G,J_Beam],...
[r_ball,J_ball,m_ball,g,J_beam]))
b_u_num = 4×1
0
4.3103
0
344.8276
b_z_num=double(subs(b_z,[r_Ball,J_Ball,m_Ball,G,J_Beam],...
[r_ball,J_ball,m_ball,g,J_beam]))
b_z_num = 4×1
0
11.1607
0
0
C_num=double(subs(C,[r_Ball,J_Ball,m_Ball,G,J_Beam],...
[r_ball,J_ball,m_ball,g,J_beam]))
C_num = 2×4
1 0 0 0
0 0 1 0
C_num_1 = C_num(1,:)
C_num_1 = 1×4
1 0 0 0
displayFormula('Delta*y(t)==C_num*Delta*x(t)')
16
-6.1335 + 0.0000i
-0.0000 + 6.3502i
-0.0000 - 6.3502i
6.1335 + 0.0000i
We can observe here that our system is not asmptotically stable, this is because the eigenvalues of
matrix A has a positive real part.
2. Controlability
Q_c = ctrb(A_num, b_u_num)
Q_c = 4×4
103 ×
0 0.0043 0 -2.4279
0.0043 0 -2.4279 0
0 0.3448 0 -0.9332
0.3448 0 -0.9332 0
d_Q_c = det(Q_c)
d_Q_c = 6.9421e+11
3. Observability
Q_o = obsv(A_num, C_num)
Q_o = 8×4
1.0000 0 0 0
0 0 1.0000 0
0 1.0000 0 0
0 0 0 1.0000
-2.7062 0 -7.0071 0
-216.4966 0 0 0
0 -2.7062 0 -7.0071
0 -216.4966 0 0
unob = length(A)-rank(Q_o)
unob = 0
The system does not have any unobservabilities. Hence, it is completely observable.
p = 1×4
-70.0000 -58.0000 -1.6000 -1.4000
k_fb = 1×4
-4.3917 -5.1595 12.9411 0.4444
17
Luenberger Observer Design
p_lo = [-60,-50,-1.75,-1.45]
p_lo = 1×4
-60.0000 -50.0000 -1.7500 -1.4500
k_lo = 1×4
103 ×
0.1132 3.3518 -1.4099 -1.3029
l_T = transpose(k_lo)
l_T = 4×1
103 ×
0.1132
3.3518
-1.4099
-1.3029
z1 = -9.0000 + 12.0000i
z2 = -9-12j
z2 = -9.0000 - 12.0000i
z3 = -12+6j
z3 = -12.0000 + 6.0000i
z4 = -12-6j
z4 = -12.0000 - 6.0000i
A_e = zeros(5,5)
A_e = 5×5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
A_e = 5×5
18
0 1.0000 0 0 0
-2.7062 0 -7.0071 0 0
0 0 0 1.0000 0
-216.4966 0 0 0 0
0 0 0 0 0
A_e(1:4, 5) = b_u_num
A_e = 5×5
0 1.0000 0 0 0
-2.7062 0 -7.0071 0 4.3103
0 0 0 1.0000 0
-216.4966 0 0 0 344.8276
0 0 0 0 0
B_e = zeros(5,1)
B_e = 5×1
0
0
0
0
0
B_e(1:4,1) = b_u_num
B_e = 5×1
0
4.3103
0
344.8276
0
C_e=zeros(1,5)
C_e = 1×5
0 0 0 0 0
C_e(1,1:4)=C_num_1
C_e = 1×5
1 0 0 0 0
l_e = 1×5
105 ×
0.0014 0.0503 -0.1421 -1.2930 -0.0168
Conclusion:
• Successful control of the model was achieved.
• Luenberger Observer has been used to estimate the states and implement a state-feedback
Controller.
• Later on the Observer was extended to observe the continuous disturbance on the input and
reduced the estimation errors.
19
• Saturation Block was used as an anti-windup measure in order to avoid negative impacts when
the requested control signal exceeds its feasible range resulting from the restricted motor power
of the laboratory system.
References
1. Kamman, James, "An Introduction to Three-Dimensional Rigid Body Dynamics", ebook, https://kamman-
dynamics-control.org/3d-dynamics-ebook/ (accessed November 6, 2023)
20