Class OCP
- All Implemented Interfaces:
AutoCloseable
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.
-
Constructor Summary
ConstructorsConstructorDescriptionOCP(int numStates, int numInputs, double dt, int numSteps, BiFunction<VariableMatrix, VariableMatrix, VariableMatrix> dynamics, DynamicsType dynamicsType, TimestepMethod timestepMethod, TranscriptionMethod transcriptionMethod) Builds an optimization problem using a system evolution function (explicit ODE or discrete state transition function).OCP(int numStates, int numInputs, double dt, int numSteps, DynamicsFunction dynamics, DynamicsType dynamicsType, TimestepMethod timestepMethod, TranscriptionMethod transcriptionMethod) Builds an optimization problem using a system evolution function (explicit ODE or discrete state transition function). -
Method Summary
Modifier and TypeMethodDescriptionvoidconstrainFinalState(double finalState) Constrains the final state.voidconstrainFinalState(org.ejml.simple.SimpleMatrix finalState) Constrains the final state.voidconstrainFinalState(Variable finalState) Constrains the final state.voidconstrainFinalState(VariableBlock finalState) Constrains the final state.voidconstrainFinalState(VariableMatrix finalState) Constrains the final state.voidconstrainInitialState(double initialState) Constrains the initial state.voidconstrainInitialState(org.ejml.simple.SimpleMatrix initialState) Constrains the initial state.voidconstrainInitialState(Variable initialState) Constrains the initial state.voidconstrainInitialState(VariableBlock initialState) Constrains the initial state.voidconstrainInitialState(VariableMatrix initialState) Constrains the initial state.dt()Gets the timestep variables.Gets the final state in the trajectory.voidforEachStep(BiConsumer<VariableMatrix, VariableMatrix> callback) Sets the constraint evaluation function.voidforEachStep(ConstraintEvaluationFunction callback) Sets the constraint evaluation function.Gets the initial state in the trajectory.voidsetLowerInputBound(double lowerBound) Sets a lower bound on the input.voidsetLowerInputBound(org.ejml.simple.SimpleMatrix lowerBound) Sets a lower bound on the input.voidsetLowerInputBound(Variable lowerBound) Sets a lower bound on the input.voidsetLowerInputBound(VariableBlock lowerBound) Sets a lower bound on the input.voidsetLowerInputBound(VariableMatrix lowerBound) Sets a lower bound on the input.voidsetMaxTimestep(double maxTimestep) Sets an upper bound on the timestep.voidsetMinTimestep(double minTimestep) Sets a lower bound on the timestep.voidsetUpperInputBound(double upperBound) Sets an upper bound on the input.voidsetUpperInputBound(org.ejml.simple.SimpleMatrix upperBound) Sets an upper bound on the input.voidsetUpperInputBound(Variable upperBound) Sets an upper bound on the input.voidsetUpperInputBound(VariableBlock upperBound) Sets an upper bound on the input.voidsetUpperInputBound(VariableMatrix upperBound) Sets an upper bound on the input.U()Gets the input variables.X()Gets the state variables.Methods inherited from class Problem
addCallback, clearCallbacks, close, costFunctionType, decisionVariable, decisionVariable, decisionVariable, equalityConstraintType, inequalityConstraintType, maximize, maximize, minimize, minimize, solve, solve, subjectTo, subjectTo, symmetricDecisionVariable
-
Constructor Details
-
OCP
public OCP(int numStates, int numInputs, double dt, int numSteps, BiFunction<VariableMatrix, VariableMatrix, VariableMatrix> dynamics, DynamicsType dynamicsType, TimestepMethod timestepMethod, TranscriptionMethod transcriptionMethod) Builds an optimization problem using a system evolution function (explicit ODE or discrete state transition function).- Parameters:
numStates- The number of system states.numInputs- The number of system inputs.dt- The timestep for fixed-step integration.numSteps- 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ₖ)
dynamicsType- The type of system evolution function.timestepMethod- The timestep method.transcriptionMethod- The transcription method.
-
OCP
public OCP(int numStates, int numInputs, double dt, int numSteps, DynamicsFunction dynamics, DynamicsType dynamicsType, TimestepMethod timestepMethod, TranscriptionMethod transcriptionMethod) Builds an optimization problem using a system evolution function (explicit ODE or discrete state transition function).- Parameters:
numStates- The number of system states.numInputs- The number of system inputs.dt- The timestep for fixed-step integration.numSteps- The number of control points.dynamics- Function representing an explicit or implicit ODE, or a discrete state transition function.- Explicit: dx/dt = f(t, x, u, *)
- Implicit: f(t, [x dx/dt]', u, *) = 0
- State transition: xₖ₊₁ = f(t, xₖ, uₖ, dt)
dynamicsType- The type of system evolution function.timestepMethod- The timestep method.transcriptionMethod- The transcription method.
-
-
Method Details
-
constrainInitialState
Constrains the initial state.- Parameters:
initialState- the initial state to constrain to.
-
constrainInitialState
Constrains the initial state.- Parameters:
initialState- the initial state to constrain to.
-
constrainInitialState
Constrains the initial state.- Parameters:
initialState- the initial state to constrain to.
-
constrainInitialState
Constrains the initial state.- Parameters:
initialState- the initial state to constrain to.
-
constrainInitialState
Constrains the initial state.- Parameters:
initialState- the initial state to constrain to.
-
constrainFinalState
Constrains the final state.- Parameters:
finalState- the final state to constrain to.
-
constrainFinalState
Constrains the final state.- Parameters:
finalState- the final state to constrain to.
-
constrainFinalState
Constrains the final state.- Parameters:
finalState- the final state to constrain to.
-
constrainFinalState
Constrains the final state.- Parameters:
finalState- the final state to constrain to.
-
constrainFinalState
Constrains the final state.- Parameters:
finalState- the final state to constrain to.
-
forEachStep
Sets the constraint evaluation function. This function is called `numSteps+1` times, with the corresponding state and input VariableMatrices.- Parameters:
callback- The callback f(x, u) where x is the state and u is the input vector.
-
forEachStep
Sets the constraint evaluation function. This function is called `numSteps+1` times, with the corresponding state and input VariableMatrices.- Parameters:
callback- The callback f(t, x, u, dt) where t is time, x is the state vector, u is the input vector, and dt is the timestep duration.
-
setLowerInputBound
Sets a lower bound on the input.- Parameters:
lowerBound- The lower bound that inputs must always be above. Must be shaped (numInputs)x1.
-
setLowerInputBound
Sets a lower bound on the input.- Parameters:
lowerBound- The lower bound that inputs must always be above. Must be shaped (numInputs)x1.
-
setLowerInputBound
Sets a lower bound on the input.- Parameters:
lowerBound- The lower bound that inputs must always be above. Must be shaped (numInputs)x1.
-
setLowerInputBound
Sets a lower bound on the input.- Parameters:
lowerBound- The lower bound that inputs must always be above. Must be shaped (numInputs)x1.
-
setLowerInputBound
Sets a lower bound on the input.- Parameters:
lowerBound- The lower bound that inputs must always be above. Must be shaped (numInputs)x1.
-
setUpperInputBound
Sets an upper bound on the input.- Parameters:
upperBound- The upper bound that inputs must always be below. Must be shaped (numInputs)x1.
-
setUpperInputBound
Sets an upper bound on the input.- Parameters:
upperBound- The upper bound that inputs must always be below. Must be shaped (numInputs)x1.
-
setUpperInputBound
Sets an upper bound on the input.- Parameters:
upperBound- The upper bound that inputs must always be below. Must be shaped (numInputs)x1.
-
setUpperInputBound
Sets an upper bound on the input.- Parameters:
upperBound- The upper bound that inputs must always be below. Must be shaped (numInputs)x1.
-
setUpperInputBound
Sets an upper bound on the input.- Parameters:
upperBound- The upper bound that inputs must always be below. Must be shaped (numInputs)x1.
-
setMinTimestep
Sets a lower bound on the timestep.- Parameters:
minTimestep- The minimum timestep in seconds.
-
setMaxTimestep
Sets an upper bound on the timestep.- Parameters:
maxTimestep- The maximum timestep in seconds.
-
X
Gets the state variables. After the problem is solved, this will contain the optimized trajectory.Shaped (numStates)x(numSteps+1).
- Returns:
- The state variable matrix.
-
U
Gets the input variables. After the problem is solved, this will contain the inputs corresponding to the optimized trajectory.Shaped (numInputs)x(numSteps+1), although the last input step is unused in the trajectory.
- Returns:
- The input variable matrix.
-
dt
Gets the timestep variables. After the problem is solved, this will contain the timesteps corresponding to the optimized trajectory.Shaped 1x(numSteps+1), although the last timestep is unused in the trajectory.
- Returns:
- The timestep variable matrix.
-
initialState
Gets the initial state in the trajectory.- Returns:
- The initial state of the trajectory.
-
finalState
Gets the final state in the trajectory.- Returns:
- The final state of the trajectory.
-