17 Ball Balancing Integral Control with Kalman Observer
Ball Balancing Project Background

Ball Balancing Project Control Theory
Luenberger Observer (Observer Taught In Class for Two Weeks and Lab 4)







The question is why we need to use observer state rather than just simply using
as the feedback as shown in the full state feedback control process. Note that
is the physical variables measured through the process such as position, velocity, and acceleration for a mechanical system. The reason that we use
rather than
is because we do not suffer the problems associated with
, for example the noise issue related to the
. It also becomes feasible to save the number of sensors needed for the full state feedback process. Without the use of the observer in the control process, for the full state feedback controller to work, we will need to measure every single state to ensure the controller able to work. Now, with the use of observer, we can just use observer to estimate the state such as position, velocity, and acceleration. The benefit is that it will save the number of sensors needed to complete the wonderful control project.
The key equations associated with observer are
This equation is to design observer gain L.
This equation is to show the estimated state .
Full State Feedback Integral Control (Seen Lecture Notes, Last Group Quiz)
Very nice! It looks like that you have understood the observer better now. Now, its time to diver deeper. As we have hinted in the ball balancing project background section that we do need to use the integral control to remove the steady state error. It means that we want the ball stays at the center of the resistive touch screen. For this purpose, with the use of only full state feedback is insufficient. Full state feedback control is not able to ensure zero steady state error. In order to do this, we need use integral control. In order to use integral control, lets review integral control. Note that the integral control is similar to the integral control in the PID controller, but we wrap around of this concept in state space based full state feedback control.
The integral control is very similar to the full state feedback control. However, it includes another outer loop feedback to feedback the Y to the reference. Note that the integral gain Ke is also involved here. With the integral gain, it becomes feasible to reduce the steady state error.
While integral control looks promising, however, it does not have an observer. It means that it still uses the raw states as the feedback. It therefore can not remove the noises of the states. To improve this situation, we need to use Kalman observer. The reason that we use Kalman observer is because we need to remove the noises from the states. Luenberger Observer is not able to achieve this goal. Instead, we need to use Kalman observer to achieve this goal.
Figure 3: The summary of the full state feedback integral control (K). It includes the feedback control gain K and Ke.
Kalman Observer Based Full State Integral Control
Kalman observer is very similar to Luenberger Observer in principle. But it has the capability to remove noises from states. So often, we call it Kalman filter instead of calling it Kalman observer. Details of the mathematics of the Kalman observer can be refereed to the model predicative controller (MPC) chapter. In this case study, we will not focus on explaining the mathematics of Lalman observer. Rather, we will focus on how to implement it with python
Figure 4: The summary of the Kalman observer based full state feedback integral control (K). It includes the Kalman observer gain (L) and feedback control gain K and Ke.
Ball Balancing Project Modeling and Implementation
For this system, it can be described as the following state space.
(1)
Where
With the state space, in python, it can be represented as below.
Figure 5: The state space representation matrix A,B,and C in Python for both initial full state feedback control and integral control.
Specifically, we also explained the correspondence of the python code, the control theory, and the control diagram. It includes the integral state (), control input (u), state space, and Kalman observer.
The ball balancing integral control diagram is shown in the following. Now the question is how to use python to implement the control theory. I have shown the process step by step:
Figure 6: The integral state using python and the related diagram.
Figure 7: The control input u using python and the related diagram.
Figure 8: The state space representation using python and the related diagram.
Figure 9: The Kalaman Observer gain L using python and the related diagram.
Figure 9: The Kalaman Observer design using python and the related diagram.
Kalman Observer Based Full State Integral Control Results With Python and Arduino
With the above control theory and python knowledge, it becomes possible that we can simulate the ball balancing system. In this simulation, we assume there is simulation and also assume there is noise condition, where noise can be equal to 0 and 10.
measuredX = x[0,0] + np.random.randn() * noise
After running the simulation, the output is shown in below. It is obvious that the use of Kalman observer is able to reduce the noises from the system.
Figure 11: The simulation of Kalman Observer Based Full State Integral Control without noises
Figure 12: The simulation of Kalman Observer Based Full State Integral Control with noises
Figure 13: The simulation of Kalman Observer Based Full State Integral Control using Arduino for Ball Balancing. It is very fun and informative, please read the Arduino code carefully for how it is able to use the Kalman Gain (L) and Integral gain (K) to implement real-time Arduino based ball balancing control precisely using Kalman Observer Based Full State Integral Control technique.