Modeling and Controlling a Ball Balancing Table with Altair Activate (co-simulation & hardware-in-the-loop)
Altair Activate® software is an open & flexible tool for rapidly modeling and simulating products as multi-disciplinary systems in the form of 1D models (expressed as signal-based or physical block diagrams), optionally coupled to 3D models. Recently, it can also run hardware in the loop simulations, making it a perfect platform to develop mechatronic systems, such as:
The Ball Balancing Table (BBT) is a well-known kit for all mechatronics enthusiasts. Even if it might appear quite simple, it allows to investigate many aspects of control, for example anti-windup scheme for PID control.
The main parts of the BBT kit are:
- Power Supply
- Controller (Arduino)
- RC Servos
- 2D resistive touch screen
- Steel Ball
The position of the ball, measured by the touchscreen, is fed as input to the controller, which comparing it with the reference produces an error signal. This error signal is converted accordingly to a certain control logic into a command which drives the RC servos. The movement of the servos is transmitted to the table through rod end bearings, allowing the ball to follow the set reference.
In this short article we will analyze this mechatronic system going through:
The closed loop system can be easily modeled in Altair Activate through this block diagram:
Where we can visualize 2 superblocks:
- plant (Ball Balancing Table)
- controller
Looking inside the plant superblock:
we find 4 different versions of the plant:
- LINEAR 1D. The BBT is described by linear equations of motion, modeled with signal-based blocks. It is a simplification, but still pretty accurate if the oscillations of the table are small. And anyway, it can be used to design a state observer.
- NONLINEAR 1D. The BBT is described by nonlinear equations of motion, modeled with signal-based blocks. This description is more accurate, but it does not consider all the physics of the problem yet (for example the contact between the ball and the table is not handled accurately).
- MULTIBODY 3D. The BBT is modeled in Altair Motion View/Motion Solve as a 3D multibody system. This is the most accurate physical description. In this case a co-simulation is run between Altair Activate and Motion Solve.
- HARDWARE. This is the real plant. We are not modeling it, we are connecting it to Altair Activate, so that a hardware in the loop simulation can be performed.
The flexibility of Altair Activate allows to keep in a single model different versions of the plant, and to smoothly switch from one to another, based on the user needs.
Once the plant has been modeled, we need to design our controller:
We can recognize a PID control with Anti-Windup (for both servos). With the Anti-Windup scheme, we will prevent the integrator to overcharge due to the saturation of the actuators. So, we will minimize the overshooting.
The gains of the controller can be set by:
- trial & error
- analytical methods
- optimization algorithms
Here we go for the 3rd option leveraging the built-in BOBYQA optimization algorithm.
The optimizer runs the Activate model by successive iterations, and varying the controller gains, it minimizes the cost function, which is proportional to the error between the actual position of the ball and the reference.
Which is the plant model that has been used for the optimization (we have 4 different versions of the plant)?
Since the optimization is an iterative process, we need a model that runs fast. Moreover, to get meaningful results this model should be accurate enough. Hence the natural choice is the NONLINEAR 1D model, whose equations of motion are:
At the end of the optimization process we get the optimal gains of the controller that we can deploy to control the more detailed and accurate 3D multibody model of the plant:
In this way we are virtually validating our controller!
The last step is to test and validate the controller with the real BBT kit. This means that we are performing a hardware in the loop simulation.
As you can see the digital twin and the real BBT kit behave almost the same:
References:
[1] Ball Balancing Table Courseware, Altair, Troy (MI)
[2] Ogata, K. (2010) Modern Control Engineering. 5th Edition, Pearson, Upper Saddle River
[3] Visioli, A. (2006) Practical PID control, Springer, London
Acknowledgements:
Special thanks to Acrome myControl and to Altair MBD Team