Code Generation for Conic Model-Predictive Control on Microcontrollers with TinyMPC

Sam Schoedel, Khai Nguyen, Elakhya Nedumaran, Brian Plancher, Zachary ManchesterarXiv 2024 · DOI

Abstract

Model-Predictive Control (MPC) is a powerful tool for robotic control due to its ability to handle constraints explicitly. However, deploying MPC on resource-constrained microcontrollers (MCUs) is challenging due to limited RAM and processing power. This paper presents Conic-TinyMPC, an extension of the TinyMPC framework designed to solve Second-Order Cone Programs (SOCPs) on embedded hardware. By utilizing cached Riccati recursion and a specialized code-generation tool, Conic-TinyMPC achieves up to a 142x speedup over state-of-the-art solvers. We validate our approach through benchmarks and real-time flight experiments on a 27g nano-quadrotor, demonstrating efficient handling of complex conic constraints.

Introduction

Robotic systems often operate under strict physical constraints, such as thrust-vector limits or obstacle avoidance. While MPC is ideal for these scenarios, its computational demands often exceed the capabilities of the microcontrollers found in small-scale robots. Existing embedded solvers primarily target Quadratic Programming (QP), which cannot represent "conic" constraints essential for modeling friction cones or glideslope requirements. General-purpose SOCP solvers like ECOS or SCS are typically too slow for high-frequency control or rely on dynamic memory allocation, which is unsuitable for safety-critical embedded systems.

Methodology

Conic-TinyMPC builds upon the Alternating Direction Method of Multipliers (ADMM) to decompose complex optimization problems into simpler sub-problems. The framework introduces several key innovations to optimize performance for MCUs:

  1. Cached Riccati Recursion: For Linear Time-Invariant (LTI) systems, the solver pre-computes matrix factorizations offline. This reduces the online primal update to simple matrix-vector products, shifting the computational complexity from $O(n^3)$ to $O(n^2)$.
  2. Conic Projections: Support for Second-Order Cones (SOCs) is implemented via closed-form projection operators. This allows for efficient handling of glideslope and thrust constraints without the overhead of interior-point methods.
  3. Code Generation: A dedicated tool generates dependency-free, division-free C++ code. By caching the inverse of Riccati terms, the solver avoids slow floating-point divisions and uses only static memory allocation to ensure runtime reliability.

Experimental Results

The solver was evaluated across three primary benchmarks: Predictive Safety Filtering (QP), Rocket Soft-Landing (SOCP), and a hardware experiment using a Crazyflie nano-quadrotor.

Hardware demonstration of Conic-TinyMPC on a Crazyflie nano-quadrotor, showing successful navigation within cone and box constraints.

In the hardware tests, the Crazyflie successfully performed a spiral landing while adhering to a 45° glideslope constraint—a task where traditional reactive controllers failed, leading to crashes. The solver's ability to warm-start from previous solutions was crucial for maintaining the high control rates (50Hz+) required for stable flight.

Performance Benchmarks

Quantitative analysis shows that Conic-TinyMPC significantly outperforms existing solvers in both speed and memory efficiency.

Performance benchmarks for Predictive Safety Filtering and Rocket Soft Landing, comparing TinyMPC against OSQP, ECOS, and SCS in terms of execution time and memory usage.

On the Rocket Soft-Landing benchmark, Conic-TinyMPC was 13.8x faster than SCS and 142.7x faster than ECOS. Furthermore, it maintained a predictable memory footprint, solving problems with 100 knot points where other solvers like OSQP failed due to memory limits at just 32 knot points. This predictability is vital for avoiding heap overflows during flight.

Conclusion

Conic-TinyMPC enables high-rate, constrained control on the smallest robotic platforms. While currently limited by the LTI assumption, the framework provides a robust, memory-safe solution for deploying advanced control strategies on resource-constrained hardware. Future work will focus on adaptive caching and reachability analysis to bridge the gap between linear models and nonlinear physics.

Summary updated

BibTeX
@misc{schoedel2024code,
  author = {Sam Schoedel and Khai Nguyen and Elakhya Nedumaran and Brian Plancher and Zachary Manchester},
  title = {{Code Generation for Conic Model-Predictive Control on Microcontrollers with TinyMPC}},
  year = {2024},
  eprint = {2403.18149},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.18149},
}
Figure