Analyze, implement, and tune the control system for a provided reaction-wheel motorcycle platform capable of autonomous lateral balance and forward motion across a 2-meter course. All mechanical hardware was pre-supplied by the course; the work centered on stability analysis, PID controller tuning, and embedded software implementation.
Platform: pre-built two-wheeled motorcycle chassis
Balancing mechanism: internal reaction flywheel
Sensor: BNO055 IMU for roll angle feedback
Microcontroller: Arduino with Motor Carrier shield
Drive motor: rear wheel DC motor
Race course: 2 meters, fully autonomous
Analyzed the motorcycle-flywheel system using a state-space dynamic model, extracting physical parameters from the provided hardware
Performed pole-zero and root locus analysis in MATLAB to characterize open-loop instability and identify the negative-gain control requirement
Interpreted stability analysis results to inform PID controller design
Iteratively tuned PID balance controller gains through hardware testing across multiple configurations
Determined open-loop drive timing values empirically through repeated physical test runs
Implemented integral anti-windup and 14° safety cutoff in the embedded controller
The motorcycle and flywheel form a coupled dynamic system whose behavior was characterized using a state-space model, parameterized with the physical measurements of the hardware — including motorcycle mass (0.2948 kg), flywheel mass (0.0695 kg), flywheel radius (0.05 m), and motor constants (Ke = Kt = 0.019). Converting the state-space representation to a transfer function using MATLAB yielded:
G(s) = −1.024s / (s³ + 0.6607s² − 96.56s − 61.92)
With the stability analysis establishing the sign and approximate magnitude of required gains, a PID balance controller was implemented in Arduino C++ using roll angle feedback from the BNO055 IMU. Using MATLAB's pidtune output as an initial reference point, gains were refined through four rounds of hardware testing:
Hardware behavior under rapid tilt changes revealed undercompensation in damping, driving increases to both the proportional and derivative gains. Final values of Kp = −6000, Ki = −25, Kd = −400 produced reliable balance with approximately 3 seconds settling time and minimal overshoot. The controller included integral anti-windup to prevent integrator saturation during large disturbances, and a hard 14° cutoff that zeros motor output beyond a recoverable tilt angle.
Forward motion was implemented as an open-loop timed sequence, fully decoupled from the balance loop. Empirical testing over four runs established that the bike covers 2 meters in an average of 1.71 seconds at full duty. A 20% time buffer was added, producing the final sequence: 5-second balance settling delay → 2 seconds at 100% duty → 0.5-second linear ramp-down to 0%. The drive motor also cuts off if tilt exceeds 14°, linking the two control loops through a shared safety condition.
Completed the 2-meter autonomous race course in 1.7 seconds
Zero falls, zero penalties
Root locus analysis confirmed negative-gain requirement — one positive pole at s = +9.82 confirmed open-loop instability
Negative-gain PID (Kp = −6000, Ki = −25, Kd = −400) achieved ~3 second settling time through iterative hardware tuning