control.flatsys.solve_flat_optimal

control.flatsys.solve_flat_optimal(sys, timepts, initial_state=0, initial_input=0, integral_cost=None, basis=None, terminal_cost=None, trajectory_constraints=None, initial_guess=None, params=None, **kwargs)[source]

Compute trajectory between an initial and final conditions.

Compute an optimal trajectory for a differentially flat system starting from an initial state and input value.

Parameters
sysFlatSystem object

Description of the differentially flat system. This object must define a function forward that takes the system state and produces the flag of flat outputs and a function reverse that takes the flag of the flat output and produces the state and input.

timeptsfloat or 1D array_like

The list of points for evaluating cost and constraints, as well as the time horizon. If given as a float, indicates the final time for the trajectory (corresponding to xf)

initial_state (or x0), input_input (or u0)1D arrays

Define the initial conditions for the system (default = 0).

initial_input (or u0)1D array_like

Initial input for the system. Defaults to zero.

basisBasisFamily object, optional

The basis functions to use for generating the trajectory. If not specified, the PolyFamily basis family will be used, with the minimal number of elements required to find a feasible trajectory (twice the number of system states)

integral_costcallable

Function that returns the integral cost given the current state and input. Called as cost(x, u).

terminal_costcallable

Function that returns the terminal cost given the state and input. Called as cost(x, u).

trajectory_constraintslist of tuples, optional

List of constraints that should hold at each point in the time vector. Each element of the list should consist of a tuple with first element given by scipy.optimize.LinearConstraint or scipy.optimize.NonlinearConstraint and the remaining elements of the tuple are the arguments that would be passed to those functions. The following tuples are supported:

  • (LinearConstraint, A, lb, ub): The matrix A is multiplied by stacked vector of the state and input at each point on the trajectory for comparison against the upper and lower bounds.

  • (NonlinearConstraint, fun, lb, ub): a user-specific constraint function fun(x, u) is called at each point along the trajectory and compared against the upper and lower bounds.

The constraints are applied at each time point along the trajectory.

initial_guess2D array_like, optional

Initial guess for the optimal trajectory of the flat outputs.

paramsdict, optional

Parameter values for the system. Passed to the evaluation functions for the system as default values, overriding internal defaults.

Returns
trajSystemTrajectory

The system trajectory is returned as an object that implements the SystemTrajectory.eval function, we can be used to compute the value of the state and input and a given time t.

Other Parameters
minimize_methodstr, optional

Set the method used by scipy.optimize.minimize.

minimize_optionsstr, optional

Set the options keyword used by scipy.optimize.minimize.

minimize_kwargsstr, optional

Pass additional keywords to scipy.optimize.minimize.

Notes

Additional keyword parameters can be used to fine tune the behavior of the underlying optimization function. See minimize_* keywords in control.optimal.OptimalControlProblem for more information.

The return data structure includes the following additional attributes:

  • success : bool indicating whether the optimization succeeded

  • cost : computed cost of the returned trajectory

  • message : message returned by optimization if success if False

A common failure in solving optimal control problem is that the default initial guess violates the constraints and the optimizer can’t find a feasible solution. Using the initial_guess parameter can often be used to overcome these errors.