Understanding PID Control: 2-DOF Ball Balancer Experiments

This article explains how to use PID controllers to solve a real-world balance problem. We need to calculate PID gains to do so. Let’s start first with the Ziegler-Nichols method:

Ziegler-Nichols Method

Ziegler-Nichols method is very useful for calculating the controller gains. This method begins by zeroing the integral and differential gains. After this step, the proportional gain is increased until the system oscillates. After finding the proportional gain that makes the system oscillate, the other gains of the controller are calculated with the help of the table below.

Ziegler-Nichols Method table
Figure 1: Ziegler-Nichols Method



To use this method, you can follow the steps below:

Figure 2: (Algorithm to calculate the PID gains using the Ziegler-Nichols method


Damping

In the real world, friction affects the behavior of the systems. If there were no frictions, the systems wouldn’t stop and oscillations would continue indefinitely.

Figure 3: The balls would keep hitting forever if there weren’t any friction (even though the video loops)

If friction becomes zero, some systems can behave infinitely like Figure 3.

If the damping ratio gets close to zero, the system will spend more time stopping. If the system can’t stop, it is called oscillation. In the oscillation, the system moves between some of the points. The step response is a commonly used method to analyze systems’ behavior. The system’s behavior can be followed by a step response. In figure 4, we can easily see the relevance between the damping ratio and system behavior. For example, the system can directly reach the set point when ζ=1 however if  ζ=0, the system can’t stop and reach the set point.

We can classify the damping ratio for its oscillation types. We can show the damping ratio with the ζ (Tau) symbol and it is classified as follows:

  • ζ<1 The system is underdamped
  • ζ>1 The system is overdamped
  • ζ=1 The system is critically damped

We can easily understand what the damping ratio means in real life using Acrome’s Ball Balancing Table. The animations below show different damping ratios which are changed using the controller’s PID parameters.

Figure 4: Critically damped PID controller exercise using Ball Balancing Table

In figure 4, the ball movement shows a critically damped behavior. It can reach to set point fastly with zero error. We can consider that the ball’s ζ is close to 1.

Figure 5: Underdamped PID controller exercise using Ball Balancing Table

Figure 6: Overdamped PID controller exercise using Ball Balancing Table

In Figure 6, the ball behaves overdamped. It reaches a set point slowly, which means the ζ>1.

Figure 7: Unstable PID controller exercise using Ball Balancing Table

In Figure 7, the ball behaves in unstable behavior. It can’t reach the set point. Also, the ball draws a random direction on the table

Figure 8: Step response of the 3 different step response types.

Balancing is a very common problem in the industry. Some of the systems are affected by balance. So the system’s balance should be under control. For example, planes can change direction by balance. Moreover, you have already seen in MotoGP™ riders change motorbikes’ slopes instead of turning the handlebar for changing direction.

Figure 9: MotoGP™ is a place where vehicle dynamics + driver abilities combine with each other for controlling the balance of the motorbike.

One Dimensional Balance Problem

Aircraft Roll Motion can also be considered as another real-life example of a balancing problem.

Figure 10 – Roll Motion of the Aircraft. Similar to BBT’s counter motor action, a counter aileron movement is required to control the rolling action.

Rotation around the front to the back axis is called roll. On the outside of a wing, there are small hinged portions called ailerons. An airplane can produce a rolling motion by using its ailerons. Ailerons usually work in opposite positions. For both wings, the lift force (Fr or Fl) of the wing section through the aileron is applied at the section’s aerodynamic center, which is some distance (L) from the aircraft’s center of gravity. This creates a torque T=F x L

Figure 11: Force vectors, CoG, and Resulting Motion happening during the aircraft’s roll motion.

If the ailerons are not controlled correctly, the aircraft will move undesirably. It is exactly what happens in a 1-D ball-balancing application. It can be simulated in a controlled lab using experiment systems such as ACROME’s Ball and Beam System. The Ball and Beam System is one of the real-life applications of the rolling event. Students can experiment with this 1-D balancing application and work with the PID controllers to understand the effect of the ailerons.

Figure 12: ACROME’s Ball and Beam


You can watch using the Ball and Beam Video

You can read more on how Ball and Beam works.

Two Dimensional Balance Problem

The Acrome Ball balancing table is a good experiment for 2-D PID control.

acrome Ball Balancing Table
Figure 13: Unlike Ball and Beam, the Ball Balancing Table controls the position of the ball in 2 dimensions.

Now let’s focus on another angle of control of the airplanes: The Pitch angle. The pitch angle of the planes can be controlled by another wing set called the Elevator. Similar to the ailerons, the elevator is also controlled (up and down) to control the pitch angle of the airplanes.

Figure 14 – The elevator is used to control the pitch (the nose) angle of the airplanes.

This is analogous to controlling the ball with 2 servo motors. How can we do that? 

One of the motors can  control x dimension and the other motor control y dimension.Each motor has different PID controlersl so one motor can only control one dimension.

pitch and roll of the Acrome Ball Balancing Table’s top plate
Figure 15: The two servo motors are used to control the pitch and roll angles of the Ball Balancing Table’s top plate.

You can read more on how the Ball Balancing Table is working.

This concludes our blog about the PID controller. We hope you enjoyed this document.

Feel free to contact us with your questions or recommendations about the PID controllers.

Ball Balancing Table Maze Solver – Reinforcement Learning

The Ball Balancing Table (BBT) is a great place to start if you want to learn and gain experience with control theory firsthand. The BBT consolidates high-grade accuracy with open-source accessibility, providing students, engineers and researchers with a ecosystem to test and improve control algorithms.

This blog is about a project where we use The Ball Balancing Table to make a PID controller and Q-Learning so that it can solve a maze. In this post, we’ll be looking at the underlying principles of both the hardware and algorithm, how maze is encoded into a matrix and what kind of real-time tweaks could break beyond current-systems capabilities. Let’s dive in!

Introduction to the Ball Balancing Table (BBT)

The Ball Balancing Table (Figure 1) is a classic experiment in control systems that bridges industrial processes and DIY projects. It consists of a flat surface (the table) where a ball is placed, and the objective is to control the tilt of the table to guide the ball to specific locations. Students can learn essential control concepts, such as feedback systems, by experimenting with different types of controllers, such as PID, and adaptive control. The open-source software integration allows users to modify and test advanced control algorithms, making it a versatile tool for both academic and real-world applications.

Figure 1: Ball Balancing Table

Control System Design

In this project, we employ a PID controller (Proportional-Integral-Derivative), one of the most used control mechanisms in automation systems. The PID controller helps maintain the desired trajectory by adjusting the angles of the BBT’s platform based on feedback from the ball’s position. Here’s how it works:

  • Proportional (P): Reacts to the current error between the target and the actual position of the ball.
  • Integral (I): Accounts for accumulated past errors to reduce steady-state error.
  • Derivative (D): Predicts future error based on the current rate of change.

Together, these terms allow the table to adjust its tilt dynamically, keeping the ball within a defined path, and ultimately solving the maze.

Encoding the Maze

The maze is represented as a matrix of 0s and 1s in Python, where:

  • 0 represents open spaces.
  • 1 represents walls or obstacles.

This matrix forms the environment within which the ball must move. The goal is to guide the ball from the start position to the maze’s exit. Here’s an example matrix representation:

maze = [

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],

[1, 0, 0, 0, 1, 0, 0, 0, 0, 1],

[1, 0, 1, 0, 1, 0, 1, 1, 0, 1],

[1, 0, 1, 0, 0, 0, 0, 1, 0, 1],

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

]

The maze to be encoded is illustrated in the following figure.

Figure 2: Maze of BBT

This image is converted to a matrix using image processing. In the following step obtained grid is mapped to the coordinates of the BBT. As the ball moves, the system interprets the matrix and sends the ball to the corresponding open spaces.

Reinforcement Learning and Q-Learning

Reinforcement learning is learning what to do—how to map situations to actions—so as to maximize a numerical reward signal. The learner is not told which actions to take, but instead must discover which actions yield the most reward by trying them. In the most interesting and challenging cases, actions may affect not only the immediate reward but also the next situation and, through that, all subsequent rewards. These two characteristics—trial-and-error search and delayed reward—are the two most important distinguishing features of reinforcement learning.

One of the most common RL algorithms in areas like shortest path is Q-learning. Here’s how it works in the context of solving the maze:

  • The ball (agent) is placed at the start of the maze.
  • For each step, the agent decides which direction to move (up, down, left, or right).
  • If the move leads to a valid position, it gets a reward; if it hits a wall, it receives a penalty.
  • Over time, the agent learns which actions maximize the cumulative reward, allowing it to find the optimal path through the maze.

The Q-learning algorithm uses the following equation to update the “quality” (Q-value) of each state-action pair:

Q(state,action)=Q(state,action)+alpha (reward+gamma max(Q(newstate,allactions) )−Q(state,action)) 

Where:

  • alpha is the learning rate, determining how much new information overrides old information.
  • gamma is the discount factor, which determines the importance of future rewards.
  • reward is the feedback received from the environment after performing an action.

In our project, Q-learning enables the ball to learn and solve the maze. Once the agent (the ball) has learned the optimal path, it starts sending commands to the BBT to follow the learned trajectory.

The solution to the maze (figure 2) is illustrated in the figure below, showcasing the optimal path determined by the Q-learning algorithm. This path represents the sequence of moves that successfully navigate the maze.

In addition, the heat map visualizes the learned Q-values for each state within the maze. The map highlights the desirability of each position based on the cumulative rewards, with warmer colors indicating higher Q-values and cooler colors representing lower values.

Figure 3: Optimal Path Determined by the Algorithm            Figure 4: Heat Map of the Solution  

Working Mechanism of the BBT Maze Solver

Here’s how the maze-solving mechanism works:

  1. Initialize the environment: The maze is encoded into a matrix, and the Q-learning agent is initialized.
  2. Learn the path: The agent iterates through the maze, exploring different paths. Over time, it learns which paths lead to the goal (exiting the maze) and which result in dead ends.
  3. Send instructions to the BBT: Once the path is learned, the coordinates of each step are converted to BBT coordinates using the function maze_to_bbt_coords().
  4. Move the ball: The ball follows the learned path, controlled by the PID algorithm, which adjusts the tilt of the table based on real-time feedback from the ball’s position.

Here’s a simplified pseudocode snippet showing how the BBT receives commands to move to specific points:

#pseudocode starts here 
FUNCTION move_bbt_to_position(setpointx, setpointy):  positionx, positiony = GET current_ball_position()  # Retrieve the current position of the ball  errorx = setpointx - positionx  # Calculate the error in x-axis  errory = setpointy - positiony  # Calculate the error in y-axis 
 outputx = APPLY_PID_controller_x(errorx)  # Calculate new position for x using PID control  outputy = APPLY_PID_controller_y(errory)  # Calculate new position for y using PID control 
 SET_servo(outputx, outputy)  # Send servo commands to adjust BBT position 
    UPDATE_device()  # Update the BBT with the new position 
#End of the pseudocode 

The application source code is available in this Github repository.

The image bellow shows the Ball Balancing Table (BBT) in conjunction with the maze.

Figure 2: BBT with Maze

In the video below, a trial example outcome of the BBT maze solver with the reinforcement learning algorithm can be seen. Please note, the video is accelerated by 10x, because the RL algorithm is not optimized for speed in this example.

Real-World Applications Examples

The BBT maze solver can be seen as a scaled-down simulation of complex industrial control systems, offering several potential applications:

  • Robotics: Autonomous navigation systems, like those used in robotic vacuum cleaners, could employ similar algorithms to navigate around obstacles.
  • Game AI: The same principles can be applied in video games where non-player characters (NPCs) need to navigate complex environments.
  • Real-Time Traffic Management: In a future where AI drives vehicles, managing traffic could resemble solving a maze, with controllers needing to adapt dynamically to real-time conditions, much like the adjustments made in the BBT Maze Solver.

Future Improvements and Directions

This project offers several avenues for further development:

  1. Real-Time Maze Recalculation: By adding a camera to the top of the BBT, the system could take snapshots of the maze and dynamically adjust the path if obstacles are moved or removed in real-time.
  2. Adaptive Control Algorithms: Implementing more advanced control algorithms, like Autonomous PID tuning, controllers itself can continuously adapt their parameters with RL, allowing the system to automatically fine-tune its response to environmental changes and disturbances.
  3. Deep Reinforcement Learning: Transitioning from Q-learning to deep reinforcement learning (using neural networks) could enable the system to solve more complex mazes with greater accuracy and flexibility such as moving in diagonals.

Conclusion

The Ball Balancing Table and Q-learning provide an exciting mix of hardware and software where classic control theory meets cutting-edge machine learning techniques. Through projects like this, we can deepen our understanding of control systems, reinforcement learning, and their potential real- world applications. With continuous improvements, these algorithms can drive self-regulating traffic networks, control autonomous robots, and advance the development of intelligent gaming systems.

By exploring these concepts and implementing them in hands-on projects, we unlock new opportunities for innovation and understanding. Whether it is for a student learning control theory or a researcher experimenting with advanced machine learning algorithms, the BBT offers a fantastic platform to bring these ideas to life.

References

  1. Acrome. Ball Balancing Table.
  2. Sutton, R. S., & Barto, A. G. (2018). Reinforcement Learning: An Introduction. MIT Press.
  3. K. J. Astrom, & T. Hagglund. (2006). Advanced PID Control. ISA – Instrumentation, Systems, and Automation Society.

SMD Blockly: Visual Programming for Smart Motion Control

Introduction

Motion control programming has traditionally been a complex process requiring expertise in programming languages such as C, Python, or embedded programming. Engineers, researchers, and hobbyists needed to understand low-level motor control algorithms, hardware communication protocols, and logic structures to efficiently operate motion devices. However, the advent of visual programming tools has made motion control significantly easier and more intuitive.

One such revolutionary tool is SMD Blockly, a block-based visual programming platform developed by Acrome that enables users to control smart motion devices without writing complex code. Instead of manually writing thousands of lines of script, users can now drag and drop graphical blocks to create logical motor control sequences with ease.

Whether you are a beginner exploring robotics, an educator teaching students, an engineer developing automation solutions, or a researcher testing new motion control algorithms, SMD Blockly is a versatile tool that simplifies the process while offering a high degree of flexibility.

What is SMD Blockly?

SMD Blockly is an intuitive visual programming interface built on Google’s Blockly framework. Instead of traditional text-based programming, it allows users to program motion devices through graphical blocks that snap together, forming logical sequences that define the behavior of motors and actuators.

This approach eliminates many of the common challenges associated with traditional coding, such as syntax errors, debugging complexities, and the steep learning curve of programming languages. It also allows for rapid prototyping, making it a highly valuable tool for education, industrial automation, and robotics research.

Basic PWM motor control setup using SMD Red with SMD Blockly

Who Can Use SMD Blockly?

SMD Blockly is designed for a wide range of users, including:

 Students & Educators: Teaching motion control concepts in a user-friendly environment.

Engineers & Researchers: Quickly testing new motor algorithms and automation workflows.

Hobbyists & Makers: Building smart projects without the need for advanced programming skills.

Industry Professionals: Simplifying automation processes and integrating motion control solutions.

Official Documentation: SMD Blockly Docs

Why Use SMD Blockly?

 1. No Coding Required

  • Designed for non-programmers and beginners.
  • Build motion control logic with drag-and-drop blocks instead of writing code.

 2. Faster Prototyping and Development

  • Rapidly test and modify motion sequences.
  • Immediate feedback without debugging complex scripts.

 3. Error-Free Programming

  • No syntax errors, no typos! Blockly ensures all blocks are pre-validated.
  • Prevents logic mistakes that commonly occur in text-based programming.

 4. Customizable and Expandable

  • Advanced users can create new Blockly blocks.
  • Integrate additional features and sensors into motion sequences.

 5. Open-Source and Free to Use

  • Available on GitHub for modification and community contributions.
  • Users can contribute new features, report bugs, and expand functionalities.

GitHub Repository: Acrome SMD Blockly

How to Use SMD Blockly

Step 1: Access SMD Blockly

SMD Blockly is a Windows application, meaning it requires installation on your computer. To start using it:

  1. Download the latest version from the official SMD Blockly GitHub repository.
  2. Install the application following the on-screen instructions.
  3. Launch SMD Blockly and start exploring the visual programming interface.

Once inside SMD Blockly, you will be greeted with an intuitive workspace where you can drag, drop, and connect blocks to create motion control programs.

Step 2: Understanding the Blockly Interface

Before creating your first program, it’s essential to get familiar with the interface. The main components include:

  • Toolbox (Left Panel) – A categorized collection of blocks, including Motion, Logic, Loops, Math, and Sensors.
  • Workspace (Center Panel) – The area where you assemble your program by connecting blocks.
  • Execution Controls (Top Panel) – Contains Run, Stop, and Reset buttons to manage your program.
  • Output Console (Bottom Panel) – Displays execution messages, errors, and feedback.

Step 3: Creating Your First Program

Example 1: Setting an RGB LED Color in SMD Blockly

This example demonstrates how to configure an RGB LED module using SMD Blockly. The program sets a specific color by adjusting the red, green, and blue intensity values.

Required Blocks

  • Define Master – Sets the communication baud rate.
  • SMD Red – Defines the SMD Red module.
  • Set RGB Color – Configures the RGB LED’s color values.

Step-by-Step Implementation

  1. Set the communication settings:
    • Drag the “Define Master” block into the workspace.
    • Set the baud rate to 115200 for proper serial communication.
  2. Initialize the SMD Red module:
    • Drag the “SMD Red” block into the workspace.
    • Set the Red ID (or adjust according to your module setup).
  3. Set the RGB LED color:
    • Drag the “Set RGB Color” block into the workspace.
    • Configure the color values as follows:
      • Red ID: Corresponding to the LED module
      • Module ID: The RGB LED module’s identifier
      • Red: Red intensity
      • Green: Green intensity
      • Blue: Blue intensity
  4. Run the program:
    • Click the Run button to execute the program and observe the LED color change.
RGB LED color configuration via SMD Blockly with SMD Red

Conclusion: Why You Should Try SMD Blockly

SMD Blockly provides an easy, powerful, and flexible way to control motors visually without needing to write code. Whether you are a beginner learning motion control or an advanced user looking for customization, the platform offers intuitive motor programming, real-time execution, and scalability.

Key Takeaways

  • Drag-and-drop programming with no coding required
  • Real-time motor control and execution
  • Error-free, fast, and efficient
  • Custom block support for advanced users
  • Open-source and freely accessible

Start Now

Unlock the power of visual programming and start controlling your motion devices today.