Interfaces
commonroad_control.vehicle_dynamics.vehicle_model_interface
VehicleModelInterface
Bases: ABC
Interface for vehicle dynamics models: among others, the classes implementing this interface provide the dynamics function, both in continous- and discrete-time, or methods for computing the longitudinal and lateral accelerations.
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.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 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 | |
disturbance_dimension
property
Returns:
| Type | Description |
|---|---|
|
dimension of the disturbance space |
input_dimension
property
Returns:
| Type | Description |
|---|---|
|
dimension of the input space |
state_dimension
property
Returns:
| Type | Description |
|---|---|
|
dimension of the state space |
__init__(params, nx, nu, nw, delta_t)
Initialize abstract baseclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
VehicleParameters
|
CommonRoad-Control vehicle parameters |
required |
nx
|
int
|
dimension of the state space |
required |
nu
|
int
|
dimension of the input space |
required |
nw
|
int
|
dimension of the disturbance space |
required |
delta_t
|
float
|
sampling time |
required |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
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 | |
_differentiate_acceleration_constraints()
Differentiation of the (normalized) acceleration constraint functions.
Returns:
| Type | Description |
|---|---|
Tuple[Function, Function, Function, Function, Function]
|
acceleration constraint functions (longitudinal and lateral, CasADi functions) and respective Jacobians (CasADi functions) |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.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 | |
_discretize_nominal()
Time-discretization of the nominal dynamics model assuming a constant control input throughout the time interval [0, delta_t].
Returns:
| Type | Description |
|---|---|
Tuple[Function, Function, Function]
|
time-discretized dynamical system (CasADi function) and its Jacobians (CasADi function) |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
_dynamics_cas(x, u, w)
abstractmethod
Continuous-time dynamics function of the vehicle model for simulation and symbolic operations using CasADi.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[sym, ndarray[tuple[float], dtype[float64]]]
|
state - CasADi symbolic/ array of dimension (self._nx,) |
required |
u
|
Union[sym, ndarray[tuple[float], dtype[float64]]]
|
control input - CasADi symbolic/ array of dimension (self._nu,) |
required |
w
|
Union[sym, ndarray[tuple[float], dtype[float64]]]
|
disturbance - CasADi symbolic/ array of dimension (self._nw,) |
required |
Returns:
| Type | Description |
|---|---|
Union[sym, ndarray]
|
dynamics function evaluated at (x,u,w) - CasADi symbolic/ array of dimension (self._nx,) |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
_set_input_bounds(params)
abstractmethod
Extract input bounds from vehicle parameters and returns them as instances of the Input class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
VehicleParameters
|
CommonRoad-Control vehicle parameters |
required |
Returns:
| Type | Description |
|---|---|
|
lower and upper bounds - InputInterface |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
275 276 277 278 279 280 281 282 | |
compute_normalized_acceleration(x, u)
abstractmethod
Computes the normalized longitudinal and lateral acceleration (w.r.t. the maximum acceleration).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[StateInterface, sym, array]
|
state - StateInterface/ CasADi symbolic/ array of dimension (self._nx,) |
required |
u
|
Union[InputInterface, sym, array]
|
control input - InputInterface/ CasADi symbolic/ array of dimension (self._nu,) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Union[float, sym], Union[float, sym]]
|
normalized longitudinal and lateral acceleration - float/ CasADi symbolic |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
194 195 196 197 198 199 200 201 202 203 204 205 206 | |
dynamics_ct(x, u, w)
Interface to the continuous-time dynamics function of the vehicle model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[StateInterface, ndarray[tuple[float], dtype[float64]]]
|
state - StateInterface/ array of dimension (self._nx,) |
required |
u
|
Union[InputInterface, ndarray[tuple[float], dtype[float64]]]
|
control input - InputInterface/ array of dimension (self._nu,) |
required |
w
|
Union[DisturbanceInterface, ndarray[tuple[float], dtype[float64]]]
|
disturbance - DisturbanceInterface/ array of dimension (self._nw,) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
dynamics function evaluated at (x, u, w) - array of dimension (self._nx,) |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
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 | |
factory_method(params, delta_t)
abstractmethod
classmethod
Factory method to generate class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
VehicleParameters
|
CommonRoad-Control vehicle parameters |
required |
delta_t
|
float
|
sampling time |
required |
Returns:
| Type | Description |
|---|---|
Any
|
instance |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
21 22 23 24 25 26 27 28 29 30 | |
input_bounds()
Returns the lower and upper bound on the control inputs.
Returns:
| Type | Description |
|---|---|
Tuple[InputInterface, InputInterface]
|
lower bound and upper bound - InputInterface |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
284 285 286 287 288 289 | |
linearize_acceleration_constraints_at(x, u)
Linearization of the (normalized) acceleration constraint functions at a given state-input-pair, e.g., for solving a convex(ified) optimal control problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[StateInterface, array]
|
state for linearization - array of dimension (self._nx,) |
required |
u
|
Union[InputInterface, array]
|
input for linearization - array of dimension (self._nu,) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[array, array, array, array, array, array]
|
(normalized) acceleration constraint functions and respective Jacobians w.r.t. x and u |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
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 | |
linearize_dt_nom_at(x, u)
Linearization of the time-discretized nominal vehicle dynamics at a given state-input-pair, e.g., for solving a convex(ified) optimal control problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[StateInterface, array]
|
state for linearization - StateInterface/ array of dimension (self._nx,) |
required |
u
|
Union[InputInterface, array]
|
input for linearization - InputInterface/ array of dimension (self._nu,) |
required |
Returns:
| Type | Description |
|---|---|
Tuple[array, array, array]
|
nominal dynamics at (x,u) and Jacobians at (x,u) w.r.t. x and u |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
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 | |
simulate_dt_nom(x, u)
One-step simulation of the time-discretized nominal vehicle dynamics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[StateInterface, ndarray[tuple[float], dtype[float64]]]
|
initial state - StateInterface/ array of dimension (self._nx,) |
required |
u
|
Union[InputInterface, ndarray[tuple[float], dtype[float64]]]
|
control input - InputInterface/ array of dimension (self._nu,) |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
nominal state at next time step |
Source code in commonroad_control/vehicle_dynamics/vehicle_model_interface.py
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 | |
commonroad_control.vehicle_dynamics.state_interface
StateInterface
dataclass
Bases: ABC
Interface for dataclass objects storing states of the vehicle models.
Source code in commonroad_control/vehicle_dynamics/state_interface.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
dim
property
Returns:
| Type | Description |
|---|---|
int
|
state dimension |
convert_to_array()
abstractmethod
Converts instance of class to numpy array.
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray of dimension (self.dim,1) |
Source code in commonroad_control/vehicle_dynamics/state_interface.py
29 30 31 32 33 34 35 | |
StateInterfaceIndex
dataclass
Bases: ABC
Interface for indices of the state variables.
Source code in commonroad_control/vehicle_dynamics/state_interface.py
7 8 9 10 11 12 13 | |
commonroad_control.vehicle_dynamics.input_interface
InputInterface
dataclass
Bases: ABC
Interface for dataclass objects storing control inputs of the vehicle models.
Source code in commonroad_control/vehicle_dynamics/input_interface.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
dim
property
Returns:
| Type | Description |
|---|---|
int
|
control input dimension |
convert_to_array()
abstractmethod
Converts instance of class to numpy array.
Returns:
| Type | Description |
|---|---|
ndarray
|
(dim, 1) np.ndarray |
Source code in commonroad_control/vehicle_dynamics/input_interface.py
29 30 31 32 33 34 35 | |
InputInterfaceIndex
dataclass
Bases: ABC
Interface for the indices of the control inputs.
Source code in commonroad_control/vehicle_dynamics/input_interface.py
7 8 9 10 11 12 13 | |
commonroad_control.vehicle_dynamics.trajectory_interface
TrajectoryInterface
dataclass
Bases: ABC
Interface for State/Input/Disturbance trajectories of a given vehicle model. Trajectory points are stored as a dict of points and assumed to be sampled at constant rate of 1/delta_t.
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
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 | |
append_point(next_point)
Appends a point to the trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
next_point
|
Union[StateInterface, InputInterface, DisturbanceInterface]
|
point to be appended |
required |
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
126 127 128 129 130 131 132 133 134 135 136 | |
check_goal_reached(planning_problem, lanelet_network)
Returns true if one of the states is within the goal state. Always returns False for input trajectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
planning_problem
|
PlanningProblem
|
CommonRoad planning problem |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True, if at least one state is within goal region of planning problem |
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
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 | |
convert_to_numpy_array(time, linear_interpolate=False, sidt_factory=None)
Extracts the trajectory points at given points in time and stores the point variables in an array. By default, the to-be-extracted points are approximated by the point at the closest discrete point in time of the trajectory. If a more accurate result is desired, the to-be-extracted points can be approximated using linear interpolation between trajectory points at adjacent time steps (see input argument: linear_interpolate).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
List[float]
|
desired points in time for sampling the trajectory - list of floats |
required |
linear_interpolate
|
bool
|
if true, compute to-be-extracted points using linear interpolation; otherwise, approximate by the closest trajectory point |
False
|
sidt_factory
|
Optional['StateInputDisturbanceTrajectoryFactoryInterface']
|
factory for generating points, required if linear_interpolate=True - StateInputDisturbanceTrajectoryFactoryInterface |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
(approximation of) desired trajectory points - array of dimension (dim, len(time)) |
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
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 | |
get_point_at_time(time, factory)
Computes a point at a given time by linearly interpolating between the trajectory points at the adjacent (discrete) time steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
float
|
time at which to interpolate |
required |
factory
|
'StateInputDisturbanceTrajectoryFactoryInterface'
|
sidt_factory for instantiating the interpolated point (dataclass object) |
required |
Returns:
| Type | Description |
|---|---|
Union[StateInterface, InputInterface, DisturbanceInterface]
|
StateInterface/InputInterface/DisturbanceInterface |
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
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 | |
get_point_at_time_step(time_step)
Returns the trajectory point at a given (discrete) time step or None if not existing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time_step
|
int
|
time step - int |
required |
Returns:
| Type | Description |
|---|---|
Union[StateInterface, InputInterface, None]
|
StateInterface/InputInterface/DisturbanceInterface at step or None if not existing |
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
100 101 102 103 104 105 106 107 | |
get_point_before_and_after_time(time)
Finds trajectory points at discrete time steps before and after a given point in time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
float
|
point in time - float |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Any, Any, int, int]
|
point before time, point after time, time step before, time step after |
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
sanity_check()
Sanity check
Source code in commonroad_control/vehicle_dynamics/trajectory_interface.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |
commonroad_control.vehicle_dynamics.disturbance_interface
DisturbanceInterface
dataclass
Bases: UncertaintyInterface
Interface for dataclass objects storing disturbances of the vehicle models.
Source code in commonroad_control/vehicle_dynamics/disturbance_interface.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
dim
property
Returns:
| Type | Description |
|---|---|
int
|
disturbance dimension |
convert_to_array()
abstractmethod
Converts instance of class to numpy array.
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray of dimension (self.dim,) |
Source code in commonroad_control/vehicle_dynamics/disturbance_interface.py
34 35 36 37 38 39 40 | |
DisturbanceInterfaceIndex
dataclass
Bases: UncertaintyInterfaceIndex
Indices of the disturbance variables.
Source code in commonroad_control/vehicle_dynamics/disturbance_interface.py
12 13 14 15 16 17 18 | |
commonroad_control.vehicle_dynamics.full_state_noise_interface
FullStateNoiseInterface
dataclass
Bases: UncertaintyInterface
Abstract base class for full state noise - required for the full state feedback sensor model.
Source code in commonroad_control/vehicle_dynamics/full_state_noise_interface.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | |
dim
property
Returns:
| Type | Description |
|---|---|
int
|
noise dimension |
convert_to_array()
abstractmethod
Converts instance of class to numpy array.
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray of dimension (self.dim,) |
Source code in commonroad_control/vehicle_dynamics/full_state_noise_interface.py
34 35 36 37 38 39 40 | |
FullStateNoiseInterfaceIndex
dataclass
Bases: UncertaintyInterfaceIndex
Indices of the noise variables.
Source code in commonroad_control/vehicle_dynamics/full_state_noise_interface.py
12 13 14 15 16 17 18 | |
commonroad_control.vehicle_dynamics.sidt_factory_interface
StateInputDisturbanceTrajectoryFactoryInterface
Bases: ABC
Factory for creating State, Input, Disturbance, or Trajectory instances from the corresponding input arguments (fields of the corresponding dataclasses) or numpy arrays.
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.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 | |
disturbance_from_args(*args)
abstractmethod
classmethod
Crate Disturbance args
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
40 41 42 43 44 45 46 | |
disturbance_from_numpy_array(w_np)
abstractmethod
classmethod
Create Disturbance from numpy array.
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
67 68 69 70 71 72 73 | |
input_from_args(*args)
abstractmethod
classmethod
Create Input args
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
32 33 34 35 36 37 38 | |
input_from_numpy_array(u_np)
abstractmethod
classmethod
Create Input from numpy array.
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
59 60 61 62 63 64 65 | |
state_from_args(*args)
abstractmethod
classmethod
Create State from args
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
24 25 26 27 28 29 30 | |
state_from_numpy_array(x_np)
abstractmethod
classmethod
Create State from numpy array.
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
48 49 50 51 52 53 54 55 56 57 | |
trajectory_from_numpy_array(traj_np, mode, time_steps, t_0, delta_t)
abstractmethod
classmethod
Create State, Input, or Disturbance Trajectory from numpy array.
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
trajectory_from_points(trajectory_dict, mode, t_0, delta_t)
abstractmethod
classmethod
Create State, Input, or Disturbance Trajectory from list of points.
Source code in commonroad_control/vehicle_dynamics/sidt_factory_interface.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |