qpsolvers / mpc_qpbenchmark

Model predictive control test set to benchmark QP solvers
Apache License 2.0
10 stars 0 forks source link

Linear centroidal model predictive control for quadruped locomotion #1

Closed paLeziart closed 6 months ago

paLeziart commented 7 months ago

Problem

I propose to add the following problem to the GitHub free-for-all test set. The problem can be built as follows by using the CentroidalQuadruped class:

def build_problem():
    # Create the optimal control problem
    gait = np.array(
        [[8, 1, 0, 0, 1], [8, 0, 1, 1, 0], [8, 1, 0, 0, 1], [8, 0, 1, 1, 0]]
    )
    vref = np.array([0.1, 0.0, 0.0]).reshape((-1, 1))
    SQ = CentroidalQuadruped(gait, vref)

    # Cost: x^T P x + q^T x
    P = SQ.get_P()
    q = SQ.get_q()

    # Inequality constraints: G x <= h
    G = SQ.get_G()
    h = SQ.get_h()

    # Equality constraints: A x == b
    A = SQ.get_A()
    b = SQ.get_b()

    # Box constraints: lb <= x <= ub
    lb = SQ.get_lb()
    ub = SQ.get_ub()

    return P, q, G, h, A, b, lb, ub, SQ

Parameter range

Internal parameter range

There are a bunch of parameters in the init of the class whose values are those used for Solo-12. I disabled the regularization cost for the contact forces to know the optimal solution in simple standing cases (see below), but it can be set up to 5e-5 if you want.

Motivation

This problem is interesting as centroidal model predictive problems are a well-known approach in the community of legged robots when the mass of the legs is not too important with respect to the one of the base.

Solution and optimal cost

As the base starts horizontal and centered in the middle of the 4 contact points, if the contact force is vertical and perfectly distributed on the four contacts to compensate the gravity, the base will stay perfectly still without tilting.

Note that in practice the QP solves for x = [X-Xref F] for all time steps stacked together, so in term of result returned by the solver, for a prediction horizon with 3 steps it is x = [X1-X1ref X2-X2ref X3-X3ref F0 F1 F2]

As the base starts horizontal and centered in the middle of the 4 contact points, if the contact force is vertical and perfectly distributed on the two contacts to compensate the gravity, the base will stay perfectly still without tilting.

These optimal solutions are only valid when the contact force regularization coefficients are 0, otherwise there is a small trade-off between state tracking and applied forces.

Source code

https://gitlab.laas.fr/paleziart/quadruped-qp-problems

Testing

You can launch centroidalMPC.py to solve an example problem with OSQP and display a bunch of plots about state tracking and contact forces.

References

1. Léziart, P. A. (2022). Locomotion control of a lightweight quadruped robot (Doctoral dissertation, UPS Toulouse).

See pages 91-95 for a description of the linear centroidal model predictive controller.

stephane-caron commented 6 months ago

Thanks a bunch @paLeziart for this contribution! I've kick-started the mpc_qpbenchmark test set with your contribution, to which I'll add the ones I have lying around for HRP-4 and Upkie. Feel free to share your thoughts on this test set and how we could improve it.

stephane-caron commented 6 months ago

I'll add the ones I have lying around for HRP-4 and Upkie.

Closing this issue now that it is done.