Real-Time Neuro-Fuzzy Control with Nonlinear Compensation for a Rotary Inverted Pendulum: Experimental Validation and Comparison with State-Feedback
Abstract:
This paper presents simulation and experimental validation of a Nonlinear Compensation-based Neuro-Fuzzy (NCNF) controller designed to balance the rotary inverted pendulum (RIP). Traditional linear controllers, such as Proportional-Integral-Derivative (PID) and state-feedback with pole placement, usually achieve satisfactory results in simulations on linearized models. However, their performance decreases in hardware implementation because of disturbances and unmodeled nonlinear effects such as Coulomb friction and mechanical backlash. To overcome these challenges, a feedforward compensation function was developed to cancel these undesired effects, which is combined with an Adaptive Neuro-Fuzzy Inference System (ANFIS) controller that updates PID gains to improve the rotary arm tracking for a square-wave reference and stabilize the pendulum at the upright position. The proposed NCNF controller is validated through hardware-in-the-loop (HIL) experiments and compared with a baseline state-feedback controller. Results show that the arm angle ($\theta$) overshoot decreased from 40.6% to 0.8% (lower step) and from 17.2% to 2.5% (upper), total steady-state $\theta$-error from 5.75° to 0.296°, and the fitness index dropped from 41.12 to 25.23. The nonlinear compensation reduced the gap between simulation and real-time performance, while the ANFIS further improved the defined control metrics. Overall, the NCNF controller achieves more stable and precise tracking than the state-feedback control.
1. Introduction
The Rotary Inverted Pendulum (RIP) is a nonlinear and underactuated system commonly used in research to evaluate different types of controllers. The system has fourth-order dynamics and unstable in open-loop. For this reason, it is often chosen as a model to reflect the complexity of real-world applications. Examples are found in robotics, transport systems such as Segways, and cranes [1]. The control problem of the RIP is demanding because it needs methods that can keep the pendulum upright and, at the same time, ensure the rotary arm follows the desired reference angle with accuracy in real-time [2]. Classical linear controllers such as Proportional-Integral-Derivative (PID), Linear Quadratic Regulator (LQR) and state-feedback techniques have been widely applied to the RIP system because they are simple and give acceptable performance on linearized models [3]. However, their fixed-gain nature makes them sensitive to nonlinear hardware effects and measurement noise. In practice, problems such as motor dead-zone, Coulomb friction, and backlash appear in hardware, together with errors in derivative estimation. These limitations usually cause unstable closed-loop behavior, poor tracking with oscillations, or delays in response [4], [5].
To deal with these issues, many control methods have been proposed. They range from robust and nonlinear controllers to adaptive and fuzzy or neuro-fuzzy approaches. Robust methods such as H-infinity control [6] and generalized dynamic inversion [7] have been used to keep the RIP stable under uncertainties and disturbances. However, their heavy mathematical design makes them hard to apply in real-time. Nonlinear controllers have also been used. Lyapunov-based methods hold stability close to equilibrium [8]. Sliding mode control rejects disturbances well but it causes chattering effect [9]. Adaptive control can adjust the parameters to address uncertainties. However, it needs more computational cost [10]. These control methods often perform better than simple linear controllers. yet, their complexity and practical constraints limit them from being widely used.
Adaptive control with intelligent algorithms such as fuzzy logic and neuro-fuzzy methods has become more common for dealing with nonlinear and uncertain dynamics. Fuzzy controllers work on a rule-based structure, while extensions such as fuzzy sliding mode control (FSMC) make transitions smoother and more stable [11]. Fuzzy observer-based control with Takagi-Sugeno models present a more organized way for the integration of fuzzy logic [12]. Results show that fuzzy logic control performs better than traditional methods in terms of stability and response time [10], [11], [12], [13]. Intelligent controllers that include neural networks make the design more adaptable, and with neuro-fuzzy systems, adding the learning feature to help better the performance over time [11]. Even with these improvements, such techniques need much more tuning for the parameters and powerful computational resources, and they are rarely tested experimentally in combination with nonlinear compensation functions.
The RIP dynamics are already nonlinear due to the equations of motion, such as the sine, cosine terms and the coupling between the pendulum and the rotary arm. In practice, the hardware also introduces extra nonlinear effects like dead-zone, backlash, and friction. Few studies developed direct compensation for these hardware effects, where unmodeled nonlinearities are seen as a challenge for a robust design [14], [15]. However, they are usually treated as an obstacle rather than the main target of compensation [16]. There has been some progress. For example, authors [17] suggested a modified signal compensation method for balance control. However, it does not directly address dead-zones or backlash. Reference [18] studied friction estimation but did not fully integrate it with the adaptive RIP control scheme. Thus, complete approaches that handle hardware nonlinearities are still limited. Recent studies narrow this gap by using intelligent control on RIP systems [19], [20]. Hybrid fuzzy-SMC and Extended Kalman Filter (EKF)-based fuzzy adaptive SMC were tested with hardware-in-the-loo (HIL) to handle disturbances and delays [21], [22]. Another work focuses on the compensation itself for mechanical backlash with an inverted pendulum [23] and RL-based friction compensation on a cart–pendulum [24]. These results support adding explicit nonlinear compensation. However, few papers combine compensation with a neuro-fuzzy controller and then validate the approach in HIL experiments. For example, a 2025 ANFIS-LQR study on a double-linked rotary pendulum reports improved tracking and disturbance rejection [25].
In this work, we introduce a Nonlinear Compensation-based Neuro-Fuzzy (NCNF) controller for the Quanser Rotary Inverted Pendulum system and compare it to a state-feedback baseline control designed using the pole placement method. The conceptual contribution is a hardware-aware control architecture that integrates real-time feedforward compensation with an ANFIS-tuned PID in one controller. The goal is to handle unmodeled hardware effects, such as Coulomb friction, backlash, and dead-zone. Unlike standard ANFIS-PID and sliding-mode controllers that treat these nonlinearities as external disturbances, our method cancels them in real-time using a feedforward correction. This makes the NCNF controller adaptive to adjust the compensation and reduce the gap between simulation and experiments. The proposed control architecture showed stable system performance with reduced overshoot and improved desired tracking under changing square-wave reference signal.
The paper is structured as follows: Section 2 presents the linearized model of the RIP system, obtained from the nonlinear equations. Section 3 describes the methodology, including the state-feedback with pole placement, nonlinear compensation, and the ANFIS-PID design. Section 4 shows the simulation and experimental (HIL) results with performance comparisons using different metrics. Finally, Section 5 summarizes the main findings in this work with future directions.
2. Model of the Rotary Inverted Pendulum
The Quanser Rotary Inverted Pendulum (RIP), shown in Figure 1a with its schematic in Figure 1b, consists of a flat arm fixed to a rotary servo base at one side and with a pendulum attached via a metal shaft at the other. The servo base is moved by a Faulhaber 2338S DC motor that turns the arm and sets the pendulum in motion. A power amplifier and data acquisition unit are necessary to control and track the system’s movement. The system is also equipped with two optical encoders, each with a high resolution of 4096 counts per revolution to measure the angles of rotary arm and pendulum [26].


The RIP dynamics were derived using the Euler-Lagrange formulation, with ($q_i$) generalized coordinates defined as:
where, $\theta(t)$ is the arm angle and $\alpha(t)$ is the pendulum angle measured from the upright position, their associated velocities are denoted as $\dot{\theta}(t)$ and $\dot{\alpha}(t)$, respectively. After applying the Euler–Lagrange equations, the obtained nonlinear dynamics of motion for the RIP system are:
The equation that relates the applied motor voltage ($V_m$) to arm torque ($\tau$) is given by:
where, the main physical parameters of the rotary inverted pendulum (RIP) are summarized in Table 1.
Symbol | Parameters | Value [Unit] |
|---|---|---|
$m_p$ | weight of the pendulum | 0.127 [kg] |
$L_p$ | pendulum full length | 0.337 [m] |
$J_p$ | moment of inertia for pendulum | 0.0012 [kg $\cdot$ m$^2$] |
$B_p$ | coefficient of viscous damping for pendulum | 0.0024 [N $\cdot$ m $\cdot$ s / rad] |
$L_r$ | rotary arm full length | 0.216 [m] |
$J_r$ | rotary arm moment of inertia | 9.98 $\times$ 10$^{-4}$ [kg $\cdot$ m$^2$] |
$B_r$ | coefficient of viscous damping for the arm | 0.0024 [N $\cdot$ m $\cdot$ s / rad] |
$g$ | acceleration due to gravity | 9.81 [m / s$^2$] |
$V_m$ | voltage applied to motor | $\pm$ 10 [V] |
$\eta_g$ | gearbox efficiency | 90 [%] |
$\eta_m$ | motor efficiency | 69 [%] |
$k_g$ | total gear ratio | 70 |
$k_t$ | motor current-torque constant | 7.68 $\times$ 10$^{-3}$ [N $\cdot$ m / A] $\pm$ 12 % |
$k_m$ | motor back-EMF constant | 7.68 $\times$ 10$^{-3}$ [V $\cdot$ s / rad] $\pm$ 12 % |
$R_m$ | motor armature resistance | 2.60 [$\Omega$] $\pm$ 12 % |
To facilitate the controller design, the nonlinear model described by Eqs. (2) and (3) is linearized around the upright equilibrium $(\alpha(t)=0, \dot{\alpha}(t)=0$ and $\dot{\theta}(t)=0)$. The resulting linearized state-space model:
By defining the state vector:
The output vector as:
Last, the input as motor voltage:
The system can be represented in the state-space form:
where:
The open-loop poles for the RIP system calculated from the matrix (A) are $p_i^{o l}=\left[\begin{array}{llll}-48.42 & 7.06 & -5.86 & 0\end{array}\right]$. Since one pole is located on the right side of the s-plane, the RIP is an unstable system in open-loop. The controllability matrix has a full rank, which means all the states can be controlled.
3. Design of the Balance Controller
Based on the derived linear state–space model of the Rotary Inverted Pendulum (RIP) in Eq. (10) and identified matrices in Eq. (11), a state-feedback controller was designed using the pole placement method [3]. The goal is to keep the pendulum angle $\alpha(t)$ balanced at the upright equilibrium while making sure the rotary arm $\theta(t)$ tracks with minimum error a square-wave reference signal described as:
The control law of the state-feedback is given by:
where, $x_d(t)$ is the desired state vector, $x(t)$ the actual system state vector, and $K$ is the state-feedback gain vector. The feedback gain ($K$) is computed based on four performance specifications in the time-domain: damping ratio of $\zeta = 0.7$, a natural frequency of $\omega_n = 4 \;\mathrm{rad} / \mathrm{s}$, and a pendulum deviation limited within $\pm\; 15^{\circ}$ and motor voltage limited to $\pm\; 10\; \mathrm{V}$ as detailed in the study [27]. These conditions meet the following desired closed-loop poles:
The resulting state-feedback gain is:
This state-feedback controller is used as the baseline for comparison. In addition to give a clear picture of the full setup, the closed-loop structure of the proposed Nonlinear Compensation-based Neuro-Fuzzy (NCNF) controller is shown in Figure 2, where it shows the main control parts: the baseline state-feedback controller, the feedforward nonlinear compensation block, and the adaptive ANFIS-PID control, where the last two are explained in the next subsections (3.2) and (3.3), respectively.

Although the state-feedback controller gives acceptable performance in simulation, real-time experiments showed clear degradation because of unmodeled nonlinearities such as motor dead-zone, mechanical backlash, and asymmetric Coulomb friction [28], [29]. These effects are not part of the RIP mathematical model but come from the hardware. That is why we designed a nonlinear compensation block as seen in Figure 2 to handle these effects by:
where, $u_{{cont }}(t)$ is the control voltage from the designed controller (for instance, state-feedback control) and $f_{ {comp }}(.)$ applies the corrections for the hardware nonlinearities. The resulting control output applied to the RIP system is $V_m(t)$.
The dead zone characteristic of the power amplifier can be modeled by a piecewise function, as shown in Eq. (17). This nonlinearity causes small control voltages to fail reach the motor. As a result, these inputs are insufficient to generate motion leading to steady-state error and small oscillations when tracking the desired system states [30].
With ($d_z$) is the half-width of dead-zone and ($k$) the gain. To make sure small control inputs bypass the dead region and take effect, a compensation was applied through an inverse mapping that shifts the input above the threshold, defined as:
The mechanical backlash comes from the gear trains, where the small gap between teeth creates free play and delay the response when the motor changes direction. The backlash was modeled as a bounded bias $s(t) \in[-b, b]$ that subtracts from the input voltage so that the effective output $y_{b l}(t)$ after backlash is:
where, $s(t)$ represents the amount of gear play (slack) and $(b)$ is the half-width of backlash zone. To reduce this effect, a compensation term $s_{{comp }} \in[-b, b]$ was added to the control input:
This backlash compensation removes the delay when motor changes direction.
Another important nonlinearity is asymmetric Coulomb friction and motor voltage limits. Their model is written as:
With ($T_c$) is the Coulomb friction torque on both the arm and the pendulum joints, and ($u_{{sat}}$) accounts for the amplifier’s saturation limits. These nonlinearity effects add a constant torque bias and clip the voltage during large transients, which reduces control authority and slows the response. While Eq. (21) shows how friction enters the system, it cannot be cancelled directly in real-time. Instead, its effect was reduced with smoothing hyperbolic tangent velocity function. This was combined with a low-pass filter and a saturation stage to keep the signal within the amplifier limits:
The compensation filter gain ($\alpha_f$) plays an important role in adjusting the correction applied during the nonlinear compensation. It fine-tunes the magnitude of control compensation to handle undesired effects. By changing the parameter ($\alpha_f$) between 0 and 1, higher values ($\alpha_f \simeq 1$) give a faster response in real-time, while lower values help reduce noise more in the output signal.
The fixed-gain of state-feedback controller provides a useful baseline, but could not adapt to unmodeled nonlinearities or disturbances. To further improve robustness and adaptability, we built an Adaptive Neuro-Fuzzy Inference System (ANFIS)-based PID controller with the integrated nonlinear compensation block (as seen in Figure 2). Similar compensatory neuro-fuzzy approaches have been successfully applied to inverted pendulum systems [31]. Our hybrid controller, called NCNF, combines the rule-base structure of fuzzy logic with the learning ability of neural networks, and the robustness of PID control. The equation that defines the ANFIS-PID control law for the rotary arm is given by Eq. (24) while for the pendulum in Eq. (25):
where, $e_\theta(t)=\theta_d(t)-\theta(t)$ is the tracking error for the rotary arm angle $(\theta)$ and $e_\alpha(t)=\alpha_d(t)-\alpha(t)$ is the calculated error for the pendulum angle $(\alpha)$. The gains $K_{\theta p}, K_{\theta i}, K_{\theta d}, K_{\alpha p}, K_{\alpha i}$ and $K_{\alpha d}$ are the time-varying variables updated online by the ANFIS-PID controllers for both the arm and pendulum.
The closed-loop control design started with two separate ANFIS-PD controllers. One controlled the arm angle to track the square-wave reference, while the other stabilized the pendulum angle at the upright position. Because the rotary arm angle follows a challenging reference signal with sudden changes (discontinuous), an integrator action was later added to the $\theta$-loop to remove the remaining steady-state errors.
The ANFIS was trained on datasets generated by the state-feedback baseline controller. By changing the desired pole’s location in closed-loop and thus the state-feedback gain ($K$), we produced different behaviors from well-damped responses. These datasets allowed ANFIS to learn fuzzy rules that linked the state errors $[e(t) \,\, \dot{e}(t)]$ to effective time-varying PID gains as in Eqs. (24) and (25). For both first ANFIS-PD controllers (arm and pendulum), we used a generalized bell-shaped membership function (five per input), while with integrator action a gaussian functions (three per input) were selected in the arm-angle loop. These functions are common in control applications, showing that gaussian and bell-shaped membership functions improve system adaptability and precision [32]. The choice of five and three membership functions is to give enough flexibility to approximate nonlinear mappings and keep the model computationally efficient in real-time performance. Training used on a hybrid algorithm of least-squares estimation and gradient descent, with up to 150 epochs and an 80/20 train-validation split of the data to avoid overfitting.
The NCNF controller is implemented with real-time interface (HIL) to the Quanser hardware. The tracking performance is evaluated using several metrics for a fair comparison against the baseline state-feedback controller. First, using the Root-Mean-Square Error (RMSE) and Integral of Absolute Error (IAE) metrics during the running time ($T$) for both the arm and the pendulum:
The following fitness function ($F$) is presented to indicate the total tracking accuracy of each designed controller in terms of IAE and RMSE using Eqs. (26) and (27):
The choice of the fitness function is subjective and depends on the designer preference, but the goal is to quantify the overall tracking of the RIP system for both the arm angle ($\theta$) and pendulum angle ($\alpha$) for comparison between different control methods. Additionally, for the arm angle response following a square-wave reference, we measure the settling time ($T s_\theta$), maximum overshoot ($M p_\theta$), and steady-state error ($E s s_\theta$). The RMSE for control voltage ($R M S E_{u_{-} c o n t}$) is also calculated to estimate the control effort:
where, $u_{ {cont }}(t)$ is the control voltage applied to motor during the running time ($T$). All the metrics are computed for both simulation and real-time experiments.
4. Results and Discussion
This section presents simulation and Hardware-in-the-loop (HIL) experimental results for the proposed Nonlinear Compensation-based Neuro-Fuzzy (NCNF) controller on the Quanser Rotary Inverted Pendulum (RIP). The objective is to stabilize the pendulum at the upright position ($\alpha_d(t)=0$) while tracking a square-wave reference for the rotary arm $\theta_d(t)$. The closed-loop control structure used for simulation and validation experiments is depicted in Figure 3 and the corresponding Quanser hardware setup is shown in Figure 4.


The real-time controller is running with a fixed sample time of T$_{ {sample }}$ = 0.002 $\mathrm{s}$ (500 $\mathrm{Hz}$) on a host laptop Intel Core i5, 8$^{\text {th }}$ generation, with 16 GB RAM to handle different types of controllers with nonlinear compensation and update the feedback of states within each cycle.
The RIP system angles are measured using optical encoders with 4096 count by rotation, which provide a resolution of 0.088$^{\circ}$ per count. To improve accuracy, a Moving Average filter with a window size of 5 is applied to smooth the signals and reduce high-frequency noise, while High-Pass Filters (HPFs) with transfer functions $H_\theta(s)=\frac{30 s}{s+30}$ for the arm angle $(\theta)$ and $H_\alpha(s)=\frac{40 s}{s+40}$ for the pendulum angle $(\alpha)$ chosen using Fast Fourier Transform (FFT) to remove unwanted low-frequency components and help obtain accurate derivatives of the angles $(\dot{\theta}$ and $\dot{\alpha})$. The dataset used for training the ANFIS controller consists of 120 seconds of motion data sampled at 500 Hz, totaling around 60,000 data points. This dataset is sufficent for training the ANFIS controller since it includes several reference trajectories like step signal and square-waves with different amplitudes.
The state-feedback controller worked quite well in simulation as shown in Figure 5, with corresponding performance metrics in Table 2. However, tracking accuracy dropped in real-time performance because of unmodeled nonlinearities such as motor dead-zone, backlash, and asymmetric Coulomb friction. These effects are present only in the real hardware system and not in the simulation model, which explains the gap between the two results.

Metric [unit] | State-Feedback Controller (SFC) | |
|---|---|---|
Simulation (Sim.) | Experiment (Exp.) | |
$R M S E_\theta\left[{ }^{\circ}\right]$ | 8.48 | 9.33 |
$R M S E_\alpha\left[{ }^{\circ}\right]$ | 1.32 | 1.65 |
$I A E_\theta\left[{ }^{\circ}\right]$ | 28.18 | 50.62 |
$I A E_\alpha\left[{ }^{\circ}\right]$ | 5.18 | 9.55 |
Fitness ($F$) | 26.49 | 41.12 |
$T s_\theta[\mathrm{s}]$ (Lower, Upper) | [0.710] | [0.616] |
U = 0.710 | U = 0.720 | |
$M p_\theta$ [%] (Lower, Upper) | L = 9.9 | L = 40.6 |
U = 9.9 | U = 17.2 | |
${Ess}_\theta\left[{ }^{\circ}\right]$ (Lower, Upper, Total) | L = 0.00076 | L = 3.93045 |
U = 0.00076 | U = 1.82234 | |
Total = 0.00153 | Total = 5.75279 | |
$R M S E_{u_{-} \text {cont }}[\mathrm{V}]$ | 0.28 | 0.48 |
A sign-dependent steady-state error was observed: during the first 5 seconds (lower region), both actual arm angle $\theta(t)$ and pendulum angle $\alpha(t)$ settled with a bias under the desired angles. However, responses remained centered during positive reference tracking (last 5 seconds, upper region) despite the transient errors. This asymmetry indicates a direction-dependent torque bias on the rotary base and which agrees with the previous reports of asymmetric friction and backlash effects in servo-driven systems, including the Quanser SRV02 and QUBE families [29], [33]. These undesired effects increase tracking errors. For example, fitness function ($F$) increased from 26.49 in simulation ($Sim.$) to 41.12 in experiment ($Exp.$). Also, maximum overshoot ($M p_\theta$) changed from 9.9% in $Sim.$ to 40.6% in $Exp.$ with Lower-region of $\theta_d(t)$ and to 17.2% in $Exp.$ with upper-region of $\theta_d(t)$. The energy consumption increased from 0.28V in $Sim.$ to 0.48V in $Exp.$, which confirms the need for compensation control to deal with these nonlinearities. In this paper, our objective is first to fill the gap between simulation and real-time experiments with satisfactory results for the RIP system. Second, we improve more the experiment results of state-feedback control to get reduced overshoot, and lower steady-state errors ($E s s_\theta$) for more accuracy.
Figure 6 presents the first statistical analysis using the mean and standard deviations ($\sigma$) for the SFC baseline controller using a set of six real-time experiments. The wider spread observed in each subplot of Figure 6 reflects increased variability between runs, which may be attributed to disturbances, unmodeled dynamics, or parameter uncertainties affecting the controller performance.



To correct for hardware nonlinearities that decrease performance near the upright equilibrium, a natural idea would be to first model the nonlinear behaviors not considered in simulation to better represent the real-world RIP system. After that, a second step would be to design a compensation function to address these modeled nonlinearities in simulation and thus test its effectiveness in real hardware system. By following this approach, Figure 7, shows the results after adding the unmodelled nonlinear dynamics to the RIP in simulation (step 1) and with the applied feedforward correction function (step 2), a detailed performance metrics are summarized in Table A (Appendix).

By introducing a feedforward nonlinear compensation, the tracking of the state-feedback control is better improved in both simulation and real-time experiments with small errors that represent other effect that might not represented or the lack of the traditional integrator action to cancel the steady state errors. Therefore, in Figure 8, we compared the results of adding the nonlinear compensation function (SFC-NC) against the state-feedback baseline controller (SFC) without it. The tracking oscillations are decreased from a fitness function of 41.12 to 30.89 after the compensation function. This reduction demonstrates that compensating unmodeled nonlinearities (friction, backlash, dead-zone) brings experimental performance closer to ideal simulation conditions (near to fitness = 26.5 in Table 2 with state-feedback in simulation). This approach is consistent with previous work showing that accurate friction estimation enhances pendulum control [18] and that signal-compensation methods can reduce unmodeled nonlinearities in RIP systems [17].

To name other improvements, maximum overshoot for arm angle ($\theta$) reduced from 40.6% (SFC) to 7.8% (SFC-NC) in lower-step tracking the desired $\theta_d(t)$ and to 11.3% in upper-part. The difference between lower and upper regions of tracking the reference arm signal comes from the mentioned asymmetry issue which will be compensated more later in this result section. In addition, total steady state error $\left(E s s_\theta\right)$ is decreased to more than half from 5.75 to 2.17. However, settling time metric $\left(T s_\theta\right)$ increased slightly from L = 0.616 and U = 0.720 (with SFC) for lower and upper rotary arm tracking segments to L = 0.96 and U = 0.8620 for the (SFC-NC) controller with nonlinear compensation.
Even though compensation-based state-feedback controller (SFC-NC) gave better tracking performance by reducing the tracking oscillations and errors, it still needs some extra work to get a satisfactory result including, reducing the existed maximum overshoots and settling-time for rapid real-time response and even cancel the steady state errors using the traditional integrator effect. Adding an integral action in feedback control rises as a simple yet efficient solution for eliminating steady-state errors when the system output fails to reach the desired setpoint. In PID controllers, the integral term accumulates the error and adjusts the control input, ensuring convergence to the reference signal [34]. In underactuated systems such as the inverted pendulum, integral action improves robustness to uncertainties and reduces residual bias, making it an effective way for accurate stabilization [35].
We notice from Figure 9 and its corresponding detailed metrics in Table A (Appendix) that by tracking the desired arm angle now is much better in settling time response ($T s_\theta$) and has lower steady-state errors ($E s s_\theta$). In real time experiments, $T s_\theta$ is improved from L = 0.960 and U = 0.862 with state-feedback using compensation (SFC-NC) to L = 0.686, U = 0.610 for the state-feedback with compensation and integrator (SFC with NC and integrator).

Additionally, the integrator action reduced steady-state $\theta$ error also by nearly 50% where $E s s_\theta$ decreased from 2.17 (SFC with NC) to $E s s_\theta=1.02$ (SFC with NC and integrator). However, adding the integrator introduced small pendulum deviation in tracking $\alpha(t)$ because of the coupled dynamics of the underactuated system. This observation shows the well-known problem of competing objectives and controllers fighting over one actuator, where improving regulation in tracking arm angle can degrade performance in the pendulum angle [4]. However, the fitness function is decreased after adding the integral action from 30.89 to 26.93. This means we accepted more accuracy for $\theta(t)$ angle in return for small errors in $\alpha(t)$ tracking. We prioritized the rotary arm since it has big changing square wave reference when compared to desired pendulum angle that is fixed in upright positive without any hard changes.
For further improvements than state-feedback and adaptability reasons, we consider ANFIS-PID controller with nonlinear compensation (NCNF) and integrator action in design. The results shown in Figure 10 and details in Table A (Appendix), where the NCNF controller indeed managed to lower the remaining overshoots from L = 9.0 and U = 10.7 in state-feedback with nonlinear compensation and integrator action (SFC with NC and integrator) to L = 3.7 and U = 6.6 using NCNF control with same nonlinear compensation and integrator action (ANFIS with NC and integrator).

Additionally, we can notice the proposed NCNF control has canceled the remaining small ripples and lowered the steady-state errors in real-time performance from $E s s_\theta=1.02$ (SFC with NC and integrator) to $E s s_\theta=0.74$ with ANFIS controller using NC and integrator (NCNF).
NCNF reduces overshoots compared to state-feedback.
Even ripples and changing overshoots from control signal are optimized compared to the state-feedback control (SFC with NC and integrator) from $R M S E_{u_{-} c o n t}=0.78\; \mathrm{V}$ to $R M S E_{u_{-} c o n t}=0.64\; \mathrm{V}$. This improvement arises from the adaptive tuning of PID gains through fuzzy rule learning, which provides nonlinear gain scheduling rather than relying on fixed linear feedback [10-11].
To push the experiments further, we tuned manually the nonlinear compensation function associated with the ANFIS-PID controller and integrator action (NCNF) to achieve our objective with the best performance across all tested configurations. The results are presented in Figure 11 with the corresponding performance metrics in Table 3.

State-Feedback Control with Tuned Compensation and Integrator Action | ANFIS Control with Tuned Compensation and Integrator Action | |||
Metric [unit] | Simulation (Sim.) | Experiment (Exp.) | Simulation (Sim.) | Experiment (Exp.) |
$R M S E_\theta\left[{ }^{\circ}\right]$ | 8.22 | 7.95 | 8.26 | 7.94 |
$R M S E_\alpha\left[{ }^{\circ}\right]$ | 1.53 | 1.86 | 1.47 | 1.77 |
$I A E_\theta\left[{ }^{\circ}\right]$ | 27.93 | 23.64 | 27.83 | 23.69 |
$I A E_\alpha\left[{ }^{\circ}\right]$ | 5.98 | 7.75 | 5.82 | 7.35 |
Fitness ($F$) | 26.70 | 25.50 | 26.56 | 25.23 |
$T s_\theta[\mathrm{s}]$ (Lower, Upper) | L = 0.638 | L = 0.762 | L = 0.646 | L = 0.618 |
U = 0.728 | U = 0.726 | U = 0.736 | U = 0.726 | |
$M p_\theta$ [%] (Lower, Upper) | L = 8.7 | L = 3.7 | L = 8.2 | L = 0.8 |
U = 2.7 | U = 3.1 | U = 4.0 | U = 2.5 | |
${Ess}_\theta\left[{ }^{\circ}\right]$ (Lower, Upper, Total) | L = 0.387 | L = 0.116 | L = 0.302 | L = 0.175 |
U = 0.333 | U = 0.214 | U = 0.260 | U = 0.121 | |
Total = 0.720 | Total = 0.415 | Total = 0.562 | Total = 0.296 | |
$R M S E_{u_{-}{cont }}[\mathrm{V}]$ | 0.47 | 0.65 | 0.46 | 0.66 |
We can notice by comparing to state-feedback control with tuned-nonlinear-compensation and integrator action (SFC with tuned-NC and integrator), the proposed ANFIS with the same tuned nonlinear compensation and integrator design (ANFIS with tuned-NC and integrator called NCNF) achieved lower maximum overshoot from L = 3.7% and U = 3.1% to L = 0.8%, U = 2.5% in real-time experiment.
Moreover, smaller steady-state error of 0.30° for ANFIS with tuned-NC and integrator (NCNF control) against 0.42° for SFC with tuned-NC and integrator. Settling times of L = 0.618 and U = 0.726 for NCNF against L = 0.762 and U = 0.726 for SFC with tuned-NC and integrator.
To assess the robustness of the NCNF control strategy, each real-time experiment was repeated five times under identical conditions. The mean system response, shown with different colors for each subplot in Figure 12, is accompanied by a shaded region representing the $\pm$ 1 standard deviation interval. The narrow spread of this region highlights the consistency, repeatability, and stability of the proposed controller.



To highlight the improvements achieved by the proposed NCNF controller in comparison to the SFC baseline in real-time validation, we summarized in Figure 13 using bar-graph the performance metrics for both controllers. The fitness function index is improved from 41.12 to 25.23 showing that the NCNF controller integrates nonlinear compensation with adaptive fuzzy learning to provide a smoother and more accurate control method for the underactuated systems like the rotary inverted pendulum.

Finally, to strengthen more the experimental validation of this work, we present the detailed statistical analysis of our results, including average data errors, standard deviations ($\sigma$), and 95% confidence intervals (CI) for the performance metrics. We conducted in total six real-time experiments for two controllers: the baseline SFC and ANFIS with tuned NC+Int (proposed NCNF) and we collected data for analysis. The box plots are depicted in Figure 14 with their corresponding detailed metrics in Table B (Appendix).


As shown in Figure 14, for example the mean for $R M S E_\theta$ metric with the SFC controller is 9.34°, with a 95% CI of [9.25°, 9.43°]. In comparison, the ANFIS with tuned NC+Int (NCNF) controller in the experiment showed a mean $R M S E_\theta$ of 7.95°, with a 95% CI of [7.92°, 7.98°]. The $R M S E_\alpha$ metric for the pendulum angle ($\alpha$) was 1.66° for SFC with a 95% CI of [1.627°, 1.696°] and 1.77° for NCNF with a 95% CI of [1.758°, 1.786°]. These standard deviations for both controllers indicate acceptable variation in results.
Since maximum overshoot ($M p_\theta$) and settling time ($T s_\theta$) metrics have two values lower and upper arm tracking regions of the square-wave reference, so we calculated the average value between them for both the mean and standard deviations. The $M p_\theta$ has the largest standard deviation ($\sigma$) of 4.16% with the mean value of 32.66 using feedback-state control and $\sigma=2.30%$ with a mean of 4.74 using the proposed NCNF. The reason is that $M p_\theta$ is measured at a single point, showing more variation in individual cases.
5. Conclusions
We presented the design and experimental validation of a Nonlinear Compensation-based Neuro-Fuzzy (NCNF) controller for balancing the Quanser rotary inverted pendulum (RIP) and compared it with a pole-placement state-feedback controller. The RIP system itself has nonlinear dynamics, but in practice the hardware also adds undesired nonlinear effects such as Coulomb friction, dead-zone, and mechanical backlash. The contribution of the NCNF controller is a hardware-based architecture that combines real-time nonlinear compensation with an ANFIS-tuned PID in one controller. Unlike standard ANFIS-PID and sliding-mode designs that treat these effects as disturbances, our method cancels them continuously using a feedforward correction. Both simulation and hardware-in-the-loop (HIL) experiments using varying square-wave reference showed that the proposed NCNF controller worked better than the baseline state-feedback controller in terms of reduced overshoots, lower steady-state errors and the defined fitness index. The results indicate that nonlinear compensation, together with adaptive neuro-fuzzy control, can indeed increase robustness and make the balancing better for underactuated systems. As a result, bringing experimental performance closer to the ideal simulated conditions. Future work will cover the extension to swing-up control to move the pendulum from downward position and validate the controller on more varying conditions.
The data used to support the findings of this study are available from the corresponding author upon request.
The authors declare that they have no conflicts of interest.
Latin symbols
$A, B, C, D$ | matrices of state-space representation |
$A m p_{s q}$ | amplitude of reference square-wave (reported), ° |
$B_P$ | viscous damping coefficient for pendulum joint, N.m.s.rad$^{-1}$ |
$B_r$ | viscous damping coefficient for rotary arm, N.m.s.rad$^{-1}$ |
$e(t)$ | tracking angle error used in control law (equation), rad |
$g$ | gravitational acceleration, m.s$^{-2}$ |
$J_p$ | pendulum moment of inertia, kg.m$^{2}$ |
$J_r$ | rotary arm moment of inertia, kg.m$^{2}$ |
$k_g$ | gear ratio |
$k_m$ | motor back-EMF constant, V.s.rad$^{-1}$ |
$k_t$ | motor torque constant, N.m.A$^{-1}$ |
$K$ | state-feedback gain vector |
$K_p, K_i, K_d$ | PID gains (proportional, integral, derivative) |
$L_p$ | pendulum length, m |
$L_r$ | rotary arm length, m |
$m_p$ | pendulum mass, kg |
$p_i^{o l}$ | open-loop poles |
$p_i^{c l}$ | desired closed-loop poles |
$R_m$ | motor armature resistance, $\Omega$ |
$T$ | duration for simulation/ experiment, s |
$T_S$ | settling time, s |
$T_{{sample}}$ | sample time for real-time experiments, s |
$u(t)$ | control input voltage, V |
$u_{s a t}$ | saturated control, V |
$V_m$ | motor voltage, V |
$x(t)$ | state vector used for state-space model |
$y(t)$ | output vector for state-space model |
Greek symbols
$\alpha$ | pendulum angle (in equations), rad |
$\eta_g, \eta_m$ | gear and motor efficiencies, % |
$\theta$ | rotary arm angle (equations), rad |
$\tau$ | motor torque, N.m |
$\omega_n$ | natural (angular) frequency, rad. s$^{-1}$ |
$\omega_{s q}$ | square-wave (angular) frequency, rad.s$^{-1}$ |
$\zeta$ | damping ratio |
$\alpha_f$ | compensation filter gain |
$\sigma$ | standard deviation |
Performance metrics (reported in degrees)
${Ess}_\theta$ | steady‑state arm error, ° |
$F$ | Fitness function index (defined in subsection 3.3) |
$I A E_\theta, I A E \alpha$ | integral of absolute angle error, °. s |
$M p_\theta$ | maximum arm overshoot, % |
$R M S E_\theta, R M S E \alpha$ | root‑mean‑square angle error, ° |
$R M S E_{u-c o n t}$ | RMSE of control voltage, V |
Subscripts
$\alpha, \theta$ | pendulum and arm angles respectively |
$d$ | desired/reference |
$m, g$ | motor, gearbox |
$p, r$ | pendulum, rotary arm |
$sq$ | square-wave |
$dz, sat$ | dead‑zone, saturation |
Two tables are provided in this appendix with the detailed metrics for transparency and completeness. Table A for the performance results of subsections (4.2), (4.3), and (4.4) for both simulation and hardware-in-the-loop (HIL) experiment. In addition, Table B summarizes the statistical analysis of results for two main controllers SFC and NCNF.
Table A. Detailed performance metrics for designed controllers, namely: (SFC with NC), (SFC with NC and integrator), and (ANFIS with NC and integrator called NCNF)
SFC with NC | SFC with NC and Integrator | |||
Metric [unit] | Simulation | Experiment | Simulation | Experiment |
$R M S E_\theta\left[{ }^{\circ}\right]$ | 8.51 | 8.49 | 8.23 | 7.84 |
$R M S E_\alpha\left[{ }^{\circ}\right]$ | 1.23 | 1.33 | 1.52 | 1.72 |
$I A E_\theta\left[{ }^{\circ}\right]$ | 35.30 | 36.26 | 30.38 | 27.43 |
$I A E_\alpha\left[{ }^{\circ}\right]$ | 5.65 | 5.89 | 6.61 | 7.30 |
Fitness ($F$) | 30.22 | 30.89 | 28.24 | 26.93 |
$T s_\theta[\mathrm{s}]$ (Lower, Upper) | L= 0.882 | L= 0.960 | L= 0.660 | L= 0.686 |
U= 1.084 | U= 0.862 | U= 0.746 | U= 0.610 | |
$M p_\theta$ [%] (Lower, Upper) | L= 6.3 | L= 7.8 | L= 8.5 | L= 9.0 |
U= 6.3 | U= 11.3 | U= 4.8 | U= 10.7 | |
${Ess}_\theta\left[{ }^{\circ}\right]$ (Lower, Upper, Total) | L= 0.965 | L= 0.827 | L= 0.707 | L= 0.462 |
U= 0.899 | U= 1.344 | U= 0.726 | U= 0.562 | |
Total = 1.854 | Total = 2.171 | Total = 1.433 | Total = 1.024 | |
$R M S E_{u_{-}{cont }}[\mathrm{V}]$ | 0.51 | 0.67 | 0.45 | 0.78 |
ANFIS with NC and Integrator | ||
Metric [unit] | Simulation | Experiment |
$R M S E_\theta\left[{ }^{\circ}\right]$ | 8.28 | 8.07 |
$R M S E_\alpha\left[{ }^{\circ}\right]$ | 1.47 | 1.75 |
$I A E_\theta\left[{ }^{\circ}\right]$ | 29.87 | 25.71 |
$I A E_\alpha\left[{ }^{\circ}\right]$ | 6.41 | 7.41 |
Fitness ($F$) | 27.90 | 26.38 |
$T s_\theta[\mathrm{s}]$ (Lower, Upper) | L= 0.664 | L= 0.736 |
U= 0.746 | U= 0.762 | |
$M p_\theta[%]$ (Lower, Upper) | L= 8.2 | L= 3.7 |
U= 6.6 | U= 6.6 | |
$Ess_\theta\left[^{\circ}\right]$ (Lower, Upper, Total) | L= 0.667 | L= 0.317 |
U= 0.470 | U= 0.421 | |
Total = 1.138 | Total = 0.739 | |
$R M S E_{{ul\_cont }}[\mathrm{V}]$ | 0.45 | 0.64 |
Table B. Statistical and distributional analysis results for two main controllers SFC and NCNF
SFC (six Exp.) | |||
Metric [unit] | Mean | Standard Deviations | 95% Confidence Intervals |
$R M S E_\theta\left[{ }^{\circ}\right]$ | 9.34 | 0.085 | [9.248, 9.425] |
$R M S E_\alpha\left[{ }^{\circ}\right]$ | 1.66 | 0.033 | [1.627, 1.696] |
$I A E_\theta\left[{ }^{\circ}\right]$ | 48.09 | 1.88 | [46.11, 50.07] |
$I A E_\alpha\left[{ }^{\circ}\right]$ | 9.32 | 0.41 | [8.889, 9.741] |
Fitness ($F$) | 39.71 | 1.20 | [38.45, 40.97] |
$T s_\theta[\mathrm{s}]$ (Average) | 0.65 | 0.0074 | [0.647, 0.662] |
$M p_\theta$ [%] (Average) | 32.66 | 4.16 | [28.29, 37.03] |
$E s s_\theta\left[{ }^{\circ}\right]$ (Total) | 5.28 | 0.60 | [4.649, 5.905] |
$R M S E_{u_{-}{cont }}$ [V] | 0.49 | 0.0075 | [0.480, 0.496] |
ANFIS with NC and Integrator (six Exp.) | |||
Metric [unit] | Mean | Standard Deviations | 95% Confidence Intervals |
$R M S E_\theta\left[{ }^{\circ}\right]$ | 7.9517 | 0.027 | [7.923, 7.980] |
$R M S E_\alpha\left[{ }^{\circ}\right]$ | 1.7717 | 0.013 | [1.758, 1.786] |
$I A E_\theta\left[{ }^{\circ}\right]$ | 24.083 | 0.52 | [23.54, 24.63] |
$I A E_\alpha\left[{ }^{\circ}\right]$ | 7.565 | 0.14 | [7.416, 7.714] |
Fitness ($F$) | 25.545 | 0.25 | [25.29, 25.81] |
$T s_\theta[\mathrm{s}]$ (Average) | 0.691 | 0.025 | [0.664, 0.718] |
$M p_\theta$ [%] (Average) | 4.7433 | 2.30 | [2.328, 7.159] |
$E s s_\theta\left[{ }^{\circ}\right]$ (Total) | 0.35 | 0.14 | [0.204, 0.488] |
$R M S E_{u_{-}{cont }}$ [V] | 0.645 | 0.0105 | [0.634, 0.656] |
Note: Since Ts (settling time) and Mp (maximum overshoot) metrics has two values lower and upper rotary arm tracking regions of the square-wave signal, we calculated the average value between them for both the mean and standard deviations
