discretization
Discretization methods for trajectory optimization.
This module provides implementations of discretization schemes that convert continuous-time optimal control problems into discrete-time approximations suitable for numerical optimization. Discretization is a critical step in trajectory optimization that linearizes the nonlinear dynamics around a reference trajectory.
Planned Architecture (ABC-based):
A base class will be introduced to enable pluggable discretization methods. This will enable users to implement custom discretization methods. Future discretizers will implement the Discretizer interface:
# discretization/base.py (planned):
class Discretizer(ABC):
def __init__(self, integrator: Integrator):
'''Initialize with a numerical integrator.'''
self.integrator = integrator
@abstractmethod
def discretize(self, dynamics, x, u, dt) -> tuple[A_d, B_d, C_d]:
'''Discretize continuous dynamics around trajectory (x, u).
Args:
dynamics: Continuous-time dynamics object
x: State trajectory
u: Control trajectory
dt: Time step
Returns:
A_d: Discretized state transition matrix
B_d: Discretized control influence matrix (current node)
C_d: Discretized control influence matrix (next node)
'''
...
calculate_discretization(x, u, state_dot: callable, A: callable, B: callable, settings: Config, params: dict)
¶
Calculate the discretized system matrices.
This function computes the discretized system matrices (A_bar, B_bar, C_bar) and defect vector (z_bar) using numerical integration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
State trajectory. |
required | |
u
|
Control trajectory. |
required | |
state_dot
|
callable
|
Function computing state derivatives. |
required |
A
|
callable
|
Function computing state Jacobian. |
required |
B
|
callable
|
Function computing control Jacobian. |
required |
settings
|
Config
|
Configuration settings for OpenSCvx. |
required |
custom_integrator
|
bool
|
Whether to use custom RK45 integrator. |
required |
debug
|
bool
|
Whether to use debug mode. |
required |
solver
|
str
|
Name of the solver to use. |
required |
rtol
|
float
|
Relative tolerance for integration. |
required |
atol
|
float
|
Absolute tolerance for integration. |
required |
dis_type
|
str
|
Discretization type ("ZOH" or "FOH"). |
required |
**kwargs
|
Additional parameters passed to state_dot, A, and B. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(A_bar, B_bar, C_bar, z_bar, Vmulti) where: - A_bar: Discretized state transition matrix - B_bar: Discretized control influence matrix - C_bar: Discretized control influence matrix for next node - z_bar: Defect vector - Vmulti: Full augmented state trajectory |
Source code in openscvx/discretization/discretization.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
dVdt(tau: float, V: jnp.ndarray, u_cur: np.ndarray, u_next: np.ndarray, state_dot: callable, A: callable, B: callable, n_x: int, n_u: int, N: int, dis_type: str, params: dict) -> jnp.ndarray
¶
Compute the time derivative of the augmented state vector.
This function computes the time derivative of the augmented state vector V, which includes the state, state transition matrix, and control influence matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tau
|
float
|
Current normalized time in [0,1]. |
required |
V
|
ndarray
|
Augmented state vector. |
required |
u_cur
|
ndarray
|
Control input at current node. |
required |
u_next
|
ndarray
|
Control input at next node. |
required |
state_dot
|
callable
|
Function computing state derivatives. |
required |
A
|
callable
|
Function computing state Jacobian. |
required |
B
|
callable
|
Function computing control Jacobian. |
required |
n_x
|
int
|
Number of states. |
required |
n_u
|
int
|
Number of controls. |
required |
N
|
int
|
Number of nodes in trajectory. |
required |
dis_type
|
str
|
Discretization type ("ZOH" or "FOH"). |
required |
**params
|
dict
|
Additional parameters passed to state_dot, A, and B. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
jnp.ndarray: Time derivative of augmented state vector. |
Source code in openscvx/discretization/discretization.py
get_discretization_solver(dyn: Dynamics, settings: Config)
¶
Create a discretization solver function.
This function creates a solver that computes the discretized system matrices using the specified dynamics and settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dyn
|
Dynamics
|
System dynamics object. |
required |
settings
|
Config
|
Configuration settings for discretization. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
callable |
A function that computes the discretized system matrices. |