Skip to Content
AutomationAutomation
  • Article
  • Open Access

13 March 2026

26 Pages

A Classic and Fuzzy Parallel Hybrid Controller of PD-PI Type for a Two-Wheeled Self-Balancing Robot

,
,
,
,
,
,
and
1
Facultad de Ingeniería, Universidad Autónoma de Querétaro, Santiago de Querétaro 76010, Mexico
2
Laboratorio de Control y Robótica, Facultad de Ingeniería en Electrónica y Comunicaciones, Universidad Veracruzana, Poza Rica 93390, Mexico
*
Author to whom correspondence should be addressed.

Abstract

Two-wheeled self-balancing robots (TWSBRs) are difficult to control because they are nonlinear, unstable, and underactuated, particularly when balance, velocity regulation, and line tracking must be achieved simultaneously. This paper proposes a hybrid parallel control architecture for a line-following TWSBR operating on straight segments, 90 ∘ curves, and a 15 ∘ slope. Balance stabilization is handled by a classical PD loop, while traslational velocity is regulated by an adaptive fuzzy PI controller, and line following is performed with an adaptive fuzzy PD controller. The fuzzy modules adjust the effective gains based on tracking errors, thereby improving robustness to disturbances, sensor noise, and changes in operating conditions. The complete strategy is implemented on a low-cost PIC18F4550 microcontroller. Experiments show that the fuzzy line-following controller reduces the orientation tracking error compared with a conventional controller. At 0.10 m s , RMSE decreases from 0.042 rad to 0.038 rad , and at 0.175 m s , it decreases from 0.083 rad to 0.066 rad . The fuzzy approach also improves IAE ( 1.317 rad s to 1.185 rad s ) and ISE ( 0.242 rad 2 s to 0.153 rad 2 s ) at 0.175 m s , while maintaining similar maximum error ( 0.299 rad to 0.261 rad ). Overall, the proposed hybrid scheme achieves better adaptability without retuning. These results support real-time deployment on resource-limited platforms.

1. Introduction

In recent decades, robotics has advanced significantly, driven by the development of autonomous systems, low-cost sensors, and advanced control techniques, and has established itself as a key area of modern engineering. In this field, TWSBRs, also known as inverted pendulum robots on wheels, have attracted particular interest due to their inherently unstable, nonlinear, and underactuated nature [1]. These platforms serve as an ideal testbench for validating control and estimation strategies, as their stability depends directly on the interactions among body dynamics, the actuation system, and sensory feedback [2]. TWSBRs have applications in the development of personal mobility systems, service robots, autonomous transportation platforms, and educational systems for learning automatic control [3]. However, their design and control pose significant engineering challenges, including sensitivity to external disturbances, parametric uncertainties, dynamic coupling between the roll angle and translational motion, and limitations imposed by inertial sensors and electric actuators [4,5,6].
To stabilize and control the motion of TWSBRs, various control strategies have been proposed, ranging from classical approaches to advanced and intelligent techniques. Proportional–integral–derivative (PID) controllers remain widely used due to their simplicity, low computational cost, and ease of implementation on embedded systems [7]; however, their performance is often limited by the presence of nonlinear dynamics, strong couplings, and parametric variations inherent to these platforms. On the other hand, nonlinear control techniques, optimal control, robust control, and artificial-intelligence-based methods have demonstrated significant improvements in stability and performance, albeit at the cost of greater computational complexity and stricter modeling requirements [8,9,10,11]. In this context, the hybrid combination of fuzzy controllers with classical PID schemes has emerged as an attractive alternative, leveraging the robustness and adaptability of fuzzy logic to handle uncertainties and nonlinearities while preserving the simple, efficient structure of the PID controller [12,13,14]. This makes it particularly suitable for stabilizing and controlling inverted pendulum robots.
Several authors have incorporated fuzzy logic as an alternative or complement to traditional PID control [15]. In particular, Mamdani-type fuzzy control schemes and fuzzy-PD controllers have been proposed, in which fuzzy logic enables modeling of the system’s nonlinear behavior and handling uncertainty without requiring a precise mathematical model. Ref. [16] demonstrated that a fuzzy controller can improve the stability and smoothness of a balancing robot’s response to disturbances, compared to conventional PID. Similarly, Ref. [17] reported that a fuzzy-PID scheme exhibits reduced overshoot and improved rejection of sensor noise, especially during start-up and recovery.
More recently, a trend toward hybrid fuzzy-PID structures has emerged, in which fuzzy logic is used either to self-adjust PID gains or to directly control critical system variables, such as the roll or balancing angle. In contrast, classical PID control is typically employed to regulate translational position. Ref. [18] proposed a computationally low-cost fuzzy-PD controller implemented using lookup tables, demonstrating that it is possible to achieve performance comparable to or better than classical PID control without significantly increasing hardware requirements. In a similar context, recent experimental studies on two-wheeled balancing robots have highlighted the practical benefits of fuzzy-logic-based controllers when implemented on embedded platforms, emphasizing their robustness, ease of implementation, and adaptability to real-world disturbances [19]. These works report successful stabilization and recovery under varying operating conditions, reinforcing the suitability of fuzzy-enhanced and hybrid control strategies for balancing robots running on microcontrollers or other resource-constrained embedded systems.
On the other hand, Ref. [20] addresses the control of a two-wheeled balancing robot using a fuzzy-logic-based controller, with an emphasis on experimental evaluation on a real physical platform. The control architecture directly regulates the stability of the balancing angle, prioritizing robustness and adaptability to changes in operating conditions. The controller design relies on intuitive linguistic rules and simple membership functions, facilitating its implementation on embedded platforms and its empirical tuning. In [21], an adaptive fuzzy controller is integrated into a complete navigation framework that combines perception, path planning, and control for TWSBRs. The controller ensures asymptotic stability and accurate trajectory tracking, while showing strong robustness against disturbances and parameter uncertainties. Both simulation and experimental results demonstrate superior performance over classical PID and conventional fuzzy controllers in terms of settling time, steady-state error, and disturbance rejection, confirming the suitability of adaptive fuzzy strategies for real-time embedded applications. Beyond conventional hybrid fuzzy-PID configurations, more advanced combinations integrating fractional-order calculus have also been investigated to further enhance robustness and disturbance rejection. In [22], a fuzzy fractional-order PID (FFOPID) controller is proposed for TWSBRs operating on inclined surfaces, where fuzzy logic is employed to adaptively tune the fractional integral and derivative orders as well as the controller gains. The study demonstrates, through comparative simulations with PID, FPID, and FOPID controllers, that the FFOPID structure achieves smaller overshoot, shorter settling time, and superior anti-disturbance capability, particularly under changes in slope angle and external perturbations.
The contributions of this paper are listed as follows:
  • This work proposes an adaptive fuzzy control scheme for velocity regulation, line following, slope transversal, and sharp 90 ∘ curve tracking, aiming to improve the dynamic response of a robotic system compared to classical control approaches.
  • A parallel control architecture is developed, in which one control loop balances the robot, the second loop controls velocity, and the third one is dedicated to line following.
  • An adaptive fuzzy inference mechanism is employed to compensate for system nonlinearities and external disturbances online, thereby enhancing robustness and tracking performance.
  • The implementation of the adaptive fuzzy controller enriches the scientific literature on the different tuning configurations that can be achieved and what is expected over a robotic system.
  • The proposed control strategy is designed with a focus on computational efficiency and implementation on a low-cost and resource-constrained microcontroller (PIC18F4550).
  • The experimental methodology proposes a way to test the TWSBR using a test track that introduces different challenging scenarios, making it efficient for designing robust controllers.
This paper is organized as follows: Section 2, Theoretical Foundation, presents the dynamical model of the TWSBR, including the linear and nonlinear representation and the classical control strategy proposed for the work. In addition, the methodology is provided, including an explanation of the fuzzy logic controller as the main focus of the work, the structure and application of the fuzzy controller on the robot, and how the experimentation is conducted. Section 3, Materials and Methods, presents the fundamental elements for the experimental implementation, including the design and composition of the TWSBR and the test track used to obtain data and test the robot’s control. Section 4, Results, provides the data recovered from the experimentation analysis, including the fuzzy controller configuration used and the graphs obtained in multiple experimental scenarios. Section 5, Discussion, provides a more detailed inspection of the results obtained in the paper as well as a mention of the state of the art. Section 6, Conclusions, summarizes the fundamental aspects of the work and promotes further investigation by proposing future work.

2. Theoretical Foundation

2.1. TWSBR Nonlinear Model

The schematic diagram, with reference frames and main conventions of the two-wheeled pendulum, is shown in Figure 1.
Figure 1. TWSBR free-body diagram [23].
The nonlinear dynamic model of the two-wheeled pendulum obtained with the Euler–Lagrange equations is given by [23]:
M ( q ) q ¨ + C ( q , q ˙ ) q ˙ + g ( q ) = B ( q ) τ
q = [ x o y o θ α ϕ r ϕ l ] T
M ( q ) = M p ( 1 + tan 2 ( β ) ) 0 Δ 1 Δ 2 0 0 0 M p Δ 3 Δ 4 0 0 Δ 1 Δ 3 Δ 5 0 0 0 Δ 2 Δ 4 0 M p C z 2 + I y y 0 0 0 0 0 0 M w R 2 + I w a 0 0 0 0 0 0 M w R 2 + I w a
Δ 1 = − M p C z sin ( α ) sin ( θ )
Δ 2 = M p C z ( cos ( α ) cos ( θ ) − sin ( α ) tan ( β ) )
Δ 3 = M p C z sin ( α ) cos ( θ )
Δ 4 = M p C z cos ( α ) sin ( θ )
Δ 5 = M p C z 2 + I x x sin 2 ( α ) + I z z cos 2 ( α ) + 2 I w d
C ( q , q ˙ ) = 0 0 Γ 1 Γ 2 0 0 0 0 Γ 3 Γ 4 0 0 0 0 Γ 5 Γ 6 0 0 0 0 − Γ 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Γ 1 = − M p C z ( θ ˙ sin ( α ) cos ( θ ) + α ˙ sin ( θ ) cos ( α ) )
Γ 2 = − M p C z ( θ ˙ sin ( θ ) cos ( α ) + α ˙ sin ( α ) cos ( θ ) + α ˙ cos ( α ) tan ( β ) )
Γ 3 = − M p C z ( θ ˙ sin ( α ) sin ( θ ) − α ˙ cos ( α ) cos ( θ ) )
Γ 4 = M p C z ( θ ˙ cos ( α ) cos ( θ ) − α ˙ sin ( α ) sin ( θ ) )
Γ 5 = ( M p C z 2 + I x x − I z z ) α ˙ sin ( α ) cos ( α )
Γ 6 = ( M p C z 2 + I x x − I z z ) θ ˙ sin ( α ) cos ( α )
g ( q ) = ( M p + 2 M w ) g tan ( β ) 0 0 − M p C z g sin ( α ) 0 0
B ( q ) = 0 0 0 0 0 0 − 1 − 1 1 0 0 1
τ = τ r τ l
where the coordinates of point O are ( x o , y o ) ; τ r is the torque applied to the right wheel; τ l is the torque applied to the left wheel; β is the angle of a slope that the robot climbs as it moves forward; R is the radius of the wheel; g = 9.81 m s 2 is the acceleration due to gravity; M p is the mass of the pendulum; C z is the distance from the center of mass of the pendulum to the point O; b is the distance from point O to point O w ; I x x is the moment of inertia calculated around the x b axis; I y y is the moment of inertia calculated around the y b axis; I z z is the moment of inertia calculated around the z b axis; I w d is the moment of inertia of the wheel about its diameter; I w a is the moment of inertia of the wheel about its axis; M w is the complete mass of the wheel (tire, rim, coupling, and rotor); ϕ r is the rotation angle of the right wheel; ϕ l is the rotation angle of the left wheel; α is the angle of inclination of the pendulum; θ is the robot’s orientation angle; and v is the translational velocity of the robot, given as:
v = R 2 ϕ ˙ r + ϕ l ˙
The orientation velocity of the wheeled pendulum is given by:
θ ˙ = R 2 b ϕ ˙ r − ϕ l ˙

2.2. TWSBR Simplified Linearized Model

When the robot performs the line-following task on a track (the desired trajectory line), measurements of the coordinates ( x o , y o ) of the point O are not necessary, since these variables are indirectly controlled when the desired trajectory is followed. The same applies to the positions of the robot’s wheels. Taking advantage of the above, it is possible to find a simplified model. Linearizing the robot’s non-holonomic constraints model, assuming β = 0 and α ≈ 0 , which implies cos ( α ) ≈ 1 , sin ( α ) ≈ α , and defining parameter I ϕ as in [23]:
I ϕ = M w R 2 + I w a
The traslational acceleration of the robot is found as:
I ϕ v ˙ = R 2 τ r + τ l
Linearizing the model in (1) gives the orientation and inclination dynamics as:
[ d 5 + I ϕ ] θ ¨ = R 2 b τ r − τ l
α ¨ − σ 1 M 22 α = − σ 2 τ r + τ l
with the corresponding parameters
d 5 = I z z + 2 I w d
M 22 = M p C z 2 + I y y
σ 1 = g M p C z
σ 2 = 1 M 22 M p C z R 2 I ϕ + 1
Thus, the simplified linearized model [23] of the TWSBR is given by (22)–(24).

2.3. Line-Tracking Controller

The proportional controller with angular velocity feedback for line tracking (robot orientation) is defined as follows [23]:
τ a = τ r − τ l = 2 b R − k v θ ˙ − k p θ ˜ , θ ˜ = θ − θ d
where k p and k v are gains, and  θ d is a constant that represents the desired value of robot orientation. Substituting (29) into (23) results in the following:
[ d 5 + I ϕ ] θ ¨ + k v θ ˙ + k p θ = k p θ d
Thus, if the coefficients of the second-order linear dynamic system in (30) are greater than zero, it ensures that θ ˙ → 0 and θ → θ d , and it requires k p > 0 and k v > 0 .

2.4. Inclination and Translational Velocity Differential Flatness-Based Controller

Now consider the following function, which is known as the flat output [23]:
y f = M 22 α + σ ∫ 0 t v ˜ ( r ) d r , σ = M p C z + 2 R I ϕ , v ˜ = v − v d
where v d is a constant and represents the desired value of the translational velocity of the robot. Differentiating (31) with respect to time three consecutive times and substituting algebraic expressions into (22) and (24), and using the definitions in (28) and (31), it is possible to obtain [23]:
y ˙ f = M 22 α ˙ + σ v ˜
y ¨ f = σ 1 α
y ⃛ f = σ 1 α ˙
Defining the control effort u as follows [23]:
u = τ r + τ l
Thus, using Equations (24), (33) and (35), the analog simulation diagram of Figure 2 can be constructed:
Figure 2. Analog simulation diagram of Equations (24) and (33).
Applying the Laplace transform to the diagram in Figure 2 yields the simplified block diagram shown in Figure 3 [23].
Figure 3. Simplified block diagram of Figure 2.
Since Figure 3 shows a fourth-order system, it is possible to arbitrarily assign the four closed-loop poles by feeding back y f , y ˙ f , y ¨ f , and  y ⃛ f . This can be achieved with the closed-loop system in Figure 4 [23]:
Figure 4. Closed-loop system block diagram.
Because the zeros are located at z 1 , z 2 , and z 3 in the feedback path of Figure 4, the following state’s feedback results in [23]:
U ( s ) = k ( s − z 1 ) ( s − z 2 ) ( s − z 3 ) Y f ( s )
which in a polynomial way is given by:
U ( s ) = k ( s 3 + a 2 s 2 + a 1 s + a 0 ) Y f ( s )
which implies:
s 3 + a 2 s 2 + a 1 s + a 0 = ( s − z 1 ) ( s − z 2 ) ( s − z 3 )
Using the inverse Laplace transform, we obtain:
u = k y ⃛ f + k a 2 y ¨ f + k a 1 y ˙ f + k a 0 y f
Thus, substituting Equations (31)–(34) into Equation (39) yields:
u = k 1 α ˙ + k 2 α + k 3 v ˜ + k 4 ∫ 0 t v ˜ ( r ) d r
where:
k 1 = k ( σ 1 + a 1 M 22 )
k 2 = k ( a 2 σ 1 + a 0 M 22 )
k 3 = k a 1 σ
k 4 = k a 0 σ
Once the zeros are positioned at z 1 , z 2 , and  z 3 , the value of k can be found using the diagram in Figure 5 with the root locus method, which allows the assignment of the four closed-loop poles in the stable region:
Figure 5. Block diagram of the closed-loop system with negative feedback, U n ( s ) = − U ( s ) .
Because the robot has two actuators (right wheel motor and left wheel motor), it is necessary that the control efforts τ a in Equation (29) and u in Equation (35) command these actuators, so their relationship with τ r and τ l is given by [23]:
τ a u = Q τ r τ l , Q = 1 − 1 1 1
Since d e t ( Q ) = 2 then Q − 1 exists, and to calculate τ r and τ l as a function of τ a and u, the following is required:
τ r τ l = Q − 1 τ a u , Q − 1 = 1 2 1 2 − 1 2 1 2
Thus, the torques applied to the robot’s wheels are:
τ r = τ a 2 + u 2
τ l = − τ a 2 + u 2

2.5. Classic Control Strategy

Starting from the controllers defined in Equations (29) and (40), together with the torque distribution relations given in Equations (47) and (48), the desired operating conditions are established as θ d = 0 for the orientation and α d = 0 for the inclination, while a constant desired translational velocity v d is considered. Accordingly, the error signals are defined as the inclination error e i = α d − α = − α , the orientation error e o = θ d − θ = − θ ˜ , and the translational velocity error e v = v d − v = − v ˜ . Furthermore, the controller gains are redefined as k p o = k p , k d o = k v , k d i = k 1 , k p i = k 2 , k p v = k 3 , and  k i v = k 4 . With these definitions, the overall control law can be reformulated into a classical parallel control structure composed of two PD controllers and one PI controller acting on the orientation, inclination, and translational velocity loops, respectively, as shown in Figure 6.
Figure 6. Classic control strategy for TWSBR.

2.6. Fuzzy Parallel Hybrid Controller of PD-PI Type

The proposed control strategy is based on a parallel hybrid control architecture designed for a TWSBR. The architecture integrates classical and adaptive intelligent controllers to simultaneously address balance stabilization, translational velocity regulation, and trajectory tracking, while traversing paths with varying curvature and slope conditions. This parallel control structure enables the simultaneous handling of multiple control objectives according to their dynamic relevance. The primary objective is to ensure the robot’s balance stabilization, which involves fast, critical dynamics. Secondary objectives, namely translational velocity regulation and trajectory tracking, are addressed through slower control loops that exhibit higher nonlinearities and uncertainties.
The balance stabilization of the robot is achieved using a classical proportional–derivative (PD) controller, selected due to its simplicity, robustness, and low computational cost. The use of a classical controller in this loop is justified by the relatively low complexity of the balancing task when compared to higher-level objectives and by the need for fast real-time execution.
The balance control law is defined in Equation (49).
U i ( s ) = k p i E i ( s ) + k d i s E i ( s )
where E i ( s ) represents the robot error tilt angle. This controller is responsible for rejecting disturbances and maintaining system stability independently of the velocity and trajectory control objectives.
The translational velocity control may exhibit nonlinear behavior due to actuator saturation, friction effects, and coupling with the balancing dynamics. To address these challenges, an adaptive fuzzy PI controller is employed.
The velocity control law is defined in Equation (50).
U v ( s ) = k p v E v ( s ) + k i v 1 s E v ( s )
k p v = ∑ i = 1 M μ i ( E v ( s ) ) Q u i ∑ i = 1 M μ i ( E v ( s ) )
k i v = ∑ j = 1 N μ j ( 1 s E v ( s ) ) O u j ∑ j = 1 N μ j ( 1 s E v ( s ) )
where k p v and k i v are adaptive gains determined by the E v ( s ) .
The fuzzy controller is implemented in the velocity loop due to the higher uncertainty and variability observed during experimental operation. This approach allows adaptive behavior while preserving the stability guaranteed by the classical balance controller.
In Table 1 and Table 2, the rules for the velocity fuzzy system are seen. The number of rules was chosen by minimizing them while maintaining a robust response, while tracking the desired velocity and traversing the slopes. It is important to mention that the outputs k i v were proposed to ensure a robust response when ascending and descending the slope, meaning that they are chosen with higher gains when in the presence of error to obtain a braking response when descending the slope and a much greater force when ascending. This is a virtue of fuzzy systems, because it allows one to characterize certain conditions and react accordingly.
Table 1. Fuzzy rule structure for adaptive PI velocity controller ( k p v ).
Table 2. Fuzzy rule structure for adaptive PI velocity controller ( k i v ).
For trajectory tracking and line-following tasks, an adaptive fuzzy PD controller is also implemented. This controller compensates for non-linearities caused by sensor noise, path curvature variations, and changes in translational velocity.
The line-following control law is given by Equation (53).
T a = k p o E o ( s ) + k d o s E o ( s )
k p o = ∑ i = 1 M μ i ( E o ( s ) ) P u i ∑ i = 1 M μ i ( E o ( s ) )
k d o = ∑ j = 1 N μ j ( s E o ( s ) ) D u j ∑ j = 1 N μ j ( s E o ( s ) )
where k p o and k d o are adaptive gains determined by E o ( s ) .
Similar to the velocity loop, a fuzzy-based approach is adopted for trajectory tracking to account for the inherent uncertainties in path geometry and environmental conditions, without requiring an explicit nonlinear system model.
In Table 3 and Table 4, the rules for the tracking fuzzy system are seen. The number of rules for the proportional system is considerably larger, because it is designed to maintain a proper response regardless of the track condition, such as a more aggressive response on curves and a more passive response on straight lines. Meanwhile, for the derivative system, the proposed rules tend to attenuate oscillations and reduce tracking error.
Table 3. Fuzzy rule structure for adaptive PD line-following controller ( k p o ).
Table 4. Fuzzy rule structure for adaptive PD line-following controller ( k d o ).
The adaptive fuzzy controllers employed in this work are based on a Mamdani-type inference system. This choice is motivated by its reduced computational complexity when compared to traditional or more complex fuzzy control schemes, such as Takagi–Sugeno models with higher-order consequents. The Mamdani approach uses simple linguistic rules and membership functions, resulting in fewer arithmetic operations during inference and defuzzification. In addition, a dynamic group of control gains is proposed that can change depending on the case scenario when traversing different trajectories and slope conditions. For the membership functions, it is proposed to use trapezoidal and triangular functions due to their low computational cost and efficiency for describing the discourse universe and computing the control response. The discourse universe of each fuzzy system is obtained by taking samples of the TWSBR during the different conditions of the track.
Figure 7 presents the diagram of the fuzzy controller implemented over the TWSBR.
Figure 7. TWSBR fuzzy controller.

3. TWSBR Platform and Experimental Setup

3.1. TWSBR Design

The TWSBR design for this work is inspired by the traditional architecture of this type of robot, characterized by a modular build composed of multiple floors that support the system’s electronic components. In Figure 8, a diagram of the TWSBR used in this work is shown, where the different mechanical and electronic components and their distances are measured in relation to the wheel axis. It is important to mention that the robot was built with a certain elevated height and that the components with more mass were positioned at the top, because this provides a slower falling dynamic for the pendulum, making it feasible at the time of designing the control laws. The masses of each component in the TWSBR are listed in Table 5.
Figure 8. TWSBR layout diagram.
Table 5. Masses of the TWSBR components.
In Figure 9, the electronic connection diagram used to build the TWSBR is shown; likewise, the components of the system are also presented. The PIC18F4550 serves as the main processing unit for sensor inputs, output commands, and control calculations. As part of the sensors, the MPU6050 works as the gyroscope to obtain the tilt angle of the robot and verify the pendulum stability; the TCRT5000 are used as the line-following analog sensors and are positioned facing each other to detect if the robot is centered to the white line; the HC-06 is a Bluetooth module that sends the data to the computer wirelessly when making the lap on the test track, and to calculate the traslational velocity of the robot, it is used as an encoder that it is situated on each DC motor. As part of the actuators, the main actuators are the DC motors that maintain the pendulum stability, and an H-bridge is also used to control the direction and voltage supplied to the motors.
Figure 9. TWSBR connection diagram.
The PIC18F4550 operates with a 20 MHz external crystal oscillator and an internal phase-locked loop (PLL), resulting in a frequency of 48 MHz . The PIC18F architecture specifies that commands are executed at one-fourth the oscillator frequency, yielding a cycle frequency of 12 MHz [24]. This frequency was proven effective when working with fuzzy strategies at a time sample of 10 ms .
The pseudocode presented in Algorithm 1 outlines the general control strategy implemented in the TWSBR for system evaluation.
Algorithm 1 TWSBR Control Algorithm
1:
Initialize sensors, encoders, and controller parameters
2:
Set sampling period
3:
while TWSBR is operating do
4:
      Acquire sensor measurements (Tcrt5000, IMU)
5:
      Read encoder counts
6:
      Compute wheel angular velocities
7:
      Estimate robot inclination
8:
      Compute system states:
9:
          Inclination α
10:
        Orientation θ
11:
        Velocity v ˜
12:
    Update derivative and integral terms
13:
    Compute control action
14:
    if adaptive fuzzy controller then
15:
        Evaluate membership functions
16:
        Apply fuzzy inference
17:
        Update controller gains
18:
    else
19:
        Apply classical control law
20:
    end if
21:
    Compute torque commands for each wheel
22:
    Convert torques to motor voltages
23:
    Apply PWM signals to motors
24:
    Transmit system variables through serial interface
25:
    Wait until next sampling instant
26:
end while

3.2. Test Track Design

To conduct proper experimentation, a test track is used that features a white line in the middle for line following, 90 ∘ curves to the right and left, and a sloped plane at the top for climbing and descending. The slope considered has a 15 ∘ incline, which is sufficient for the robot to ascend and descend. Figure 10 shows the test track and the dimensions for the build.
Figure 10. Line-Following Path Design.

4. Results

The experimental results were obtained by positioning the TWSBR on the test track and analyzing its behavior as it traversed it. In Figure 11, the TWSBR is observed on different segments of the test track. It is important to note that the pendulum position differs when the robot is on a plane surface rather than on a slope, and this is due to the controller’s robustness, which adapts the pendulum’s tilt angle to the effort required by the slope.
Figure 11. TWSBR on the test track: (a) top view, (b) lateral view, (c) ascend, (d) descend.
The first experimental test focused on determining the adaptability of the fuzzy line-following controller compared to the classical controller. The experiments were determined by taking a single lap by using the whole test track, and it was determined to use different traslational velocities due to the impact that it has on the line-following tasks. For both the classical and fuzzy control, balancing gains ( k p o , k d o ) and velocity gains ( k p v , k i v ) were used, as seen in the Table 6. For the classical controller, a different set of gains is used for the line-following loop, seen in the Table 7. The system was not able to track the line when the traslational velocity was modified. The starting point for these gains was theoretically calculated using the masses and distances of the TWSBR and analyzed using its root locus to avoid instability.
Table 6. Balancing and velocity gains.
Table 7. Line-following gains used for the conventional controller.
In contrast to the classical controller, the fuzzy line-following controller needed only one set of parameters to work on different traslational velocities. Table 8 shows the fuzzy rules declared for k p o , and Table 9 shows the fuzzy rules declared for k d o . These rules were chosen based on heuristic knowledge. The gains of each system were based over the installed capacity of each CC motor, in order to avoid saturation.
Table 8. Fuzzy system parameters for k p o .
Table 9. Fuzzy system parameters for k d o .
Figure 12 shows the fuzzy input rules and how the line-following control gains behave depending on the presence of error. The control surface of this fuzzy controller is also presented.
Figure 12. Fuzzy rules and control surface for the fuzzy line-following controller.
The experimental graphs obtained from the TWSBR consider the traslational velocity (v), the orientation ( θ ), the tilt angle ( α ), the velocity ( ω ), and the voltage (u) supplied to each wheel. For the line-following controller, it is important to note that in the orientation graph, every peaked segment corresponds to a curve. Meanwhile, for the velocity controller, it is important to see the velocity tracking.
The traslational velocities chosen for the first experimental test were 0.1 m s and 0.175 m s , because these were found to be appropriate for the low/high velocities and because these velocities were the maximum that the robot reached before saturation on the control response. Figure 13 and Figure 14 present experimental graphs of the classical and fuzzy controllers, respectively, at 0.1 m s .
Figure 13. Experimental response of the classical line-following controller at 0.1 m s .
Figure 14. Experimental response of the fuzzy line-following controller at 0.1 m s .
Figure 15 presents a case where the classical controller without tuning was not able to complete the test track when the traslational velocity changed. This is seen in graph α , where the system eventually collapsed and lost balance.
Figure 15. Performance of the classical line-following controller at 0.175 m s without tuning.
Figure 16 and Figure 17 present the experimental graphs of the classical and fuzzy controllers, respectively, at 0.175 m s .
Figure 16. Experimental response of the classical line-following controller at 0.175 m s .
Figure 17. Experimental response of the fuzzy line-following controller at 0.175 m s .
Table 10 presents a comparison of both controllers, where the line-following controller performance was measured in terms of its error ( e o ). At a low speed of 0.10 m s , the fuzzy controller achieves a lower RMSE ( 0.0380 rad ) and ISE ( 0.0897 rad 2 s ) than the conventional approach ( 0.0424 rad and 0.1089 rad 2 s , respectively), indicating improved tracking accuracy and reduced accumulated squared error. Although the conventional controller exhibits a slightly smaller IAE at this velocity, both controllers show comparable maximum errors. At a higher speed of 0.175 m/s, the advantages of the fuzzy controller become more pronounced, yielding a significant reduction in RMSE ( 0.0663 rad vs. 0.0833 rad ), IAE ( 1.1852 rad s vs. 1.3167 rad s ), ISE ( 0.1529 rad 2 s vs. 0.2424 rad 2 s ), and maximum error ( 0.261 rad vs. 0.299 rad ). These results demonstrate that the fuzzy line-following controller provides superior robustness and tracking performance, particularly as translational velocity increases.
Table 10. Performance comparison of the line-following controller.
The second experimental test focused on the versatility of the fuzzy velocity controller compared to the classical controller when moving up and down the slope, because the velocity controller is responsible for generating the control response during ascent and descent and for stabilizing the robot on the plane surface. The classical controller maintained the same tuning as in the previous experiment. The fuzzy controller maintained the previous line-following fuzzy controller with the addition of the velocity fuzzy controller.
Table 11 shows the fuzzy rules declared for k p v , and Table 12 shows the fuzzy rules declared for k i v . As previously mentioned, the classical gains were chosen based on the stability indicated by the root locus analysis; the fuzzy gains were maintained in a close region to these gains to maintain stability; and the gains were then tuned heuristically within this region.
Table 11. Fuzzy system parameters for k p v .
Table 12. Fuzzy system parameters for k i v .
In Figure 18, the fuzzy input rules and how the line-following control gains behave depending on the presence of error can be observed, as well as a control surface of this fuzzy controller.
Figure 18. Fuzzy rules and control surface for the fuzzy velocity controller.
The experimental graphs obtained from the TWSBR contain the same information as the line-following tests, but they include three segments: the ascending, the plane output, and the descending. Each requires specific control responses due to gravity and stability after exiting the slope.
Figure 19 and Figure 20 present the classical and fuzzy controller, respectively, at 0.1 m s . The ascending segment goes up to 6 s, the plane output up to 10 s, and the descending up to 14 s.
Figure 19. Experimental response of the conventional velocity controller at 0.1 m s .
Figure 20. Experimental response of the fuzzy velocity controller at 0.1 m s .
Figure 21 and Figure 22 present the classical and fuzzy controller, respectively, at 0.15 m s . The ascending segment goes up to 5.5 s, the plane output up to 7.6 s, and the descending up to 10.6 s.
Figure 21. Experimental response of the conventional velocity controller at 0.15 m s .
Figure 22. Experimental response of the fuzzy velocity controller at 0.15 m s .
Table 13 presents a comparison of both controllers, where the velocity controller performance was measured in terms of its error ( e v ). At 0.10 m s , both controllers exhibit very similar behavior, with comparable RMSE, IAE, ISE, and maximum error values, indicating that either strategy can satisfactorily regulate velocity at low speeds. When the desired velocity increases to 0.15 m s , the fuzzy controller shows a consistent improvement over the conventional scheme, achieving lower RMSE ( 0.1828 m s vs. 0.1928 m s ), IAE ( 1.6995 m s 2 vs. 1.7451 m s 2 ), and ISE ( 0.3800 m 2 s 2 vs. 0.4067 m 2 s 2 ). This behavior suggests that the fuzzy velocity controller offers better adaptability to changes in operating conditions, particularly as the translational speed increases.
Table 13. Performance comparison of the velocity controller.

5. Discussion

This work presented the design and experimental validation of a TWSBR capable of maintaining stability while performing translational motion and line-following tasks over trajectories that include straight segments, tight curves, and ascending and descending slopes. The main contribution of this paper is a comparative analysis between a classical control architecture and a fuzzy-logic-based control approach, with particular emphasis on traslational velocity regulation and line-following performance while preserving a conventional balance stabilization loop. Additionally, this study demonstrates the feasibility of implementing fuzzy-based control strategies on a resource-constrained microcontroller such as the PIC18F4550, highlighting its suitability for low-cost embedded platforms.
Recent research on TWSBRs has primarily focused on balance stabilization and relatively simple tasks. In contrast, the present work expands the experimental scope by considering simultaneous line following, translational motion, and slope traversal using adaptive fuzzy control schemes. A similar study is reported in [18], where a fuzzy-PD controller is implemented on a low-cost microcontroller for balance stabilization; however, only basic tasks are considered. In [8], metaheuristic algorithms are employed for offline optimization of an LQR controller, achieving improved stabilization performance at the expense of requiring an accurate model and higher computational resources. Meanwhile, Ref. [19] presents a fuzzy-logic-based controller that demonstrates robustness for real-time balancing, although more complex tasks, such as trajectory tracking, are not addressed. Another relevant contribution is [25], where a TWSBR is used within a SLAM-based agricultural monitoring system, and fuzzy control is adopted to enhance robustness on uneven terrain. A direct numerical comparison with these works is not feasible, since most existing studies evaluate performance mainly in terms of tilt angle or balance deviation, without considering additional metrics such as translational velocity tracking or line-following accuracy. In the present work, a small steady tilt is intentionally allowed to enable forward motion.
Regarding experimental performance, the classical control architecture exhibited adequate balance stabilization and acceptable line-following behavior at low translational velocities, as shown in Figure 13. However, abrupt changes in velocity significantly degraded tracking performance, particularly on tight 90 ∘ curves, leading to failure to complete the test track (Figure 16). Restoring satisfactory performance required retuning the controller gains for higher velocities (Figure 21), which is evidence of the limited robustness of the classical approach.
In contrast, the fuzzy line-following controller maintained stable operation under different traslational velocities without retuning, as illustrated in Figure 14 and Figure 17. This behavior is attributed to the error-dependent adaptive gains, which allow the controller to apply more aggressive actions on curves and smoother actions on straight segments. Furthermore, Table 10 shows that the fuzzy controller consistently achieves lower tracking errors than the classical controller, confirming its superior adaptability and robustness.
Multiple studies have investigated the control of a TWSBR operating on inclined surfaces, as seen in Table 14. For instance, Ref. [26] proposes a cascaded PID controller to stabilize the robot while on slopes. Similarly, Ref. [27] presents a TWSBR implementing an adaptive controller to ensure stability while operating on unknown slopes. In other related work, Ref. [28] presents a unicycle self-balancing robot by using a LQR, providing stabilization over slopes and forward motion. In general, these studies are focused on maintaining balance on uneven terrains. In contrast, the approach of the current work is to address a more demanding challenge. Besides stabilizing the robot and ascending/descending slopes during motion, the proposed controllers, in a parallel way, perform trajectory tracking and velocity regulation at high translational speeds compared to other works. In addition, in this work, highly demanding control is achieved with limited computational resources (specifically, the PIC18F4550).
Table 14. Comparison of balancing robots operating on sloped surfaces.

6. Conclusions

This study proposed a comparison between a classical and a fuzzy-logic control architecture for a TWSBR with the capacity for self-balancing, line following, slope climbing, and slope descending. An adaptive-gains-type fuzzy logic controller was considered to explore the controller’s adaptability across different case scenarios when traversing a test track. The experimental results demonstrated that the fuzzy controller can improve the system’s response by adapting its gains.
The first comparative analysis focused on the fuzzy line-following controller, which lacked robustness and required retuning when the velocity changed. In contrast, the fuzzy controller only requires an established fuzzy controller to work in several velocities. For the second comparison, the slope segment was used to verify the velocity controller, where the classical and fuzzy controllers behaved similarly, with the fuzzy controller reducing oscillations during descent.
Between the line-following and velocity fuzzy controllers, it is important to mention that the line-following one demonstrated a better performance than the velocity controller, despite demonstrating adaptability. For this reason, it is proposed to continue working on the fuzzy line-following controller.
For future work, it is proposed to continue developing the fuzzy line-following controller and to explore the system’s adaptability across different test tracks and by making further changes to the following, while continuing to investigate the use of dynamic gains and their impact on adaptability.

Author Contributions

Conceptualization, R.R.-G., R.V.C.-S. and J.R.G.-M.; methodology, R.R.-G., R.V.C.-S. and J.R.G.-M.; software, R.R.-G., T.M.-S. and J.A.R.-M.; validation, M.T.-P., J.G.R.-M. and J.R.-R.; formal analysis, R.R.-G., R.V.C.-S. and J.R.G.-M.; investigation, R.R.-G., T.M.-S. and J.A.R.-M.; resources, J.R.-R., R.V.C.-S. and J.R.G.-M.; data curation, M.T.-P., J.G.R.-M. and J.R.-R.; writing—original draft preparation, R.R.-G., R.V.C.-S. and J.R.G.-M.; writing—review and editing, T.M.-S., M.T.-P. and J.G.R.-M.; visualization, R.R.-G., T.M.-S. and J.A.R.-M.; supervision, J.R.-R., R.V.C.-S. and J.R.G.-M.; project administration, R.R.-G., R.V.C.-S. and J.R.G.-M.; funding acquisition, R.R.-G., R.V.C.-S., J.R.G.-M., M.T.-P., J.G.R.-M. and T.M.-S. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Data Availability Statement

Data are contained within the article.

Acknowledgments

Ricardo Rojas Galván (CVU:2154185) and Josue Adad Romero Moreno (CVU:1358181) are thankful for the financial support provided by SECIHTI as part of the Master in Science of Embedded Systems and Control at Universidad Autónoma de Querétaro. Grammarly 1.155.0.0 was used to perform grammar and language checks of the manuscript.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations/symbols are used in this manuscript:
TWSBRTwo-wheeled self-balancing robot
USBRUnicycle self-balancing robot
PIDProportional–integral–derivative
LQRLinear quadratic regulator
MFMembership function
PLLInternal phase-locked
PO-VPProportional orientation—very positive
PO-PProportional orientation—positive
PO-ZProportional orientation—zero
PO-NProportional orientation—negative
PO-VNProportional orientation—very negative
DO-PDerivative orientation—positive
DO-ZDerivative orientation—zero
DO-NDerivative orientation—negative
PV-PProportional velocity—positive
PV-ZProportional velocity—zero
PV-NProportional velocity—negative
IV-PIntegral velocity—positive
IV-ZIntegral velocity—zero
IV-NIntegral velocity—negative
RMSERoot rean square error
IAEIntegral absolute error
ISEIntegral square error
Symbols
τ r Right wheel torque
τ l Left wheel torque
β Slope angle
RWheel radius
gGravity
M p Mass of the pendulum
M w Mass of the wheel
IMoment of inertia
ϕ r Right wheel rotation angle
ϕ l Left wheel rotation angle
α Pendulum’s inclination angle
α d Desired pendulum’s inclination angle
θ Robot’s orientation angle
θ d Desired robot’s orientation angle
vTranslational velocity of the robot
v d Desired translational velocity of the robot
kController gains
k p i , k d i Balancing gains
k p v , k i v Velocity gains
k p o , k d o Tracking gains
uControl effort
e i Inclination error
e o Orientation error
e v Velocity error

References

  1. Zhang, H.; Mohamad Nor, N. Control strategies for two-wheeled self-balancing robotic systems: A comprehensive review. Robotics 2025, 14, 101. [Google Scholar] [CrossRef] [Scilit]
  2. Mon, Y.J. Image-Tracking-Driven Symmetrical Steering Control with Long Short-Term Memory for Linear Charge-Coupled-Device-Based Two-Wheeled Self-Balancing Cart. Symmetry 2025, 17, 747. [Google Scholar]
  3. Gadekar, A.; Sawant, S.; Potode, I.; Sharma, A.; Nikam, S.; Patel, V.; Barve, S. Recent developments in the applications of two-wheeled robots: A review. Asia-Pac. J. Sci. Technol. 2024, 29, APST-29. [Google Scholar] [CrossRef]
  4. Papadimitriou, K.D.; Murasovs, N.; Giannaccini, M.E.; Aphale, S. Genetic algorithm-based control of a two-wheeled self-balancing robot. J. Intell. Robot. Syst. 2025, 111, 34. [Google Scholar] [CrossRef] [Scilit]
  5. Sun, Z.; Dong, R.; Zhao, N. Standard dynamic model and control of a two-wheeled inverted pendulum robot on inclined planes. Int. J. Dyn. Control 2026, 14, 56. [Google Scholar] [CrossRef] [Scilit]
  6. Han, J.; Li, X.; Qin, Q. Design of two-wheeled self-balancing robot based on sensor fusion algorithm. Int. J. Autom. Technol. 2014, 8, 216–221. [Google Scholar] [CrossRef] [Scilit]
  7. Ali, A.T.; Mohamedy, A.M.; Salimz, A.S.; El-Aminx, E.A.O.; Ahmed, O.M. Design and implementation of two-wheeled self-balancing robot using pid controller. In Proceedings of the 2020 International Conference on Computer, Control, Electrical, and Electronics Engineering (ICCCEEE), Khartoum, Sudan, 26 February–1 March 2021; IEEE: Piscataway, NJ, USA, 2021; pp. 1–5. [Google Scholar]
  8. Rivera-Ruiz, J.R.; Rojas-Galvan, R.; García-Martínez, J.R.; Cruz-Miguel, E.E.; Barra-Vázquez, O.A.; Cruz-Orduña, M.I.; Escalante-Martínez, J.E.; Rodríguez-Reséndiz, J. Performance Evaluation of Metaheuristics for LQR Controller Optimization: A Two-Wheel Balancing Robot Case Study. IEEE Access 2025, 13, 97870–97888. [Google Scholar] [CrossRef] [Scilit]
  9. Zhang, H.; Mohamad Nor, N.; Umar, S.N.H. Modified Dual Hierarchical Terminal Sliding Mode Control Design for Two-Wheeled Self-Balancing Robot. Electronics 2025, 14, 2692. [Google Scholar] [CrossRef] [Scilit]
  10. Guo, L.; Rizvi, S.A.A.; Lin, Z. Optimal control of a two-wheeled self-balancing robot by reinforcement learning. Int. J. Robust Nonlinear Control 2021, 31, 1885–1904. [Google Scholar] [CrossRef] [Scilit]
  11. Esmaeili, N.; Alfi, A.; Khosravi, H. Balancing and trajectory tracking of two-wheeled mobile robot using backstepping sliding mode control: Design and experiments. J. Intell. Robot. Syst. 2017, 87, 601–613. [Google Scholar] [CrossRef] [Scilit]
  12. Sadeghian, R.; Masoule, M.T. An experimental study on the PID and Fuzzy-PID controllers on a designed two-wheeled self-balancing autonomous robot. In Proceedings of the 2016 4th International Conference on Control, Instrumentation, and Automation (ICCIA), Qazvin, Iran, 27–28 January 2016; IEEE: Piscataway, NJ, USA, 2016; pp. 313–318. [Google Scholar]
  13. Hasanah, N.; Alasiry, A.H.; Sumantri, B. Two wheels line following balancing robot control using fuzzy logic and pid on sloping surface. In Proceedings of the 2018 International Electronics Symposium on Engineering Technology and Applications (IES-ETA), Bali, Indonesia, 29–30 October 2018; IEEE: Piscataway, NJ, USA, 2018; pp. 210–215. [Google Scholar]
  14. Rojas-Galván, R.; García-Martínez, J.R.; Cruz-Miguel, E.E.; Barra-Vázquez, O.A.; Olmedo-García, L.F.; Rodríguez-Reséndiz, J. Hunting Search Algorithm-Based Adaptive Fuzzy Tracking Controller for an Aero-Pendulum. Technologies 2024, 12, 63. [Google Scholar] [CrossRef] [Scilit]
  15. Mai, T.A.; Dang, T.S.; Ta, H.C.; Ho, S.P. Comprehensive optimal fuzzy control for a two-wheeled balancing mobile robot. J. Ambient Intell. Humaniz. Comput. 2023, 14, 9451–9467. [Google Scholar]
  16. Moness, M.; Mahmoud, D.; Hussein, A. Real-time Mamdani-like fuzzy and fusion-based fuzzy controllers for balancing two-wheeled inverted pendulum. J. Ambient Intell. Humaniz. Comput. 2022, 13, 3577–3593. [Google Scholar]
  17. Santoso, I.A.W.; Slamet, P.; Andriawan, A.H.; Algopiki, A.R. Design and Build Two Wheel Balancing Robot Simulation with Fuzzy PID. 2023. Available online: https://www.scitepress.org/publishedPapers/2023/121083/pdf/index.html (accessed on 13 December 2025).
  18. Bach, S.H.; Yi, S.Y. A Fuzzy-PD Controller for A Low-Cost Two-Wheeled Self-Balancing Robot. J. Robot. Control (JRC) 2025, 6, 2373–2379. [Google Scholar]
  19. Mora-González, I.; García-Martínez, J.R.; Pérez-Juárez, J.G.; Martínez-Sánchez, T.; Olmedo-García, L.F.; Rojas-Galván, R. Experimental Evaluation of a Fuzzy Logic-Based Controller for a Two-Wheeled Balancing Robot. In Proceedings of the 2025 Mexican International Conference on Computer Science (ENC), Orizaba, Mexico, 10–14 November 2025; pp. 1–7. [Google Scholar] [CrossRef] [Scilit]
  20. Mai, T.A.; Anisimov, D.; Dang, T.S.; Dinh, V.N. Development of a microcontroller-based adaptive fuzzy controller for a two-wheeled self-balancing robot. Microsyst. Technol. 2018, 24, 3677–3687. [Google Scholar]
  21. Nguyen, V.T.; Duong, D.N.; Dang, T.V. Optimal two-wheeled self-balancing mobile robot strategy of navigation using adaptive fuzzy controller-based KD-SegNet. Intell. Serv. Robot. 2025, 18, 661–685. [Google Scholar] [CrossRef] [Scilit]
  22. Zhang, J.; Zhao, T.; Guo, B.; Dian, S. Fuzzy fractional-order PID control for two-wheeled self-balancing robots on inclined road surface. Syst. Sci. Control Eng. 2022, 10, 289–299. [Google Scholar]
  23. Hernández-Guzmán, V.M.; Silva-Ortigoza, R.; Orrante-Sakanassi, J.A. Control of Wheeled Pendulum. In Automatic Control with Experiments; Springer International Publishing: Cham, Switzerland, 2024; pp. 789–862. [Google Scholar] [CrossRef] [Scilit]
  24. Microchip Technology Inc. PIC18F2455/2550/4455/4550 Data Sheet, ds39632e (Final) ed.; PIC18F4550 Microcontroller Datasheet; Microchip Technology: Chandler, AZ, USA, 2009; Available online: https://ww1.microchip.com/downloads/en/devicedoc/39632c.pdf (accessed on 30 October 2025).
  25. Simon, J. Fuzzy Control of Self-Balancing, Two-Wheel-Driven, SLAM-Based, Unmanned System for Agriculture 4.0 Applications. Machines 2023, 11, 467. [Google Scholar] [CrossRef] [Scilit]
  26. Nguyen, T.D. Controlling Two-Wheeled Self-Balancing Robot Moving on Inclined Plane. Sci. Technol. Dev. J. 2017, 20, 45–52. [Google Scholar] [CrossRef] [Scilit]
  27. Chen, Z.; He, N.; Xu, Z.; Dou, M.; He, L. Design and Implementation of a Novel Two-Wheeled Composite Self-Balancing Robot for Stationary Operations in Unknown Terrain. IEEE Access 2025, 13, 86032–86045. [Google Scholar] [CrossRef] [Scilit]
  28. Guo, D.; Peng, Q.; Zhang, G.; Liu, X. LQR Control for a Self-Balancing Unicycle Robot on Inclined Plane. J. Syst. Des. Dyn. 2012, 6, 685–699. [Google Scholar] [CrossRef] [Scilit]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Article Metrics

Citations

Article Access Statistics

Multiple requests from the same IP address are counted as one view.