drake

How to add linear constraints on Cartesian position for a trajectory optimization?


I'm struggling to linearize a Drake trajectory optimization problem and am hoping for some high-level guidance.

Background

I've got some KinematicTrajectoryOptimization code working that finds a ping-ping swing (YouTube vid) via SNOPT. My goal is to linearize the problem so it's a QP. Then, I could use Linear MPC which would update based on the ping-pong ball estimate from cameras.

My nonlinear problem has PositionConstraint/OrientationConstraint and SpatialVelocityConstraint added to the trajopt with AddPathPositionConstraint and AddVelocityConstraintAtNormalizedTime respectively. These constraints are at the predicted moment of contact time (there's also a few less relevant start/end constraints).

Question

I'm trying to move this program to either a DirectCollocation or plain MathematicalProgram, but am having trouble finding linear alternatives to the constraints that bound the cartesian position of robot frames.

Is it possible to add linear Cartesian constraints of the end-effector position? The two possibilities I thought of were...


Solution

  • Is it possible to add linear cartesian constraints of the end-effector position?

    You can use PolyhedronConstraint, https://drake.mit.edu/doxygen_cxx/classdrake_1_1multibody_1_1_polyhedron_constraint.html which says that the end-effector pose should lie within a polyhedron (hence a linear constraint on the end-effector position). This will add a nonlinear constraint on the generalized position q. If you linearize this nonlinear constraint (for example, using Eval function with autodiff, you then get the linearized version of the constraint).

    When linearizing the dynamics, do you linearize once per MPC loop at the initial state, or N types per MPC loop, once at each collocation point, using it's values from the initial guess? I think my system is control-affine so it doesn't matter what u is linearized about.

    Do you already have a trajectory that you want to follow, or do you only know the current state at the beginning of the MPC loop? If you know the entire trajectory you want to follow, then I would suggest to linearize at every dt around the future state on the tracked trajectory. Otherwise you can linearize around the current state.