Skip to content

TV Linear

Time-varying linear vehicle dynamics.

Notes

Defines a linear time-varying dynamics model with matrices A and B, registered via ModelSpec for integration with the optimization stack.

Param

Parameters for the time-varying linear model.

Attributes:

Name Type Description
A Array

State/control matrix of shape (STATE_DIM, STATE_DIM + CONTROL_DIM).

B Array

Bias term of shape (STATE_DIM,).

timestep float

Physics integration timestep.

timestep_ratio int

Simulation steps per control step (static field).

vehicle_dynamics_tv_linear

vehicle_dynamics_tv_linear(x_and_u, params)

Evaluate the time-varying linear dynamics.

Parameters:

Name Type Description Default
x_and_u Array

Vehicle state-control vector of shape (STATE_DIM + CONTROL_DIM,):

  • x0: x position (global)
  • x1: y position (global)
  • x2: steering angle of front wheels
  • x3: velocity in x direction
  • x4: yaw angle
  • u0: steering angle velocity of front wheels
  • u1: longitudinal acceleration
required
params Param

Parameter dataclass containing the linear map A and offset B.

required

Returns:

Type Description
Array

Time derivative of the state-control vector, shape (STATE_DIM + CONTROL_DIM,).

yaw_normalized_loss

yaw_normalized_loss(output_states, target_states)

Yaw-normalized loss between output and target states.

Handles angular differences by wrapping them to [-pi, pi] and uses L1 loss for non-angular components.

Parameters:

Name Type Description Default
output_states Array

Predicted states of shape (..., 5).

required
target_states Array

Target states of shape (..., 5).

required

Returns:

Type Description
float

Total loss summed over all elements.

yaw_normalized_loss_per_element

yaw_normalized_loss_per_element(
    output_states, target_states
)

Yaw-normalized loss per state dimension.

Parameters:

Name Type Description Default
output_states Array

Predicted states of shape (B, T, 5).

required
target_states Array

Target states of shape (B, T, 5).

required

Returns:

Type Description
Array

Loss per dimension of shape (B, 5).

yaw_normalized_loss_per_item

yaw_normalized_loss_per_item(output_states, target_states)

Yaw-normalized loss per item in the batch.

Assumes input shape is (B, T, D) where D=5.

Parameters:

Name Type Description Default
output_states Array

Predicted states of shape (B, T, 5).

required
target_states Array

Target states of shape (B, T, 5).

required

Returns:

Type Description
Array

Loss per batch item of shape (B,).

yaw_normalized_loss_weighted

yaw_normalized_loss_weighted(
    output_states, target_states, weights=None
)

Weighted yaw-normalized loss for state dimensions.

Parameters:

Name Type Description Default
output_states Array

Predicted states of shape (..., 5).

required
target_states Array

Target states of shape (..., 5).

required
weights Array

Per-dimension weights of shape (5,). Defaults to ones.

None

Returns:

Type Description
float

Weighted loss value.

Raises:

Type Description
ValueError

If weights has an unexpected shape.