Inferensys

Glossary

Quadratic Program (QP) Formulation

A Quadratic Program (QP) formulation is a mathematical optimization problem with a quadratic cost function and linear constraints, used for real-time robot control tasks like inverse dynamics and whole-body control.
Control room desk with laptops and a large orchestration network display.
OPTIMIZATION

What is Quadratic Program (QP) Formulation?

A mathematical framework for solving constrained optimization problems with quadratic objectives, foundational to real-time robotic control.

A Quadratic Program (QP) Formulation is a constrained optimization problem characterized by a quadratic objective function and linear constraints. In legged robot locomotion, it is the computational engine for whole-body control (WBC) and inverse dynamics, solving for optimal joint torques and contact forces that satisfy physical laws like dynamics, friction cones, and actuation limits in real-time. This formulation transforms high-level locomotion tasks into a numerically tractable convex optimization problem.

The standard QP for robotics minimizes a cost like tracking error, often expressed as (1/2)x^T Q x + c^T x, subject to linear equality constraints (e.g., Newton-Euler equations) and inequality constraints (e.g., ground reaction force limits). Solvers exploit the problem's convex structure for millisecond-scale solutions, enabling reactive balance and push recovery. This approach is central to model predictive control (MPC) pipelines, where it is solved repeatedly in a receding horizon to generate dynamically feasible, stable motions.

QUADRATIC PROGRAM (QP) FORMULATION

Core Components of a Robotics QP

A Quadratic Program (QP) is the mathematical engine for real-time robot control. It solves for optimal actuator commands by minimizing a quadratic cost function subject to linear constraints on dynamics, safety, and physical limits.

01

Quadratic Cost Function

The objective function that the QP minimizes. It is mathematically expressed as (1/2) x^T Q x + c^T x, where x is the vector of optimization variables (e.g., joint accelerations, contact forces).

  • Purpose: Encodes the primary control task, such as tracking a desired center-of-mass trajectory or minimizing joint torques.
  • Matrix Q: A positive semi-definite matrix that weights the importance of different terms in the cost.
  • Real Example: For a humanoid robot, the primary cost might be to minimize the error between the current and desired centroidal momentum, heavily weighted by Q.
02

Linear Equality Constraints

Hard mathematical rules that the solution must satisfy exactly. Represented as A_eq x = b_eq.

  • Core Use: Enforce the fundamental physics of the system, primarily the floating-base dynamics equations (F = ma). This ensures any solution is dynamically consistent.
  • Other Uses: Enforcing contact constraints (e.g., a foot in contact must have zero velocity) or specific task constraints (e.g., keeping the torso upright).
  • Critical Role: These constraints are non-negotiable; a QP solver will fail if it cannot find a solution that satisfies them.
03

Linear Inequality Constraints

Boundaries that define the feasible region of solutions, expressed as A_ineq x ≤ b_ineq.

  • Actuator Limits: Enforce maximum joint torques, velocities, and accelerations based on motor specifications.
  • Friction Cones: Ensure contact forces lie within a pyramid defined by the coefficient of friction, preventing foot slippage. This is a linear approximation of a non-linear constraint.
  • Stability Margins: Constrain the Center of Pressure (CoP) to remain within the support polygon for balance.
  • Self-Collision Avoidance: Often formulated as linear constraints on joint positions to keep links apart.
04

Optimization Variables (x)

The vector of unknowns the QP solves for at each control time step (typically every 1-10 ms).

  • Typical Variables:
    • Joint accelerations (or torques via inverse dynamics).
    • Contact forces at each foot.
    • Centroidal spatial forces (net force and moment on the robot).
  • Dimensionality: For a complex humanoid with 30 joints and 2 feet in contact, x may have 50+ dimensions. The QP efficiently finds the optimal combination of these variables to satisfy all tasks and constraints.
05

Hierarchical Task Prioritization

A method to manage competing objectives when all cannot be fully satisfied. It is implemented via a sequence of QPs or a single weighted QP.

  • Strict Priority (Sequential QP): Solve a QP for the highest-priority task (e.g., dynamic consistency), then solve a subsequent QP for the next task (e.g., foot tracking) in the null space of the first.
  • Weighted Priority (Single QP): Assign different weights in the Q matrix of the cost function. Higher-priority tasks get larger weights, but all tasks are solved simultaneously, potentially with trade-offs.
  • Example: Balance is always highest priority, followed by swing foot trajectory, then torso orientation.
OPTIMIZATION ENGINE

How QP Formulation Works for Robot Control

Quadratic Program (QP) formulation is the mathematical backbone for real-time, optimal control in legged and mobile robots, transforming high-level locomotion tasks into solvable numerical optimization.

A Quadratic Program (QP) formulation in robotics is a constrained optimization problem with a quadratic objective function and linear constraints, solved in real-time to compute optimal control commands. It is the core computational engine for Whole-Body Control (WBC) and inverse dynamics, enabling a robot to simultaneously execute multiple tasks—like maintaining balance and tracking a foot trajectory—while strictly respecting physical limits on joint torques, friction cones, and Zero-Moment Point (ZMP) stability. The quadratic cost typically penalizes tracking errors and control effort, while linear constraints encode the robot's floating base dynamics and contact conditions.

The solver computes optimal ground reaction forces (GRFs) and joint accelerations or torques at control rates (e.g., 1 kHz). This formulation is central to Model Predictive Control (MPC) for locomotion, where a QP is solved repeatedly over a receding horizon to plan stable motions. Its power lies in balancing competing objectives under hard constraints, providing the mathematical guarantee needed for dynamic, physically interactive tasks like push recovery and terrain adaptation on unstructured ground.

QUADRATIC PROGRAM (QP) FORMULATION

Primary Applications in Legged Locomotion

In legged robotics, Quadratic Program (QP) formulations are the computational engine for real-time, whole-body control. They solve for optimal joint torques and contact forces by minimizing a quadratic cost (e.g., tracking error) subject to linear physical constraints (e.g., friction cones, torque limits).

01

Whole-Body Control (WBC)

Whole-Body Control uses QP to coordinate all robot joints to execute multiple, often competing, tasks simultaneously. The QP's quadratic cost function prioritizes tasks (e.g., foot tracking is more important than torso orientation), while linear equality and inequality constraints enforce physical laws like dynamics and contact stability. This allows a humanoid to walk while moving its arms, all while respecting actuator limits.

02

Inverse Dynamics with Constraints

Standard inverse dynamics computes torques for a desired motion but can violate physical limits. A QP formulation solves this by finding the torques that best achieve the desired joint accelerations while strictly enforcing:

  • Torque limits of each actuator.
  • Friction cone constraints to prevent foot slipping (|f_tangential| ≤ μ * f_normal).
  • Unilateral force constraints (feet can only push, not pull, on the ground). This yields physically feasible torques for stable locomotion on real hardware.
03

Centroidal Momentum Control

Controlling the robot's aggregate linear and angular momentum (centroidal momentum) is key for balance. A QP solves for the optimal ground reaction forces (GRFs) at the feet to regulate this momentum. The cost minimizes deviation from a desired momentum rate, while constraints ensure:

  • The net GRF equals the required centroidal wrench.
  • Each foot's force lies within its friction pyramid.
  • The Center of Pressure (CoP) remains inside the support polygon. This is the core of many dynamic balancing algorithms.
04

Task-Space Force Control

For manipulation with legs or compliant interaction, QPs distribute forces across multiple contacts. Given a desired net wrench to apply to an object or the environment, the QP solves for the individual contact forces at each foot or hand. Constraints ensure:

  • The sum of forces equals the desired net force/moment.
  • Each contact force satisfies friction and unilateral constraints.
  • Forces stay within the actuator force-capacity limits. This is essential for robots performing cooperative lifting or pushing against surfaces.
05

Hierarchical Optimization (Lexicographic)

When tasks have strict priorities (e.g., balance over arm motion), a single QP with weighted costs is insufficient. Hierarchical QP (or lexicographic optimization) solves a sequence of QPs. The first QP optimizes the highest-priority task (e.g., maintaining ZMP stability). The second QP optimizes the next task (e.g., swing foot trajectory) subject to the constraint that the solution does not degrade the first task's optimal value. This guarantees critical constraints are never violated for less important objectives.

06

Real-Time Solver Integration

For legged locomotion, QPs must be solved at control rates (500-1000 Hz). This requires specialized real-time QP solvers like OSQP, qpOASES, or HPIPM. These solvers exploit the problem's structure:

  • The Hessian matrix (from the quadratic cost) is often constant, allowing for pre-computation.
  • Warm-starting uses the previous solution to accelerate convergence.
  • Active-set or interior-point methods are tailored for the dense, small-to-medium-sized QPs typical in locomotion. Integration with the robot's real-time operating system is critical for deterministic loop timing.
QUADRATIC PROGRAM (QP) FORMULATION

Frequently Asked Questions

Quadratic Program (QP) formulation is a cornerstone mathematical tool for real-time robotic control. These questions address its core mechanics, applications in legged locomotion, and practical implementation details.

A Quadratic Program (QP) is a mathematical optimization problem characterized by a quadratic objective function and linear constraints. In robotics, particularly for legged and mobile systems, QPs are solved in real-time (often at 1 kHz) to compute optimal control commands. The quadratic cost function allows the formulation to naturally express trade-offs between competing objectives—like tracking a desired foot trajectory while minimizing joint torques—and the linear constraints rigorously encode physical limits, such as actuator torque limits, friction cone constraints to prevent slipping, and kinematic reachability. This combination makes QP formulation the computational engine for advanced control paradigms like Whole-Body Control (WBC) and certain Model Predictive Control (MPC) implementations, enabling robots to dynamically balance and move while respecting their physical reality.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.