The DCost class defines the incremental and terminal costs of a trajectory during a discrete trajectory optimization. It is used in conjunction with DSystem and DOptimizer.
The discrete trajectory optimization finds a trajectory that minimizes a cost of the form:
DCost defines the costs \(\ell(x, u, k)\) and \(m(x)\) for a system and calculates their 1st and 2nd derivatives.
The current implementation defines a suitable cost for tracking a desired trajectory:
where \(x_d(k)\) and \(u_d(k)\) are the desired state and input trajectories and \(Q\) and \(R\) are positive definite matrices that define their weighting.
Parameters: |
|
---|
Create a new cost object for the desired states xd weighted by Q and the desired inputs ud weighted by R.
(numpy array, shape (nX, nX))
The weights of the states.
(numpy array, shape (nU, nU))
The weights of the inputs.
Parameters: |
|
---|---|
Return type: | float |
Calculate the incremental cost of xk and uk at discrete time k.
Parameters: | xkf (numpy array, shape (nX)) – Final state |
---|---|
Return type: | float |
Calculate the terminal cost of xk.
Parameters: |
|
---|---|
Return type: | numpy array, shape (nX) |
Calculate the derivative of the incremental cost with respect to the state.
Parameters: |
|
---|---|
Return type: | numpy array, shape (nU) |
Calculate the derivative of the incremental cost with respect to the input.
Parameters: | xkf (numpy array, shape (nX)) – Current state |
---|---|
Return type: | numpy array, shape (nX) |
Calculate the derivative of the terminal cost with respect to the final state.
Parameters: |
|
---|---|
Return type: | numpy array, shape (nX, nX) |
Calculate the second derivative of the incremental cost with respect to the state. For this implementation, this is always equal to Q.
Parameters: |
|
---|---|
Return type: | numpy array, shape (nU, nU) |
Calculate the second derivative of the incremental cost with respect to the inputs. For this implementation, this is always equal to R.
Parameters: |
|
---|---|
Return type: | numpy array, shape (nX, nU) |
Calculate the second derivative of the incremental cost with respect to the state and inputs. For this implementation, this is always equal to zero.