![]() |
Sleipnir Python API
|
Public Member Functions | |
| None | __init__ (self, int num_states, int num_inputs, datetime.timedelta|float dt, int num_steps, Callable[[VariableMatrix, VariableMatrix], VariableMatrix] dynamics, DynamicsType dynamics_type=DynamicsType.EXPLICIT_ODE, TimestepMethod timestep_method=TimestepMethod.FIXED, TranscriptionMethod transcription_method=TranscriptionMethod.DIRECT_TRANSCRIPTION) |
| None | constrain_initial_state (self, float initial_state) |
| None | constrain_initial_state (self, int initial_state) |
| None | constrain_initial_state (self, Variable initial_state) |
| None | constrain_initial_state (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] initial_state) |
| None | constrain_initial_state (self, VariableMatrix|VariableBlock initial_state) |
| None | constrain_final_state (self, float final_state) |
| None | constrain_final_state (self, int final_state) |
| None | constrain_final_state (self, Variable final_state) |
| None | constrain_final_state (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] final_state) |
| None | constrain_final_state (self, VariableMatrix|VariableBlock final_state) |
| None | for_each_step (self, Callable[[VariableMatrix, VariableMatrix], None] callback) |
| None | set_lower_input_bound (self, float lower_bound) |
| None | set_lower_input_bound (self, int lower_bound) |
| None | set_lower_input_bound (self, Variable lower_bound) |
| None | set_lower_input_bound (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] lower_bound) |
| None | set_lower_input_bound (self, VariableMatrix|VariableBlock lower_bound) |
| None | set_upper_input_bound (self, float upper_bound) |
| None | set_upper_input_bound (self, int upper_bound) |
| None | set_upper_input_bound (self, Variable upper_bound) |
| None | set_upper_input_bound (self, Annotated[NDArray[numpy.float64], dict(shape=(None, None))] upper_bound) |
| None | set_upper_input_bound (self, VariableMatrix|VariableBlock upper_bound) |
| None | set_min_timestep (self, datetime.timedelta|float min_timestep) |
| None | set_max_timestep (self, datetime.timedelta|float max_timestep) |
| VariableMatrix | X (self) |
| VariableMatrix | U (self) |
| VariableMatrix | dt (self) |
| VariableMatrix | initial_state (self) |
| VariableMatrix | final_state (self) |
Public Member Functions inherited from sleipnir.optimization.Problem | |
| Variable | decision_variable (self) |
| VariableMatrix | decision_variable (self, int rows, int cols=1) |
| VariableMatrix | symmetric_decision_variable (self, int rows) |
| None | minimize (self, float cost) |
| None | minimize (self, Variable cost) |
| None | minimize (self, VariableMatrix|VariableBlock cost) |
| None | maximize (self, float objective) |
| None | maximize (self, Variable objective) |
| None | maximize (self, VariableMatrix|VariableBlock objective) |
| None | subject_to (self, EqualityConstraints constraint) |
| None | subject_to (self, InequalityConstraints constraint) |
| ExpressionType | cost_function_type (self) |
| ExpressionType | equality_constraint_type (self) |
| ExpressionType | inequality_constraint_type (self) |
| ExitStatus | solve (self, *float tolerance=1e-08, int max_iterations=5000, float timeout=float('inf'), bool feasible_ipm=False, bool diagnostics=False, bool spy=False) |
| None | add_callback (self, Callable[[IterationInfo], bool] callback) |
| None | clear_callbacks (self) |
This class allows the user to pose and solve a constrained optimal
control problem (OCP) in a variety of ways.
The system is transcripted by one of three methods (direct
transcription, direct collocation, or single-shooting) and additional
constraints can be added.
In direct transcription, each state is a decision variable constrained
to the integrated dynamics of the previous state. In direct
collocation, the trajectory is modeled as a series of cubic
polynomials where the centerpoint slope is constrained. In single-
shooting, states depend explicitly as a function of all previous
states and all previous inputs.
Explicit ODEs are integrated using RK4.
For explicit ODEs, the function must be in the form dx/dt = f(t, x,
u). For discrete state transition functions, the function must be in
the form xₖ₊₁ = f(t, xₖ, uₖ).
Direct collocation requires an explicit ODE. Direct transcription and
single-shooting can use either an ODE or state transition function.
https://underactuated.mit.edu/trajopt.html goes into more detail on
each transcription method.
Template Args:
Scalar: Scalar type.
| None sleipnir.optimization.OCP.__init__ | ( | self, | |
| int | num_states, | ||
| int | num_inputs, | ||
| datetime.timedelta | float | dt, | ||
| int | num_steps, | ||
| Callable[[VariableMatrix, VariableMatrix], VariableMatrix] | dynamics, | ||
| DynamicsType | dynamics_type = DynamicsType.EXPLICIT_ODE, |
||
| TimestepMethod | timestep_method = TimestepMethod.FIXED, |
||
| TranscriptionMethod | transcription_method = TranscriptionMethod.DIRECT_TRANSCRIPTION |
||
| ) |
Builds an optimization problem using a system evolution function
(explicit ODE or discrete state transition function).
Args:
num_states: The number of system states.
num_inputs: The number of system inputs.
dt: The timestep for fixed-step integration.
num_steps: The number of control points.
dynamics: Function representing an explicit or implicit ODE, or a
discrete state transition function.
* Explicit: dx/dt = f(x, u, *)
* Implicit: f([x dx/dt]', u, *) = 0
* State transition: xₖ₊₁ = f(xₖ, uₖ)
dynamics_type: The type of system evolution function.
timestep_method: The timestep method.
transcription_method: The transcription method.
Reimplemented from sleipnir.optimization.Problem.
| None sleipnir.optimization.OCP.constrain_final_state | ( | self, | |
| Annotated[NDArray[numpy.float64], dict(shape=(None, None))] | final_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_final_state | ( | self, | |
| float | final_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_final_state | ( | self, | |
| int | final_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_final_state | ( | self, | |
| Variable | final_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_final_state | ( | self, | |
| VariableMatrix | VariableBlock | final_state | ||
| ) |
Constrains the final state.
Args:
final_state: the final state to constrain to.
| None sleipnir.optimization.OCP.constrain_initial_state | ( | self, | |
| Annotated[NDArray[numpy.float64], dict(shape=(None, None))] | initial_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_initial_state | ( | self, | |
| float | initial_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_initial_state | ( | self, | |
| int | initial_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_initial_state | ( | self, | |
| Variable | initial_state | ||
| ) |
| None sleipnir.optimization.OCP.constrain_initial_state | ( | self, | |
| VariableMatrix | VariableBlock | initial_state | ||
| ) |
Constrains the initial state.
Args:
initial_state: the initial state to constrain to.
| VariableMatrix sleipnir.optimization.OCP.dt | ( | self | ) |
Gets the timestep variables. After the problem is solved, this will
contain the timesteps corresponding to the optimized trajectory.
Shaped 1x(num_steps+1), although the last timestep is unused in the
trajectory.
Returns:
The timestep variable matrix.
| VariableMatrix sleipnir.optimization.OCP.final_state | ( | self | ) |
Gets the final state in the trajectory.
Returns:
The final state of the trajectory.
| None sleipnir.optimization.OCP.for_each_step | ( | self, | |
| Callable[[VariableMatrix, VariableMatrix], None] | callback | ||
| ) |
Sets the constraint evaluation function. This function is called
`num_steps+1` times, with the corresponding state and input
VariableMatrices.
Args:
callback: The callback f(x, u) where x is the state and u is the
input vector.
| VariableMatrix sleipnir.optimization.OCP.initial_state | ( | self | ) |
Gets the initial state in the trajectory.
Returns:
The initial state of the trajectory.
| None sleipnir.optimization.OCP.set_lower_input_bound | ( | self, | |
| Annotated[NDArray[numpy.float64], dict(shape=(None, None))] | lower_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_lower_input_bound | ( | self, | |
| float | lower_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_lower_input_bound | ( | self, | |
| int | lower_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_lower_input_bound | ( | self, | |
| Variable | lower_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_lower_input_bound | ( | self, | |
| VariableMatrix | VariableBlock | lower_bound | ||
| ) |
Sets a lower bound on the input.
Args:
lower_bound: The lower bound that inputs must always be above.
Must be shaped (num_inputs)x1.
| None sleipnir.optimization.OCP.set_max_timestep | ( | self, | |
| datetime.timedelta | float | max_timestep | ||
| ) |
Sets an upper bound on the timestep.
Args:
max_timestep: The maximum timestep.
| None sleipnir.optimization.OCP.set_min_timestep | ( | self, | |
| datetime.timedelta | float | min_timestep | ||
| ) |
Sets a lower bound on the timestep.
Args:
min_timestep: The minimum timestep.
| None sleipnir.optimization.OCP.set_upper_input_bound | ( | self, | |
| Annotated[NDArray[numpy.float64], dict(shape=(None, None))] | upper_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_upper_input_bound | ( | self, | |
| float | upper_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_upper_input_bound | ( | self, | |
| int | upper_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_upper_input_bound | ( | self, | |
| Variable | upper_bound | ||
| ) |
| None sleipnir.optimization.OCP.set_upper_input_bound | ( | self, | |
| VariableMatrix | VariableBlock | upper_bound | ||
| ) |
Sets an upper bound on the input.
Args:
upper_bound: The upper bound that inputs must always be below.
Must be shaped (num_inputs)x1.
| VariableMatrix sleipnir.optimization.OCP.U | ( | self | ) |
Gets the input variables. After the problem is solved, this will
contain the inputs corresponding to the optimized trajectory.
Shaped (num_inputs)x(num_steps+1), although the last input step is
unused in the trajectory.
Returns:
The input variable matrix.
| VariableMatrix sleipnir.optimization.OCP.X | ( | self | ) |
Gets the state variables. After the problem is solved, this will
contain the optimized trajectory.
Shaped (num_states)x(num_steps+1).
Returns:
The state variable matrix.