{"id":145,"date":"2025-04-17T12:27:55","date_gmt":"2025-04-17T12:27:55","guid":{"rendered":"https:\/\/libraryresources.nse.org.ng\/robotics\/chapter\/ball-balancing-integral-control\/"},"modified":"2026-03-16T14:24:27","modified_gmt":"2026-03-16T14:24:27","slug":"ball-balancing-integral-control","status":"publish","type":"chapter","link":"https:\/\/libraryresources.nse.org.ng\/robotics\/chapter\/ball-balancing-integral-control\/","title":{"raw":"Ball Balancing Integral Control with Kalman Observer","rendered":"Ball Balancing Integral Control with Kalman Observer"},"content":{"raw":"[latexpage]\n<h1>Ball Balancing Project Background<\/h1>\nIn this chapter, we will discuss an open source project available on Hackaday. The project is about controlling a ball balancing on a resistive touchscreen surface. The project link is listed below.\n\n<img class=\"size-medium wp-image-132 aligncenter\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-300x221.png\" alt=\"\" width=\"300\" height=\"221\">\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/hackaday.io\/project\/175294-adventures-in-state-space-control-arduino-edition\" rel=\"noopener\">Ball Balancing Project Hackaday Link<\/a><\/strong><\/p>\nThe project is well done in a few aspects. First, the project is closely related to the state space applications in practical engineering control. Second, the author has released all the important project files to the control engineering community, which is very useful and beneficial to control engineering applications.\n\nThe project overall goal is to achieve the control of ball balancing on the resistive touch screen. The author has put a YouTube video link below to explain the project in detail.\n<ul>\n \t<li><a href=\"https:\/\/www.youtube.com\/watch?v=IjByGk3S7Fg&amp;t=38s\" rel=\"noopener\"><strong>Ball Balancing Project Hackaday YouTube Link<\/strong><\/a><\/li>\n \t<li><strong><a href=\"https:\/\/youtu.be\/zj92io9M25Q\" rel=\"noopener\">Explanation of code<\/a><\/strong><\/li>\n<\/ul>\n<span style=\"font-size: 1em;\">Overall, we want to achieve the control of the system using the integral control technique. In contrast to the full state feedback controller, which suffers from the steady state error problem, integral control is able to reduce the steady state error of the system. As such, it becomes an effective approach for controlling the balance of the ball to enable it to stay at the center of the resistive touch screen.<\/span>\n<h1>Ball Balancing Project Control Theory<\/h1>\n<h2>Luenberger Observer (Observer Taught in Class for Two Weeks and Lab 4)<\/h2>\n<div>\n\nThe system involves the use of a Kalman observer to estimate the states and then remove the noise from the system. A Kalman observer is similar to a Luenberger observer.\u00a0 We learned about the Luenberger observer in the previous chapter of our class. Hopefully you understood it, but we will review the Luenberger observer again just in case.\n\nIt should be noted that in class, we did not call it a \"Luenberger observer\" much. Instead, we just called it an \"observer\" for convenience. Hopefully this new terminology has not confused you.\u00a0 A Luenberger observer is the default observer introduced in many textbooks. As such, people just tend to call it simply \"observer\" for convenience. The Luenberger is one of the simplest observers available to teach in control class.\n\nA full state feedback control diagram is shown below.\n\n[caption id=\"attachment_135\" align=\"aligncenter\" width=\"533\"]<img class=\"wp-image-133\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-300x116.png\" alt=\"The full state feedback control diagram. The state space representation matrix includes A, B, and C. It also includes the gain of K.\" width=\"533\" height=\"206\"> Figure 1: The full state feedback control diagram. The state space representation matrix includes A, B, and C. It also includes the gain of K.[\/caption]\n\nA Luenberger observer is shown below in the control diagram.\n\n[caption id=\"attachment_135\" align=\"aligncenter\" width=\"516\"]<img class=\"wp-image-134\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-300x140.png\" alt=\"The summary of observer (L) and observer-based controller (L).\" width=\"516\" height=\"241\"> Figure 2: The summary of observer (L) and observer-based controller (L).[\/caption]\n\n<span style=\"text-align: initial; font-size: 1em;\">Figure 2 shows that we use full state feedback with an observer to implement the control using an observer. Note that there is an obvious benefit to use an observer on $\\hat{x}$ rather than the original state<\/span><em style=\"text-align: initial; font-size: 1em;\"> X<\/em><span style=\"text-align: initial; font-size: 1em;\"> to achieve the control. First, we can save some sensors to not measure every single state. Instead, we just use the observer to <\/span><em style=\"text-align: initial; font-size: 1em;\">estimate<\/em><span style=\"text-align: initial; font-size: 1em;\"> these states. Second, we can remove noise from the measured states.<\/span>\n\nThe overall purpose of the Luenberger observer is to estimate the state so that we do not have to use many sensors to measure the states. The Luenberger observer shows that it is feasible to estimate the state of the plant through the use of the observer gain L matrix shown in Figure 2 above.\u00a0 With the observer gain L matrix, it becomes feasible to estimate $ \\hat{x} $.\n\nThrough the feedback process, with the feedback gain $K$, we do not use the original state $x$ anymore. Instead, we will use $ \\hat{x} $ as the feedback.\n\nThe question is, why do we need to use the observer state $ \\hat{x}$ rather than just simply using $x$ for the feedback as shown in the full state feedback control process? Note that $x$ contains the physical variables measured through the process, such as position, velocity, and acceleration for a mechanical system. The reason that we use $ \\hat{x}$ rather than $ x $ is because this way we do not suffer the problems associated with $x$; for example, the noise issue related to the $x$. It also becomes feasible to reduce 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 would need to measure every single state to ensure the controller is able to work. Now, with the use of the observer, we can just use the observer to <em>estimate<\/em> the states, such as position, velocity, and acceleration. The benefit is that it will reduce the number of sensors needed to complete this wonderful control project.\n\nThe key equations associated with observer are:\n\nThe equation used to design observer gain L:\n\\[\n\\dot{e} = (A - LC)e\n\\]\n\nThe equation to show the estimated state $\\hat{x}$:\n\\[\n\\hat{x} = A\\hat{x} + Bu + L(y - \\hat{y})\n\\]\n<h2>Full State Feedback Integral Control (Seen Lecture Notes, Last Group Quiz)<\/h2>\nVery nice! It looks like you understand the observer better now. Now, it is time to diver deeper. As we hinted in the ball balancing project background section, we need to use integral control to remove the steady state error. We want the ball to stay at the center of the resistive touch screen. For this purpose, 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 to use integral control. In order to use integral control, let us first review it. Note that the integral control here is similar to the integral control in the PID controller, but we return to this concept in state space based full state feedback control.\n\nIntegral control is very similar to the full state feedback control. However, it includes another outer feedback loop to feed back the output <em>Y<\/em> to the reference <em>r<\/em>. Note that the integral gain <em>Ke<\/em> is also involved here. With the integral gain, it becomes feasible to reduce the steady state error.\n\nWhile integral control looks promising, it does not have an observer. This means that it still uses the raw states as the feedback. It therefore can not remove the noise of the states. To improve this situation, we need to use a Kalman observer to remove the noise. A Luenberger observer is not able to achieve this goal, so instead, we need to use a Kalman observer.\n\n[caption id=\"attachment_135\" align=\"aligncenter\" width=\"475\"]<img class=\"wp-image-135\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-300x137.png\" alt=\"The summary of the full state feedback integral control (K). It includes the feedback control gain K and Ke.\" width=\"475\" height=\"217\"> Figure 3: The summary of the full state feedback integral control (K). It includes the feedback control gain K and Ke.[\/caption]\n\n&nbsp;\n\n<\/div>\n<h2>Kalman Observer Based Full State Integral Control<\/h2>\n<div>\n\nA Kalman observer is very similar to a Luenberger observer in principle, but it has the capability to remove noises from states. So often, we call it a Kalman filter instead of calling it a Kalman observer. Details of the mathematics of the Kalman observer can be referred to in the <a href=\"https:\/\/libraryresources.nse.org.ng\/robotics\/chapter\/model-predictive-control\/\">model predicative controller (MPC) chapter<\/a>. In this case study, we will not focus on explaining the mathematics of the Kalman observer; rather, we will focus on how to implement it with python.\n\n[caption id=\"attachment_136\" align=\"aligncenter\" width=\"670\"]<img class=\"wp-image-136\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-300x128.png\" alt=\"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.\" width=\"670\" height=\"286\"> 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 gains K and Ke.[\/caption]\n\n<\/div>\n<h1>Ball Balancing Project Modeling and Implementation<\/h1>\n<div>\n\nThis system can be described by the following state space:\n\n\\begin{equation}\n\\dot{x} = A x + b\n\\end{equation}\n\nWhere\n\n\\[\nA = \\begin{bmatrix}\n0 &amp; 1 \\\\\n0 &amp; 0\n\\end{bmatrix}, \\quad\nB = \\begin{bmatrix}\n0 \\\\\n350\n\\end{bmatrix}, \\quad\nC = \\begin{bmatrix}\n1 \\\\\n0\n\\end{bmatrix}\n\\]\n\n\\[\nA_a = \\begin{bmatrix}\n0 &amp; 1 &amp; 0 \\\\\n0 &amp; 0 &amp; 0 \\\\\n1 &amp; 0 &amp; 0\n\\end{bmatrix}, \\quad\nB_a = \\begin{bmatrix}\n0 \\\\\n350 \\\\\n0\n\\end{bmatrix}, \\quad\nB_r = \\begin{bmatrix}\n0 \\\\\n0 \\\\\n-1\n\\end{bmatrix}, \\quad\nC_a = \\begin{bmatrix}\n1 &amp; 0 &amp; 0\n\\end{bmatrix}\n\\]\n\nThe state space in python can be represented as shown below.\n\n[caption id=\"attachment_141\" align=\"alignnone\" width=\"753\"]<img class=\"wp-image-137\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-300x110.png\" alt=\"The state space representation matrices A, B, and C in Python for both initial full state feedback control and integral control.\" width=\"753\" height=\"276\"> Figure 5: The state space representation matrices A, B, and C in Python for both initial full state feedback control and integral control.[\/caption]\n\n&nbsp;\n\nSpecifically, we also explained the correspondence of the python code, the control theory, and the control diagram. This includes the integral state ($X_{N}$), control input (u), state space, and Kalman observer.\n\nThe ball balancing integral control diagram is shown in the following.\u00a0 Now the question is how to use python to implement the control theory. The process is shown below step by step:\n\n&nbsp;\n\n[caption id=\"attachment_141\" align=\"aligncenter\" width=\"483\"]<img class=\"wp-image-138\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-300x143.png\" alt=\"The integral state Xn using python and the related diagram.\" width=\"483\" height=\"230\"> Figure 6: The integral state Xn using python and the related diagram.[\/caption]\n\n&nbsp;\n\n[caption id=\"attachment_141\" align=\"aligncenter\" width=\"499\"]<img class=\"wp-image-138\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-300x143.png\" alt=\"The control input u using python and the related diagram.\" width=\"499\" height=\"238\"> Figure 7: The control input u using python and the related diagram.[\/caption]\n\n&nbsp;\n\n[caption id=\"attachment_141\" align=\"aligncenter\" width=\"546\"]<img class=\"wp-image-139\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-300x140.png\" alt=\"The state space representation \" width=\"546\" height=\"255\"> Figure 8: The state space representation \"$ \\dot{x} = A x + b $\" using python and the related diagram.[\/caption]\n\n&nbsp;\n\n[caption id=\"attachment_141\" align=\"aligncenter\" width=\"551\"]<img class=\"wp-image-140\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-300x152.png\" alt=\"The integral controller using python and the related diagram.\" width=\"551\" height=\"279\"> Figure 9: The integral controller using python and the related diagram.[\/caption]\n\n&nbsp;\n\n[caption id=\"attachment_141\" align=\"aligncenter\" width=\"540\"]<img class=\"wp-image-141\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-300x124.png\" alt=\"The Kalman observer design using python and the related diagram.\" width=\"540\" height=\"223\"> Figure 10: The Kalman observer design using python and the related diagram.[\/caption]\n\n&nbsp;\n\n<\/div>\n<h1>Kalman Observer Based Full State Integral Control Results With Python and Arduino<\/h1>\n<div>\n\nWith 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.\n<p style=\"text-align: center;\">measuredX = x[0,0] + np.random.randn() * noise<\/p>\nAfter running the simulation, the output is shown in below.\u00a0 It is obvious that the use of Kalman observer is able to reduce the noises from the system.\n\n[caption id=\"attachment_144\" align=\"aligncenter\" width=\"300\"]<img class=\"wp-image-142 size-medium\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-300x198.png\" alt=\"The simulation of a Kalman Observer based full state integral Control without noise\" width=\"300\" height=\"198\"> Figure 11: The simulation of a Kalman Observer based full state integral Control without noise[\/caption]\n\n&nbsp;\n\n[caption id=\"attachment_144\" align=\"aligncenter\" width=\"300\"]<img class=\"wp-image-143 size-medium\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-300x202.png\" alt=\"The simulation of a Kalman Observer based full state integral control with noise\" width=\"300\" height=\"202\"> Figure 12: The simulation of a Kalman Observer based full state integral control with noise[\/caption]\n\n&nbsp;\n<div>Here is the link to the code used to produce the simulation results:<\/div>\n<div><\/div>\n<div><a href=\"https:\/\/mtmailmtsu-my.sharepoint.com\/:u:\/g\/personal\/hbzhang_mtsu_edu\/EeZ0k4k-KIVEv8El7oATulsBjOXNxnkdjCV5P_iivNDBxQ?e=NtDc6K\">ballbalance.py<\/a><\/div>\n<div>\n\nYou also can actually implement the Arduino code using Kalman Observer Based Full State Integral Control to control two servo motors. To make Arduino using the code to do this, we need to calculate the Kalman gain (L)\u00a0 and Integral gain (K) first using Python. Then we will use the the K and L computed with Python to do Arduino-based control.\u00a0 The Arduino code and results are shown below.\n<a href=\"https:\/\/wokwi.com\/projects\/415045376930392065\" rel=\"noopener\"><strong>Arduino Code and Simulation Link<\/strong><\/a>\n\n<\/div>\n&nbsp;\n\n[caption id=\"attachment_144\" align=\"aligncenter\" width=\"418\"]<img class=\"wp-image-144\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-300x204.png\" alt=\"The simulation of a Kalman Observer Based Full State Integral Control using Arduino for Ball Balancing.\" width=\"418\" height=\"284\"> Figure 13: The simulation of a Kalman Observer Based Full State Integral Control using Arduino for Ball Balancing.[\/caption]\n\n<span style=\"text-align: initial; font-size: 1em;\">This exercise is very fun and informative.\u00a0 Please read the Arduino code carefully for how to use the Kalman gain (L) and Integral gain (K) to implement real-time Arduino-based ball balancing control precisely, using the Kalman Observer Based Full State Integral Control technique.<\/span>\n\n<\/div>","rendered":"<p>[latexpage]<\/p>\n<h1>Ball Balancing Project Background<\/h1>\n<p>In this chapter, we will discuss an open source project available on Hackaday. The project is about controlling a ball balancing on a resistive touchscreen surface. The project link is listed below.<\/p>\n<p><img decoding=\"async\" class=\"size-medium wp-image-132 aligncenter\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-300x221.png\" alt=\"\" width=\"300\" height=\"221\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-300x221.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-768x565.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-65x48.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-225x165.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2025\/01\/ball-350x257.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2025\/01\/ball.png 990w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p style=\"text-align: center;\"><strong><a href=\"https:\/\/hackaday.io\/project\/175294-adventures-in-state-space-control-arduino-edition\" rel=\"noopener\">Ball Balancing Project Hackaday Link<\/a><\/strong><\/p>\n<p>The project is well done in a few aspects. First, the project is closely related to the state space applications in practical engineering control. Second, the author has released all the important project files to the control engineering community, which is very useful and beneficial to control engineering applications.<\/p>\n<p>The project overall goal is to achieve the control of ball balancing on the resistive touch screen. The author has put a YouTube video link below to explain the project in detail.<\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=IjByGk3S7Fg&amp;t=38s\" rel=\"noopener\"><strong>Ball Balancing Project Hackaday YouTube Link<\/strong><\/a><\/li>\n<li><strong><a href=\"https:\/\/youtu.be\/zj92io9M25Q\" rel=\"noopener\">Explanation of code<\/a><\/strong><\/li>\n<\/ul>\n<p><span style=\"font-size: 1em;\">Overall, we want to achieve the control of the system using the integral control technique. In contrast to the full state feedback controller, which suffers from the steady state error problem, integral control is able to reduce the steady state error of the system. As such, it becomes an effective approach for controlling the balance of the ball to enable it to stay at the center of the resistive touch screen.<\/span><\/p>\n<h1>Ball Balancing Project Control Theory<\/h1>\n<h2>Luenberger Observer (Observer Taught in Class for Two Weeks and Lab 4)<\/h2>\n<div>\n<p>The system involves the use of a Kalman observer to estimate the states and then remove the noise from the system. A Kalman observer is similar to a Luenberger observer.\u00a0 We learned about the Luenberger observer in the previous chapter of our class. Hopefully you understood it, but we will review the Luenberger observer again just in case.<\/p>\n<p>It should be noted that in class, we did not call it a &#8220;Luenberger observer&#8221; much. Instead, we just called it an &#8220;observer&#8221; for convenience. Hopefully this new terminology has not confused you.\u00a0 A Luenberger observer is the default observer introduced in many textbooks. As such, people just tend to call it simply &#8220;observer&#8221; for convenience. The Luenberger is one of the simplest observers available to teach in control class.<\/p>\n<p>A full state feedback control diagram is shown below.<\/p>\n<figure id=\"attachment_135\" aria-describedby=\"caption-attachment-135\" style=\"width: 533px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-133\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-300x116.png\" alt=\"The full state feedback control diagram. The state space representation matrix includes A, B, and C. It also includes the gain of K.\" width=\"533\" height=\"206\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-300x116.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-768x296.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-65x25.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-225x87.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81-350x135.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp81.png 912w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><figcaption id=\"caption-attachment-135\" class=\"wp-caption-text\">Figure 1: The full state feedback control diagram. The state space representation matrix includes A, B, and C. It also includes the gain of K.<\/figcaption><\/figure>\n<p>A Luenberger observer is shown below in the control diagram.<\/p>\n<figure id=\"attachment_135\" aria-describedby=\"caption-attachment-135\" style=\"width: 516px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-134\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-300x140.png\" alt=\"The summary of observer (L) and observer-based controller (L).\" width=\"516\" height=\"241\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-300x140.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-1024x477.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-768x358.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-65x30.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-225x105.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82-350x163.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp82.png 1512w\" sizes=\"(max-width: 516px) 100vw, 516px\" \/><figcaption id=\"caption-attachment-135\" class=\"wp-caption-text\">Figure 2: The summary of observer (L) and observer-based controller (L).<\/figcaption><\/figure>\n<p><span style=\"text-align: initial; font-size: 1em;\">Figure 2 shows that we use full state feedback with an observer to implement the control using an observer. Note that there is an obvious benefit to use an observer on $\\hat{x}$ rather than the original state<\/span><em style=\"text-align: initial; font-size: 1em;\"> X<\/em><span style=\"text-align: initial; font-size: 1em;\"> to achieve the control. First, we can save some sensors to not measure every single state. Instead, we just use the observer to <\/span><em style=\"text-align: initial; font-size: 1em;\">estimate<\/em><span style=\"text-align: initial; font-size: 1em;\"> these states. Second, we can remove noise from the measured states.<\/span><\/p>\n<p>The overall purpose of the Luenberger observer is to estimate the state so that we do not have to use many sensors to measure the states. The Luenberger observer shows that it is feasible to estimate the state of the plant through the use of the observer gain L matrix shown in Figure 2 above.\u00a0 With the observer gain L matrix, it becomes feasible to estimate $ \\hat{x} $.<\/p>\n<p>Through the feedback process, with the feedback gain $K$, we do not use the original state $x$ anymore. Instead, we will use $ \\hat{x} $ as the feedback.<\/p>\n<p>The question is, why do we need to use the observer state $ \\hat{x}$ rather than just simply using $x$ for the feedback as shown in the full state feedback control process? Note that $x$ contains the physical variables measured through the process, such as position, velocity, and acceleration for a mechanical system. The reason that we use $ \\hat{x}$ rather than $ x $ is because this way we do not suffer the problems associated with $x$; for example, the noise issue related to the $x$. It also becomes feasible to reduce 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 would need to measure every single state to ensure the controller is able to work. Now, with the use of the observer, we can just use the observer to <em>estimate<\/em> the states, such as position, velocity, and acceleration. The benefit is that it will reduce the number of sensors needed to complete this wonderful control project.<\/p>\n<p>The key equations associated with observer are:<\/p>\n<p>The equation used to design observer gain L:<br \/>\n\\[<br \/>\n\\dot{e} = (A &#8211; LC)e<br \/>\n\\]<\/p>\n<p>The equation to show the estimated state $\\hat{x}$:<br \/>\n\\[<br \/>\n\\hat{x} = A\\hat{x} + Bu + L(y &#8211; \\hat{y})<br \/>\n\\]<\/p>\n<h2>Full State Feedback Integral Control (Seen Lecture Notes, Last Group Quiz)<\/h2>\n<p>Very nice! It looks like you understand the observer better now. Now, it is time to diver deeper. As we hinted in the ball balancing project background section, we need to use integral control to remove the steady state error. We want the ball to stay at the center of the resistive touch screen. For this purpose, 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 to use integral control. In order to use integral control, let us first review it. Note that the integral control here is similar to the integral control in the PID controller, but we return to this concept in state space based full state feedback control.<\/p>\n<p>Integral control is very similar to the full state feedback control. However, it includes another outer feedback loop to feed back the output <em>Y<\/em> to the reference <em>r<\/em>. Note that the integral gain <em>Ke<\/em> is also involved here. With the integral gain, it becomes feasible to reduce the steady state error.<\/p>\n<p>While integral control looks promising, it does not have an observer. This means that it still uses the raw states as the feedback. It therefore can not remove the noise of the states. To improve this situation, we need to use a Kalman observer to remove the noise. A Luenberger observer is not able to achieve this goal, so instead, we need to use a Kalman observer.<\/p>\n<figure id=\"attachment_135\" aria-describedby=\"caption-attachment-135\" style=\"width: 475px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-135\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-300x137.png\" alt=\"The summary of the full state feedback integral control (K). It includes the feedback control gain K and Ke.\" width=\"475\" height=\"217\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-300x137.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-1024x466.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-768x350.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-65x30.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-225x102.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83-350x159.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp83.png 1190w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><figcaption id=\"caption-attachment-135\" class=\"wp-caption-text\">Figure 3: The summary of the full state feedback integral control (K). It includes the feedback control gain K and Ke.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<\/div>\n<h2>Kalman Observer Based Full State Integral Control<\/h2>\n<div>\n<p>A Kalman observer is very similar to a Luenberger observer in principle, but it has the capability to remove noises from states. So often, we call it a Kalman filter instead of calling it a Kalman observer. Details of the mathematics of the Kalman observer can be referred to in the <a href=\"https:\/\/libraryresources.nse.org.ng\/robotics\/chapter\/model-predictive-control\/\">model predicative controller (MPC) chapter<\/a>. In this case study, we will not focus on explaining the mathematics of the Kalman observer; rather, we will focus on how to implement it with python.<\/p>\n<figure id=\"attachment_136\" aria-describedby=\"caption-attachment-136\" style=\"width: 670px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-136\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-300x128.png\" alt=\"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.\" width=\"670\" height=\"286\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-300x128.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-1024x439.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-768x329.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-1536x658.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-65x28.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-225x96.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84-350x150.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp84.png 1840w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><figcaption id=\"caption-attachment-136\" class=\"wp-caption-text\">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 gains K and Ke.<\/figcaption><\/figure>\n<\/div>\n<h1>Ball Balancing Project Modeling and Implementation<\/h1>\n<div>\n<p>This system can be described by the following state space:<\/p>\n<p>\\begin{equation}<br \/>\n\\dot{x} = A x + b<br \/>\n\\end{equation}<\/p>\n<p>Where<\/p>\n<p>\\[<br \/>\nA = \\begin{bmatrix}<br \/>\n0 &amp; 1 \\\\<br \/>\n0 &amp; 0<br \/>\n\\end{bmatrix}, \\quad<br \/>\nB = \\begin{bmatrix}<br \/>\n0 \\\\<br \/>\n350<br \/>\n\\end{bmatrix}, \\quad<br \/>\nC = \\begin{bmatrix}<br \/>\n1 \\\\<br \/>\n0<br \/>\n\\end{bmatrix}<br \/>\n\\]<\/p>\n<p>\\[<br \/>\nA_a = \\begin{bmatrix}<br \/>\n0 &amp; 1 &amp; 0 \\\\<br \/>\n0 &amp; 0 &amp; 0 \\\\<br \/>\n1 &amp; 0 &amp; 0<br \/>\n\\end{bmatrix}, \\quad<br \/>\nB_a = \\begin{bmatrix}<br \/>\n0 \\\\<br \/>\n350 \\\\<br \/>\n0<br \/>\n\\end{bmatrix}, \\quad<br \/>\nB_r = \\begin{bmatrix}<br \/>\n0 \\\\<br \/>\n0 \\\\<br \/>\n-1<br \/>\n\\end{bmatrix}, \\quad<br \/>\nC_a = \\begin{bmatrix}<br \/>\n1 &amp; 0 &amp; 0<br \/>\n\\end{bmatrix}<br \/>\n\\]<\/p>\n<p>The state space in python can be represented as shown below.<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 753px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"wp-image-137\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-300x110.png\" alt=\"The state space representation matrices A, B, and C in Python for both initial full state feedback control and integral control.\" width=\"753\" height=\"276\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-300x110.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-1024x375.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-768x281.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-1536x562.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-65x24.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-225x82.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85-350x128.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp85.png 1842w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">Figure 5: The state space representation matrices A, B, and C in Python for both initial full state feedback control and integral control.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>Specifically, we also explained the correspondence of the python code, the control theory, and the control diagram. This includes the integral state ($X_{N}$), control input (u), state space, and Kalman observer.<\/p>\n<p>The ball balancing integral control diagram is shown in the following.\u00a0 Now the question is how to use python to implement the control theory. The process is shown below step by step:<\/p>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 483px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-138\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-300x143.png\" alt=\"The integral state Xn using python and the related diagram.\" width=\"483\" height=\"230\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-300x143.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-1024x489.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-768x367.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-1536x733.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-65x31.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-225x107.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-350x167.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86.png 1734w\" sizes=\"(max-width: 483px) 100vw, 483px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">Figure 6: The integral state Xn using python and the related diagram.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 499px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-138\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-300x143.png\" alt=\"The control input u using python and the related diagram.\" width=\"499\" height=\"238\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-300x143.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-1024x489.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-768x367.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-1536x733.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-65x31.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-225x107.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86-350x167.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp86.png 1734w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">Figure 7: The control input u using python and the related diagram.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 546px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-139\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-300x140.png\" alt=\"The state space representation\" width=\"546\" height=\"255\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-300x140.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-1024x478.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-768x359.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-1536x717.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-65x30.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-225x105.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87-350x163.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp87.png 1748w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">Figure 8: The state space representation &#8220;$ \\dot{x} = A x + b $&#8221; using python and the related diagram.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 551px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-140\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-300x152.png\" alt=\"The integral controller using python and the related diagram.\" width=\"551\" height=\"279\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-300x152.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-1024x519.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-768x389.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-1536x779.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-65x33.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-225x114.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88-350x177.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp88.png 1574w\" sizes=\"(max-width: 551px) 100vw, 551px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">Figure 9: The integral controller using python and the related diagram.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_141\" aria-describedby=\"caption-attachment-141\" style=\"width: 540px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-141\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-300x124.png\" alt=\"The Kalman observer design using python and the related diagram.\" width=\"540\" height=\"223\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-300x124.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-1024x424.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-768x318.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-1536x636.png 1536w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-65x27.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-225x93.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89-350x145.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp89.png 1922w\" sizes=\"(max-width: 540px) 100vw, 540px\" \/><figcaption id=\"caption-attachment-141\" class=\"wp-caption-text\">Figure 10: The Kalman observer design using python and the related diagram.<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<\/div>\n<h1>Kalman Observer Based Full State Integral Control Results With Python and Arduino<\/h1>\n<div>\n<p>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.<\/p>\n<p style=\"text-align: center;\">measuredX = x[0,0] + np.random.randn() * noise<\/p>\n<p>After running the simulation, the output is shown in below.\u00a0 It is obvious that the use of Kalman observer is able to reduce the noises from the system.<\/p>\n<figure id=\"attachment_144\" aria-describedby=\"caption-attachment-144\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-142 size-medium\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-300x198.png\" alt=\"The simulation of a Kalman Observer based full state integral Control without noise\" width=\"300\" height=\"198\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-300x198.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-768x508.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-65x43.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-225x149.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810-350x231.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp810.png 1010w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-144\" class=\"wp-caption-text\">Figure 11: The simulation of a Kalman Observer based full state integral Control without noise<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_144\" aria-describedby=\"caption-attachment-144\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-143 size-medium\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-300x202.png\" alt=\"The simulation of a Kalman Observer based full state integral control with noise\" width=\"300\" height=\"202\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-300x202.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-768x518.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-65x44.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-225x152.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811-350x236.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp811.png 946w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-144\" class=\"wp-caption-text\">Figure 12: The simulation of a Kalman Observer based full state integral control with noise<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<div>Here is the link to the code used to produce the simulation results:<\/div>\n<div><\/div>\n<div><a href=\"https:\/\/mtmailmtsu-my.sharepoint.com\/:u:\/g\/personal\/hbzhang_mtsu_edu\/EeZ0k4k-KIVEv8El7oATulsBjOXNxnkdjCV5P_iivNDBxQ?e=NtDc6K\">ballbalance.py<\/a><\/div>\n<div>\n<p>You also can actually implement the Arduino code using Kalman Observer Based Full State Integral Control to control two servo motors. To make Arduino using the code to do this, we need to calculate the Kalman gain (L)\u00a0 and Integral gain (K) first using Python. Then we will use the the K and L computed with Python to do Arduino-based control.\u00a0 The Arduino code and results are shown below.<br \/>\n<a href=\"https:\/\/wokwi.com\/projects\/415045376930392065\" rel=\"noopener\"><strong>Arduino Code and Simulation Link<\/strong><\/a><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<figure id=\"attachment_144\" aria-describedby=\"caption-attachment-144\" style=\"width: 418px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-144\" src=\"https:\/\/libraryresources.nse.org.ng\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-300x204.png\" alt=\"The simulation of a Kalman Observer Based Full State Integral Control using Arduino for Ball Balancing.\" width=\"418\" height=\"284\" srcset=\"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-300x204.png 300w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-1024x697.png 1024w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-768x523.png 768w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-65x44.png 65w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-225x153.png 225w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812-350x238.png 350w, https:\/\/libraryresources.nse.org.ng\/robotics\/wp-content\/uploads\/sites\/18\/2026\/03\/chp812.png 1292w\" sizes=\"(max-width: 418px) 100vw, 418px\" \/><figcaption id=\"caption-attachment-144\" class=\"wp-caption-text\">Figure 13: The simulation of a Kalman Observer Based Full State Integral Control using Arduino for Ball Balancing.<\/figcaption><\/figure>\n<p><span style=\"text-align: initial; font-size: 1em;\">This exercise is very fun and informative.\u00a0 Please read the Arduino code carefully for how to use the Kalman gain (L) and Integral gain (K) to implement real-time Arduino-based ball balancing control precisely, using the Kalman Observer Based Full State Integral Control technique.<\/span><\/p>\n<\/div>\n","protected":false},"author":1,"menu_order":17,"template":"","meta":{"pb_show_title":"","pb_short_title":"","pb_subtitle":"","pb_authors":["hbzhang"],"pb_section_license":""},"chapter-type":[],"contributor":[61],"license":[],"class_list":["post-145","chapter","type-chapter","status-publish","hentry","contributor-hbzhang"],"part":66,"_links":{"self":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/users\/1"}],"version-history":[{"count":1,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/145\/revisions"}],"predecessor-version":[{"id":146,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/145\/revisions\/146"}],"part":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/parts\/66"}],"metadata":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapters\/145\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/media?parent=145"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/pressbooks\/v2\/chapter-type?post=145"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/contributor?post=145"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/libraryresources.nse.org.ng\/robotics\/wp-json\/wp\/v2\/license?post=145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}