Block library
collimator.library
Abs
Bases: FeedthroughBlock
Output the absolute value of the input signal.
Input ports
None
Output ports
(0) The absolute value of the input signal.
Events
An event is triggered when the output changes from positive to negative or vice versa.
Source code in collimator/library/primitives.py
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 |
|
Adder
Bases: ReduceBlock
Computes the sum/difference of the input.
The add/subtract operation can be switched by setting the operators
parameter.
For example, a 3-input block specified as Adder(3, operators="+-+")
would add
the first and third inputs and subtract the second input.
Input ports
(0..n_in-1) The input signals to add/subtract.
Output ports
(0) The sum/difference of the input signals.
Source code in collimator/library/primitives.py
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 |
|
Arithmetic
Bases: ReduceBlock
Performs addition, subtraction, multiplication, and division on the input.
The arithmetic operation is determined by setting the operators
parameter.
For example, a 4-input block specified as Arithmetic(4, operators="+-*/")
would:
- Add the first input,
- Subtract the second input,
- Multiply the third input,
- Divide by the fourth input.
Input ports
(0..n_in-1) The input signals for the specified arithmetic operations.
Output ports
(0) The result of the specified arithmetic operations on the input signals.
Source code in collimator/library/primitives.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
BatteryCell
Bases: LeafSystem
Dynamic electro-checmical Li-ion cell model.
Based on Tremblay and Dessaint (2009).
By using appropriate parameters, the cell model can be used to model a battery pack with the assumption that the cells of the pack behave as a single unit.
Parameters E0, K, A, below are abstract parameters used in the model presented in the reference paper. As described in the reference paper, these parameters can be extracted from typical cell manufacturer datasheets; see section 3. Section 3 also provides a table of example values for these parameters.
Input ports
(0) The current (A) flowing through the cell. Positive is discharge.
Output ports
(0) The voltage across the cell terminals (V) (1) The state of charge of the cell (normalized between 0 and 1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
E0
|
float
|
described as "battery constant voltage (V)" by the reference paper. |
3.366
|
K
|
float
|
described as "polarization constant (V/Ah)" by the reference paper. |
0.0076
|
Q
|
float
|
battery capacity in Ah |
2.3
|
R
|
float
|
internal resistance (Ohms) |
0.01
|
A
|
float
|
described as "exponential zone amplitude (V)" by the reference paper. |
0.26422
|
B
|
float
|
described as "exponential zone time constant inverse (1/Ah)" by the reference paper. |
26.5487
|
initial_SOC
|
float
|
initial state of charge, normalized between 0 and 1. |
1.0
|
Source code in collimator/library/battery_cell.py
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 |
|
Chirp
Bases: SourceBlock
Produces a signal like the linear method of
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.chirp.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f0
|
float
|
Frequency (Hz) at time t=phi. |
required |
f1
|
float
|
Frequency (Hz) at time t=stop_time. |
required |
stop_time
|
float
|
Time to end the signal (seconds). |
required |
phi
|
float
|
Phase offset (radians). |
0.0
|
Input ports
None
Output ports
(0) The chirp signal.
Source code in collimator/library/primitives.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
|
Clock
Bases: SourceBlock
Source block returning simulation time.
Input ports
None
Output ports
(0) The simulation time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dtype
|
The data type of the output signal. The default is "None", which will default to the current default floating point precision |
None
|
Source code in collimator/library/primitives.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|
Comparator
Bases: LeafSystem
Compare two signals using typical relational operators.
When using == and != operators, the block uses tolerances to determine if the expression is true or false.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
one of ("==", "!=", ">=", ">", ">=", "<") |
None
|
|
atol
|
the absolute tolerance value used with "==" or "!=" |
1e-05
|
|
rtol
|
the relative tolerance value used with "==" or "!=" |
1e-08
|
Input Ports
(0) The left side operand (1) The right side operand
Output Ports
(0) The result of the comparison (boolean signal)
Events
An event is triggered when the output changes from true to false or vice versa.
Source code in collimator/library/primitives.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
Constant
Bases: LeafSystem
A source block that emits a constant value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
The constant value of the block. |
required |
Input ports
None
Output ports
(0) The constant value.
Source code in collimator/library/primitives.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
ContinuousTimeInfiniteHorizonKalmanFilter
Bases: LeafSystem
Continuous-time Infinite Horizon Kalman Filter for the following system:
dot_x = A x + B u + G w
y = C x + D u + v
E(w) = E(v) = 0
E(ww') = Q
E(vv') = R
E(wv') = N = 0
Input ports
(0) u : continuous-time control vector (1) y : continuous-time measurement vector
Output ports
(1) x_hat : continuous-time state vector estimate
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
ndarray State transition matrix |
required | |
B
|
ndarray Input matrix |
required | |
C
|
ndarray Output matrix |
required | |
D
|
ndarray Feedthrough matrix |
required | |
G
|
ndarray Process noise matrix |
required | |
Q
|
ndarray Process noise covariance matrix |
required | |
R
|
ndarray Measurement noise covariance matrix |
required | |
x_hat_0
|
ndarray Initial state estimate |
required |
Source code in collimator/library/state_estimators/continuous_time_infinite_horizon_kalman_filter.py
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 |
|
for_continuous_plant(plant, x_eq, u_eq, Q, R, G=None, x_hat_bar_0=None, name=None)
staticmethod
Obtain a continuous-time Infinite Horizon Kalman Filter system for a continuous-time plant after linearization at equilibrium point (x_eq, u_eq)
The input plant contains the deterministic forms of the forward and observation operators:
dx/dt = f(x,u)
y = g(x,u)
Note: Only plants with one vector-valued input and one vector-valued output are currently supported. Furthermore, the plant LeafSystem/Diagram should have only one vector-valued integrator.
A plant with disturbances of the following form is then considered following form:
dx/dt = f(x,u) + G w
y = g(x,u) + v
where:
`w` represents the process noise,
`v` represents the measurement noise,
and
E(w) = E(v) = 0
E(ww') = Q
E(vv') = R
E(wv') = N = 0
This plant with disturbances is linearized (only f
and q
) around the
equilibrium point to obtain:
d/dt (x_bar) = A x_bar + B u_bar + G w --- (C1)
y_bar = C x_bar + D u_bar + v --- (C2)
where,
x_bar = x - x_eq
u_bar = u - u_eq
y_bar = y - y_bar
y_eq = g(x_eq, u_eq)
A continuous-time Kalman Filter estimator for the system of equations (C1) and
(C2) is returned. This filter is in the x_bar
, u_bar
, and y_bar
states.
The returned system will have
Input ports
(0) u_bar : continuous-time control vector relative to equilibrium point (1) y_bar : continuous-time measurement vector relative to equilibrium point
Output ports
(1) x_hat_bar : continuous-time state vector estimate relative to equilibrium point
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
a |
required | |
x_eq
|
ndarray Equilibrium state vector for discretization |
required | |
u_eq
|
ndarray Equilibrium control vector for discretization |
required | |
Q
|
ndarray Process noise covariance matrix. |
required | |
R
|
ndarray Measurement noise covariance matrix. |
required | |
G
|
ndarray
Process noise matrix. If |
None
|
|
x_hat_bar_0
|
ndarray Initial state estimate relative to equilibrium point. If None, an identity matrix is assumed. |
None
|
Source code in collimator/library/state_estimators/continuous_time_infinite_horizon_kalman_filter.py
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 |
|
CoordinateRotation
Bases: LeafSystem
Computes the rotation of a 3D vector between coordinate systems.
Given sufficient information to construct a rotation matrix C_AB
from orthogonal
coordinate system B
to orthogonal coordinate system A
, along with an input
vector x_B
expressed in B
-axes, this block will compute the matrix-vector
product x_A = C_AB @ x_B
.
Note that depending on the type of rotation representation, this matrix may not be explicitly computed. The types of rotations supported are Quaternion, Euler Angles, and Direction Cosine Matrix (DCM).
By default, the rotations have the following convention:
-
Quaternion: The rotation is represented by a 4-component quaternion
q
. The rotation is carried out by the productp_A = q⁻¹ * p_B * q
, whereq⁻¹
is the quaternion inverse ofq
,*
is the quaternion product, andp_A
andp_B
are the quaternion extensions of the vectorsx_A
andx_B
, i.e.p_A = [0, x_A]
andp_B = [0, x_B]
. -
Roll-Pitch-Yaw (Euler Angles): The rotation is represented by the set of Euler angles ϕ (roll), θ (pitch), and ψ (yaw), in the "1-2-3" convention for intrinsic rotations. The resulting rotation matrix
C_AB(ϕ, θ, ψ)
is the same as the product of the three single-axis rotation matricesC_AB = Cz(ψ) * Cy(θ) * Cx(ϕ)
.For example, if
B
represents a fixed "world" frame with axesxyz
andA
is a body-fixed frame with axesXYZ
, thenC_AB
represents a rotation from the world frame to the body frame, in the following sequence:- Right-hand rotation about the world frame
x
-axis byϕ
(roll), resulting in the intermediate framex'y'z'
withx' = x
. - Right-hand rotation about the intermediate frame
y'
-axis byθ
(pitch), resulting in the intermediate framex''y''z''
withy'' = y'
. - Right-hand rotation about the intermediate frame
z''
-axis byψ
(yaw), resulting in the body frameXYZ
withz = z''
.
- Right-hand rotation about the world frame
-
Direction Cosine Matrix: The rotation is directly represented as a 3x3 matrix
C_AB
. The rotation is carried out by the matrix-vector productx_A = C_AB @ x_B
.
Input ports
(0): The input vector x_B
expressed in the B
-axes.
(1): (if enable_external_rotation_definition=True
) The rotation
representation (quaternion, Euler angles, or cosine matrix) that defines
the rotation from B
to A
(or A
to B
if inverse=True
).
Output ports
(0): The output vector x_A
expressed in the A
-axes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rotation_type
|
str
|
The type of rotation representation to use. Must be one of ("quaternion", "roll_pitch_yaw", "dcm"). |
required |
enable_external_rotation_definition
|
If |
True
|
|
inverse
|
If |
False
|
|
quaternion
|
Array
|
The quaternion representation of the rotation
if |
None
|
roll_pitch_yaw
|
Array
|
The Euler angles representation of the
rotation if |
None
|
direction_cosine_matrix
|
Array
|
The direction cosine matrix
representation of the rotation if |
None
|
Source code in collimator/library/rotations.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
|
CoordinateRotationConversion
Bases: LeafSystem
Converts between different representations of rotations.
See CoordinateRotation block documentation for descriptions of the different rotation representations supported. This block supports conversion between quaternion, roll-pitch-yaw (Euler angles), and direction cosine matrix (DCM).
Note that conversions are reversible in terms of the abstract rotation, although creating a quaternion from a direction cosine matrix (and therefore creating a quaternion from roll-pitch-yaw sequence) results in an arbitrary sign assignment.
Input ports
(0): The input rotation representation.
Output ports
(1): The output rotation representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conversion_type
|
str
|
The type of rotation conversion to perform. Must be one of ("quaternion_to_euler", "quaternion_to_dcm", "euler_to_quaternion", "euler_to_dcm", "dcm_to_quaternion", "dcm_to_euler") |
required |
Source code in collimator/library/rotations.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
|
CrossProduct
Bases: ReduceBlock
Compute the cross product between the inputs.
See NumPy docs for details: https://numpy.org/doc/stable/reference/generated/numpy.cross.html
Input ports
(0) The first input vector. (1) The second input vector.
Output ports
(0) The cross product of the inputs.
Source code in collimator/library/primitives.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 |
|
CustomJaxBlock
Bases: LeafSystem
JAX implementation of the PythonScript block.
A few important notes and changes/limitations to this JAX implementation:
- For this block all code must be written using the JAX-supported subset of Python:
* Numerical operations should use jax.numpy = jnp
instead of numpy = np
* Standard control flow is not supported (if/else, for, while, etc.). Instead
use lax.cond
, lax.fori_loop
, lax.while_loop
, etc.
https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#structured-control-flow-primitives
Where possible, NumPy-style operations like jnp.where
or jnp.select
should
be preferred to lax control flow primitives.
* Functions must be pure and arrays treated as immutable.
https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#in-place-updates
Provided these assumptions hold, the code can be JIT compiled, differentiated,
run on GPU, etc.
- Variable scoping: the init_code
and step_code
are executed in the same scope,
so variables declared in the init_code
will be available in the step_code
and can be modified in that scope. Internally, everything declared in
init_code
is treated as a single state-like cache entry.
However, variables declared in the step_code
will NOT persist between
evaluations. Users should think of step_code
as a normal Python function
where locally declared variables will disappear on leaving the scope.
- Persistent variables (outputs and anything declared in init_code
) must have
static shapes and dtypes. This means that you cannot declare x = 0.0
in
init_code
and then later assign x = jnp.zeros(4)
in step_code
.
These changes mean that many older PythonScript blocks may not be backwards compatible.
Input ports
Variable number of input ports, one for each input variable declared in inputs
.
The order of the input ports is the same as the order of the input variables.
Output ports
Variable number of output ports, one for each output variable declared in outputs
.
The order of the output ports is the same as the order of the output variables.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float
|
The discrete time step of the block, or None if the block is in agnostic time mode. |
None
|
init_script
|
str
|
A string containing Python code that will be executed
once when the block is initialized. This code can be used to declare
persistent variables that will be available in the |
''
|
user_statements
|
str
|
A string containing Python code that will be executed
once per time step (or per output port evaluation, in agnostic mode).
This code can use the persistent variables declared in |
''
|
finalize_script
|
str
|
A string containing Python code that will be executed
once when the block is finalized. This code can use the persistent
variables declared in |
''
|
accelerate_with_jax
|
bool
|
If True, the block will be JIT compiled. If False, the block will be executed in pure Python. This parameter exists for compatibility with UI options; when creating pure Python blocks from code (e.g. for testing), explicitly create the CustomPythonBlock class. |
True
|
time_mode
|
str
|
One of "discrete" or "agnostic". If "discrete", the block step code will be evaluated at peridodic intervals specified by "dt". If "agnostic", the block step code will be evaluated once per output port evaluation, and the block will not have a discrete time step. |
'discrete'
|
inputs
|
List[str]
|
A list of input variable names. The order of the input ports is the same as the order of the input variables. |
None
|
outputs
|
Mapping[str, Tuple[DTypeLike, ShapeLike]]
|
A dictionary mapping output variable names to a tuple of dtype and shape. The order of the output ports is the same as the order of the output variables. |
None
|
static_parameters
|
Mapping[str, Array]
|
A dictionary mapping parameter names to values. Parameters are treated as immutable and cannot be modified in the step code. Static parameters can't be used in ensemble simulations or optimization workflows. |
None
|
dynamic_parameters
|
Mapping[str, Array]
|
A dictionary mapping parameter names to values. Parameters are treated as immutable and cannot be modified in the step code. Dynamic parameters can be arrays or scalars, but must have static shapes and dtypes in order to support JIT compilation. |
None
|
Source code in collimator/library/custom.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
|
check_types(context, error_collector=None)
Test-compile the init and step code to check for errors.
Source code in collimator/library/custom.py
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
|
CustomPythonBlock
Bases: CustomJaxBlock
Container for arbitrary user-defined Python code.
Implemented to support legacy PythonScript blocks.
Not traceable (no JIT compilation or autodiff). The internal implementation and behavior of this block differs vastly from the JAX-compatible block as this block stores state directly within the Python instance. Objects and modules can be kept as discrete state.
Note that in "agnostic" mode, the step code will be evaluated once per output port evaluation. Because locally defined environment variables (in the init script) are preserved between evaluations, any mutation of these variables will be preserved. This can lead to unexpected behavior and should be avoided. Stateful behavior should be implemented using discrete state variables instead.
Source code in collimator/library/custom.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 |
|
DataSource
Bases: SourceBlock
Produces outputs from an imported .csv file.
The block's output(s) must be synchronized with simulation time. This can be achieved by two mechanisms:
-
Each data row in the file is accompanied by a time value. The time value for each row is provided as a column in the data file. For this option, the values in the time column must be strictly increasing, with no duplicates, from the first data row to the last. The block will check that this condition is satisfied at compile time. The column with the time values is identified by the column index. This option assumes the left most column is index 0, counting up to the right. to select this option, set Time samples as column to True, and provide the index of the column.
-
The time value for each data row is defined using a fixed time step between each row. For this option, the Sampling parameter defines the time step. The block then computes the time values for each data row starting with zero for the first row. Note that by definition, this results in a strictly increasing set. To select this option, set
time_samples_as_column
to False, and provide thesampling_interval
value.
When block output(s) are requested at a simulation time that falls between time values for adjacent data rows, there are two options for how the block should compute the interpolation:
-
Zero Order Hold: the block returns data from the row with the lower time value.
-
Linear: the block performs a linear interpolation between the lower and higher time value data rows.
There are several mechanism for selecting which data columns are included in the
block output(s). All options are applied using the data_columns
parameter:
-
Column name: enter a string that matches a column name in the header. For this option,
header_as_first_row
must be set to True. For this option, it is only possible to select a single column for the output. The block will output a scalar. -
Column index: enter an integer index for the desired column. This option again assumes the left most column is index 0, counting up to the right. This option assumes the same column index regardless of of whether
time_samples_as_column
is True or False, therefore it is possible to select the same column for time and output. With this option, the block will output a scalar. -
Slice: enter a slice used to identify a set of sequential columns to be used as the desired data for output. The slice works like a NumPy slice. For example, if the file has 10 columns,
3:8
will results in the block returning a vector of length 5, containing, in order, columns 3,4,5,6,7. Note that like NumPy, the second integer in the slice is excluded in the set of indices. Only positive integers are allowed for the slice (e.g.2:-1
,-3:-1
, and3:
are not allowed).
Presently, there is only one option for extrapolation beyond the end of data in the file. The block will have reached the end of data if the simulation time is greater than the time value for the last row of data. Once this occurs, the block output(s) will be the values in the last row of data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
The name of the imported file which contains the data. |
required |
header_as_first_row
|
bool
|
Check this box if the first row is meant to be a header. |
False
|
time_samples_as_column
|
bool
|
Check this box to select a column form the file to use as the time values. Uncheck it to provide time as a fixed time step between rows. |
False
|
time_column
|
str
|
Only used when |
'0'
|
sampling_interval
|
float
|
only used when |
1.0
|
data_columns
|
str
|
Enter name, index, or slice to select columns from the data file. |
'1'
|
extrapolation
|
str
|
the extrapolation method. One of "hold" or "zero". |
'hold'
|
interpolation
|
str
|
the interpolation method. One of "zero_order_hold" or "linear". |
'zero_order_hold'
|
Source code in collimator/library/data_source.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
__init__(file_name, data_columns='1', extrapolation='hold', header_as_first_row=False, interpolation='zero_order_hold', sampling_interval=1.0, time_column='0', time_samples_as_column=False, **kwargs)
Source code in collimator/library/data_source.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
DeadZone
Bases: FeedthroughBlock
Generates zero output within a specified range.
Applies the following function:
[ input, input < -half_range
output = | 0, -half_range <= input <= half_range
[ input input > half_range
Parameters:
Name | Type | Description | Default |
---|---|---|---|
half_range
|
The range of the dead zone. Must be > 0. |
1.0
|
Input ports
(0) The input signal.
Output ports
(0) The input signal modified by the dead zone.
Events
An event is triggered when the signal enters or exits the dead zone in either direction.
Source code in collimator/library/primitives.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
|
Demultiplexer
Bases: LeafSystem
Split a vector signal into its components.
Input ports
(0) The vector signal to split.
Output ports
(0..n_out-1) The components of the input signal.
Source code in collimator/library/primitives.py
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 |
|
Derivative
Bases: LTISystem
Causal estimate of the derivative of a signal in continuous time.
This is implemented as a state-space system with matrices (A, B, C, D), which are then used to create a (first-order) LTISystem. Note that this only supports single-input, single-output derivative blocks.
The derivative is implemented as a filter with a filter coefficient of N
,
which is used to construct the following proper transfer function:
H(s) = Ns / (s + N)
As N -> ∞, the transfer function approaches a pure differentiator. However, this system becomes increasingly stiff and difficult to integrate, so it is recommended to select a value of N based on the time scales of the system.
From the transfer function, scipy.signal.tf2ss
is used to convert to
state-space form and create an LTISystem.
Input ports
(0) u: Input (scalar)
Output ports
(0) y: Output (scalar), estimating the time derivative du/dt
Source code in collimator/library/linear_system.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
DerivativeDiscrete
Bases: LeafSystem
Discrete approximation to the derivative of the input signal w.r.t. time.'
By default the block uses a simple backward difference approximation:
y[k] = (u[k] - u[k-1]) / dt
However, the block can also be configured to use a recursive filter for a
better approximation. In this case the filter coefficients are determined
by the filter_type
and filter_coefficient
parameters. The filter is
a pair of two-element arrays a
and b
and the filter equation is:
a0*y[k] + a1*y[k-1] = b0*u[k] + b1*u[k-1]
Denoting the filter_coefficient
parameter by N
, the following filters are
available:
- "none": The default, a simple finite difference approximation.
- "forward": A filtered forward Euler discretization. The filter is:
a = [1, (N*dt - 1)]
and b = [N, -N]
.
- "backward": A filtered backward Euler discretization. The filter is:
a = [(1 + N*dt), -1]
and b = [N, -N]
.
- "bilinear": A filtered bilinear transform discretization. The filter is:
a = [(2 + N*dt), (-2 + N*dt)]
and b = [2*N, -2*N]
.
Input ports
(0) The input signal.
Output ports
(0) The approximate derivative of the input signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
The time step of the discrete approximation. |
required | |
filter_type
|
One of "none", "forward", "backward", or "bilinear". This determines the type of filter used to approximate the derivative. The default is "none", corresponding to a simple backward difference approximation. |
'none'
|
|
filter_coefficient
|
The coefficient in the filter ( |
1.0
|
Source code in collimator/library/primitives.py
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
|
initialize_static_data(context)
Infer the size and dtype of the internal states
Source code in collimator/library/primitives.py
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
|
DirectShootingNMPC
Bases: NonlinearMPCIpopt
Implementation of nonlinear MPC with a direct shooting transcription and IPOPT as the NLP solver.
Input ports
(0) x_0 : current state vector. (1) x_ref : reference state trajectory for the nonlinear MPC. (2) u_ref : reference input trajectory for the nonlinear MPC.
Output ports
(1) u_opt : the optimal control input to be applied at the current time step as determined by the nonlinear MPC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
LeafSystem or Diagram The plant to be controlled. |
required | |
Q
|
Array State weighting matrix in the cost function. |
required | |
QN
|
Array Terminal state weighting matrix in the cost function. |
required | |
R
|
Array Control input weighting matrix in the cost function. |
required | |
N
|
int The prediction horizon, an integer specifying the number of steps to predict. Note: prediction and control horizons are identical for now. |
required | |
nh
|
int Number of minor steps to take within an RK4 major step. |
required | |
dt
|
float: Major time step, a scalar indicating the increment in time for each step in the prediction and control horizons. |
required | |
lb_u
|
Array Lower bound on the control input vector. |
None
|
|
ub_u
|
Array Upper bound on the control input vector. |
None
|
|
u_optvars_0
|
Array Initial guess for the control vector optimization variables in the NLP. |
None
|
Source code in collimator/library/nmpc/direct_shooting_ipopt_nmpc.py
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 |
|
DirectTranscriptionNMPC
Bases: NonlinearMPCIpopt
Implementation of nonlinear MPC with direct transcription and IPOPT as the NLP solver.
Input ports
(0) x_0 : current state vector. (1) x_ref : reference state trajectory for the nonlinear MPC. (2) u_ref : reference input trajectory for the nonlinear MPC.
Output ports
(1) u_opt : the optimal control input to be applied at the current time step as determined by the nonlinear MPC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
LeafSystem or Diagram The plant to be controlled. |
required | |
Q
|
Array State weighting matrix in the cost function. |
required | |
QN
|
Array Terminal state weighting matrix in the cost function. |
required | |
R
|
Array Control input weighting matrix in the cost function. |
required | |
N
|
int The prediction horizon, an integer specifying the number of steps to predict. Note: prediction and control horizons are identical for now. |
required | |
nh
|
int Number of minor steps to take within an RK4 major step. |
required | |
dt
|
float: Major time step, a scalar indicating the increment in time for each step in the prediction and control horizons. |
required | |
lb_x
|
Array Lower bound on the state vector. |
None
|
|
ub_x
|
Array Upper bound on the state vector. |
None
|
|
lb_u
|
Array Lower bound on the control input vector. |
None
|
|
ub_u
|
Array Upper bound on the control input vector. |
None
|
|
x_optvars_0
|
Array Initial guess for the state vector optimization variables in the NLP. |
None
|
|
u_optvars_0
|
Array Initial guess for the control vector optimization variables in the NLP. |
None
|
Source code in collimator/library/nmpc/direct_transcription_ipopt_nmpc.py
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 |
|
DiscreteClock
Bases: LeafSystem
Source block that produces the time sampled at a fixed rate.
The block maintains the most recently sampled time as a discrete state, provided to the output port during the following interval. Graphically, a discrete clock sampled at 100 Hz would have the following time series:
x(t) ●━
| ┆
.03 | ●━━━━○
| ┆
.02 | ●━━━━○
| ┆
.01 | ●━━━━○
| ┆
0 ●━━━━○----+----+----+-- t
0 .01 .02 .03 .04
The recorded states are the closed circles, which should be interpreted at index
n
as the value seen by all other blocks on the interval (t[n], t[n+1])
.
Input ports
None
Output ports
(0) The sampled time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
The sampling period of the clock. |
required | |
start_time
|
The simulation time at which the clock starts. Defaults to 0. |
0
|
Source code in collimator/library/primitives.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 |
|
DiscreteInitializer
Bases: LeafSystem
Discrete Initializer.
Outputs True for first discrete step, then outputs False there after. Or, outputs False for first discrete step, then outputs True there after. Practical for cases where it is necessary to have some signal fed initially by some initialization, but then after from else in the model.
Input ports
None
Output ports
(0) The dot product of the inputs.
Source code in collimator/library/primitives.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
|
DiscreteTimeLinearQuadraticRegulator
Bases: LeafSystem
Linear Quadratic Regulator (LQR) for a discrete-time system: x[k+1] = A x[k] + B u[k]. Computes the optimal control input: u[k] = -K x[k], where u minimises the cost function over [0, ∞)]: J = ∑(x[k].T Q x[k] + u[k].T R u[k]).
Input ports
(0) x[k]: state vector of the system.
Output ports
(0) u[k]: optimal control vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
Array State matrix of the system. |
required | |
B
|
Array Input matrix of the system. |
required | |
Q
|
Array State cost matrix. |
required | |
R
|
Array Input cost matrix. |
required | |
dt
|
float Sampling period of the system. |
required |
Source code in collimator/library/lqr.py
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 |
|
DotProduct
Bases: ReduceBlock
Compute the dot product between the inputs.
This block dispatches to jax.numpy.dot
, so the semantics, broadcasting rules,
etc. are the same. See the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.dot.html
Input ports
(0) The first input vector. (1) The second input vector.
Output ports
(0) The dot product of the inputs.
Source code in collimator/library/primitives.py
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 |
|
EdgeDetection
Bases: LeafSystem
Output is true only when the input signal changes in a specified way.
The block updates at a discrete rate, checking the boolean- or binary-valued input signal for changes. Available edge detection modes are: - "rising": Output is true when the input changes from False (0) to True (1). - "falling": Output is true when the input changes from True (1) to False (0). - "either": Output is true when the input changes in either direction
Input ports
(0) The input signal. Must be boolean or binary-valued.
Output ports
(0) The edge detection output signal. Boolean-valued.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
The sampling period of the block. |
required | |
edge_detection
|
One of "rising", "falling", or "either". Determines the type of edge detection performed by the block. |
required | |
initial_state
|
The initial value of the output signal. |
False
|
Source code in collimator/library/primitives.py
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 |
|
Exponent
Bases: FeedthroughBlock
Compute the exponential of the input signal.
Input ports
(0) The input signal.
Output ports
(0) The exponential of the input signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
One of "exp" or "2". Determines the base of the exponential function. |
required |
Source code in collimator/library/primitives.py
950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 |
|
ExtendedKalmanFilter
Bases: KalmanFilterBase
Extended Kalman Filter (EKF) for the following system:
```
x[n+1] = f(x[n], u[n]) + G(t[n]) w[n]
y[n] = g(x[n], u[n]) + v[n]
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Q(t[n], x[n], u[n])
E(v[n]v'[n] = R(t[n])
E(w[n]v'[n] = N(t[n]) = 0
```
f
and g
are discrete-time functions of state x[n]
and control u[n]
,
while Rand
Gare discrete-time functions of time
t[n].
Qis a discrete-time
function of
t[n], x[n], u[n]`. This last aspect is included for zero-order-hold
discretization of a continuous-time system
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float Time step of the discrete-time system |
required | |
forward
|
Callable
A function with signature f(x[n], u[n]) -> x[n+1] that represents |
required | |
observation
|
Callable
A function with signature g(x[n], u[n]) -> y[n] that represents |
required | |
G_func
|
Callable
A function with signature G(t[n]) -> G[n] that represents |
required | |
Q_func
|
Callable
A function with signature Q(t[n], x[n], u[n]) -> Q[n] that represents |
required | |
R_func
|
Callable
A function with signature R(t[n]) -> R[n] that represents |
required | |
x_hat_0
|
ndarray Initial state estimate |
required | |
P_hat_0
|
ndarray Initial state covariance matrix estimate |
required |
Source code in collimator/library/state_estimators/extended_kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
for_continuous_plant(plant, dt, G_func, Q_func, R_func, x_hat_0, P_hat_0, discretization_method='euler', discretized_noise=False, name=None, ui_id=None)
staticmethod
Extended Kalman Filter system for a continuous-time plant.
The input plant contains the deterministic forms of the forward and observation operators:
dx/dt = f(x,u)
y = g(x,u)
Note: (i) Only plants with one vector-valued input and one vector-valued output are currently supported. Furthermore, the plant LeafSystem/Diagram should have only one vector-valued integrator; (ii) the user may pass a plant with disturbances (not recommended) as the input plant. In this case, the forward and observation evaluations will be corrupted by noise.
A plant with disturbances of the following form is then considered:
dx/dt = f(x,u) + G(t) w -- (C1)
y = g(x,u) + v -- (C2)
where:
`w` represents the process noise,
`v` represents the measurement noise,
and
E(w) = E(v) = 0
E(ww') = Q(t)
E(vv') = R(t)
E(wv') = N(t) = 0
This plant is discretized to obtain the following form:
x[n+1] = fd(x[n], u[n]) + Gd w[n] -- (D1)
y[n] = gd(x[n], u[n]) + v[n] -- (D2)
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Qd
E(v[n]v'[n] = Rd
E(w[n]v'[n] = Nd = 0
The above discretization is performed either via the euler
or the zoh
method, and an Extended Kalman Filter estimator for the system of equations
(D1) and (D2) is returned.
Note: If discretized_noise
is True, then it is assumed that the user is
directly providing Gd, Qd and Rd. If False, then Qd and Rd are computed from
continuous-time Q, R, and G, and Gd is set to an Identity matrix.
The returned system will have:
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
a |
required | |
dt
|
float Time step for the discretization. |
required | |
G_func
|
Callable
A function with signature G(t) -> G that represents |
required | |
Q_func
|
Callable
A function with signature Q(t) -> Q that represents |
required | |
R_func
|
Callable
A function with signature R(t) -> R that represents |
required | |
x_hat_0
|
ndarray Initial state estimate |
required | |
P_hat_0
|
ndarray
Initial state covariance matrix estimate. If |
required | |
discretization_method
|
str ("euler" or "zoh") Method to discretize the continuous-time plant. Default is "euler". |
'euler'
|
|
discretized_noise
|
bool
Whether the user is directly providing Gd, Qd and Rd. Default is False.
If True, |
False
|
Source code in collimator/library/state_estimators/extended_kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
|
from_operators(dt, forward, observation, G_func, Q_func, R_func, x_hat_0, P_hat_0, name=None, ui_id=None)
staticmethod
Extended Kalman Filter (UKF) for the following system:
x[n+1] = f(x[n], u[n]) + G(t[n]) w[n]
y[n] = g(x[n], u[n]) + v[n]
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Q(t[n], x[n], u[n])
E(v[n]v'[n] = R(t[n])
E(w[n]v'[n] = N(t[n]) = 0
f
and g
are discrete-time functions of state x[n]
and control u[n]
,
while Q
and R
and G
are discrete-time functions of time t[n]
.
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float Time step of the discrete-time system |
required | |
forward
|
Callable
A function with signature f(x[n], u[n]) -> x[n+1] that represents |
required | |
observation
|
Callable
A function with signature g(x[n], u[n]) -> y[n] that represents |
required | |
G_func
|
Callable
A function with signature G(t[n]) -> G[n] that represents |
required | |
Q_func
|
Callable
A function with signature Q(t[n]) -> Q[n] that represents
|
required | |
R_func
|
Callable
A function with signature R(t[n]) -> R[n] that represents |
required | |
x_hat_0
|
ndarray Initial state estimate |
required | |
P_hat_0
|
ndarray Initial state covariance matrix estimate |
required |
Source code in collimator/library/state_estimators/extended_kalman_filter.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
|
FeedthroughBlock
Bases: LeafSystem
Simple feedthrough blocks with a function of a single input
Source code in collimator/library/generic.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
FilterDiscrete
Bases: LeafSystem
Finite Impulse Response (FIR) filter.
Similar to https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.lfilter.html Note: does not implement the IIR filter.
Input ports
(0) The input signal.
Output ports
(0) The filtered signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
b_coefficients
|
Array of filter coefficients. |
required |
Source code in collimator/library/primitives.py
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
|
FiniteHorizonLinearQuadraticRegulator
Bases: LeafSystem
Finite Horizon Linear Quadratic Regulator (LQR) for a continuous-time system. Solves the Riccati Differential Equation (RDE) to compute the optimal control for the following finitie horizon cost function over [t0, tf]:
Minimise cost J:
J = [x(tf) - xd(tf)].T Qf [x(tf) - xd(tf)]
+ ∫[(x(t) - xd(t)].T Q [(x(t) - xd(t)] dt
+ ∫[(u(t) - ud(t)].T R [(u(t) - ud(t)] dt
+ 2 ∫[(x(t) - xd(t)].T N [(u(t) - ud(t)] dt
subject to the constraints:
dx(t)/dt - dx0(t)/dt = A [x(t)-x0(t)] + B [u(t)-u0(t)] - c(t),
where, x(t) is the state vector, u(t) is the control vector, xd(t) is the desired state vector, ud(t) is the desired control vector, x0(t) is the nominal state vector, u0(t) is the nominal control vector, Q, R, and N are the state, input, and cross cost matrices, Qf is the final state cost matrix,
and A, B, and c are computed from linearisation of the plant df/dx = f(x, u)
around the nominal trajectory (x0(t), u0(t)).
A = df/dx(x0(t), u0(t), t)
B = df/du(x0(t), u0(t), t)
c = f(x0(t), u0(t), t) - dx0(t)/dt
The optimal control u
obtained by the solution of the above problem is output.
See Section 8.5.1 of https://underactuated.csail.mit.edu/lqr.html#finite_horizon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t0
|
float Initial time of the finite horizon. |
required | |
tf
|
float Final time of the finite horizon. |
required | |
plant
|
a |
required | |
Qf
|
Array Final state cost matrix. |
required | |
func_Q
|
Callable
A function that returns the state cost matrix Q at time |
required | |
func_R
|
Callable
A function that returns the input cost matrix R at time |
required | |
func_N
|
Callable
A function that returns the cross cost matrix N at time |
required | |
func_x_0
|
Callable
A function that returns the nominal state vector |
required | |
func_u_0
|
Callable
A function that returns the nominal control vector |
required | |
func_x_d
|
Callable
A function that returns the desired state vector |
None
|
|
func_u_d
|
Callable
A function that returns the desired control vector |
None
|
Source code in collimator/library/lqr.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
|
Gain
Bases: FeedthroughBlock
Multiply the input signal by a constant value.
Input ports
(0) The input signal.
Output ports
(0) The input signal multiplied by the gain: y = gain * u
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gain
|
The value to scale the input signal by. |
required |
Source code in collimator/library/primitives.py
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 |
|
HermiteSimpsonNMPC
Bases: NonlinearMPCIpopt
Implementation of nonlinear MPC with Hermite-Simpson collocation and IPOPT as the NLP solver.
Input ports
(0) x_0 : current state vector. (1) x_ref : reference state trajectory for the nonlinear MPC. (2) u_ref : reference input trajectory for the nonlinear MPC.
Output ports
(1) u_opt : the optimal control input to be applied at the current time step as determined by the nonlinear MPC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
LeafSystem or Diagram The plant to be controlled. |
required | |
Q
|
Array State weighting matrix in the cost function. |
required | |
QN
|
Array Terminal state weighting matrix in the cost function. |
required | |
R
|
Array Control input weighting matrix in the cost function. |
required | |
N
|
int The prediction horizon, an integer specifying the number of steps to predict. Note: prediction and control horizons are identical for now. |
required | |
dt
|
float: Major time step, a scalar indicating the increment in time for each step in the prediction and control horizons. |
required | |
lb_x
|
Array Lower bound on the state vector. |
None
|
|
ub_x
|
Array Upper bound on the state vector. |
None
|
|
lb_u
|
Array Lower bound on the control input vector. |
None
|
|
ub_u
|
Array Upper bound on the control input vector. |
None
|
|
include_terminal_x_as_constraint
|
bool If True, the terminal state is included as a constraint in the NLP. |
False
|
|
include_terminal_u_as_constraint
|
bool If True, the terminal control input is included as a constraint in the NLP. |
False
|
|
x_optvars_0
|
Array Initial guess for the state vector optimization variables in the NLP. |
None
|
|
u_optvars_0
|
Array Initial guess for the control vector optimization variables in the NLP. |
None
|
Source code in collimator/library/nmpc/hermite_simpson_ipopt_nmpc.py
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 250 251 252 253 254 255 256 257 258 259 260 261 |
|
IOPort
Bases: FeedthroughBlock
Simple class for organizing input/output ports for groups/submodels.
Since these are treated as standalone blocks in the UI rather than specific input/output ports exported to the parent model, it is more straightforward to represent them that way here as well.
This class represents a simple one-input, one-output feedthrough block where the feedthrough function is an identity. The input (resp. output) port can then be exported to the parent model to create an Inport (resp. Outport).
Source code in collimator/library/primitives.py
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 |
|
IfThenElse
Bases: LeafSystem
Applies a conditional expression to the input signals.
Given inputs pred
, true_val
, and false_val
, the block computes:
y = true_val if pred else false_val
The true and false values may be any arrays, but must have the same shape and dtype.
Input ports
(0) The boolean predicate. (1) The true value. (2) The false value.
Output ports
(0) The result of the conditional expression. Shape and dtype will match the true and false values.
Events
An event is triggered when the output changes from true to false or vice versa.
Source code in collimator/library/primitives.py
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 |
|
InfiniteHorizonKalmanFilter
Bases: KalmanFilterBase
Infinite Horizon Kalman Filter for the following system:
x[n+1] = A x[n] + B u[n] + G w[n]
y[n] = C x[n] + D u[n] + v[n]
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Q
E(v[n]v'[n]) = R
E(w[n]v'[n]) = N = 0
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float Time step of the discrete-time system |
required | |
A
|
ndarray State transition matrix |
required | |
B
|
ndarray Input matrix |
required | |
C
|
ndarray
Output matrix. If |
None
|
|
D
|
ndarray
Feedthrough matrix. If |
None
|
|
G
|
ndarray
Process noise matrix. If |
None
|
|
Q
|
ndarray
Process noise covariance matrix. If |
None
|
|
R
|
ndarray
Measurement noise covariance matrix. If |
None
|
|
x_hat_0
|
ndarray
Initial state estimate. If |
None
|
Source code in collimator/library/state_estimators/infinite_horizon_kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
for_continuous_plant(plant, x_eq, u_eq, dt, Q=None, R=None, G=None, x_hat_bar_0=None, discretization_method='zoh', discretized_noise=False, name=None, ui_id=None)
staticmethod
Obtain an Infinite Horizon Kalman Filter system for a continuous-time plant after linearization at equilibrium point (x_eq, u_eq)
The input plant contains the deterministic forms of the forward and observation operators:
dx/dt = f(x,u)
y = g(x,u)
Note: (i) Only plants with one vector-valued input and one vector-valued output
are currently supported. Furthermore, the plant LeafSystem/Diagram should have
only one vector-valued integrator. (ii) the user may pass a plant with
disturbances as the input plant. However, computation of y_eq
will be fraught
with disturbances.
A plant with disturbances of the following form is then considered following form:
dx/dt = f(x,u) + G w --- (C1)
y = g(x,u) + v --- (C2)
where:
`w` represents the process noise,
`v` represents the measurement noise,
and
E(w) = E(v) = 0
E(ww') = Q
E(vv') = R
E(wv') = N = 0
This plant with disturbances is linearized (only f
and g
) around the
equilibrium point to obtain:
d/dt (x_bar) = A x_bar + B u_bar + G w
y_bar = C x_bar + D u_bar + v
where,
x_bar = x - x_eq
u_bar = u - u_eq
y_bar = y - y_bar
y_eq = g(x_eq, u_eq)
The linearized plant is then discretized via euler
or zoh
method to obtain:
x_bar[n] = Ad x_bar[n] + Bd u_bar[n] + Gd w[n] --- (L1)
y_bar[n] = Cd x_bar[n] + Dd u_bar[n] + v[n] --- (L2)
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Qd
E(v[n]v'[n]) = Rd
E(w[n]v'[n]) = Nd = 0
Note: If discretized_noise
is True, then it is assumed that the user is
providing Gd, Qd and Rd. If False, then Qd and Rd are computed from
continuous-time Q, R, and G, and Gd is set to Identity matrix.
An Infinite Horizon Kalman Filter estimator for the system of equations (L1)
and (L2) is returned. This filter is in the x_bar
, u_bar
, and y_bar
states.
This returned system will have
Input ports
(0) u_bar[n] : control vector at timestep n, relative to equilibrium (1) y_bar[n] : measurement vector at timestep n, relative to equilibrium
Output ports
(1) x_hat_bar[n] : state vector estimate at timestep n, relative to equilibrium
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
a |
required | |
x_eq
|
ndarray Equilibrium state vector for discretization |
required | |
u_eq
|
ndarray Equilibrium control vector for discretization |
required | |
dt
|
float Time step for the discretization. |
required | |
Q
|
ndarray
Process noise covariance matrix. If |
None
|
|
R
|
ndarray
Measurement noise covariance matrix. If |
None
|
|
G
|
ndarray
Process noise matrix. If |
None
|
|
x_hat_bar_0
|
ndarray Initial state estimate relative to equilibrium. If None, an identity matrix is assumed. |
None
|
|
discretization_method
|
str ("euler" or "zoh") Method to discretize the continuous-time plant. Default is "euler". |
'zoh'
|
|
discretized_noise
|
bool
Whether the user is directly providing Gd, Qd and Rd. Default is False.
If True, |
False
|
Source code in collimator/library/state_estimators/infinite_horizon_kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
global_filter_for_continuous_plant(plant, x_eq, u_eq, dt, Q=None, R=None, G=None, x_hat_0=None, discretization_method='euler', discretized_noise=False, name=None, ui_id=None)
staticmethod
See docs for for_continuous_plant
, which returns the local infinite horizon
Kalman Filter. This method additionally converts the local Kalman Filter to a
global estimator. See docs for make_global_estimator_from_local
for details.
Source code in collimator/library/state_estimators/infinite_horizon_kalman_filter.py
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
Integrator
Bases: LeafSystem
Integrate the input signal in time.
The Integrator block is the main primitive for building continuous-time
models. It is a first-order integrator, implementing the following linear
time-invariant ordinary differential equation for input values u
and output
values y
:
ẋ = u
y = x
where x
is the state of the integrator. The integrator is initialized
with the value of the initial_state
parameter.
The Integrator block is also designed to detect "Zeno" behavior, where the reset events happen asymptotically closer together. This is a pathological case that can cause numerical issues in the simulation and should typically be avoided by introducing some physically realistic hysteresis into the model. However, in the event that Zeno behavior is unavoidable, the integrator will enter a "Zeno" state where the output is held constant until the trigger changes value to False. See the "bouncing ball" demo for a Zeno example.
Input ports
(0) The input signal. Must match the shape and dtype of the initial
continuous state.
(1) The reset trigger. Optional, only if enable_reset
is True.
(2) The reset value. Optional, only if enable_external_reset
is True.
(3) The hold trigger. Optional, only if 'enable_hold' is True.
Output ports
(0) The continuous state of the integrator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_state
|
The initial value of the integrator state. Can be any array, or even a nested structure of arrays, but the data type should be floating-point. |
required | |
enable_reset
|
If True, the integrator will reset its state to the initial value when the reset trigger is True. Adds an additional input port for the reset trigger. This signal should be boolean- or binary-valued. |
False
|
|
enable_external_reset
|
If True, the integrator will reset its state to the value provided by the reset value input port when the reset trigger is True. Otherwise, the integrator will reset to the initial value. Adds an additional input port for the reset value. This signal should match the shape and dtype of the initial continuous state. |
False
|
|
enable_limits
|
If True, the integrator will constrain its state and output to within the upper and lower limits. Either limit may be disbale by setting its value to None. |
False
|
|
enable_hold
|
If True, the integrator will hold integration when the hold trigger is True. |
False
|
|
reset_on_enter_zeno
|
If True, the integrator will reset its state to the initial value
when the integrator enters the Zeno state. This option is ignored unless
|
False
|
|
zeno_tolerance
|
The tolerance used to determine if the integrator is in the Zeno state.
If the time between events is less than this tolerance, then the
integrator is in the Zeno state. This option is ignored unless
|
1e-06
|
Events
An event is triggered when the "reset" port changes.
An event is triggered when the state hit one of the limits.
An event is triggered when the "hold" port changes.
Another guard is conditionally active when the integrator is in the Zeno state, and is triggered when the "reset" port changes from True to False. This event is used to exit the Zeno state and resume normal integration.
Source code in collimator/library/primitives.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
|
IntegratorDiscrete
Bases: LeafSystem
Discrete first-order integrator.
This block is a discrete-time approximation to the behavior of the Integrator
block. It implements the following linear time-invariant difference equation
for input values u
and output values y
:
x[k+1] = x[k] + dt * u[k]
y[k] = x[k]
where x
is the state of the integrator. The integrator is initialized with
the value of the initial_state
parameter.
Unlike the continuous-time integrator, the discrete integrator does not detect Zeno behavior, since this is not a concern in discrete-time systems.
Input ports
(0) The input signal. Must match the shape and dtype of the initial
state.
(1) The reset trigger. Optional, only if enable_reset
is True.
(2) The reset value. Optional, only if enable_external_reset
is True.
(3) The hold trigger. Optional, only if 'enable_hold' is True.
Output ports
(0) The current state of the integrator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_state
|
The initial value of the integrator state. Can be any array, or even a nested structure of arrays, but the data type should be floating-point. |
required | |
enable_reset
|
If True, the integrator will reset its state to the initial value when the reset trigger is True. Adds an additional input port for the reset trigger. This signal should be boolean- or binary-valued. |
False
|
|
enable_external_reset
|
If True, the integrator will reset its state to the value provided by the reset value input port when the reset trigger is True. Otherwise, the integrator will reset to the initial value. Adds an additional input port for the reset value. This signal should match the shape and dtype of the initial continuous state. |
False
|
|
enable_limits
|
If True, the integrator will constrain its state and output to within the upper and lower limits. Either limit may be disbale by setting its value to None. |
False
|
|
enable_hold
|
If True, the integrator will hold integration when the hold trigger is True. |
False
|
Source code in collimator/library/primitives.py
1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 |
|
KalmanFilter
Bases: KalmanFilterBase
Kalman Filter for the following system:
x[n+1] = A x[n] + B u[n] + G w[n]
y[n] = C x[n] + D u[n] + v[n]
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Q
E(v[n]v'[n] = R
E(w[n]v'[n] = N = 0
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float Time step of the discrete-time system |
required | |
A
|
ndarray State transition matrix |
required | |
B
|
ndarray Input matrix |
required | |
C
|
ndarray
Output matrix. If |
None
|
|
D
|
ndarray
Feedthrough matrix. If |
None
|
|
G
|
ndarray
Process noise matrix. If |
None
|
|
Q
|
ndarray
Process noise covariance matrix. If |
None
|
|
R
|
ndarray
Measurement noise covariance matrix. If |
None
|
|
x_hat_0
|
ndarray
Initial state estimate. If |
None
|
|
P_hat_0
|
ndarray
Initial state covariance matrix estimate. If |
None
|
Source code in collimator/library/state_estimators/kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
for_continuous_plant(plant, x_eq, u_eq, dt, Q=None, R=None, G=None, x_hat_bar_0=None, P_hat_bar_0=None, discretization_method='euler', discretized_noise=False, name=None, ui_id=None)
staticmethod
Obtain a Kalman Filter system for a continuous-time plant after linearization at equilibrium point (x_eq, u_eq)
The input plant contains the deterministic forms of the forward and observation operators:
dx/dt = f(x,u)
y = g(x,u)
Note: (i) Only plants with one vector-valued input and one vector-valued output are currently supported. Furthermore, the plant LeafSystem/Diagram should have only one vector-valued integrator.
A plant with disturbances of the following form is then considered following form:
dx/dt = f(x,u) + G w --- (C1)
y = g(x,u) + v --- (C2)
where:
`w` represents the process noise,
`v` represents the measurement noise,
and
E(w) = E(v) = 0
E(ww') = Q
E(vv') = R
E(wv') = N = 0
This plant with disturbances is linearized (only f
and g
) around the
equilibrium point to obtain:
d/dt (x_bar) = A x_bar + B u_bar + G w
y_bar = C x_bar + D u_bar + v
where,
x_bar = x - x_eq
u_bar = u - u_eq
y_bar = y - y_bar
y_eq = g(x_eq, u_eq)
The linearized plant is then discretized via euler
or zoh
method to obtain:
x_bar[n] = Ad x_bar[n] + Bd u_bar[n] + Gd w[n] --- (L1)
y_bar[n] = Cd x_bar[n] + Dd u_bar[n] + v[n] --- (L2)
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Qd
E(v[n]v'[n]) = Rd
E(w[n]v'[n]) = Nd = 0
Note: If discretized_noise
is True, then it is assumed that the user is
providing Gd, Qd and Rd. If False, then Qd and Rd are computed from
continuous-time Q, R, and G, and Gd is set to Identity matrix.
A Kalman Filter estimator for the system of equations (L1) and (L2) is
created and returned. This filter is in the x_bar
, u_bar
, and y_bar
states.
This returned system will have
Input ports
(0) u_bar[n] : control vector at timestep n, relative to equilibrium (1) y_bar[n] : measurement vector at timestep n, relative to equilibrium
Output ports
(1) x_hat_bar[n] : state vector estimate at timestep n, relative to equilibrium
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
a |
required | |
x_eq
|
ndarray Equilibrium state vector for discretization |
required | |
u_eq
|
ndarray Equilibrium control vector for discretization |
required | |
dt
|
float Time step for the discretization. |
required | |
Q
|
ndarray
Process noise covariance matrix. If |
None
|
|
R
|
ndarray
Measurement noise covariance matrix. If |
None
|
|
G
|
ndarray
Process noise matrix. If |
None
|
|
x_hat_bar_0
|
ndarray Initial state estimate, relative to equilirium. If None, an identity matrix is assumed. |
None
|
|
P_hat_bar_0
|
ndarray
Initial covariance matrix estimate for state, relative to equilibrium.
If |
None
|
|
discretization_method
|
str ("euler" or "zoh") Method to discretize the continuous-time plant. Default is "euler". |
'euler'
|
|
discretized_noise
|
bool
Whether the user is directly providing Gd, Qd and Rd. Default is False.
If True, |
False
|
Source code in collimator/library/state_estimators/kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
global_filter_for_continuous_plant(plant, x_eq, u_eq, dt, Q=None, R=None, G=None, x_hat_0=None, P_hat_0=None, discretization_method='euler', discretized_noise=False, name=None, ui_id=None)
staticmethod
See docs for for_continuous_plant
, which returns the local Kalman
Filter. This method additionally converts the local Kalman Filter to a
global estimator. See docs for make_global_estimator_from_local
for details.
Source code in collimator/library/state_estimators/kalman_filter.py
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
LTISystem
Bases: LTISystemBase
Continuous-time linear time-invariant system.
Implements the following system of ODEs:
ẋ = Ax + Bu
y = Cx + Du
Input ports
(0) u: Input vector of size m
Output ports
(0) y: Output vector of size p. Note that this is feedthrough from the input port if and only if D is nonzero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
State matrix of size n x n |
required | |
B
|
Input matrix of size n x m |
required | |
C
|
Output matrix of size p x n |
required | |
D
|
Feedthrough matrix of size p x m |
required | |
initialize_states
|
Initial state vector of size n (default: 0) |
None
|
Source code in collimator/library/linear_system.py
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 |
|
ss
property
State-space representation of the system.
LTISystemDiscrete
Bases: LTISystemBase
Discrete-time linear time-invariant system.
Implements the following system of ODEs:
x[k+1] = A x[k] + B u[k]
y[k] = C x[k] + D u[k]
Input ports
(0) u[k]: Input vector of size m
Output ports
(0) y[k]: Output vector of size p. Note that this is feedthrough from the input port if and only if D is nonzero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
State matrix of size n x n |
required | |
B
|
Input matrix of size n x m |
required | |
C
|
Output matrix of size p x n |
required | |
D
|
Feedthrough matrix of size p x m |
required | |
dt
|
Sampling period |
required | |
initialize_states
|
Initial state vector of size n (default: 0) |
None
|
Source code in collimator/library/linear_system.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
|
ss
property
State-space representation of the system.
LinearDiscreteTimeMPC
Bases: LeafSystem
Model predictive control for a linear discrete-time system.
Notes
This block is feedthrough, meaning that every time the output port is
evaluated, the solver is run. This is in order to avoid a "data flow" delay
between the solver and the output port (see also the PIDDiscrete
block).
This means that either the input or output signal should be discrete-time in
order for the block to work as intended. Ideally, the output signal should
be passed to a zero-order hold block so that the solver only needs to be run
once per step.
Source code in collimator/library/mpc.py
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 |
|
LinearDiscreteTimeMPC_OSQP
Bases: LeafSystem
Same as above, but using OSQP. This is an example of a case where a traced array gets passed to a function that doesn't know how to handle it.
Source code in collimator/library/mpc.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
LinearQuadraticRegulator
Bases: FeedthroughBlock
Linear Quadratic Regulator (LQR) for a continuous-time system: dx/dt = A x + B u. Computes the optimal control input: u = -K x, where u minimises the cost function over [0, ∞)]: J = ∫(x.T Q x + u.T R u) dt.
Input ports
(0) x: state vector of the system.
Output ports
(0) u: optimal control vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
A
|
Array State matrix of the system. |
required | |
B
|
Array Input matrix of the system. |
required | |
Q
|
Array State cost matrix. |
required | |
R
|
Array Input cost matrix. |
required |
Source code in collimator/library/lqr.py
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 |
|
Logarithm
Bases: FeedthroughBlock
Compute the logarithm of the input signal.
This block dispatches to jax.numpy.log
, jax.numpy.log2
, or jax.numpy.log10
,
so the semantics, broadcasting rules, etc. are the same. See the JAX docs for
details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.log.html
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.log2.html
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.log10.html
Input ports
(0) The input signal.
Output ports
(0) The logarithm of the input signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
One of "natural", "2", or "10". Determines the base of the logarithm. The default is "natural". |
'natural'
|
Source code in collimator/library/primitives.py
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 |
|
LogicalOperator
Bases: LeafSystem
Apply a boolean function elementwise to the input signals.
This block implements the following boolean functions
- "or": same as np.logical_or
- "and": same as np.logical_and
- "not": same as np.logical_not
- "nor": equivalent to np.logical_not(np.logical_or(in_0,in_1))
- "nand": equivalent to np.logical_not(np.logical_and(in_0,in_1))
- "xor": same as np.logical_xor
Input ports
(0,1) The input signals. If numeric, they are interpreted as boolean types (so 0 is False and any other value is True).
Output ports
(0) The result of the logical operation, a boolean-valued signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function
|
The boolean function to apply. One of "or", "and", "not", "nor", "nand", or "xor". |
required |
Events
An event is triggered when the output changes from True to False or vice versa.
Source code in collimator/library/primitives.py
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 |
|
LogicalReduce
Bases: FeedthroughBlock
Apply a boolean reduce function to the elements of the input signal.
This block implements the following boolean functions
- "any": Output is True if any input element is True.
- "all": Output is True if all input elements are True.
Input ports
(0) The input signal. If numeric, they are interpreted as boolean types (so 0 is False and any other value is True).
Output ports
(0) The result of the logical operation, a boolean-valued signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function
|
The boolean function to apply. One of "any", "all". |
required | |
axis
|
Axis or axes along which a logical OR/AND reduction is performed. |
None
|
Events
An event is triggered when the output changes from True to False or vice versa.
Source code in collimator/library/primitives.py
1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 |
|
LookupTable1d
Bases: FeedthroughBlock
Interpolate the input signal into a static lookup table.
If a function y = f(x)
is sampled at a set of points (x_i, y_i)
, then this
block will interpolate the input signal x
to compute the output signal y
.
The behavior is modeled after scipy.interpolate.interp1d
but is implemented
in JAX. Available interpolation modes are:
- "linear": Linear interpolation using jax.interp
.
- "nearest": Nearest-neighbor interpolation.
- "flat": Flat interpolation.
Input ports
(0) The input signal, which is used as the interpolation coordinate.
Output ports
(0) The interpolated output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_array
|
The array of input values at which the output values are provided. |
required | |
output_array
|
The array of output values. |
required | |
interpolation
|
One of "linear", "nearest", or "flat". Determines the type of interpolation performed by the block. |
required |
Notes
Currently restricted to 1D input and output data. This may be expanded to support multi-dimensional output arrays in the future.
Source code in collimator/library/primitives.py
2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 |
|
LookupTable2d
Bases: LeafSystem
Interpolate the input signals into a static lookup table.
The behavior is modeled on scipy.interpolate.interp2d
but is implemented
in JAX. The only currently implemented interpolation mode is "linear". The
input arrays must be 1D and the output array must be 2D.
Input ports
(0) The first input signal, used as the first interpolation coordinate. (1) The second input signal, used as the second interpolation coordinate.
Output ports
(0) The interpolated output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_x_array
|
The array of input values at which the output values are provided, corresponding to the first input signal. Must be 1D |
required | |
input_y_array
|
The array of input values at which the output values are provided, corresponding to the second input signal. Must be 1D |
required | |
output_table_array
|
The array of output values. Must be 2D with shape |
required | |
interpolation
|
Only "linear" is supported. |
'linear'
|
Source code in collimator/library/primitives.py
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 |
|
MJX
Bases: MuJoCoBase
A system that wraps a MuJoCo model and provides a continuous-time ODE LeafSystem. Currently only supports a single body system.
Input ports
(0) The control input vector control
.
Output ports
(0) The generalized position coordinates qpos
.
(1) The generalized velocity coordinates qvel
.
(2) The actuator coordinates act
.
(3) The sensor data sensor_data
(if enabled).
(4) The video output video
as RGB frames of shape (H,W,3) (if enabled).
(5) A fake output port, present only if vHIL=True
and outputs Array(0.0).
(6+) Custom output ports, defined with user-specified python scripts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
The path to the MuJoCo XML model file. |
required |
dt
|
float
|
If None, collimator's internal solver will be used and this block can
be considered as a continuous block. If set, the model will be run in
a discrete mode with the specified timestep, using MJX's solver, more like
Co-Simulation. In that case, it might be favorable to set |
None
|
key_frame_0
|
int | str
|
The keyframe to initialize the model from. |
None
|
qpos_0
|
Array
|
The initial generalized position coordinates. |
None
|
qvel_0
|
Array
|
The initial generalized velocity coordinates. |
None
|
act_0
|
Array
|
The initial actuator coordinates. |
None
|
enable_sensor_data
|
bool
|
Whether to output the sensor data to an optional port named 'sensor_data'. |
False
|
enable_video_output
|
bool
|
Whether to output the rendered video frames to an optional port named 'video'. |
False
|
video_size
|
tuple[int, int]
|
The size of the video output frames as a (H,W) tuple. |
None
|
enable_mocap_pos
|
bool
|
Whether to enable the mocap_pos input port for motion capture tracking. |
False
|
vHIL
|
bool
|
Whether to run in virtual hardware-in-the-loop mode. |
False
|
vHIL_dt
|
float
|
The timestep for the virtual hardware-in-the-loop mode. |
0.01
|
Notes:
(i) _model
and _data
refer to MuJoCo's mjModel
and mjData
objects
respectively. model
and data
are the corresponding MJX objects.
(ii) While sensordata
output is supported as a pure callback to MuJoCo since MJX
has not yet implemented this aspect. This can be expensive.
Source code in collimator/library/mujoco.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 |
|
normalize_qpos_quat(qpos)
Normalize the quaternion components of the generalized position coordinates.
Source code in collimator/library/mujoco.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 |
|
MLP
Bases: FeedthroughBlock
A feedforward neural network block representing an Equinox multi-layer
perceptron (MLP). The output y
of the MLP is computed as
y = MLP(x, theta)
where theta
are the parameters of the MLP, and x
is the input to the MLP.
This block is differentialble w.r.t. the MLP parameters theta
. Note that theta
,
does not include the hyperparameters representing the architecture of the MLP.
Input ports
(0) The input to the MLP.
Output ports
(0) The output of the MLP.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_size
|
int
|
The dimension of the input to the MLP. |
None
|
out_size
|
int
|
The dimension of the output of the MLP. |
None
|
width_size
|
int
|
The width of every hidden layers of the MLP. |
None
|
depth
|
int
|
The depth of the MLP. This represents the number of hidden layers, including the output layer. |
None
|
seed
|
int
|
The seed for the random number generator for initialization of the MLP parameters (weights and biases of every layer). If None, a random 32-bit seed will be generated. |
None
|
activation_str
|
str
|
The activation function to use after each internal layer of the MLP. Possible values are "relu", "sigmoid", "tanh", "elu", "swish", "rbf", and "identity". Default is "relu". |
'relu'
|
final_activation_str
|
str
|
The activation function to use for the output layer of the MLP. Possible values are "relu", "sigmoid", "tanh", "elu", "swish", "rbf", and "identity". Default is "identity". |
'identity'
|
use_bias
|
bool
|
Whether to add a bias to the internal layers of the MLP. Default is True. |
True
|
use_final_bias
|
bool
|
Wheter to add a bias to the output layer of the MLP. Default is True. |
True
|
file_name
|
str
|
Optional file name containing the serialized parameters of the MLP. If provided, the parameters are loaded from the file, and set as the parameters of the MLP. Default is None. |
None
|
Source code in collimator/library/nn.py
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 |
|
__init__(in_size=None, out_size=None, width_size=None, depth=None, seed=None, activation_str='relu', final_activation_str='identity', use_bias=True, use_final_bias=True, file_name=None, **kwargs)
see https://docs.kidger.site/equinox/examples/serialisation/ for rationale of implementation here. We can't serialize the activation function, so we serialize a string representing a selection for activation function amongst a finite set of options.
Source code in collimator/library/nn.py
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 |
|
serialize(file_name, mlp_params=None)
Serialize only the parameters of the MLP. Note that the hyperparameters
representing the architecture of the MLP are not serialized. This is because
of the following use-cases imagined:
(i) The user may train the Equinox MLP outside of Collimator. In this case,
it seems unnecessary to force the user to serialize the hyperparameters of the
MLP in the strict form chosen by Collimator. It would seem much easier
for the user to just input these hyperparameters when creating the MLP block
in Collimator UI, and upload the naturally produced serialized parameters file
by Equinox.
(ii) The user may want to train the Equinox MLP within Collimator in a notebook,
and then use the block within Colimator UI. In this case, while serialization of
the hyperparameters of the MLP would be a litte more convenient compared
to manually inputting the hyperparameters in the UI, it seems like a small
convenience relative to disadvantages of (i). Ideally the user should be
able to use the API to push the learnt parameters.
(iii) When we support training in the UI, the hyperparameters are naturally
serialzed with declare_configuraton_parameters
, and thus, in this case too,
only serializatio of the MLP parameters is necessary.
The choice of an optional mlp_params
is to enable training of the
models in a notebook and easily seralizing them for use in the UI.
Source code in collimator/library/nn.py
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 |
|
MatrixConcatenation
Bases: ReduceBlock
Concatenate two matrices along a given axis.
Dispatches to jax.numpy.concatenate
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.concatenate.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
The axis along which the matrices are concatenated. 0 for vertical and 1 for horizontal. Default is 0. |
0
|
Input ports
(0, 1) The input matrices A
and B
Output ports
(0) The concatenation input matrices: e.g. [A,B]
.
Source code in collimator/library/primitives.py
2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 |
|
MatrixInversion
Bases: FeedthroughBlock
Compute the matrix inverse of the input signal.
Dispatches to jax.numpy.inv
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.linalg.inv.html
Input ports
(0) The input matrix.
Output ports
(0) The inverse of the input matrix.
Source code in collimator/library/primitives.py
2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 |
|
MatrixMultiplication
Bases: ReduceBlock
Compute the matrix product of the input signals.
Dispatches to jax.numpy.matmul
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.matmul.html
Input ports
(0, 1) The input matrices A
and B
Output ports
(0) The matrix product of the input matrices: A @ B
.
Source code in collimator/library/primitives.py
2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 |
|
MatrixTransposition
Bases: FeedthroughBlock
Compute the matrix transpose of the input signal.
Dispatches to jax.numpy.transpose
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.transpose.html
Input ports
(0) The input matrix.
Output ports
(0) The transpose of the input matrix.
Source code in collimator/library/primitives.py
2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 |
|
MinMax
Bases: ReduceBlock
Return the extremum of the input signals.
Input ports
(0..n_in-1) The input signals.
Output ports
(0) The minimum or maximum of the input signals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
One of "min" or "max". Determines whether the block returns the minimum or maximum of the input signals. |
required |
Events
An event is triggered when the extreme input signal changes. For example, if the block is configured as a "max" block with two inputs and the second signal becomes greater than the first, a zero-crossing event will be triggered.
Source code in collimator/library/primitives.py
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 |
|
ModelicaFMU
Bases: LeafSystem
Source code in collimator/library/fmu_import.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
__init__(file_name, dt, name=None, input_names=None, output_names=None, parameters=None, start_time=0.0, **kwargs)
Load and execute an FMU for Co-Simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
path to FMU file |
required |
dt
|
float
|
stepsize for FMU simulation |
required |
name
|
str
|
name of block |
None
|
input_names
|
list[str]
|
if set, only expose these inputs |
None
|
output_names
|
list[str]
|
if set, only expose these outputs |
None
|
parameters
|
dict
|
dictionary of parameter overrides |
None
|
kwargs
|
ignored |
{}
|
Source code in collimator/library/fmu_import.py
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 |
|
MuJoCo
Bases: MuJoCoBase
MuJoCo implementation without MJX.
Refer to MJX for the main docs.
Unlike the MJX variant of the block, this version uses the solver provided by mujoco itself and the physics are fully handled by mujoco. This behaves like a Co-Simulation environment.
This variant may be used to speed up compilation times or in situations where full JAX is not available or practical.
Source code in collimator/library/mujoco.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 |
|
Multiplexer
Bases: ReduceBlock
Stack the input signals into a single output signal.
Dispatches to jax.numpy.hstack
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.hstack.html
Input ports
(0..n_in-1) The input signals.
Output ports
(0) The stacked output signal.
Source code in collimator/library/primitives.py
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 |
|
Offset
Bases: FeedthroughBlock
Add a constant offset or bias to the input signal.
Given an input signal u
and offset value b
, this will return y = u + b
.
Input ports
(0) The input signal.
Output ports
(0) The input signal plus the offset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
offset
|
The constant offset to add to the input signal. |
required |
Source code in collimator/library/primitives.py
2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 |
|
PID
Bases: LTISystem
Continuous-time PID controller.
The PID controller is implemented as a state-space system with matrices (A, B, C, D), which are then used to create a (second-order) LTISystem. Note that this only supports single-input, single-output PID controllers.
The PID controller implements the following control law:
u = kp * e + ki * ∫e + kd * ė
where e is the error signal, and ∫e and ė are the integral and derivative of the error signal, respectively.
With a filter coefficient of n
(to make the transfer function proper), the
state-space form of the system is:
A = [[0, 1], [0, -n]]
B = [[0], [1]]
C = [[ki * n, (kp * n + ki) - (kp + kd * n) * n]]
D = [[kp + kd * n]]
Since D is nonzero, the block is feedthrough.
Input ports
(0) e: Error signal (scalar)
Output ports
(0) u: Control signal (scalar)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kp
|
Proportional gain |
required | |
ki
|
Integral gain |
required | |
kd
|
Derivative gain |
required | |
n
|
Derivative filter coefficient |
required | |
initial_state
|
Initial state of the integral term (default: 0) |
0.0
|
Source code in collimator/library/linear_system.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
|
PIDDiscrete
Bases: LeafSystem
Discrete-time PID controller.
This block implements a discrete-time PID controller with a first-order approximation to the integrated error and an optional derivative filter. The integrated error term is computed as:
e_int[k+1] = e_int[k] + e[k] * dt
where e
is the error signal and dt
is the sampling period. The derivative
term is computed in the same way as for the DerivativeDiscrete block, including
filter options described there. With the running error integral e_int
and
current estimate of the time derivative of the error e_dot
, the output is:
u[k] = kp * e[k] + ki * e_int[k] + kd * e_dot[k]
Input ports
(0) The error signal.
Output ports
(0) The control signal computed by the PID algorithm.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kp
|
The proportional gain (scalar) |
1.0
|
|
ki
|
The integral gain (scalar) |
1.0
|
|
kd
|
The derivative gain (scalar) |
1.0
|
|
dt
|
The sampling period of the block. |
required | |
initial_state
|
The initial value of the running error integral. Default is 0. |
0.0
|
|
enable_external_initial_state
|
Source for the value used for the integrator initial state. True=from inport, False=from the initial_state parameter. |
False
|
|
filter_type
|
One of "none", "forward", "backward", or "bilinear". Determines the type of filter used to estimate the derivative of the error signal. Default is "none". See DerivativeDiscrete documentation for details. |
'none'
|
|
filter_coefficient
|
The filter coefficient for the derivative filter. Default is 1.0. See DerivativeDiscrete documentation for details. |
1.0
|
Source code in collimator/library/primitives.py
2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 |
|
initialize_static_data(context)
Set the initial state from the input port, if specified via config
Source code in collimator/library/primitives.py
2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 |
|
Power
Bases: FeedthroughBlock
Raise the input signal to a constant power.
Dispatches to jax.numpy.power
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.power.html
For input signal u
with exponent p
, the output will be y = u ** p
.
Input ports
(0) The input signal.
Output ports
(0) The input signal raised to the power of the exponent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exponent
|
The exponent to which the input signal is raised. |
required |
Source code in collimator/library/primitives.py
2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 |
|
Product
Bases: ReduceBlock
Compute the product and/or quotient of the input signals.
The block will multiply or divide the input signals, depending on the specified
operators. For example, if the block has three inputs u1
, u2
, and u3
and
is configured with operators="**/", then the output signal will be
y = u1 * u2 / u3
. By default, the block will multiply all of the input signals.
Input ports
(0..n_in-1) The input signals.
Output ports
(0) The product and/or quotient of the input signals.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_in
|
The number of input ports. |
required | |
operators
|
A string of length |
None
|
|
denominator_limit
|
Currently unsupported |
None
|
|
divide_by_zero_behavior
|
Currently unsupported |
None
|
Source code in collimator/library/primitives.py
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 |
|
ProductOfElements
Bases: FeedthroughBlock
Compute the product of the elements of the input signal.
Dispatches to jax.numpy.prod
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.prod.html
Input ports
(0) The input signal.
Output ports
(0) The product of the elements of the input signal.
Source code in collimator/library/primitives.py
2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 |
|
Pulse
Bases: SourceBlock
A periodic pulse signal.
Given amplitude a
, pulse width w
, and period p
, the output signal is:
y(t) = a if t % p < w else 0
where %
is the modulo operator.
Input ports
None
Output ports
(0) The pulse signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amplitude
|
The amplitude of the pulse signal. |
1.0
|
|
pulse_width
|
The fraction of the period during which the pulse is "high". |
0.5
|
|
period
|
The period of the pulse signal. |
1.0
|
|
phase_delay
|
Currently unsupported. |
0.0
|
Source code in collimator/library/primitives.py
2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 |
|
PyTorch
Bases: LeafSystem
Block to perform inference with a pre-trained PyTorch model saved as TorchScript.
The input to the block should be of compatible type and shape expected by
the TorchScript. For example, if the TorchScript model expects
a torch.float32
tensor of shape (3, 224, 224)
, the input to the block should be
a jax.numpy
array of shape (3, 224, 224) of dtype jnp.float32
.
For output types, if no casting is specified through the cast_outputs_to_dtype
parameter, the output of the block will have the same dtype as the TorchScript
model output, but expressed as jax.numpy
types. For example. if the
TorchScript model outputs a torch.float32
tensor, the output of the block will be
a jax.numpy
array of dtype jnp.float32
.
If casting is specified through cast_outputs_to_dtype
parameter, all the outputs,
of the block will be casted to this specific jax.numpy
dtype.
Input ports
(i) The ith input to the model.
Output ports
(j) The jth output of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Path to the model Torchscript |
required |
num_inputs
|
int
|
The number of inputs to the model. Only required for TorchScript models. |
1
|
num_outputs
|
int
|
The number of outputs of the model. |
1
|
cast_outputs_to_dtype
|
str
|
The dtype to cast all the outputs of the block to. Must correspond to a
|
None
|
add_batch_dim_to_inputs
|
bool
|
Whether to add a new first dimension to the inputs before evaluating the TorchScript or TensorFlow model. This is useful when the model expects a batch dimension. |
False
|
Source code in collimator/library/predictor.py
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 |
|
initialize_static_data(context)
Infer the output shapes and dtypes of the ML model.
Source code in collimator/library/predictor.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
QuadraticCost
Bases: ReduceBlock
LQR-type quadratic cost function for a state and input.
Computes the cost as x'Qx + u'Ru, where Q and R are the cost matrices.
In order to compute a running cost, combine this with an Integrator
or IntegratorDiscrete
block.
Source code in collimator/library/costs_and_losses.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
QuanserHAL
Bases: LeafSystem
Hardware Abstraction Layer for Quanser hardware.
This block provides an interface to virtual or physical Quanser hardware. It requires that the Quanser hardware or QLabs simulator be properly configured and that the Quanser python library is available on the system path. See the Quanser documentation for more information.
To use an idealized model of the Qube Servo hardware, see the
collimator.library.QubeServoModel
block, which may be run without hardware
or in the cloud-based simulation UI.
Input ports
(0) Control signal to the motor in volts
Output ports
(0) The observed rotor and pendulum angles in radians
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
The time step of the simulation. |
required | |
version
|
The version of the Qube hardware (2 or 3). By default, version 2 is
used with |
2
|
|
hardware
|
If True, connect to the physical hardware. If False, connect to the QLabs simulator. |
False
|
|
name
|
The name of the system in the Collimator model. |
'QuanserHAL'
|
Source code in collimator/library/quanser.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
Quantizer
Bases: FeedthroughBlock
Discritize the input signal into a set of discrete values.
Given an input signal u
and a resolution intervals
, this block will
quantize the input signal into a set of intervals
discrete values.
The output signal will be y = intervals * round(u / intervals)
.
Input ports
(0) The continuous input signal. In most cases, should be scaled to the range
[0, intervals]
.
Output ports
(0) The quantized output signal, on the same scale as the input signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval
|
The number of discrete values into which the input signal is quantized. |
required |
Source code in collimator/library/primitives.py
2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 |
|
QubeServoModel
Bases: LeafSystem
Plant model for the Quanser Qube Servo Furuta Pendulum.
The Quanser Qube Servo is a pendulum controlled by a rotary arm. The rotary arm is actuated by a DC motor. The pendulum is free to rotate about the rotary arm.
The state of the system is given by the rotor angle (theta), pendulum angle (alpha), rotor angular velocity, and pendulum angular velocity. The input to the system is the voltage applied to the motor, which is converted to torque by a simple linear model.
Input ports
(0) The motor voltage signal
Output ports
(0) If full_state_output
is False, the rotor angle and pendulum angle.
Otherwise, will return the entire continuous state vector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x0
|
Initial state of the system [theta, alpha, theta_dot, alpha_dot] |
[0.0, 0.0, 0.0, 0.0]
|
|
Rm
|
Motor resistance (Ohms) |
8.4
|
|
km
|
Back-emf constant (V-s/rad) |
0.042
|
|
mr
|
Rotary arm mass (kg) |
0.095
|
|
Lr
|
Rotor arm length (m) |
0.085
|
|
br
|
Rotor arm damping coefficient (N-m-s/rad) |
0.0005
|
|
mp
|
Pendulum mass (kg) |
0.024
|
|
Lp
|
Pendulum arm length (m) |
0.129
|
|
bp
|
Pendulum damping coefficient (N-m-s/rad) |
2.5e-05
|
|
g
|
Gravitational constant (m/s^2) |
9.81
|
|
kr
|
Feedback control to send the rotor back to zero |
0.0
|
|
full_state_output
|
If True, output the full state vector. Otherwise, only output the rotor and pendulum angles. |
False
|
Source code in collimator/library/quanser.py
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 |
|
Ramp
Bases: SourceBlock
Output a linear ramp signal in time.
Given a slope m
, a start value y0
, and a start time t0
, the output signal is:
y(t) = m * (t - t0) + y0 if t >= t0 else y0
where t
is the current simulation time.
Input ports
None
Output ports
(0) The ramp signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_value
|
The value of the output signal at the start time. |
0.0
|
|
slope
|
The slope of the ramp signal. |
1.0
|
|
start_time
|
The time at which the ramp signal begins. |
1.0
|
Source code in collimator/library/primitives.py
3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 |
|
RandomNumber
Bases: LeafSystem
Discrete-time random number generator.
Generates independent, identically distributed random numbers at each time step.
Dispatches to jax.random
for the actual random number generation.
Supported distributions include "ball", "cauchy", "choice", "dirichlet", "exponential", "gamma", "lognormal", "maxwell", "normal", "orthogonal", "poisson", "randint", "truncated_normal", and "uniform".
See https://jax.readthedocs.io/en/latest/jax.random.html#random-samplers for a full list of available distributions and associated parameters.
Although the JAX random number generator is a deterministic function of the key, this block maintains the key as part of the discrete state, making it a stateful RNG. The block can be seeded for reproducibility by passing an integer seed; if None, a random seed will be generated using numpy.random.
Note that this block should typically not be used as a source of randomness for
continuous-time systems, as it generates a discrete-time signal. For continuous
systems, use a continuous-time noise source, such as WhiteNoise
.
Input ports
None
Output ports
(0) The most recently generated random number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float
|
The rate at which random numbers are generated. |
required |
distribution
|
str
|
The name of the random distribution to sample from. |
'normal'
|
seed
|
int
|
An integer seed for the random number generator. If None, a random 32-bit seed will be generated. |
None
|
dtype
|
DTypeLike
|
data type of the random number. If None, the default data type for the specified distribution will be used. Not all distributions support all data types; check the JAX documentation for details. |
None
|
distribution_parameters
|
A dictionary of additional parameters to pass to the distribution function. |
{}
|
Source code in collimator/library/random.py
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 |
|
RateLimiter
Bases: LeafSystem
Limit the time derivative of the block output.
Given an input signal u
computes the derivative of the output signal as:
y_rate = (u(t) - y(Tprev))/(t - Tprev)
Where Tprev is the last time the block was called for output update.
When y_rate is greater than the upper_limit, the output is:
y(t) = (t - Tprev)*upper_limit + y(Tprev)
When y_rate is less than the lower_limit, the output is:
y(t) = (t - Tprev)*lower_limit + y(Tprev)
If the lower_limit is greater than the upper_limit, and both are being violated, the upper_limit takes precedence.
Optionally, the block can also be configured with "dynamic" limits, which will add input ports for time-varying upper and lower limits.
Presently, the block is constrainted to periodic updates.
Input ports
(0) The input signal. (1) The upper limit, if dynamic limits are enabled. (2) The lower limit, if dynamic limits are enabled. (Will be indexed as 1 if dynamic upper limits are not enabled.)
Output ports
(0) The rate limited output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
upper_limit
|
The upper limit of the input signal. Default is |
inf
|
|
enable_dynamic_upper_limit
|
If True, then the upper limit can be set by an external signal. Default is False. |
False
|
|
lower_limit
|
The lower limit of the input signal. Default is |
-inf
|
|
enable_dynamic_lower_limit
|
If True, then the lower limit can be set by an external signal. Default is False. |
False
|
Source code in collimator/library/primitives.py
3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 |
|
initialize_static_data(context)
Infer the size and dtype of the internal states
Source code in collimator/library/primitives.py
3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 |
|
Reciprocal
Bases: FeedthroughBlock
Compute the reciprocal of the input signal.
Input ports
(0) The input signal.
Output ports
(0) The reciprocal of the input signal: y = 1 / u
.
Source code in collimator/library/primitives.py
3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 |
|
ReferenceSubdiagram
Source code in collimator/library/reference_subdiagram.py
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 |
|
create_diagram(ref_id, instance_name, *args, instance_parameters=None, **kwargs)
classmethod
Create a diagram based on the given reference ID and parameters.
Note that for submodels we evaluate all parameters, there is no "pure" string parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_id
|
str
|
The reference ID of the diagram. |
required |
*args
|
Variable length arguments. |
()
|
|
instance_parameters
|
dict[str, Any]
|
The instance parameters for the diagram. Defaults to None. example: {"gain": 3.0} |
None
|
**kwargs
|
Keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Diagram |
Diagram
|
The created diagram. |
Raises:
Type | Description |
---|---|
ValueError
|
If the reference subdiagram with the given ref_id is not found. |
Source code in collimator/library/reference_subdiagram.py
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 |
|
Relay
Bases: LeafSystem
Simple state machine implementing hysteresis behavior.
The input-output map is as follows:
output
|
on_value | -------<------<---------------------
| | |
| ⌄ ^
| | |
off_value |----------|-------->----->-----|
|
|---------------------------------------------- input
| off_threshold | on_threshold
Note that the "time mode" behavior of this block will follow the input signal. That is, if the input signal varies continuously in time, then the zero-crossing event from OFF->ON or vice versa will be localized in time. On the other hand, if the input signal varies only as a result of periodic updates to the discrete state, the relay will only change state at those instants. If the input signal is continuous, the block can be "forced" to this discrete-time periodic behavior by adding a ZeroOrderHold block before the input.
The exception to this is the case where there are no blocks in the system containing either discrete or continuous state. In this case the state changes will only be localized to the resolution of the major step.
Input ports
(0) The input signal.
Output ports
(0) The relay output signal, which is equal to either the on_value or the off_value, depending on the internal state of the relay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
on_threshold
|
When input rises above this value, the internal state transitions to ON. |
required | |
off_threshold
|
When input falls below this value, the internal state transitions to OFF. |
required | |
on_value
|
Value of the output signal when state is ON. |
required | |
off_value
|
Value of the output signal when state is OFF |
required | |
initial_state
|
If equal to on_value, the block will be initialized in the ON state. Otherwise, it will be initialized to the OFF state. |
required |
Events
There are two zero-crossing events: one to transition from OFF->ON and one for the opposite transition from ON->OFF.
Source code in collimator/library/primitives.py
2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 |
|
RigidBody
Bases: LeafSystem
Implements dynamics of a single three-dimensional body.
The block models both translational and rotational degrees of freedom, for a total of 6 degrees of freedom. With second-order equations, the block has 12 state variables, 6 for the position/orientation and 6 for the velocities/rates.
Currently only a roll-pitch-yaw (Euler angle) representation is supported for the orientation.
The full 12-dof state vector is x = [p_i, Φ, vᵇ, ωᵇ]
, where pⁱ
is the
position in an inertial "world" frame i
, Φ
is the (roll, pitch, and yaw)
Euler angle sequence defining the rotation from the inertial "world" frame to
the body frame, vᵇ
is the translational velocity with respect to body-fixed
axes b
, and ωᵇ
is the angular velocity about the body-fixed axes.
The mass and inertia properties of the block can independently be defined statically as parameters, or dynamically as inputs to the block.
Input ports
(0) force_vector: 3D force vector, defined in the body-fixed coordinate frame. For example, if gravity is acting on the body, the gravity vector should be pre-rotated using CoordinateRotation.
(1) torque_vector: 3D torque vector, be defined in the body-fixed coordinate frame.
(2) inertia: If enable_external_inertia_matrix=True
, this input provides
the time-varying body-fixed inertia matrix.
Output ports
(0): The position in the inertial "world" frame pⁱ
.
(1): The orientation of the body, represented as a roll-pitch-yaw Euler angle sequence.
(2): The translational velocity with respect to body-fixed axes vᵇ
.
(3): The angular velocity about the body-fixed axes ωᵇ
.
(4): (if enable_output_state_derivatives=True
) The time derivatives of the
position variables in the world frame ṗⁱ
. Not generally equal to the state
vᵇ
, defining time derivatives in the body frame.
(5): (if enable_output_state_derivatives=True
) The "Euler rates" Φ̇
,
which are the time derivatives of the Euler angles. Not generally equal to
the angular velocity ωᵇ
.
(6): (if enable_output_state_derivatives=True
) The body-fixed acceleration
vector aᵇ
.
(7): (if enable_output_state_derivatives=True
) The angular acceleration in
body-fixed axes ω̇ᵇ
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
initial_position
|
Array
|
The initial position in the inertial frame. |
required |
initial_orientation
|
Array
|
The initial orientation of the body, represented as a roll-pitch-yaw Euler angle sequence. |
required |
initial_velocity
|
Array
|
The initial translational velocity with respect to body-fixed axes. |
required |
initial_angular_velocity
|
Array
|
The initial angular velocity about the body-fixed axes. |
required |
enable_external_mass
|
bool
|
If |
False
|
mass
|
float
|
The constant value for the body mass when
|
1.0
|
enable_external_inertia_matrix
|
bool
|
If |
False
|
inertia_matrix
|
The constant value for the body inertia matrix when
|
eye(3)
|
|
enable_output_state_derivatives
|
bool
|
If |
False
|
gravity_vector
|
Array
|
The constant gravitational acceleration vector
acting on the body, defined in the inertial frame. If |
zeros(3)
|
Notes
Assumes that the inertia matrix is computed at the center of mass.
Assumes that the mass and inertia matrix are quasi-steady. This means that
if one or both is specified as "dynamic" inputs their time derivative is
neglected in the dynamics. For instance, for pure translation (w_b=0
) the
approximation to Newton's law is F_net = (d/dt)(m * v) ≈ m * (dv/dt)
.
Source code in collimator/library/rotations.py
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 |
|
Ros2Publisher
Bases: LeafSystem
Ros2Publisher block can emit signals to a ROS2 topic, based on input signal data.
Source code in collimator/library/ros2.py
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 |
|
__init__(dt, topic, msg_type, fields, **kwargs)
Publish messages to a ROS2 topic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float
|
Period of the system, in both sim and real (ros2) time. |
required |
topic
|
str
|
ROS2 topic to publish to. Eg. |
required |
msg_type
|
type
|
ROS2 message type, e.g. |
required |
fields
|
dict[str, type]
|
Ordered dictionary of default values to extract from the received message. The keys are the full attribute path (with dots) to the value in the message, and the values are the default values. This is used to create the output ports with valid data types. Use Python or Numpy data types, not JAX.
|
required |
Source code in collimator/library/ros2.py
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 |
|
Ros2Subscriber
Bases: LeafSystem
Ros2Subscriber block listens to messages over a ROS2 topic and outputs them as signals in collimator.
Source code in collimator/library/ros2.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
__init__(dt, topic, msg_type, fields, read_before_start=True, **kwargs)
Subscribe to a ROS2 topic and extract message values to output ports.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
Period of the system, in both sim and real (ros2) time. |
required | |
topic
|
str
|
ROS2 topic to subscribe to. Eg. |
required |
msg_type
|
type
|
ROS2 message type, e.g. |
required |
fields
|
dict[str, type]
|
Ordered dictionary of default values to extract from the received message. The keys are the full attribute path (with dots) to the value in the message, and the values are the default values. This is used to create the output ports with valid data types. Use Python or Numpy data types, not JAX.
|
required |
read_before_start
|
If True, the subscriber will read the first message before the simulation starts. Otherwise, the initial outputs will be 0. |
True
|
Source code in collimator/library/ros2.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
Saturate
Bases: LeafSystem
Clip the input signal to a specified range.
Given an input signal u
and upper and lower limits ulim
and llim
,
the output signal is:
y = max(llim, min(ulim, u))
where max
and min
are the element-wise maximum and minimum functions.
This is equivalent to y = clip(u, llim, ulim)
.
Optionally, the block can also be configured with "dynamic" limits, which will add input ports for time-varying upper and lower limits.
Input ports
(0) The input signal. (1) The upper limit, if dynamic limits are enabled. (2) The lower limit, if dynamic limits are enabled. (Will be indexed as 1 if dynamic upper limits are not enabled.)
Output ports
(0) The clipped output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
upper_limit
|
The upper limit of the input signal. Default is |
None
|
|
enable_dynamic_upper_limit
|
If True, then the upper limit can be set by an external signal. Default is False. |
False
|
|
lower_limit
|
The lower limit of the input signal. Default is |
None
|
|
enable_dynamic_lower_limit
|
If True, then the lower limit can be set by an external signal. Default is False. |
False
|
Events
The block will trigger an event when the input signal crosses either the upper or lower limit. For example, if the block is configured with static upper and lower limits and the input signal crosses the upper limit, then a zero-crossing event will be triggered.
Source code in collimator/library/primitives.py
3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 |
|
Sawtooth
Bases: SourceBlock
Produces a modulated linear sawtooth signal.
The signal is similar to: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.sawtooth.html
Given amplitude a
, period p
, and phase delay phi
, the output signal is:
y(t) = a * ((t - phi) % p)
where %
is the modulo operator.
Input ports
None
Output ports
(0) The sawtooth signal.
Source code in collimator/library/primitives.py
3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 |
|
ScalarBroadcast
Bases: FeedthroughBlock
Broadcast a scalar to a vector or matrix.
Given a scalar input u
and dimensions m
and n
, this block will return
a vector or matrix of shape (m, n)
with all elements equal to u
.
Input ports
(0) The scalar input signal.
Output ports
(0) The broadcasted output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
m
|
The number of rows in the output matrix. If |
required | |
n
|
The number of columns in the output matrix. If |
required |
Source code in collimator/library/primitives.py
3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 |
|
SignalDatatypeConversion
Bases: FeedthroughBlock
Convert the input signal to a different data type. Input ports: (0) The input signal. Output ports: (0) The input signal converted to the specified data type. Parameters: dtype: The data type to which the input signal is converted. Must be a valid NumPy data type, e.g. "float32", "int64", etc.
Source code in collimator/library/primitives.py
3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 |
|
Sindy
Bases: LeafSystem
This class implements System Identification (SINDy) algorithm with or without control inputs for contiuous-time and discrete-time systems.
The learned continuous-time dynamical system model will be of the form:
dx/dt = f(x, u)
where x
is the state vector and u
is the optional control input vector. The
block will output the full state vector x
of the system.
The learned discrete-time dynamical system model will be of the form:
x_{k+1} = f(x_k, u_k)
where x_k
is the state vector at time step k
and u_k
is the optional control
vector. The block will update the output to x_k
at an interval provided by the
parameter discrete_time_update_interval
.
Input ports
(0) u: control vector for the system. This port is only available if the Sindy
model is trained with control inputs, i.e. control_input_columns
is not
None
during training.
Output ports
(0) x: full state output of the system.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Path to the CSV file containing training data. |
None
|
header_as_first_row
|
bool
|
If True, the first row of the CSV file is treated as the header. |
False
|
state_columns
|
int | str | list[int] | list[str]
|
For training, either one of the following for CSV columns representing
state variables |
1
|
control_input_columns
|
int | str | list[int] | list[str]
|
For training, either one of the following for CSV columns representing
control inputs |
None
|
dt
|
float
|
Fixed value of dt if rows of the CSV file represent equidistant time steps. |
None
|
time_column
|
(str, int)
|
Column name (str) for column index (int) for time data |
None
|
state_derivatives_columns
|
int | str | list[int] | list[str]
|
For training, either one of the following for csv columns representing
state derivatives |
None
|
discrete_time
|
bool
|
If True, the SINDy model will be trained for discrete-time systems. In
this case, the dynamical system is treated as a map. Rather than
predicting derivatives, the right hand side functions step the system
forward by one time step. If False, dynamical system is assumed to be a
flow (right-hand side functions predict continuous time derivatives).
See documentation for |
False
|
differentiation_method
|
str
|
Method to use for differentiating the state data |
'centered difference'
|
threshold
|
float
|
Threshold for the Sequentially thresholded least squares (STLSQ) algorithm used for training SINDy model. |
0.1
|
alpha
|
float
|
Regularization strength for the STLSQ algorithm. |
0.05
|
max_iter
|
int
|
Maximum number of iterations for the STLSQ algorithm. |
20
|
normalize_columns
|
bool
|
If True, normalize the columns of the data matrix before regression. |
False
|
poly_order
|
int
|
Degree of polynomial features. Set to |
2
|
fourier_n_frequencies
|
int
|
Number of Fourier frequencies. Set to |
None
|
custom_basis_functions
|
list of functions
|
A list of custom basis functions to use for training the SINDy model.
For example to include Currently only supported for pycollimator interface. Calls from UI and pretrained model loading does not support custom basis functions. |
None
|
pretrained
|
bool
|
If True, use a pretrained model specified by the |
False
|
pretrained_file_path
|
str
|
Path to the pretrained model file. |
None
|
initial_state
|
ndarray
|
|
None
|
discrete_time_update_interval
|
float
|
Interval at which the discrete-time model should be updated. Default is 1.0. |
1.0
|
equations
|
list of strings
|
(For internal UI use only) The identified system equations. |
None
|
base_feature_names
|
list of strings
|
(For internal UI use only) Features x_i and u_i. |
None
|
feature_names
|
list of strings
|
(For internal UI use only) Composed features with basis libraries. |
None
|
coefficients
|
ndarray
|
(For internal UI use only) Coefficients of the identified model. |
None
|
has_control_input
|
bool
|
(For internal UI use only) If True, the model was trained with control.
For standard training from CSV file, this is inferred from the
parameter |
True
|
Source code in collimator/library/sindy.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
|
serialize(filename)
Save the relevant class attributes post training so that model state can be restored
Source code in collimator/library/sindy.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
|
serialize_trained_pysindy_model(model, filename)
staticmethod
Serialize a PySindy model trained outside of Collimator. The saved file can be used as a pretrained model in Collimator.
Source code in collimator/library/sindy.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 |
|
Sine
Bases: SourceBlock
Generates a sinusoidal signal.
Given amplitude a
, frequency f
, phase phi
, and bias b
, the output signal is:
y(t) = a * sin(f * t + phi) + b
Input ports
None
Output ports
(0) The sinusoidal signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
amplitude
|
The amplitude of the sinusoidal signal. |
1.0
|
|
frequency
|
The frequency of the sinusoidal signal. |
1.0
|
|
phase
|
The phase of the sinusoidal signal. |
0.0
|
|
bias
|
The bias of the sinusoidal signal. |
0.0
|
Source code in collimator/library/primitives.py
3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 |
|
Slice
Bases: FeedthroughBlock
Slice the input signal using Python indexing rules.
Input ports
(0) The input signal.
Output ports
(0) The sliced output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
slice_
|
The slice operator to apply to the input signal. Must be specified as a
string input, e.g. the output |
required |
Notes
Currently only up to 3-dimensional slices are supported.
Source code in collimator/library/primitives.py
3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 |
|
SourceBlock
Bases: LeafSystem
Simple blocks with a single time-dependent output
Source code in collimator/library/generic.py
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 |
|
__init__(func, **kwargs)
Create a source block with a time-dependent output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable
|
A function of time and parameters that returns a single value.
Signature should be |
required |
Source code in collimator/library/generic.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
SquareRoot
Bases: FeedthroughBlock
Compute the square root of the input signal.
Dispatches to jax.numpy.sqrt
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.sqrt.html
Input ports
(0) The input signal.
Output ports
(0) The square root of the input signal.
Source code in collimator/library/primitives.py
3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 |
|
Stack
Bases: ReduceBlock
Stack the input signals into a single output signal along a new axis.
Dispatches to jax.numpy.stack
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.stack.html
Input ports
(0..n_in-1) The input signals.
Output ports
(0) The stacked output signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
axis
|
The axis along which the input signals are stacked. Default is 0. |
0
|
Source code in collimator/library/primitives.py
3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 |
|
StateMachine
Bases: LeafSystem
Finite State Machine similar to Mealy Machine. https://en.wikipedia.org/wiki/Mealy_machine
The state machine can be executed either periodically or by zero_crossings.
Each state as 0 or more exit transitions. These are prioritized such that when 2 exits are simultaneously valid, the higher priority is executed. It is not allowed for a state to have more than one exit transition with no guard. Guardless exits only make sense in the periodic case.
Each transitions may have 0 or more actions. Each action is a python statement that modifies the value of an output. When a transitions is executed (i.e. it's guard evaluates to true), its actions are then processed.
If 'time' is needed for guards or actions, pass 'time' in from clock block.
Whether executed periodically or by zero_crossings, the states are constant between transitions executions. In the zero_crossing case, all guards for transitions exiting the current state are continuously checked, and if any 'triggers', then the earlist point in time that any guard becomes true is determined, the actions of the earliest (and highest priority if multiple trigger simultaneously) guard are executed at that time, and the simulation continues afterwards.
Input ports
User specified.
Output ports
User specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
Either Float or None. When not None, state machine is executed periodically. When None, the transitions are monitored by zero_crossing events. |
None
|
|
accelerate_with_jax
|
bool
|
Bool. When True, the actions and guards are JIT-compiled with JAX. Default is False. |
False
|
Source code in collimator/library/state_machine.py
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
|
Step
Bases: SourceBlock
A step signal.
Given start value y0
, end value y1
, and step time t0
, the
output signal is:
y(t) = y0 if t < t0 else y1
Input ports
None
Output ports
(0) The step signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_value
|
The value of the output signal before the step time. |
0.0
|
|
end_value
|
The value of the output signal after the step time. |
1.0
|
|
step_time
|
The time at which the step occurs. |
1.0
|
Source code in collimator/library/primitives.py
3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 |
|
Stop
Bases: LeafSystem
Stop the simulation early as soon as the input signal becomes True.
If the input signal changes as a result of a discrete update, the simulation will terminate the major step early (before advancing continuous time).
Input ports
(0): the boolean- or binary-valued termination signal
Output ports
None
Source code in collimator/library/primitives.py
3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 |
|
SumOfElements
Bases: FeedthroughBlock
Compute the sum of the elements of the input signal.
Dispatches to jax.numpy.sum
, so see the JAX docs for details:
https://jax.readthedocs.io/en/latest/_autosummary/jax.numpy.sum.html
Input ports
(0) The input signal.
Output ports
(0) The sum of the elements of the input signal.
Source code in collimator/library/primitives.py
3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 |
|
TensorFlow
Bases: LeafSystem
Block to perform inference with a pre-trained TensorFlow SavedModel.
The input to the block should be of compatible type and shape expected by
the TensorFlow model. For example, if the TensorFlow SavedModel model expects a
tf.float32
tensor of shape (3, 224, 224)
, the input to the block should be a
jax.numpy
array of shape (3, 224, 224) of dtype jnp.float32
.
For output types, if no casting is specified through the cast_outputs_to_dtype
parameter, the output of the block will have the same dtype as the
TensorFlow model output, but expressed as jax.numpy
types. For example. if the
TensorFlow model outputs a tf.float32
tensor, the output of the block will be
a jax.numpy
array of dtype jnp.float32
.
If casting is specified through cast_outputs_to_dtype
parameter, all the outputs,
of the block will be casted to this specific jax.numpy
dtype.
Input ports
(i) The ith input to the model.
Output ports
(j) The jth output of the model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Path to the model file. This should be a |
required |
cast_outputs_to_dtype
|
str
|
The dtype to cast all the outputs of the block to. Must correspond to a
|
None
|
add_batch_dim_to_inputs
|
bool
|
Whether to add a new first dimension to the inputs before evaluating the TorchScript or TensorFlow model. This is useful when the model expects a batch dimension. |
False
|
Source code in collimator/library/predictor.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
initialize_static_data(context)
Infer the output shapes and dtypes of the ML model.
Source code in collimator/library/predictor.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
TransferFunction
Bases: LTISystem
Continuous-time LTI system specified as a transfer function.
The transfer function is converted to state-space form using scipy.signal.tf2ss
.
https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.tf2ss.html
The resulting system will be in canonical controller form with matrices (A, B, C, D), which are then used to create an LTISystem. Note that this only supports single-input, single-output systems.
Input ports
(0) u: Input vector (scalar)
Output ports
(0) y: Output vector (scalar). Note that this is feedthrough from the input port iff D is nonzero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
Numerator polynomial coefficients, in descending powers of s |
required | |
den
|
Denominator polynomial coefficients, in descending powers of s |
required |
Source code in collimator/library/linear_system.py
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 |
|
TransferFunctionDiscrete
Bases: LTISystemDiscrete
Implements a Discrete Time Transfer Function.
https://en.wikipedia.org/wiki/Z-transform#Transfer_function
The resulting system will be in canonical controller form with matrices (A, B, C, D), which are then used to create an LTISystem. Note that this only supports single-input, single-output systems.
Input ports
(0) u[k]: Input vector (scalar)
Output ports
(0) y[k]: Output vector (scalar). Note that this is feedthrough from the input port if and only if D is nonzero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
Sampling period of the discrete system. |
required | |
num
|
Numerator polynomial coefficients, in descending powers of z |
required | |
den
|
Denominator polynomial coefficients, in descending powers of z |
required | |
initialize_states
|
Initial state vector (default: 0) |
None
|
Source code in collimator/library/linear_system.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
|
Trigonometric
Bases: FeedthroughBlock
Apply a trigonometric function to the input signal.
Available functions are
sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh
Dispatches to jax.numpy.sin
, jax.numpy.cos
, etc, so see the JAX docs for details.
Input ports
(0) The input signal.
Output ports
(0) The trigonometric function applied to the input signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function
|
The trigonometric function to apply to the input signal. Must be one of "sin", "cos", "tan", "asin", "acos", "atan", "sinh", "cosh", "tanh", "asinh", "acosh", "atanh". |
required |
Source code in collimator/library/primitives.py
3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 |
|
UnitDelay
Bases: LeafSystem
Hold and delay the input signal by one time step.
This block implements a "unit delay" with the following difference equation
for internal state x
, input signal u
, and output signal y
:
x[k+1] = u[k]
y[k] = x[k]
Or, in a hybrid context, the discrete update advances the internal state from
the "pre" or "minus" value x⁻ to the "post" or "plus" value x⁺ at time
tₖ = t0 + k * dt
. According to the discrete update rules, this calculation
happens using the input values computed during the update step (i.e. by computing
upstream outputs before evaluating the inputs to this block). That is, the update
rule can be written x⁺(tₖ) = f(tₖ, x⁻(tₖ), u(tₖ))
. The values of u
are not
distinguished as "pre" or "post" because there is only one value at the update
time. In the difference equation notation, x⁺(tₖ) ≡ x[k+1],
x⁻(tₖ) ≡ x[k],
and u(tₖ) ≡ u[k]. The hybrid update rule is then:
x⁺(tₖ) = u(tₖ)
y(t) = x⁻(tₖ), between tₖ⁺ and (tₖ+dt)⁻
The output signal "seen" by all other blocks on the time interval (tₖ, tₖ+dt) is then the value of the input signal u(tₖ) at the previous update. Therefore, all downstream discrete-time blocks updating at the same time tₖ will still see the value of x⁻(tₖ), the value of the internal state prior to the update.
Input ports
(0) The input signal.
Output ports
(0) The input signal delayed by one time step
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
The time step of the discrete update. |
required | |
initial_state
|
The initial state of the block. Default is 0.0. |
required |
Source code in collimator/library/primitives.py
3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 |
|
UnscentedKalmanFilter
Bases: KalmanFilterBase
Unscented Kalman Filter (UKF) for the following system:
```
x[n+1] = f(x[n], u[n]) + G(t[n]) w[n]
y[n] = g(x[n], u[n]) + v[n]
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Q(t[n], x[n], u[n])
E(v[n]v'[n] = R(t[n])
E(w[n]v'[n] = N(t[n]) = 0
```
f
and g
are discrete-time functions of state x[n]
and control u[n]
,
while Rand
Gare discrete-time functions of time
t[n].
Qis a discrete-time
function of
t[n], x[n], u[n]`. This last aspect is included for zero-order-hold
discretization of a continuous-time system
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float Time step of the discrete-time system |
required | |
forward
|
Callable
A function with signature f(x[n], u[n]) -> x[n+1] that represents |
required | |
observation
|
Callable
A function with signature g(x[n], u[n]) -> y[n] that represents |
required | |
G_func
|
Callable
A function with signature G(t[n]) -> G[n] that represents |
required | |
Q_func
|
Callable
A function with signature Q(t[n], x[n], u[n]) -> Q[n] that represents |
required | |
R_func
|
Callable
A function with signature R(t[n]) -> R[n] that represents |
required | |
x_hat_0
|
ndarray Initial state estimate |
required | |
P_hat_0
|
ndarray Initial state covariance matrix estimate |
required | |
alpha
|
float Sigma point spread to control the amount of nonlinearities taken into account. Usually set to a value (1e-04<= alpha <= 1.0). Default is 1.0. |
1.0
|
|
beta
|
float Scaling constant to include prior information about the distribution of the state. Default is 0.0. |
0.0
|
|
kappa
|
float Relatively non-critical parameter to control the kurtosis of sigma point distribution. Default is 0.0. |
0.0
|
Source code in collimator/library/state_estimators/unscented_kalman_filter.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
for_continuous_plant(plant, dt, G_func, Q_func, R_func, x_hat_0, P_hat_0, discretization_method='euler', discretized_noise=False, alpha=1.0, beta=0.0, kappa=0.0, name=None, ui_id=None)
staticmethod
Unscented Kalman Filter system for a continuous-time plant.
The input plant contains the deterministic forms of the forward and observation operators:
dx/dt = f(x,u)
y = g(x,u)
Note: (i) Only plants with one vector-valued input and one vector-valued output are currently supported. Furthermore, the plant LeafSystem/Diagram should have only one vector-valued integrator; (ii) the user may pass a plant with disturbances (not recommended) as the input plant. In this case, the forward and observation evaluations will be corrupted by noise.
A plant with disturbances of the following form is then considered:
dx/dt = f(x,u) + G(t) w -- (C1)
y = g(x,u) + v -- (C2)
where:
`w` represents the process noise,
`v` represents the measurement noise,
and
E(w) = E(v) = 0
E(ww') = Q(t)
E(vv') = R(t)
E(wv') = N(t) = 0
This plant is discretized to obtain the following form:
x[n+1] = fd(x[n], u[n]) + Gd w[n] -- (D1)
y[n] = gd(x[n], u[n]) + v[n] -- (D2)
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Qd
E(v[n]v'[n] = Rd
E(w[n]v'[n] = Nd = 0
The above discretization is performed either via the euler
or the zoh
method, and an Unscented Kalman Filter estimator for the system of equations
(D1) and (D2) is returned.
Note: If discretized_noise
is True, then it is assumed that the user is
directly providing Gd, Qd and Rd. If False, then Qd and Rd are computed from
continuous-time Q, R, and G, and Gd is set to an Identity matrix.
The returned system will have:
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plant
|
a |
required | |
dt
|
float Time step for the discretization. |
required | |
G_func
|
Callable
A function with signature G(t) -> G that represents |
required | |
Q_func
|
Callable
A function with signature Q(t) -> Q that represents |
required | |
R_func
|
Callable
A function with signature R(t) -> R that represents |
required | |
x_hat_0
|
ndarray Initial state estimate |
required | |
P_hat_0
|
ndarray
Initial state covariance matrix estimate. If |
required | |
discretization_method
|
str ("euler" or "zoh") Method to discretize the continuous-time plant. Default is "euler". |
'euler'
|
|
discretized_noise
|
bool
Whether the user is directly providing Gd, Qd and Rd. Default is False.
If True, |
False
|
|
alpha
|
float Sigma point spread to control the amount of nonlinearities taken into account. Usually set to a value (1e-04<= alpha <= 1.0). Default is 1.0. |
1.0
|
|
beta
|
float Scaling constant to include prior information about the distribution of the state. Default is 0.0. |
0.0
|
|
kappa
|
float Relatively non-critical parameter to control the kurtosis of sigma point distribution. Default is 0.0. |
0.0
|
Source code in collimator/library/state_estimators/unscented_kalman_filter.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
|
from_operators(dt, forward, observation, G_func, Q_func, R_func, x_hat_0, P_hat_0, alpha=1.0, beta=0.0, kappa=0.0, name=None, ui_id=None)
staticmethod
Unscented Kalman Filter (UKF) for the following system:
x[n+1] = f(x[n], u[n]) + G(t[n]) w[n]
y[n] = g(x[n], u[n]) + v[n]
E(w[n]) = E(v[n]) = 0
E(w[n]w'[n]) = Q(t[n], x[n], u[n])
E(v[n]v'[n] = R(t[n])
E(w[n]v'[n] = N(t[n]) = 0
f
and g
are discrete-time functions of state x[n]
and control u[n]
,
while Q
and R
and G
are discrete-time functions of time t[n]
.
Input ports
(0) u[n] : control vector at timestep n (1) y[n] : measurement vector at timestep n
Output ports
(1) x_hat[n] : state vector estimate at timestep n
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float Time step of the discrete-time system |
required | |
forward
|
Callable
A function with signature f(x[n], u[n]) -> x[n+1] that represents |
required | |
observation
|
Callable
A function with signature g(x[n], u[n]) -> y[n] that represents |
required | |
G_func
|
Callable
A function with signature G(t[n]) -> G[n] that represents |
required | |
Q_func
|
Callable
A function with signature Q(t[n]) -> Q[n] that represents
|
required | |
R_func
|
Callable
A function with signature R(t[n]) -> R[n] that represents |
required | |
x_hat_0
|
ndarray Initial state estimate |
required | |
P_hat_0
|
ndarray Initial state covariance matrix estimate |
required | |
alpha
|
float Sigma point spread to control the amount of nonlinearities taken into account. Usually set to a value (1e-04<= alpha <= 1.0). Default is 1.0. |
1.0
|
|
beta
|
float Scaling constant to include prior information about the distribution of the state. Default is 0.0. |
0.0
|
|
kappa
|
float Relatively non-critical parameter to control the kurtosis of sigma point distribution. Default is 0.0. |
0.0
|
Source code in collimator/library/state_estimators/unscented_kalman_filter.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
VideoSink
Bases: LeafSystem
Records RGB frames to a video file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
float
|
Interval at which to record frames. |
required |
file_name
|
str
|
Name of the video file to write to (optional). |
required |
Source code in collimator/library/video.py
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 |
|
VideoSource
Bases: LeafSystem
Reads frames from a video file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_name
|
str
|
Name of the video file to read from. |
required |
no_repeat
|
Whether to stop at the end of the video or loop back to the beginning. |
False
|
Source code in collimator/library/video.py
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 250 251 |
|
WhiteNoise
Bases: LeafSystem
Continuous-time white noise generator.
Generates a band-limited white noise signal using a sinc-interpolated random number generator. The output signal is a continuous-time signal, but the underlying random number generator is discrete-time. As a result, the signal is not truly white, but is band-limited by the sample rate. The resulting signal has the following approximate power spectral density:
S(f) = A * fs if |f| < fs else 0,
where A
is the noise power and fs = 1/dt
is the sample rate.
See Ch. 10.4 in Baraniuk, "Signal Processing and Modeling" for details: https://shorturl.at/floRZ
The output signal will have variance A
, zero mean, and will decorrelate at
the sample rate.
Input ports
None
Output ports
(0) The band-limited white noise signal with variance noise_power
, zero
mean, and correlation time dt
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
correlation_time
|
The correlation time of the output signal and the inverse of the bandwidth. It is the sample frequency of the underlying random number generator. |
required | |
noise_power
|
float
|
The variance of the white noise signal. Also scales the amplitude of the power spectral density. |
1.0
|
num_samples
|
int
|
The number of samples to use for sinc interpolation. More samples will result in a more accurate approximation of the ideal power spectrum, but will also increase the computational cost. The default of 10 is sufficient for most applications. |
10
|
seed
|
int
|
An integer seed for the random number generator. If None, a random 32-bit seed will be generated. |
None
|
dtype
|
DTypeLike
|
data type of the random number. If None, defaults to float. |
None
|
shape
|
ShapeLike
|
The shape of the output signal. If empty, the output will be a scalar. |
()
|
Source code in collimator/library/random.py
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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
ZeroOrderHold
Bases: LeafSystem
Implements a "zero-order hold" A/D conversion.
https://en.wikipedia.org/wiki/Zero-order_hold
The block implements a "zero-order hold" with the following difference equation
for input signal u
and output signal y
:
y[k] = u[k]
The block does not maintain an internal state, but simply holds the value of the input signal at the previous update time. As a result, the block is "feedthrough" from its inputs to outputs and cannot be used to break an algebraic loop. The data type of this hold value is inferred from upstream blocks.
Input ports
(0) The input signal.
Output ports
(0) The "hold" value of the input signal. If the input signal is continuous, then the output will be the value of the input signal at the previous update time. If the input signal is discrete and synchonous with the block, the output will be the value of the input signal at the current time (i.e. identical to the input signal).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt
|
The time step of the discrete update. |
required |
Source code in collimator/library/primitives.py
3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 |
|
linearize(system, base_context, name=None, output_index=None)
Linearize the system about an operating point specified by the base context.
For now, only implemented for systems with one each (vector-valued) input and output. The system may have multiple output ports, but only one will be treated as the measurement.
Source code in collimator/library/linear_system.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|