Say I have a Drake Diagram
with an input port and and output port. I happen to know that, holding the state of the diagram constant, these input and output ports have an affine relationship, i.e. y = A(x) u + b(x) where x is the full state of the Diagram
. However, the Diagram is not explicitly an AffineSystem
since its dependence on state is nonlinear.
What is the best way to generate a corresponding AffineSystem
, or extract the matrices A and b for a given state of the diagram? Currently, I'm using
# set state
context.get_mutable_continuous_state_vector().SetFromVector(x)
# inputs to zero to get affine term
diagram.get_input_port().FixValue(context, np.zeros(k))
b = diagram.get_output_port().Eval(context)
# get linear term coefficient matrix
linearized = Linearize(
diagram,
context,
input_index,
output_index,
equilibrium_check_tolerance=1e20
)
A = linearized.D()
where the 1e20
tolerance basically just forces Drake to linearize the system even though it's not at an equilibrium. But I'm wondering if there's a more principled way to do this.
The reason I want to do this is similar to the question of this user about input allocation for underactuated systems. For a diagram consisting of a MultibodyPlant
, Propeller
, and a Multiplexer
which multiplexes the input port to Propeller
commands and JointActuator
commands, I'd like to compute the affine relationship between inputs and generalized accelerations, so I can use this data in a QP for input allocation.
Thanks in advance for your help!