time
Time
¶
Bases: State
Time state variable for trajectory optimization.
Time is a State representing physical time along the trajectory. Used for time-optimal control and problems with time-dependent dynamics/constraints.
Since Time is a State, it can be:
- Used directly in constraint expressions (e.g.,
time[0] <= 5.0) - Added to the states list, or auto-added via the
time=argument
The constructor accepts scalar values for convenience, which are converted to arrays internally to match State's API. All parameters can also be set via property setters after construction.
Time dilation bounds and guesses can also be configured here via
time_dilation_min, time_dilation_max, and time_dilation_guess.
These control the augmented time dilation variable that the solver adds
internally, and can be updated between solves (e.g. in a receding horizon
loop) without reconstructing the problem.
Note
time_dilation_min and time_dilation_max are absolute bounds
on the time dilation control variable.
Attributes:
| Name | Type | Description |
|---|---|---|
derivative |
float
|
Always 1.0 - time derivative in normalized coordinates. |
Example
Constructor style::
time = ox.Time(initial=0.0, final=10.0, min=0.0, max=20.0)
problem = Problem(..., time=time)
Setter style::
time = ox.Time()
time.min = 0.0
time.max = 20.0
time.initial = 0.0
time.final = ox.Minimize(10.0)
With guess and time-dilation overrides::
time = ox.Time(
initial=0.0,
final=("minimize", 10.0),
min=0.0,
max=20.0,
guess=np.linspace(0, 10, 50).reshape(-1, 1),
time_dilation_min=1.0,
time_dilation_max=30.0,
)
Using time in constraints::
time = ox.Time(initial=0.0, final=10.0, min=0.0, max=20.0)
states = [position, velocity, time]
constraint = ox.ctcs(time[0] <= 5.0)
Source code in openscvx/symbolic/expr/time.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
time_dilation_guess: Optional[np.ndarray]
property
writable
¶
Initial guess for time dilation, shape (N, 1).
time_dilation_max: Optional[float]
property
writable
¶
Absolute maximum bound for time dilation.
time_dilation_min: Optional[float]
property
writable
¶
Absolute minimum bound for time dilation.
__init__(initial: Optional[Union[float, tuple]] = None, final: Optional[Union[float, tuple]] = None, min: Optional[float] = None, max: Optional[float] = None, *, guess: Optional[np.ndarray] = None, time_dilation_min: Optional[float] = None, time_dilation_max: Optional[float] = None, time_dilation_guess: Optional[np.ndarray] = None, uniform_time_grid: bool = False)
¶
Initialize a Time state.
All parameters are optional and can be set later via property setters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial
|
Optional[Union[float, tuple]]
|
Initial time. Either a float (fixed) or tuple like ("free", value), ("minimize", value), ("maximize", value). |
None
|
final
|
Optional[Union[float, tuple]]
|
Final time. Same format as initial. |
None
|
min
|
Optional[float]
|
Minimum time bound. |
None
|
max
|
Optional[float]
|
Maximum time bound. |
None
|
guess
|
Optional[ndarray]
|
Initial guess for the time trajectory. 1D array of shape (N,) or 2D of shape (N, 1). If not provided, a linear interpolation from initial to final is generated. |
None
|
time_dilation_min
|
Optional[float]
|
Absolute minimum bound for time dilation.
Defaults to |
None
|
time_dilation_max
|
Optional[float]
|
Absolute maximum bound for time dilation.
Defaults to |
None
|
time_dilation_guess
|
Optional[ndarray]
|
Initial guess for time dilation. 1D array of shape (N,) or 2D of shape (N, 1). Overrides the default finite-difference computation. |
None
|
uniform_time_grid
|
bool
|
If True, constrain the time dilation to be the same across all nodes (uniform time steps). Defaults to False. |
False
|
Source code in openscvx/symbolic/expr/time.py
final(val)
¶
Set the final time. Accepts a scalar, tuple, or array.
guess(arr)
¶
Set the time guess. Accepts 1D (N,) or 2D (N, 1) arrays.
initial(val)
¶
Set the initial time. Accepts a scalar, tuple, or array.
max(val)
¶
Set the maximum time bound. Accepts a scalar or array.
min(val)
¶
Set the minimum time bound. Accepts a scalar or array.
TimeSpec
¶
Bases: StateSpec
Validates Time configuration from YAML/JSON/dict input.
Extends :class:StateSpec with time-specific fields. name and
shape are fixed ("time" and [1]), and initial/final
are required (a Time must have boundary conditions).
YAML scalars and [tag, value] pairs are normalised into the
List forms that :class:StateSpec expects via field_validator
so that no field type overrides are needed.