Sensor Fusion and State Feedback Control for a Reaction Wheel Based Self-Balancing System

SangHyun Kim


'Sensor Fusion and State Feedback Control for a Reaction Wheel Based Self-Balancing System'


Abstract
This paper presents the design and embedded control implementation of a reaction wheel-based self-balancing cube for vertex balancing. In the initial experiment, a PID-inspired attitude-error-based controller was implemented using PWM commands as the main actuator input. However, because this approach did not directly measure the actual reaction wheel speeds, discrepancies between PWM commands and motor responses caused asymmetric torque distribution, residual yaw-axis rotation, and rapid actuator saturation. As a result, the cube was able to maintain vertex balancing for only approximately 1–2 s.
To improve the balancing performance, the control strategy was changed to an encoder-based state feedback controller implemented on an ESP32 platform. The final controller incorporated IMU-based attitude estimation, encoder-based wheel speed feedback, wheel speed integral terms, yaw suppression, and cross-axis attitude feedback. Experimental results showed that the final system extended the vertex-balancing duration from approximately 1–2 s to approximately 35 s. These results demonstrate that stable vertex balancing requires not only attitude feedback, but also actual wheel speed feedback, compensation for cross-axis coupling, and practical hardware optimization under real physical constraints.

1. Introduction
In recent years, active attitude control of multi-input multi-output (MIMO) systems has become increasingly important in various engineering applications, including spacecraft attitude control, robotic systems, and autonomous mobility platforms. Among the many experimental platforms used to investigate such control problems, reaction wheel-based self-balancing systems provide an effective means of studying unstable equilibrium stabilization and multi-axis control.
The self-balancing cube, commonly known through the Cubli project, is a representative example of a reaction wheel-based balancing system. By utilizing three reaction wheels mounted inside a cube, the system can balance on an edge or even on a single vertex without any external support. Compared with edge balancing, vertex balancing is considerably more challenging because it requires simultaneous stabilization of multiple coupled rotational axes while continuously compensating for gravitational disturbances.
During the development of the present system, initial implementations were capable of maintaining vertex balancing only for a short duration before instability occurred. Through repeated hardware modifications and control experiments, several practical issues affecting balancing performance were identified, including mass distribution imbalance, power supply limitations, wheel-speed accumulation, and cross-axis coupling effects.
To address these issues, this project adopted an integrated hardware and software improvement strategy. The hardware architecture was refined to improve mass symmetry and power distribution, while the control system was implemented on an ESP32-based platform. Sensor fusion techniques were employed for attitude estimation, and a state feedback controller utilizing IMU and encoder measurements was implemented to achieve robust vertex balancing.

2. Related Work
Reaction wheel-based balancing systems have been widely studied as experimental platforms for nonlinear attitude control and unstable equilibrium stabilization. A representative example is the Cubli developed by ETH Zurich, which demonstrated that a cube equipped with three reaction wheels can perform jump-up maneuvers and maintain balance on both edges and vertices without external support. This work established the feasibility of three-dimensional balancing using momentum exchange.
Previous studies have shown that edge balancing can often be approximated as a single-axis control problem, while vertex balancing requires simultaneous stabilization of multiple coupled axes. In addition to academic studies, open-source implementations such as the re-mrc project provide a practical implementation framework that includes IMU-based attitude estimation, encoder-based wheel speed measurement, and state feedback control.
However, reproducing stable vertex balancing on a custom-built hardware platform remains challenging. Real systems are affected by mass distribution errors, motor output mismatch, sensor noise, power supply limitations, and computational constraints. Therefore, the present project focuses on the practical implementation and refinement of a reaction wheel-based self-balancing cube under real hardware constraints.

3. Method

3.1. System Architecture


Figure 1. Overall control flow of the proposed self-balancing cube system. IMU-based attitude states and encoder-based wheel speed states are combined to construct the state variables for the state feedback controller.

The overall control architecture consists of three main subsystems: an attitude estimation module, a wheel state measurement module, and a state feedback control module. The attitude estimation module is based on an MPU6050 inertial measurement unit (IMU), and a complementary filter is used to combine accelerometer and gyroscope data to estimate the attitude angles and angular velocities along the X and Y axes.
The wheel state measurement module uses rotary encoders attached to the three BLDC motors. Since the three reaction wheels are arranged at approximately 120° intervals inside the cube, the measured wheel speeds are transformed into equivalent X-, Y-, and Z-axis components. The estimated attitude states and transformed wheel speed states are then used to construct the state variables for the state feedback controller, which generates PWM commands to produce reaction torque for vertex balancing.

3.2. Hardware Optimization

  
Figure 2. Comparison between the initial (left) and redesigned (right) circuit configurations. The redesigned circuit separates the control power path from the motor power path and uses a DC-DC buck converter to provide a stable logic supply.

The initial system was developed based on the open-source re-mrc architecture, consisting of three Nidec 24H BLDC motors, an MPU6050 IMU, rotary encoders, and a 3S 11.1V LiPo battery. Several hardware-related limitations were identified, including mass distribution imbalance, power supply instability, thermal failure of the control board, and insufficient computational resources for real-time encoder-based state feedback control.

3.2.1. Mechanical Symmetry and Mass Distribution
In a reaction wheel-based self-balancing cube, mass distribution plays a critical role in determining the difficulty of balancing. If the center of mass is shifted from the ideal balancing axis, a constant gravitational disturbance torque is generated, approximated as:

    τbias ≈ mgΔr

where m is the total mass of the cube, g is the gravitational acceleration, and Δr is the horizontal offset of the center of mass from the ideal balancing axis. During development, an additional 3500 mAh battery was temporarily installed, which significantly changed the mass distribution and introduced a large mechanical asymmetry. The motors rapidly reached actuator saturation while trying to compensate for the gravitational bias. Consequently, the asymmetric battery configuration was abandoned, and the system was restored to a symmetric structure using a single 3S 11.1V 500 mAh LiPo battery.

3.2.2. Power Supply Architecture and Thermal Failure Analysis
In the initial configuration, the 11.1V battery voltage was stepped down to 5V through an LDO regulator to power the logic board. The power loss of the linear regulator is determined by:

    Ploss = (Vin − Vout)Iout

With an input of approximately 11.1V and output of 5V, the regulator had to dissipate approximately 6.1V as heat, eventually causing the control board to fail. The power supply was redesigned using a high-efficiency DC-DC buck converter, which greatly reduced thermal loss. The redesigned system was divided into two independent power paths: a Control Power Path (battery → buck converter → 5V logic) and a Motor Power Path (battery → motor driver directly at 11.1V).

3.2.3. Microcontroller Upgrade and Encoder-Based Wheel Speed Measurement
The implementation of state feedback control requires not only attitude information from the IMU but also dynamic information about the reaction wheels. The initial Arduino Nano-based controller had limited computational resources for processing multiple encoder interrupts and real-time control simultaneously. The control board was therefore replaced with an ESP32 microcontroller, which provides higher computational performance and more hardware resources, enabling real-time encoder-based wheel speed feedback within the 15 ms control loop.

3.3. Sensor Fusion and Signal Processing

3.3.1. Conversion of IMU Measurements
The raw accelerometer and gyroscope outputs were first corrected using experimentally obtained offset values. The accelerometer-based attitude angles were calculated as:

    θacc,Y = atan2(AcX, −AcZ) × 180/π
    θacc,X = −atan2(AcY, −AcZ) × 180/π

The gyroscope measurements were converted into angular velocities using the sensitivity factor of 131 LSB/(deg/s):

    θ̇X = GcX / 131.0,   θ̇Y = GcY / 131.0,   θ̇Z = GcZ / 131.0

3.3.2. Attitude Estimation Using a Complementary Filter
A complementary filter was applied to combine the short-term accuracy of the gyroscope with the long-term stability of the accelerometer. The control loop was designed with a sampling period of dt = 0.015 s. The filter equations are:

    θX(k) = Kgyro[θX(k−1) + θ̇X(k)·dt] + (1−Kgyro)θacc,X(k)
    θY(k) = Kgyro[θY(k−1) + θ̇Y(k)·dt] + (1−Kgyro)θacc,Y(k)

In the final implementation, Kgyro = 0.996 was used, giving 99.6% weight to the gyroscope prediction and 0.4% to the accelerometer correction. This high gyroscope weighting was selected to suppress high-frequency mechanical vibration from the BLDC motors and reaction wheels.

3.3.3. Low-Pass Filtering of Angular Velocity
A first-order low-pass filter was applied to the gyroscope-based angular velocity signal:

    θ̇filtered(k) = αθ̇(k) + (1−α)θ̇filtered(k−1)

In this project, α = 0.7 was used as an experimental compromise to suppress reaction wheel vibration while maintaining sufficient response speed for balancing control.

3.4. Edge Balancing Dynamics and Torque-Based Control Principle

3.4.1. Reaction Wheel Torque Generation
A reaction wheel generates control torque by accelerating or decelerating its motor. The angular momentum of the reaction wheel is Hw = Jwωw, and the reaction torque acting on the cube body is:

    τc = −Jwω̇w

This relation shows that the corrective torque is generated when the wheel speed changes, not simply because the wheel is rotating at high speed.

3.4.2. Edge Balancing Dynamics
For edge balancing, the cube can be approximated as an inverted pendulum. The linearized rotational dynamics are:

    Jcθ̈ = mglθ − u

where Jc is the moment of inertia about the contact edge, m is the mass, g is gravitational acceleration, l is the distance from the contact edge to the center of mass, and u is the motor torque. The unstable gravitational component mgl/Jcθ requires continuous active control to stabilize the cube.

3.4.3. State-Space Representation for Edge Balancing
The state vector for edge balancing is x = [θ, θ̇, ωw]T, and a state feedback controller is expressed as:

    u = −kθθ − kθ̇θ̇ − kωωw

The wheel speed feedback term kωωw helps suppress excessive wheel speed accumulation, which is one of the major causes of actuator saturation.

3.5. Vertex Balancing Dynamics and Three-Wheel Coordinate Transformation


Figure 3. Geometric arrangement of the three reaction wheels and the Cartesian coordinate system used for wheel-speed transformation and control allocation. The three wheels are placed at approximately 120° intervals.

3.5.1. Extension from Edge Balancing to Vertex Balancing
In vertex balancing, the attitude of the cube is represented by two small tilt angles q = [θX, θY]T. Assuming small-angle motion, the rotational dynamics can be approximated as:

    JXθ̈X = mglXθX − τX
    JYθ̈Y = mglYθY − τY

3.5.2. Multi-Axis Dynamics and Cross-Axis Coupling
During practical experiments, it was observed that tilting motion in one axis could influence the balancing behavior of the other axis, due to assembly tolerances, non-uniform mass distribution, actuator differences, and sensor alignment errors. This motivated the inclusion of cross-axis attitude feedback in the state feedback controller.

3.5.3. Three-Wheel to Cartesian Coordinate Transformation
Let ω1, ω2, and ω3 denote the measured rotational speeds of the three reaction wheels. The equivalent X- and Y-axis wheel speed components were calculated as:

    ωX = 0.905(ω3 − (ω1 + ω2)/2)
    ωY = 0.787(ω2 − ω1)
    ωZ = ω1 + ω2 + ω3

3.5.4. Control Input Allocation to Three Reaction Wheels
The Cartesian control commands uX and uY are distributed to the three motor PWM inputs as:

    m1 = (0.5uX − 0.866uY) / 1.37 + uZ
    m2 = (0.5uX + 0.866uY) / 1.37 + uZ
    m3 = −uX / 1.37 + uZ

After the motor commands were calculated, they were constrained within the allowable PWM range: mi ∈ [−255, 255].

3.6. State Feedback Controller Design

3.6.1. State Variable Definition
The X-axis controller state vector is defined as:

    xX = [θX, θY, θ̇X, ωX, IX]T

where IX is the integral of the X-axis wheel speed. Similarly, the Y-axis controller state vector is:

    xY = [θY, θX, θ̇Y, ωY, IY]T

The wheel speed integral terms are calculated as:

    IX(k) = IX(k−1) + ωX(k)·dt
    IY(k) = IY(k−1) + ωY(k)·dt

3.6.2. State Feedback Control Law
The X-axis control input is computed as:

    uX = −(kXθθX + kXcθY + kXθ̇θ̇X + kXωωX + kXIIX)

Similarly, the Y-axis control input is computed as:

    uY = −(kYθθY + kYcθX + kYθ̇θ̇Y + kYωωY + kYIIY)

The cross-axis attitude term kXcθY (and kYcθX) was included to improve robustness against coupling effects observed in the actual hardware.

3.6.5. Experimental Gain Tuning Procedure


Figure 4. Experimental setup for axis-constrained gain tuning using physical barriers. The barriers were used to limit excessive cube motion and to verify the control direction and damping response of each axis.

The feedback gains were determined through an iterative experimental tuning process. Axis-by-axis tuning was first performed by physically constraining the cube's motion using mechanical barriers. After the basic response of each axis was confirmed, the barriers were removed and full vertex balancing tests were performed. In this stage, wheel speed accumulation, PWM saturation, residual yaw rotation, and diagonal tilting motion were observed, and gains were adjusted accordingly.

3.7. Yaw Suppression and Practical Compensation
The yaw suppression command was implemented as:

    uZ = −(kZψ̇ψ̇ + kZωωZ)

where kZψ̇ is the yaw-rate feedback gain and kZω is the yaw-related wheel speed feedback gain. The first term suppresses the actual yaw rotation of the cube body, while the second term suppresses the accumulated yaw-related wheel speed component.

4. Experiments

4.1. Experimental Setup
Experiments were conducted using the developed reaction wheel-based self-balancing cube prototype, consisting of three BLDC motors with reaction wheels, an MPU6050 IMU, rotary encoders, an ESP32 microcontroller, and a 3S 11.1V LiPo battery. The control loop and filter parameters are summarized in Table 1.

Table 1. Control loop and filter parameters.

ParameterPIDSF
dt10 ms15 ms
Kgyro0.1 / 0.9960.996
α0.760.74
fc19.1 Hz14.3 Hz
PWM range[−255, 255][−255, 255]


4.2. Initial Attitude-Error-Based Control Test
The initial balancing experiment was conducted using a PD-type attitude controller:

    u(t) = Kpe(t) + Kd de(t)/dt

In this initial control approach, the PWM command was used as the motor control input, but the actual rotational speed of each reaction wheel was not directly measured. During the initial vertex balancing experiments, the cube maintained balancing motion for approximately 1–2 s before losing stability. The most notable failure behavior was that the cube rotated about the yaw axis and then fell. This yaw-axis rotation suggested that the three reaction wheels were not generating ideally balanced outputs, particularly that the third motor appeared to produce a different effective output compared with the other two motors.

4.3. Hardware Modification and Failure Analysis
After the initial control test, several hardware-related limitations were analyzed. First, the asymmetric battery configuration was abandoned and the system was restored to a symmetric single-battery configuration. Second, the LDO regulator was replaced with a DC-DC buck converter to eliminate the thermal failure mechanism. Third, the control board was upgraded from Arduino Nano to ESP32. Finally, motor output imbalance was identified as an important factor causing yaw-axis rotation, motivating the introduction of encoder-based wheel speed measurement.

4.4. State Feedback Controller Implementation
After identifying the limitations of the initial controller, an encoder-based state feedback controller was implemented. The encoder measurements were used to estimate the rotational speeds of the three reaction wheels, and these speeds were transformed into Cartesian components ωX, ωY, and ωZ. The controller was tuned experimentally in several steps: first attitude angle gains, then angular velocity gains, then wheel speed and integral gains, and finally cross-axis attitude feedback and yaw suppression gains.

4.5. Vertex Balancing Performance


Figure 5. Preliminary edge balancing test of the self-balancing cube. This test was used to verify the basic operation of the reaction wheel system before conducting vertex balancing experiments.


Figure 6. Final vertex balancing experiment of the self-balancing cube. The cube remained balanced on a single vertex without external support for approximately 35 s.

After applying the hardware modifications and implementing the encoder-based state feedback controller, the cube was able to maintain vertex balancing for approximately 35 s in the final experiment, compared with approximately 1–2 s for the initial implementation. During the final balancing test, the X- and Y-axis attitude angles oscillated around the balancing point rather than diverging immediately, indicating that the state feedback controller was able to generate corrective motor commands in response to both body attitude states and wheel speed states.

Table 2. Comparison of vertex balancing performance.

ConfigurationBalancing Duration
Initial controller1–2 s
Final state feedback controller35 s


  
Figure 7. Comparison of balancing performance between the initial PID-based controller (left) and the final state feedback controller (right).

5. Conclusion
In this project, a reaction wheel-based self-balancing cube was developed and experimentally tested for vertex balancing. In the initial experiment, an attitude-error-based controller was used, and the cube was able to maintain vertex balancing for only approximately 1–2 s. The most common failure behavior was yaw-axis rotation followed by falling, attributed to the discrepancy between PWM commands and actual motor speeds, motor output imbalance, and the absence of encoder-based wheel speed feedback.
A key finding of this project was that the X- and Y-axis balancing motions of the actual cube could not be treated as completely independent. Tilting motion in one axis affected the balancing behavior of the other axis. To address this cross-axis coupling, the final state feedback controller included the Y-axis attitude angle in the X-axis controller and vice versa. The final controller also incorporated encoder-based wheel speed feedback, allowing the controller to respond more effectively to motor response differences and residual yaw motion.
As a result, the final system was able to maintain vertex balancing for approximately 35 s, a significant improvement compared with the initial implementation. This result indicates that stable vertex balancing requires not only attitude feedback, but also actual wheel speed feedback, cross-axis attitude feedback, hardware symmetry, and power supply stability. The most important insight is that, in a real multi-axis balancing system, controlling each axis independently is not sufficient; cross-axis coupling and actual actuator states must be considered together to achieve stable vertex balancing.

References
[1] Michael Muehlebach and Raffaello D'Andrea. The cubli: A cube that can jump up and balance. In 2013 IEEE/RSJ International Conference on Intelligent Robots and Systems, pages 3722–3727. IEEE, 2013.
[2] remrc. Self-Balancing-Cube. https://github.com/remrc/Self-Balancing-Cube, 2024. Open-source reaction wheel-based self-balancing cube project.