1. Introduction
The “ball and beam” system represents a class of nonlinear systems and serves as a typical academic example for illustrating various real-world problems and practical applications. One such application is the stabilization of cameras on drones or other platforms, where the camera must track a target and maintain its position despite platform movement or external disturbances. Similarly, the stabilization of mirrors in optical telescopes or platforms in weapon systems follows the same control principles. Stabilized platforms on ships and aircraft also commonly employ similar control strategies, wherein an object must be precisely positioned and maintained at a specified location.
Controlling the ball and beam system is not a trivial task. Without considering friction, the ball moves freely due to gravity and cannot maintain a stable position without controller intervention. Traditional approaches such as PID controllers or state feedback often fail to achieve optimal results when system parameters change or external disturbances occur.
The ball and beam system belongs to the class of underactuated systems; i.e., it is not possible to directly control the movement of the ball but only to adjust the tilt of the beam. To address this limitation, more sophisticated control algorithms are usually used. A review of the literature offers insight into various control strategies developed for such systems.
The system can be controlled by an adaptive controller [
1] or fractional order PD controller [
2]. Another way to control the system is by using the underactuated back-stepping method [
3], or
-method matching control law, which was shown in [
4]. Another paper [
5] suggests using an advanced velocity observer-based self-tuning stabilizing controller. A tracking controller based on the approximate input–output linearization was introduced in [
6]. A sliding mode controller was derived in [
7,
8]. Other authors developed a nonlinear active disturbance rejection control using a predictive nonlinear extended state observer [
9]. Based on the energy approach and the passivity properties of the system, Lyapunov function candidates were defined in [
10], and a passivity-based control approach was also used in [
11].
Apart from these analytical controllers, there is also a category of advanced intelligent control methods that utilize artificial intelligence and learning to improve control performance. This category includes controllers that make use of fuzzy logic, neural networks, and machine learning techniques.
In practical applications of ball and beam systems, a variety of controller designs have been implemented. Among the most relevant examples are a fuzzy PID controller [
12], simplified fuzzy controller [
13], adaptive fuzzy sliding mode controller [
14], and fuzzy fractional order PID controller, which were tuned via the particle swarm optimization algorithm [
15].
Another approach was shown in [
16] where the authors introduced the detail-reward function in the deep reinforcement learning algorithm.
Finally, let us also mention an example of a PID controller whose parameters are determined using three optimization algorithms: genetic algorithm, particle swarm optimization, and differential evolution [
17].
This paper presents a novel compensator with weighted input parameters that enables more precise ball and beam control. The goal is to propose a straightforward design procedure that, based on a simple and relatively imprecise experimental identification of the device dynamics (using a double integrator), ensures that the system output follows the desired prescribed behavior. The whole procedure consists of only three steps that can also be replicated for other systems. The algorithm is validated on a newly developed modular device that is distinguished by its adaptability, ease of reproduction, and flexibility in selecting the actuator and microprocessor based on user preferences.
The following sections of the paper first present various structural solutions for the system (
Section 2), which were followed by the implementation of the developed Automatic Ball-Balancing Mechatronic System (
Section 3), which required system identification to obtain a mathematical model (
Section 4). Then, the design and implementation of the proposed compensator are described (
Section 5). The final section presents the results of simulations and experiments.
2. Alternative Design Solutions for the System
The ball and beam system can be implemented through several approaches. The specific design attributes of each implementation differ in two main characteristics: the position of the pivot joint responsible for the arm tilting and the actuator point of action, which inclines the arm out of its horizontal alignment. Typically, the system allows two primary mounting configurations of the swing arm with possible adjustments for further needs.
In the initial configuration, the pivot joint is positioned at the center of the arm, and the actuator applies action directly at this location, enabling straightforward mechanical operation (
Figure 1). This design is distinguished by its straightforward implementation, which was primarily attributed to a decrease in the number of components required. The accuracy of the arm’s angular movement is fundamentally dependent on the actuator’s ability to achieve precise rotational steps. This particular configuration has been empirically verified through earlier studies, as highlighted in the research conducted by Wang in 2007 [
18], by Lieberman in 2004 [
19], and by Hirsch in 1998 [
20].
The enhancement of tilt precision, with only slight changes in design, is achievable by altering the primary configuration using diverse transmission configurations. The first possible option is the use of a simple friction drive using smooth wheels at the arm pivot point (
Figure 2). This type of transmission mechanism causes the arm to tilt in the opposite direction of the actuator action. Since smooth wheel transmissions can result in undesirable slippage, a suitable solution to this issue is the use of spur gears. Such a system configuration approach was described, e.g., by Rosales (2004) [
21] or Ito (2004) [
22].
Another alternative to the previous configuration is the use of a belt or a chain drive (
Figure 3). The larger pulley, permanently connected to the arm, is driven by the smaller pulley, which is attached to the actuator output. This type of transmission ensures that the arm inclines in the same direction as the action of the actuator. Furthermore, the use of gears in a belt or chain drive configuration significantly reduces the potential risk of unwanted belt slippage. Implementations of these concepts are used in the Amira BW500 [
23] and TecQuipment CE106 [
24] commercial ball and beam systems. Their practical application has been described, e.g., by Chien et al. (2010) [
25], Colón et al. (2013) [
26] or Kagami et al. (2020) [
27].
The second possible configuration is to attach one end of the arm to a support structure using a pivot joint. The other end of the arm is coupled to the actuator output via mechanical linkage (
Figure 4). This setup is more complex by design, as it requires more additional components and supplies. A key benefit of the described configuration is increased flexibility concerning the arm tilt range, which can be further adjusted by moving the linkage action point on the arm or altering the linkage component lengths. In general practice, the second configuration is most commonly used, especially in commercial solutions, such as Quanser [
28], RYC-BB [
29] or GBB1004 [
30] as utilized in the studies conducted by Al-Dujaili et al. (2021) [
31] as well as Yongun, Seok-Kyoon, and Choon (2021) [
32]. A similar approach, based on the described configuration, can be found in proprietary, custom, or academic construction solutions of the ball and beam system, e.g., Nowoposki (2013) [
33], Awadalla et al. (2017) [
34], Hadipour et al. (2021) [
35], and Versloot et al. (2020) [
36].
Modification of the second configuration by displacing the pivot point to the center of the arm provides a greater range of arm tilt angle while preserving its initial length without the need to modify the linkage mechanism (
Figure 5). This design is particularly convenient for actuators with a limited range of output shaft rotation or for the installation of the lever mechanism in tight conditions. A possible drawback of this configuration may occur when less precise actuators are used, resulting in the inaccurate setting of the arm tilt angle. This setup is implemented in commercial solutions like Acrome [
37] and GBB2004 [
30] systems with practical implementation proposed by Bao et al. (2021) [
8].
Looking back at the presented configurations, it is possible to classify them according to two major groups: in the first case, the actuator is situated in the middle of the arm and acts directly at the pivot point, and in the second case, the actuator is offset to the side and acts on the arm via a linkage transmission. The first implementation is structurally more straightforward as it involves fewer mechanical components. In addition, the ball behaves symmetrically on both sides of the pivot point, which makes it easier to model the entire system. Although the second design is more complex to build, it enhances the beam positioning precision, thereby increasing the accuracy of ball position control. Moreover, the lever linkage mechanism enables the utilization of more compact actuators and minimizes the deterioration of motor gears, thereby prolonging their operational life.
We designed and constructed a custom system based on the second configuration, implementing a lever-linkage actuator mechanism. We decided to adopt a modular approach to the system’s architecture to enable easy modification. This approach allows for multiple system configurations, utilizing different actuators, sensors, and control units, thereby enhancing both the evaluation process and the broader applicability of the device in educational environments.
3. Automatic Ball-Balancing Mechatronic System
The Automatic Ball-Balancing Mechatronic System (ABMS) is an experimental platform that is being developed for educational purposes, enabling users to test and validate control algorithms for a selected class of nonlinear systems. The system is designed to be compact, portable, and robust enough to perform various experiments.
The central component of the system is the beam, which is composed of two smooth aluminium profiles on which a stainless steel ball rolls (
Figure 6).
Figure 6b shows a detailed cross-section of the beam. One of the aluminium profiles is embedded in a plastic casing, which enables the attachment of a pressure-activated position sensor. The arm profiles are capped with a pivot joint mechanism that incorporates two ball bearings on one side, ensuring smooth movement of the arm in the vertical plane. The opposite end of the arm is connected to the actuator output via a linkage mechanism. The system frame components are manufactured using a 3D printer with the FFF (Fused Filament Fabrication) method. These components are made from a strong, lightweight material that ensures the stability of the device while minimizing the overall weight. The components are assembled and fastened with metal screws, facilitating the easy swapping or replacement of individual parts.
From a functional point of view, the ABMS system is composed of three main parts: the control unit, the ball position sensors, and the actuator.
The control unit is responsible for communication with the sensors, processing the acquired data, and controlling the actuator. The platform is designed to be compatible with the Arduino Due and STM32 Nucleo64 development boards, both of which use 32-bit ARM processors. Specifically, the Arduino Due features a SAM3X8E ARM Cortex-M3 processor, while the STM32 Nucleo64 is equipped with an ARM Cortex-M4 processor. The ability to choose between development boards allows customization of the system to meet different needs. The Arduino platform offers an easy-to-use interface and broad community support, while the STM32 provides higher performance and more flexible configuration options, making it suitable for professional applications.
The system can utilize two independent position sensing methods to accurately determine the position of the ball. The primary method is direct contact detection, in which the rolling ball applies pressure to a Spectra Symbol ThinPot membrane potentiometer mounted on one of the aluminium profiles (see the blue section in
Figure 6b). This potentiometer acts as a voltage divider with the ball’s position determined by the voltage difference across the potentiometer terminals. The ball, with a diameter of 36.4 mm and a weight of 0.2 kg, applies sufficient pressure to the diaphragm, allowing accurate and reliable measurements. However, a limitation of this method is that the ball is pushed into the diaphragm, resulting in insensitivity due to dry friction. The effect of dry friction must be addressed when designing the system controller.
The second method for determining the ball’s position is non-contact measurement using the ST VL53L1X laser sensor, which is mounted at the end of the arm near the pivot joint. This sensor employs the time-of-flight (ToF) technology to measure the distance between the ball and the sensor. The use of redundant sensors enhances system reliability and allows for comparison of the performance of different sensing methods.
However, discrepancies in the measurement between a touch potentiometer and a laser time-of-flight sensor must be accounted for. The potentiometer determines the position of the center of the ball, whereas the laser sensor measures the distance, which includes the radius of the ball. As a result, the zero positions of the two sensors are different, which requires necessary software or hardware compensation. Additionally, it should be noted that the used laser sensor has a minimum detectable measurement threshold of 4 cm. We were able to mitigate this limitation by appropriately positioning the sensor at a sufficient distance from the possible ball positions (
Figure 6).
The actuator of the system consists of a single servomotor that controls the tilt of the arm, thereby influencing the movement of the ball. During development, we tested several structural options using both digital and analogue servomotors. The digital servomotors considered, such as the Waveshare ST3020 or SC15, offer higher torque and more precise control but require an additional proprietary UART converter for communication. In contrast, analogue PWM-controlled servos, such as the Waveshare MG996R or JX RD-5622-MG, are easier to integrate and do not require an additional interface for control.
The ABMS device design is based on a modular architecture approach in terms of its functional components. The assembly, composed of separate 3D-printable parts, supports the integration of various types of servomotors and control units. Multiple mounting components have been developed to enable a straightforward interchangeability of both servomotors and control units. This significantly enhances the system’s adaptability for diverse experimental setups and ensures compatibility with a wide range of platforms. Currently, two functional prototypes of the system are in use, supporting ongoing development of hardware components, the software package, and testing of the complete ABMS platform solution.
The configuration used for the results presented in this publication consists of an Arduino Due microcontroller, a Spectra Symbol ThinPot 200 mm potentiometer, a JX RD-5622-180-MG servomotor, and a smooth steel ball with a diameter of 36.4 mm. The device that was used in this configuration for the purposes of this publication is shown in
Figure 6a. The microcontroller can be found beneath the casing that supports the installation of the swing arm. Components for mounting a DC motor with a gearbox and a counterweight arm to offload the actuator’s action are currently under development.
The used servomotor has an operating range of the output shaft in the span from −90° to +90°. In the context of the ABMS system, only a partial segment of this range is used for the arm tilting movement. Utilizing a servomotor with a reduced output shaft rotation range, e.g., (−30°, +30°) can improve the precision of the arm’s inclination while maintaining equivalent input signal resolution. An illustrative example demonstrating how the pulse width of the input signal impacts servomotor rotation is provided in [
38].
The system’s control and data acquisition are facilitated by a serial communication interface utilizing a standard USB connection. The interaction is achieved using a custom communication protocol based on ASCII-encoded text messages. This protocol provides instructions for the operation and control of the actuators as well as for transmitting sensor data between the system and a computer.
To control the inclination of the arm, the system can receive messages that determine the position of the servomotor. These messages contain information about the desired rotation of the actuator’s output relative to the arm’s horizontal position. The user can accurately manipulate both the direction and the rotation angle. The movement of the arm takes place within a predefined range, allowing the position of the steel ball to be adjusted. The system’s algorithm incorporates a safeguard that limits the actuator’s maximum rotational increment, thereby protecting both the components and the overall structure from inadvertent tampering and potential damage.
The ABMS system also provides output feedback messages containing information about the actual position of the ball and the rotation of the servomotor. This allows the user to monitor the system’s behavior in real time. More details on the format of the messages can be found in [
39].
4. System Identification
In several publications dedicated to the control of the beam and ball system, the mathematical model is derived based on Newton’s second law or Lagrange equations, considering the real physical characteristics of the device and the ball [
40,
41].
The mathematical model is often represented as a double integrator (see, e.g., [
2,
5,
42,
43,
44])
to which the dynamics of the servomechanism approximated by a first-order system is added (in some cases, e.g., [
45])
The time constant
can be replaced by a dead time [
46]
However, the dead time is also influenced by the A/D converter, the measurement filter, dry friction, and the implementation of calculations in the control structure.
Our system consists of a servosystem [
47], which receives a PWM signal as input (
Figure 7).
According to the datasheet, the PWM signal has a repetition frequency
Hz. Instead of setting the PWM duty cycle, we specify the duration of the logical value 1 in microseconds (
s). The zero position is given by a pulse of
s. A higher or lower tilt angle of the servosystem is achieved by adjusting the pulse duration. In our case, the range is
s
s. This corresponds to a rotation angle of
(
Figure 8). Similar behavior can also be found in [
38].
The values of the key system parameters were determined experimentally by applying a step input to the device and comparing its response with a real-time simulation implemented on a microcomputer.
Figure 9 shows a comparison of the response
to a step change of
s for the model described by the transfer function (
1), where
mm/
s a
s. The variables
and
denote the measured filtered and non-filtered output, respectively.
The response is limited by the physical constraints of the beam along which the ball can move. The graph also clearly indicates that the gain is not the same for both movement directions of the ball.
By considering s, we reduced the identification process to determining a single parameter , which will represent all the variable factors of the system (servosystem properties, gears and also the processing of information from the A/D converter to the Arduino Due).
When searching for a dynamic model of the system, we also considered the transfer function (
3). We found that the dead time is approximately
ms. Due to its small value, we decided to neglect it for the purposes of this paper.
For the proposed system model, we designed a controller that was first tested in the MATLAB/Simulink (2023b) environment. After successful simulation verification, the system was implemented on a microprocessor platform, where the control process was executed in real time. Finally, the controller was applied to the physical system. This step-by-step approach allowed us to minimize the accumulation of errors.
5. Control Structure Design
The whole controller design was implemented in the continuous domain, while the final implementation was in digital form (
Figure 10). The sampling periods of the individual blocks are set so that the resulting system exhibits behavior similar to that of a continuous system. Minor deviations arising in the digital implementation are compensated by the controller and by the principle of negative feedback.
System control design is usually based on a pre-designed controller structure, where the controller parameters are calculated using a chosen synthesis method. The PID controller structure is very commonly used, for which the individual synthesis methods are summarized, e.g., in [
48]. The main limitation of this approach is that the controller’s action is often calculated solely based on a single input: the control error
where
is the reference signal and
is the system output.
We based the controller design on the control structure shown in
Figure 11, where the input to the controller is not the control error but rather the output of the system and its desired value.
As already mentioned, for simplicity, we will describe the mathematical model of the ABMS system using a double integrator (
1). The control of such a system has been addressed in publications such as [
49,
50].
The whole design of our controller will consist of three steps: stabilizing the
system, ensuring the desired behavior of the
system, and ensuring the realizability of the entire control structure [
51].
5.1. System Stabilization
The transfer function (
1) that describes the motion of the ball is not stable. The first step in the controller design is to stabilize the system, to which we want to impose the desired feedback behavior using stabilizing feedback. For this reason, in the control scheme shown in
Figure 11, we can replace the controller block
with blocks
and
(
Figure 12).
The controller structure can be derived from the equation
where
represents the desired behavior of the system achieved by the internal feedback
, and
is the desired behavior of the control loop as a whole. The order of the transfer function
is influenced by the order of the controlled process.
In our case, we require the transfer function
to behave like a second-order system
The transfer function
represents the stabilizing feedback
Following (
7), we obtain
Since the second derivative is difficult to implement, we will require
. This approach allows us to eliminate the number of differential equations to be solved and to significantly reduce the computation time. Therefore, we require
from which we obtain
Therefore, the stabilizing feedback is described by a first-order polynomial
5.2. Desired System Behavior
After stabilizing the system, we can design the transfer function , which ensures the desired behavior of the control structure.
Since the transfer function (
7) is of second order, we can require that the desired transfer function of the closed-loop system
is also of second order
If we consider the block diagram shown in
Figure 12, then for the regulator
, we have
Substituting (
13) and (
7)
In the design, we have ensured that the transfer functions
and
correspond to an improper second-order system, ensuring a stable system without overshoot. Choosing any value for
could lead to oscillations or even instability. This can be eliminated by appropriate adjustment of the controller parameters
. If we choose the following
then
5.3. Realizability of the Solution
Finally, let us look at the whole control scheme from the point of view of its realizability. The stabilizing feedback is represented by a first-order polynomial (
12). For its realizability, it is necessary that it is complemented by at least a first-order filter. We used a second-order filter to improve filtering properties.
At the same time, the considered control scheme (
Figure 12) is supplemented with a second-order filter
This filter allows filtering the measured signal. The resulting control structure is shown in
Figure 13.
The developed controller was implemented on a microcontroller. All derivatives were replaced by finite differences with the sampling period selected to be sufficiently small. This ensured that the combined transfer function of the hold circuit and sampler remained approximately constant and equal to one across the relevant frequency spectrum.
6. Experimental Results and Discussion
First, we compared the desired trajectory of the ball’s position
defined by (
13) with the simulation of the identified device model
(
1), which was performed in real time on a microcomputer. In this case, dry friction does not appear during the experiment. The parameters used in the implementation are listed in
Table 1.
The system gain
and the time constant of the system
were already justified in
Section 4. The time constants
and the controller parameter
were chosen so that the dominant time constant of systems (
1) and (
6) would be the same. The time constants
and the controller parameter
were selected to achieve a faster system response compared to the equivalent second-order system (
13) while also keeping the regulator time constants equal for simplicity. The time constant of the filter was chosen to ensure that the transfer function (
20) is realizable without making the system prone to instability.
From
Figure 14, it can be seen that these trajectories are practically identical, although at higher zoom levels, it is apparent that the simulation output slightly precedes the desired trajectory. This is due to the negligible but nevertheless present delays.
Since dry friction (
s) will also appear in the real device, it is necessary to excite the control input
with sufficiently large oscillations at a higher frequency (
Figure 15). This can be achieved in several ways. We increased the time constant of the filter in the stabilizing feedback to
s. Then, the output variable stabilizes more or less at the desired set point value. The imperfection of the parameter settings is visible in
. In steady state, the control signal is not at zero value. Additionally, the low frequency of the generated oscillations caused these oscillations to be transmitted to the system’s output.
However, we can use the proposed control structure in a real experiment, the results of which are shown in
Figure 16. We used the parameters listed in
Table 1 except for two parameters that had to be adjusted:
mm/
s and
s. These parameters allowed us to overcome dry friction and at the same time achieve high frequencies of the control signal that appear as random noise in the control signal. These high frequencies are filtered out and therefore do not appear in the system’s output.
7. Conclusions
In this paper, after analyzing various design solutions, we proposed and implemented an Automatic Ball-Balancing Mechatronic System (ABMS) with a lever transmission, which provides higher positioning accuracy for the ball. The identification of the system was performed experimentally, and the results confirmed the suitability of the chosen mathematical model.
Then, we designed and tested a new compensator, which was successfully implemented in real time on a microprocessor platform. Both simulation and experimental results demonstrated that the proposed controller provides stable and accurate control of the system under various step changes in the input signal.
The goal of the paper was to achieve the same trajectory of the ball’s position change on the real device as we previously obtained in simulation. The main issue was that initially, we were unable to achieve zero steady-state control error on the real device. As the transient response approached the desired value, friction between the ball and the sensor became significant, causing the ball to stop due to insufficient control action. Although the controller attempted to eliminate the error, the process was too slow, which was not acceptable for our requirements. When we claimed to have achieved higher positioning accuracy, we took into account this unfavorable effect of dry friction. To address this, we first introduced high-frequency oscillations into the control action, which the system naturally filtered out.
In this paper, we have identified the system by a double integrator in which we neglected dead time. However, in the future, we plan to include it in the controller design to further improve the control quality.