pydrake.systems.primitives

Bindings for the primitives portion of the Systems framework.

class pydrake.systems.primitives.Adder

Bases: pydrake.systems.framework.LeafSystem

An adder for arbitrarily many inputs of equal size.

u0→
...→
u(N-1)→
Adder
→ sum

Note

This class is templated; see Adder_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.Adder, num_inputs: int, size: int) None

Construct an Adder System.

Parameter num_inputs:

is the number of input ports to be added.

Parameter size:

number of elements in each input and output signal.

template pydrake.systems.primitives.Adder_

Instantiations: Adder_[float], Adder_[AutoDiffXd], Adder_[Expression]

class pydrake.systems.primitives.Adder_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

An adder for arbitrarily many inputs of equal size.

u0→
...→
u(N-1)→
Adder
→ sum
__init__(self: pydrake.systems.primitives.Adder_[AutoDiffXd], num_inputs: int, size: int) None

Construct an Adder System.

Parameter num_inputs:

is the number of input ports to be added.

Parameter size:

number of elements in each input and output signal.

class pydrake.systems.primitives.Adder_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

An adder for arbitrarily many inputs of equal size.

u0→
...→
u(N-1)→
Adder
→ sum
__init__(self: pydrake.systems.primitives.Adder_[Expression], num_inputs: int, size: int) None

Construct an Adder System.

Parameter num_inputs:

is the number of input ports to be added.

Parameter size:

number of elements in each input and output signal.

pydrake.systems.primitives.AddRandomInputs(*args, **kwargs)

Overloaded function.

  1. AddRandomInputs(sampling_interval_sec: float, builder: pydrake.systems.framework.DiagramBuilder) -> int

For each subsystem input port in builder that is (a) not yet connected and (b) labeled as random in the InputPort, this method will add a new RandomSource system of the appropriate type and connect it to the subsystem input port.

Parameter sampling_interval_sec:

interval to be used for all new sources.

Returns

the total number of RandomSource systems added.

See also

stochastic_systems

  1. AddRandomInputs(sampling_interval_sec: float, builder: pydrake.systems.framework.DiagramBuilder_[AutoDiffXd]) -> int

For each subsystem input port in builder that is (a) not yet connected and (b) labeled as random in the InputPort, this method will add a new RandomSource system of the appropriate type and connect it to the subsystem input port.

Parameter sampling_interval_sec:

interval to be used for all new sources.

Returns

the total number of RandomSource systems added.

See also

stochastic_systems

class pydrake.systems.primitives.AffineSystem

Bases: pydrake.systems.framework.LeafSystem

A discrete OR continuous affine system (with constant coefficients).

u0→
AffineSystem
→ y0

Let u denote the input vector, x denote the state vector, and y denote the output vector.

If time_period > 0.0, the affine system will have the following discrete-time state update:

\[x(t+h) = A x(t) + B u(t) + f_0,\]

where h is the time_period. If time_period == 0.0, the affine system will have the following continuous-time state update:

\[\dot{x} = A x + B u + f_0.\]

In both cases, the system will have the output:

\[y = C x + D u + y_0,\]

See also

LinearSystem

See also

MatrixGain

Note

This class is templated; see AffineSystem_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.AffineSystem, A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), f0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), y0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), time_period: float = 0.0) None

Constructs an Affine system with a fixed set of coefficient matrices A, B,``C``, and D as well as fixed initial velocity offset xDot0 and output offset y0. The coefficient matrices must obey the following dimensions : | Matrix | Num Rows | Num Columns | |:-------:|:———–:|:-----------:| | A | num states | num states | | B | num states | num inputs | | f0 | num_states | 1 | | C | num outputs | num states | | D | num outputs | num inputs | | y0 | num_outputs | 1 |

Empty matrices are treated as zero matrices with the appropriate number of rows and columns.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

Subclasses must use the protected constructor, not this one.

A(self: pydrake.systems.primitives.AffineSystem) numpy.ndarray[numpy.float64[m, n]]

@name Helper getter methods.

B(self: pydrake.systems.primitives.AffineSystem) numpy.ndarray[numpy.float64[m, n]]
C(self: pydrake.systems.primitives.AffineSystem) numpy.ndarray[numpy.float64[m, n]]
configure_default_state(self: pydrake.systems.primitives.AffineSystem, x0: numpy.ndarray[numpy.float64[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.AffineSystem, covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.AffineSystem) numpy.ndarray[numpy.float64[m, n]]
f0(self: pydrake.systems.primitives.AffineSystem) numpy.ndarray[numpy.float64[m, 1]]
num_inputs(self: pydrake.systems.primitives.AffineSystem) int
num_outputs(self: pydrake.systems.primitives.AffineSystem) int
num_states(self: pydrake.systems.primitives.AffineSystem) int
time_period(self: pydrake.systems.primitives.AffineSystem) float
UpdateCoefficients(self: pydrake.systems.primitives.AffineSystem, A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), f0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), y0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64)) None

Updates the coefficients of the affine system. The new coefficients must have the same size as existing coefficients.

y0(self: pydrake.systems.primitives.AffineSystem) numpy.ndarray[numpy.float64[m, 1]]
template pydrake.systems.primitives.AffineSystem_

Instantiations: AffineSystem_[float], AffineSystem_[AutoDiffXd], AffineSystem_[Expression]

class pydrake.systems.primitives.AffineSystem_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A discrete OR continuous affine system (with constant coefficients).

u0→
AffineSystem
→ y0

Let u denote the input vector, x denote the state vector, and y denote the output vector.

If time_period > 0.0, the affine system will have the following discrete-time state update:

\[x(t+h) = A x(t) + B u(t) + f_0,\]

where h is the time_period. If time_period == 0.0, the affine system will have the following continuous-time state update:

\[\dot{x} = A x + B u + f_0.\]

In both cases, the system will have the output:

\[y = C x + D u + y_0,\]

See also

LinearSystem

See also

MatrixGain

__init__(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd], A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), f0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), y0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), time_period: float = 0.0) None

Constructs an Affine system with a fixed set of coefficient matrices A, B,``C``, and D as well as fixed initial velocity offset xDot0 and output offset y0. The coefficient matrices must obey the following dimensions : | Matrix | Num Rows | Num Columns | |:-------:|:———–:|:-----------:| | A | num states | num states | | B | num states | num inputs | | f0 | num_states | 1 | | C | num outputs | num states | | D | num outputs | num inputs | | y0 | num_outputs | 1 |

Empty matrices are treated as zero matrices with the appropriate number of rows and columns.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

Subclasses must use the protected constructor, not this one.

A(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, n]]

@name Helper getter methods.

B(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, n]]
C(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, n]]
configure_default_state(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd], x0: numpy.ndarray[object[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd], covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, n]]
f0(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, 1]]
num_inputs(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) int
num_outputs(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) int
num_states(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) int
time_period(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) float
UpdateCoefficients(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd], A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), f0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), y0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64)) None

Updates the coefficients of the affine system. The new coefficients must have the same size as existing coefficients.

y0(self: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, 1]]
class pydrake.systems.primitives.AffineSystem_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A discrete OR continuous affine system (with constant coefficients).

u0→
AffineSystem
→ y0

Let u denote the input vector, x denote the state vector, and y denote the output vector.

If time_period > 0.0, the affine system will have the following discrete-time state update:

\[x(t+h) = A x(t) + B u(t) + f_0,\]

where h is the time_period. If time_period == 0.0, the affine system will have the following continuous-time state update:

\[\dot{x} = A x + B u + f_0.\]

In both cases, the system will have the output:

\[y = C x + D u + y_0,\]

See also

LinearSystem

See also

MatrixGain

__init__(self: pydrake.systems.primitives.AffineSystem_[Expression], A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), f0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), y0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), time_period: float = 0.0) None

Constructs an Affine system with a fixed set of coefficient matrices A, B,``C``, and D as well as fixed initial velocity offset xDot0 and output offset y0. The coefficient matrices must obey the following dimensions : | Matrix | Num Rows | Num Columns | |:-------:|:———–:|:-----------:| | A | num states | num states | | B | num states | num inputs | | f0 | num_states | 1 | | C | num outputs | num states | | D | num outputs | num inputs | | y0 | num_outputs | 1 |

Empty matrices are treated as zero matrices with the appropriate number of rows and columns.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

Subclasses must use the protected constructor, not this one.

A(self: pydrake.systems.primitives.AffineSystem_[Expression]) numpy.ndarray[numpy.float64[m, n]]

@name Helper getter methods.

B(self: pydrake.systems.primitives.AffineSystem_[Expression]) numpy.ndarray[numpy.float64[m, n]]
C(self: pydrake.systems.primitives.AffineSystem_[Expression]) numpy.ndarray[numpy.float64[m, n]]
configure_default_state(self: pydrake.systems.primitives.AffineSystem_[Expression], x0: numpy.ndarray[object[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.AffineSystem_[Expression], covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.AffineSystem_[Expression]) numpy.ndarray[numpy.float64[m, n]]
f0(self: pydrake.systems.primitives.AffineSystem_[Expression]) numpy.ndarray[numpy.float64[m, 1]]
num_inputs(self: pydrake.systems.primitives.AffineSystem_[Expression]) int
num_outputs(self: pydrake.systems.primitives.AffineSystem_[Expression]) int
num_states(self: pydrake.systems.primitives.AffineSystem_[Expression]) int
time_period(self: pydrake.systems.primitives.AffineSystem_[Expression]) float
UpdateCoefficients(self: pydrake.systems.primitives.AffineSystem_[Expression], A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), f0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), y0: numpy.ndarray[numpy.float64[m, 1]] = array([], dtype=float64)) None

Updates the coefficients of the affine system. The new coefficients must have the same size as existing coefficients.

y0(self: pydrake.systems.primitives.AffineSystem_[Expression]) numpy.ndarray[numpy.float64[m, 1]]
class pydrake.systems.primitives.BarycentricMeshSystem

Bases: pydrake.systems.framework.LeafSystem

A (stateless) vector system implemented as a multi-linear (barycentric) interpolation on a mesh over the inputs.

u0→
BarycentricMeshSystem
→ y0

This has many potential uses, including representing the policies that are generated by numerical control design methods like approximate dynamic programming.

See also

math::BarycentricMesh

__init__(self: pydrake.systems.primitives.BarycentricMeshSystem, arg0: pydrake.math.BarycentricMesh, arg1: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Constructs the system from a mesh and the associated mesh values. output_values is a matrix with each column representing the value to output if the input is the associated mesh point. It must have the same number of columns as mesh.get_num_mesh_points(); mesh.MeshValuesFrom(function) is one useful tool for creating it.

get_mesh(self: pydrake.systems.primitives.BarycentricMeshSystem) pydrake.math.BarycentricMesh

Returns a reference to the mesh.

get_output_values(self: pydrake.systems.primitives.BarycentricMeshSystem) numpy.ndarray[numpy.float64[m, n]]

Returns a reference to the output values.

class pydrake.systems.primitives.ConstantValueSource

Bases: pydrake.systems.framework.LeafSystem

A source block that always outputs a constant value.

ConstantValueSource
→ y0

Note

This class is templated; see ConstantValueSource_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.ConstantValueSource, value: pydrake.common.value.AbstractValue) None
Parameter value:

The constant value to emit, which is copied by this system.

template pydrake.systems.primitives.ConstantValueSource_

Instantiations: ConstantValueSource_[float], ConstantValueSource_[AutoDiffXd], ConstantValueSource_[Expression]

class pydrake.systems.primitives.ConstantValueSource_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A source block that always outputs a constant value.

ConstantValueSource
→ y0
__init__(self: pydrake.systems.primitives.ConstantValueSource_[AutoDiffXd], value: pydrake.common.value.AbstractValue) None
Parameter value:

The constant value to emit, which is copied by this system.

class pydrake.systems.primitives.ConstantValueSource_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A source block that always outputs a constant value.

ConstantValueSource
→ y0
__init__(self: pydrake.systems.primitives.ConstantValueSource_[Expression], value: pydrake.common.value.AbstractValue) None
Parameter value:

The constant value to emit, which is copied by this system.

class pydrake.systems.primitives.ConstantVectorSource

Bases: pydrake.systems.framework.LeafSystem

A source block with a constant output port at all times. The value of the output port is a parameter of the system (see Parameters).

ConstantVectorSource
→ y0

Note

This class is templated; see ConstantVectorSource_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.ConstantVectorSource, source_value: numpy.ndarray[numpy.float64[m, 1]]) None

Constructs a system with a vector output that is constant and equals the supplied source_value at all times.

Parameter source_value:

the constant value of the output so that y = source_value at all times.

get_mutable_source_value(self: pydrake.systems.primitives.ConstantVectorSource, context: pydrake.systems.framework.Context) pydrake.systems.framework.BasicVector

Return a mutable reference to the source value of this block in the given context.

get_source_value(self: pydrake.systems.primitives.ConstantVectorSource, context: pydrake.systems.framework.Context) pydrake.systems.framework.BasicVector

Return a read-only reference to the source value of this block in the given context.

template pydrake.systems.primitives.ConstantVectorSource_

Instantiations: ConstantVectorSource_[float], ConstantVectorSource_[AutoDiffXd], ConstantVectorSource_[Expression]

class pydrake.systems.primitives.ConstantVectorSource_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A source block with a constant output port at all times. The value of the output port is a parameter of the system (see Parameters).

ConstantVectorSource
→ y0
__init__(self: pydrake.systems.primitives.ConstantVectorSource_[AutoDiffXd], source_value: numpy.ndarray[object[m, 1]]) None

Constructs a system with a vector output that is constant and equals the supplied source_value at all times.

Parameter source_value:

the constant value of the output so that y = source_value at all times.

get_mutable_source_value(self: pydrake.systems.primitives.ConstantVectorSource_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.systems.framework.BasicVector_[AutoDiffXd]

Return a mutable reference to the source value of this block in the given context.

get_source_value(self: pydrake.systems.primitives.ConstantVectorSource_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.systems.framework.BasicVector_[AutoDiffXd]

Return a read-only reference to the source value of this block in the given context.

class pydrake.systems.primitives.ConstantVectorSource_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A source block with a constant output port at all times. The value of the output port is a parameter of the system (see Parameters).

ConstantVectorSource
→ y0
__init__(self: pydrake.systems.primitives.ConstantVectorSource_[Expression], source_value: numpy.ndarray[object[m, 1]]) None

Constructs a system with a vector output that is constant and equals the supplied source_value at all times.

Parameter source_value:

the constant value of the output so that y = source_value at all times.

get_mutable_source_value(self: pydrake.systems.primitives.ConstantVectorSource_[Expression], context: pydrake.systems.framework.Context_[Expression]) pydrake.systems.framework.BasicVector_[Expression]

Return a mutable reference to the source value of this block in the given context.

get_source_value(self: pydrake.systems.primitives.ConstantVectorSource_[Expression], context: pydrake.systems.framework.Context_[Expression]) pydrake.systems.framework.BasicVector_[Expression]

Return a read-only reference to the source value of this block in the given context.

pydrake.systems.primitives.ControllabilityMatrix(arg0: pydrake.systems.primitives.LinearSystem) numpy.ndarray[numpy.float64[m, n]]

Returns the controllability matrix: R = [B, AB, …, A^{n-1}B].

class pydrake.systems.primitives.Demultiplexer

Bases: pydrake.systems.framework.LeafSystem

This system splits a vector valued signal on its input into multiple outputs.

The input to this system directly feeds through to its output.

u0→
Demultiplexer
→ y0
→ ...
→ y(N-1)

Note

This class is templated; see Demultiplexer_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Demultiplexer, size: int, output_ports_size: int = 1) -> None

Constructs Demultiplexer with one vector valued input port of size size and vector valued output ports of size output_ports_size.

u0→
Demultiplexer
→ y0
→ ...
→ y((size / output_ports_size) - 1)
Raises

RuntimeError if output_ports_sizes can not exactly divide

:raises size`. The number of output ports is therefore size : :raises output_ports_size.:

Parameter size:

is the size of the input signal to be demultiplexed into its individual components.

Parameter output_ports_size:

The size of the output ports. size must be a multiple of output_ports_size.

  1. __init__(self: pydrake.systems.primitives.Demultiplexer, output_ports_sizes: list[int]) -> None

Constructs Demultiplexer with one vector valued output ports with sizes specified as the vector output_ports_sizes. The number of output ports is the length of this vector. The size of each output port is the value of the corresponding element of the vector output_ports_sizes.

u0→
Demultiplexer
→ y0
→ ...
→ y(output_ports_sizes.size() - 1)
Raises
  • RuntimeError if output_ports_sizes is a zero length vector.

  • RuntimeError if any element of the output_ports_sizes is zero.

  • Therefore, the Demultiplexer does not allow zero size output

  • ports.

Parameter output_ports_sizes:

Contains the sizes of each output port. The number of output ports is determined by the length of output_ports_sizes. The accumulative value of the all the values in output_ports_sizes will be the size of the input port.

get_output_ports_sizes(self: pydrake.systems.primitives.Demultiplexer) list[int]
template pydrake.systems.primitives.Demultiplexer_

Instantiations: Demultiplexer_[float], Demultiplexer_[AutoDiffXd], Demultiplexer_[Expression]

class pydrake.systems.primitives.Demultiplexer_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

This system splits a vector valued signal on its input into multiple outputs.

The input to this system directly feeds through to its output.

u0→
Demultiplexer
→ y0
→ ...
→ y(N-1)
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Demultiplexer_[AutoDiffXd], size: int, output_ports_size: int = 1) -> None

Constructs Demultiplexer with one vector valued input port of size size and vector valued output ports of size output_ports_size.

u0→
Demultiplexer
→ y0
→ ...
→ y((size / output_ports_size) - 1)
Raises

RuntimeError if output_ports_sizes can not exactly divide

:raises size`. The number of output ports is therefore size : :raises output_ports_size.:

Parameter size:

is the size of the input signal to be demultiplexed into its individual components.

Parameter output_ports_size:

The size of the output ports. size must be a multiple of output_ports_size.

  1. __init__(self: pydrake.systems.primitives.Demultiplexer_[AutoDiffXd], output_ports_sizes: list[int]) -> None

Constructs Demultiplexer with one vector valued output ports with sizes specified as the vector output_ports_sizes. The number of output ports is the length of this vector. The size of each output port is the value of the corresponding element of the vector output_ports_sizes.

u0→
Demultiplexer
→ y0
→ ...
→ y(output_ports_sizes.size() - 1)
Raises
  • RuntimeError if output_ports_sizes is a zero length vector.

  • RuntimeError if any element of the output_ports_sizes is zero.

  • Therefore, the Demultiplexer does not allow zero size output

  • ports.

Parameter output_ports_sizes:

Contains the sizes of each output port. The number of output ports is determined by the length of output_ports_sizes. The accumulative value of the all the values in output_ports_sizes will be the size of the input port.

get_output_ports_sizes(self: pydrake.systems.primitives.Demultiplexer_[AutoDiffXd]) list[int]
class pydrake.systems.primitives.Demultiplexer_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

This system splits a vector valued signal on its input into multiple outputs.

The input to this system directly feeds through to its output.

u0→
Demultiplexer
→ y0
→ ...
→ y(N-1)
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Demultiplexer_[Expression], size: int, output_ports_size: int = 1) -> None

Constructs Demultiplexer with one vector valued input port of size size and vector valued output ports of size output_ports_size.

u0→
Demultiplexer
→ y0
→ ...
→ y((size / output_ports_size) - 1)
Raises

RuntimeError if output_ports_sizes can not exactly divide

:raises size`. The number of output ports is therefore size : :raises output_ports_size.:

Parameter size:

is the size of the input signal to be demultiplexed into its individual components.

Parameter output_ports_size:

The size of the output ports. size must be a multiple of output_ports_size.

  1. __init__(self: pydrake.systems.primitives.Demultiplexer_[Expression], output_ports_sizes: list[int]) -> None

Constructs Demultiplexer with one vector valued output ports with sizes specified as the vector output_ports_sizes. The number of output ports is the length of this vector. The size of each output port is the value of the corresponding element of the vector output_ports_sizes.

u0→
Demultiplexer
→ y0
→ ...
→ y(output_ports_sizes.size() - 1)
Raises
  • RuntimeError if output_ports_sizes is a zero length vector.

  • RuntimeError if any element of the output_ports_sizes is zero.

  • Therefore, the Demultiplexer does not allow zero size output

  • ports.

Parameter output_ports_sizes:

Contains the sizes of each output port. The number of output ports is determined by the length of output_ports_sizes. The accumulative value of the all the values in output_ports_sizes will be the size of the input port.

get_output_ports_sizes(self: pydrake.systems.primitives.Demultiplexer_[Expression]) list[int]
class pydrake.systems.primitives.DiscreteDerivative

Bases: pydrake.systems.framework.LeafSystem

System that outputs the discrete-time derivative of its input: y(t) = (u[n] - u[n-1])/h, where n = floor(t/h), where h is the time period.

This is implemented as the linear system

Click to expand C++ code...
x₀[n+1] = u[n],
  x₁[n+1] = x₀[n],
  y(t) = (x₀[n]-x₁[n])/h.
  x₀[0] and x₁[0] are initialized in the Context (default is zeros).

Alternatively, when suppress_initial_transient = true is passed to the constructor, the output remains zero until u[n] has been sampled twice.

This is implemented as the non-linear system

Click to expand C++ code...
x₀[n+1] = u[n],
  x₁[n+1] = x₀[n],
  x₂[n+1] = x₂[n] + 1,
  y(t) = { 0.0              if x₂ <  2 }
         { (x₀[n]-x₁[n])/h  if x₂ >= 2 }
  x₀[0], x₁[0], x₂[0] are initialized in the Context (default is zeros).

Note

Calling set_input_history() effectively disables the transient suppression by setting x_2 = 2.

Note

For dynamical systems, a derivative should not be computed in continuous-time, i.e. y(t) = (u(t) - u[n])/(t-n*h). This is numerically unstable since the time interval t-n*h could be arbitrarily close to zero. Prefer the discrete-time implementation for robustness.

u→
DiscreteDerivative
→ dudt

Note

This class is templated; see DiscreteDerivative_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.DiscreteDerivative, num_inputs: int, time_step: float, suppress_initial_transient: bool = True) None

Constructor taking num_inputs, the size of the vector to be differentiated, and time_step, the sampling interval. If suppress_initial_transient is true (the default), then the output will be zero for the first two time steps (see the class documentation for details and exceptions).

suppress_initial_transient(self: pydrake.systems.primitives.DiscreteDerivative) bool

Returns the suppress_initial_transient passed to the constructor.

time_step(self: pydrake.systems.primitives.DiscreteDerivative) float
template pydrake.systems.primitives.DiscreteDerivative_

Instantiations: DiscreteDerivative_[float], DiscreteDerivative_[AutoDiffXd], DiscreteDerivative_[Expression]

class pydrake.systems.primitives.DiscreteDerivative_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

System that outputs the discrete-time derivative of its input: y(t) = (u[n] - u[n-1])/h, where n = floor(t/h), where h is the time period.

This is implemented as the linear system

Click to expand C++ code...
x₀[n+1] = u[n],
  x₁[n+1] = x₀[n],
  y(t) = (x₀[n]-x₁[n])/h.
  x₀[0] and x₁[0] are initialized in the Context (default is zeros).

Alternatively, when suppress_initial_transient = true is passed to the constructor, the output remains zero until u[n] has been sampled twice.

This is implemented as the non-linear system

Click to expand C++ code...
x₀[n+1] = u[n],
  x₁[n+1] = x₀[n],
  x₂[n+1] = x₂[n] + 1,
  y(t) = { 0.0              if x₂ <  2 }
         { (x₀[n]-x₁[n])/h  if x₂ >= 2 }
  x₀[0], x₁[0], x₂[0] are initialized in the Context (default is zeros).

Note

Calling set_input_history() effectively disables the transient suppression by setting x_2 = 2.

Note

For dynamical systems, a derivative should not be computed in continuous-time, i.e. y(t) = (u(t) - u[n])/(t-n*h). This is numerically unstable since the time interval t-n*h could be arbitrarily close to zero. Prefer the discrete-time implementation for robustness.

u→
DiscreteDerivative
→ dudt
__init__(self: pydrake.systems.primitives.DiscreteDerivative_[AutoDiffXd], num_inputs: int, time_step: float, suppress_initial_transient: bool = True) None

Constructor taking num_inputs, the size of the vector to be differentiated, and time_step, the sampling interval. If suppress_initial_transient is true (the default), then the output will be zero for the first two time steps (see the class documentation for details and exceptions).

suppress_initial_transient(self: pydrake.systems.primitives.DiscreteDerivative_[AutoDiffXd]) bool

Returns the suppress_initial_transient passed to the constructor.

time_step(self: pydrake.systems.primitives.DiscreteDerivative_[AutoDiffXd]) float
class pydrake.systems.primitives.DiscreteDerivative_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

System that outputs the discrete-time derivative of its input: y(t) = (u[n] - u[n-1])/h, where n = floor(t/h), where h is the time period.

This is implemented as the linear system

Click to expand C++ code...
x₀[n+1] = u[n],
  x₁[n+1] = x₀[n],
  y(t) = (x₀[n]-x₁[n])/h.
  x₀[0] and x₁[0] are initialized in the Context (default is zeros).

Alternatively, when suppress_initial_transient = true is passed to the constructor, the output remains zero until u[n] has been sampled twice.

This is implemented as the non-linear system

Click to expand C++ code...
x₀[n+1] = u[n],
  x₁[n+1] = x₀[n],
  x₂[n+1] = x₂[n] + 1,
  y(t) = { 0.0              if x₂ <  2 }
         { (x₀[n]-x₁[n])/h  if x₂ >= 2 }
  x₀[0], x₁[0], x₂[0] are initialized in the Context (default is zeros).

Note

Calling set_input_history() effectively disables the transient suppression by setting x_2 = 2.

Note

For dynamical systems, a derivative should not be computed in continuous-time, i.e. y(t) = (u(t) - u[n])/(t-n*h). This is numerically unstable since the time interval t-n*h could be arbitrarily close to zero. Prefer the discrete-time implementation for robustness.

u→
DiscreteDerivative
→ dudt
__init__(self: pydrake.systems.primitives.DiscreteDerivative_[Expression], num_inputs: int, time_step: float, suppress_initial_transient: bool = True) None

Constructor taking num_inputs, the size of the vector to be differentiated, and time_step, the sampling interval. If suppress_initial_transient is true (the default), then the output will be zero for the first two time steps (see the class documentation for details and exceptions).

suppress_initial_transient(self: pydrake.systems.primitives.DiscreteDerivative_[Expression]) bool

Returns the suppress_initial_transient passed to the constructor.

time_step(self: pydrake.systems.primitives.DiscreteDerivative_[Expression]) float
class pydrake.systems.primitives.DiscreteTimeDelay

Bases: pydrake.systems.framework.LeafSystem

A discrete time delay block with input u, which is vector-valued (discrete or continuous) or abstract, and output delayed_u which is previously received input, delayed by the given amount. The initial output will be a vector of zeros for vector-valued or a given value for abstract-valued until the delay time has passed.

u→
DiscreteTimeDelay
→ delayed_u

Let t,z ∈ ℕ be the number of delay time steps and the input vector size. For abstract-valued DiscreteTimeDelay, z is 1. The state x ∈ ℝ⁽ᵗ⁺¹⁾ᶻ is partitioned into t+1 blocks x[0] x[1] … x[t], each of size z. The input and output are u,y ∈ ℝᶻ. The discrete state space dynamics of DiscreteTimeDelay is:

Click to expand C++ code...
xₙ₊₁ = xₙ[1] xₙ[2] ... xₙ[t] uₙ  // update
  yₙ = xₙ[0]                       // output
  x₀ = xᵢₙᵢₜ                       // initialize

where xᵢₙᵢₜ = 0 for vector-valued DiscreteTimeDelay and xᵢₙᵢₜ is a given value for abstract-valued DiscreteTimeDelay.

See discrete_systems “Discrete Systems” for general information about discrete systems in Drake, including how they interact with continuous systems.

Note

While the output port can be sampled at any continuous time, this system does not interpolate.

Note

This class is templated; see DiscreteTimeDelay_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.DiscreteTimeDelay, update_sec: float, delay_time_steps: int, vector_size: int) -> None

Constructs a DiscreteTimeDelay system updating every update_sec and delaying a vector-valued input of size vector_size for delay_time_steps number of updates.

  1. __init__(self: pydrake.systems.primitives.DiscreteTimeDelay, update_sec: float, delay_time_steps: int, abstract_model_value: pydrake.common.value.AbstractValue) -> None

Constructs a DiscreteTimeDelay system updating every update_sec and delaying an abstract-valued input of type abstract_model_value for delay_time_steps number of updates.

template pydrake.systems.primitives.DiscreteTimeDelay_

Instantiations: DiscreteTimeDelay_[float], DiscreteTimeDelay_[AutoDiffXd], DiscreteTimeDelay_[Expression]

class pydrake.systems.primitives.DiscreteTimeDelay_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A discrete time delay block with input u, which is vector-valued (discrete or continuous) or abstract, and output delayed_u which is previously received input, delayed by the given amount. The initial output will be a vector of zeros for vector-valued or a given value for abstract-valued until the delay time has passed.

u→
DiscreteTimeDelay
→ delayed_u

Let t,z ∈ ℕ be the number of delay time steps and the input vector size. For abstract-valued DiscreteTimeDelay, z is 1. The state x ∈ ℝ⁽ᵗ⁺¹⁾ᶻ is partitioned into t+1 blocks x[0] x[1] … x[t], each of size z. The input and output are u,y ∈ ℝᶻ. The discrete state space dynamics of DiscreteTimeDelay is:

Click to expand C++ code...
xₙ₊₁ = xₙ[1] xₙ[2] ... xₙ[t] uₙ  // update
  yₙ = xₙ[0]                       // output
  x₀ = xᵢₙᵢₜ                       // initialize

where xᵢₙᵢₜ = 0 for vector-valued DiscreteTimeDelay and xᵢₙᵢₜ is a given value for abstract-valued DiscreteTimeDelay.

See discrete_systems “Discrete Systems” for general information about discrete systems in Drake, including how they interact with continuous systems.

Note

While the output port can be sampled at any continuous time, this system does not interpolate.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.DiscreteTimeDelay_[AutoDiffXd], update_sec: float, delay_time_steps: int, vector_size: int) -> None

Constructs a DiscreteTimeDelay system updating every update_sec and delaying a vector-valued input of size vector_size for delay_time_steps number of updates.

  1. __init__(self: pydrake.systems.primitives.DiscreteTimeDelay_[AutoDiffXd], update_sec: float, delay_time_steps: int, abstract_model_value: pydrake.common.value.AbstractValue) -> None

Constructs a DiscreteTimeDelay system updating every update_sec and delaying an abstract-valued input of type abstract_model_value for delay_time_steps number of updates.

class pydrake.systems.primitives.DiscreteTimeDelay_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A discrete time delay block with input u, which is vector-valued (discrete or continuous) or abstract, and output delayed_u which is previously received input, delayed by the given amount. The initial output will be a vector of zeros for vector-valued or a given value for abstract-valued until the delay time has passed.

u→
DiscreteTimeDelay
→ delayed_u

Let t,z ∈ ℕ be the number of delay time steps and the input vector size. For abstract-valued DiscreteTimeDelay, z is 1. The state x ∈ ℝ⁽ᵗ⁺¹⁾ᶻ is partitioned into t+1 blocks x[0] x[1] … x[t], each of size z. The input and output are u,y ∈ ℝᶻ. The discrete state space dynamics of DiscreteTimeDelay is:

Click to expand C++ code...
xₙ₊₁ = xₙ[1] xₙ[2] ... xₙ[t] uₙ  // update
  yₙ = xₙ[0]                       // output
  x₀ = xᵢₙᵢₜ                       // initialize

where xᵢₙᵢₜ = 0 for vector-valued DiscreteTimeDelay and xᵢₙᵢₜ is a given value for abstract-valued DiscreteTimeDelay.

See discrete_systems “Discrete Systems” for general information about discrete systems in Drake, including how they interact with continuous systems.

Note

While the output port can be sampled at any continuous time, this system does not interpolate.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.DiscreteTimeDelay_[Expression], update_sec: float, delay_time_steps: int, vector_size: int) -> None

Constructs a DiscreteTimeDelay system updating every update_sec and delaying a vector-valued input of size vector_size for delay_time_steps number of updates.

  1. __init__(self: pydrake.systems.primitives.DiscreteTimeDelay_[Expression], update_sec: float, delay_time_steps: int, abstract_model_value: pydrake.common.value.AbstractValue) -> None

Constructs a DiscreteTimeDelay system updating every update_sec and delaying an abstract-valued input of type abstract_model_value for delay_time_steps number of updates.

class pydrake.systems.primitives.DiscreteTimeIntegrator

Bases: pydrake.systems.framework.LeafSystem

A discrete-time integrator for a vector input, using explicit Euler integration.

u→
DiscreteTimeIntegrator
→ y

The discrete state space dynamics of DiscreteTimeIntegrator with time step h is:

Click to expand C++ code...
xₙ₊₁ = xₙ + h uₙ  // update
yₙ = xₙ           // output
x₀ = xᵢₙᵢₜ        // initialize

where xᵢₙᵢₜ = 0 by default. Use set_integral_value() to set xₙ in the context. The output at time t is xₙ where n = ceil(t/h). See discrete_systems.

Note

This class is templated; see DiscreteTimeIntegrator_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.DiscreteTimeIntegrator, size: int, time_step: float) None

Constructs an DiscreteTimeIntegrator system.

Parameter size:

number of elements in the signal to be processed.

Parameter time_step:

the discrete time step.

Precondition:

size > 0. time_step > 0.

set_integral_value(self: pydrake.systems.primitives.DiscreteTimeIntegrator, context: pydrake.systems.framework.Context, value: numpy.ndarray[numpy.float64[m, 1]]) None

Sets the value of the integral modifying the state in the context. value must be a column vector of the appropriate size.

time_step(self: pydrake.systems.primitives.DiscreteTimeIntegrator) float

Returns the time_step used by the integrator.

template pydrake.systems.primitives.DiscreteTimeIntegrator_

Instantiations: DiscreteTimeIntegrator_[float], DiscreteTimeIntegrator_[AutoDiffXd], DiscreteTimeIntegrator_[Expression]

class pydrake.systems.primitives.DiscreteTimeIntegrator_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A discrete-time integrator for a vector input, using explicit Euler integration.

u→
DiscreteTimeIntegrator
→ y

The discrete state space dynamics of DiscreteTimeIntegrator with time step h is:

Click to expand C++ code...
xₙ₊₁ = xₙ + h uₙ  // update
yₙ = xₙ           // output
x₀ = xᵢₙᵢₜ        // initialize

where xᵢₙᵢₜ = 0 by default. Use set_integral_value() to set xₙ in the context. The output at time t is xₙ where n = ceil(t/h). See discrete_systems.

__init__(self: pydrake.systems.primitives.DiscreteTimeIntegrator_[AutoDiffXd], size: int, time_step: float) None

Constructs an DiscreteTimeIntegrator system.

Parameter size:

number of elements in the signal to be processed.

Parameter time_step:

the discrete time step.

Precondition:

size > 0. time_step > 0.

set_integral_value(self: pydrake.systems.primitives.DiscreteTimeIntegrator_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], value: numpy.ndarray[object[m, 1]]) None

Sets the value of the integral modifying the state in the context. value must be a column vector of the appropriate size.

time_step(self: pydrake.systems.primitives.DiscreteTimeIntegrator_[AutoDiffXd]) float

Returns the time_step used by the integrator.

class pydrake.systems.primitives.DiscreteTimeIntegrator_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A discrete-time integrator for a vector input, using explicit Euler integration.

u→
DiscreteTimeIntegrator
→ y

The discrete state space dynamics of DiscreteTimeIntegrator with time step h is:

Click to expand C++ code...
xₙ₊₁ = xₙ + h uₙ  // update
yₙ = xₙ           // output
x₀ = xᵢₙᵢₜ        // initialize

where xᵢₙᵢₜ = 0 by default. Use set_integral_value() to set xₙ in the context. The output at time t is xₙ where n = ceil(t/h). See discrete_systems.

__init__(self: pydrake.systems.primitives.DiscreteTimeIntegrator_[Expression], size: int, time_step: float) None

Constructs an DiscreteTimeIntegrator system.

Parameter size:

number of elements in the signal to be processed.

Parameter time_step:

the discrete time step.

Precondition:

size > 0. time_step > 0.

set_integral_value(self: pydrake.systems.primitives.DiscreteTimeIntegrator_[Expression], context: pydrake.systems.framework.Context_[Expression], value: numpy.ndarray[object[m, 1]]) None

Sets the value of the integral modifying the state in the context. value must be a column vector of the appropriate size.

time_step(self: pydrake.systems.primitives.DiscreteTimeIntegrator_[Expression]) float

Returns the time_step used by the integrator.

class pydrake.systems.primitives.FirstOrderLowPassFilter

Bases: pydrake.systems.framework.LeafSystem

An element-wise first order low pass filter system that filters the i-th input uᵢ into the i-th output zᵢ. This system has one continuous state per filtered input signal. Therefore, the i-th state of the system zᵢ evolves according to:

Click to expand C++ code...
żᵢ = -1/τᵢ (zᵢ - uᵢ)

where τᵢ is the time constant of the i-th filter. The i-th output of the system is given by:

Click to expand C++ code...
yᵢ = zᵢ

The transfer function for the i-th filter corresponds to:

Click to expand C++ code...
H(s) = 1 / (1 + τᵢ s)

The Bode plot for the i-th filter exhibits a cutoff frequency (angular frequency) at 1/τᵢ and a gain of one. For frequencies higher than the cutoff frequency, the Bode plot approaches a 20 dB per decade negative slope. The Bode plot in phase exhibits a -90 degrees shift (lag) for frequencies much larger than the cutoff frequency and a zero shift for low frequencies.

u0→
FirstOrderLowPassFilter
→ y0

Note

This class is templated; see FirstOrderLowPassFilter_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.FirstOrderLowPassFilter, time_constant: float, size: int = 1) -> None

Constructs a FirstOrderLowPassFilter system that filters all input signals with the same time constant, i.e. τᵢ = τ, ∀ i.

Parameter time_constant:

the time constant τ of the filter. It must be a positive number.

Parameter size:

number of elements in the signal to be processed.

  1. __init__(self: pydrake.systems.primitives.FirstOrderLowPassFilter, time_constants: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a FirstOrderLowPassFilter so that the i-th component of the input signal vector is low pass filtered with a time constant given in the i-th component τᵢ of the input time_constants vector.

Parameter time_constants:

Vector of time constants. Each entry in this vector must be positive.

get_time_constant(self: pydrake.systems.primitives.FirstOrderLowPassFilter) float

Returns the time constant of the filter for filters that have the same time constant τ for all signals. This method aborts if called on filters if with different time constants per input signal.

See also

get_time_constants_vector().

get_time_constants_vector(self: pydrake.systems.primitives.FirstOrderLowPassFilter) numpy.ndarray[numpy.float64[m, 1]]

Returns the vector of time constants for this filter.

set_initial_output_value(self: pydrake.systems.primitives.FirstOrderLowPassFilter, arg0: pydrake.systems.framework.Context, arg1: numpy.ndarray[numpy.float64[m, 1]]) None

Sets the initial conditions on the output value of the filtered signal.

Parameter context:

The current system context.

Parameter z0:

The vector on initial conditions on the output value.

template pydrake.systems.primitives.FirstOrderLowPassFilter_

Instantiations: FirstOrderLowPassFilter_[float], FirstOrderLowPassFilter_[AutoDiffXd], FirstOrderLowPassFilter_[Expression]

class pydrake.systems.primitives.FirstOrderLowPassFilter_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

An element-wise first order low pass filter system that filters the i-th input uᵢ into the i-th output zᵢ. This system has one continuous state per filtered input signal. Therefore, the i-th state of the system zᵢ evolves according to:

Click to expand C++ code...
żᵢ = -1/τᵢ (zᵢ - uᵢ)

where τᵢ is the time constant of the i-th filter. The i-th output of the system is given by:

Click to expand C++ code...
yᵢ = zᵢ

The transfer function for the i-th filter corresponds to:

Click to expand C++ code...
H(s) = 1 / (1 + τᵢ s)

The Bode plot for the i-th filter exhibits a cutoff frequency (angular frequency) at 1/τᵢ and a gain of one. For frequencies higher than the cutoff frequency, the Bode plot approaches a 20 dB per decade negative slope. The Bode plot in phase exhibits a -90 degrees shift (lag) for frequencies much larger than the cutoff frequency and a zero shift for low frequencies.

u0→
FirstOrderLowPassFilter
→ y0
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[AutoDiffXd], time_constant: float, size: int = 1) -> None

Constructs a FirstOrderLowPassFilter system that filters all input signals with the same time constant, i.e. τᵢ = τ, ∀ i.

Parameter time_constant:

the time constant τ of the filter. It must be a positive number.

Parameter size:

number of elements in the signal to be processed.

  1. __init__(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[AutoDiffXd], time_constants: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a FirstOrderLowPassFilter so that the i-th component of the input signal vector is low pass filtered with a time constant given in the i-th component τᵢ of the input time_constants vector.

Parameter time_constants:

Vector of time constants. Each entry in this vector must be positive.

get_time_constant(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[AutoDiffXd]) float

Returns the time constant of the filter for filters that have the same time constant τ for all signals. This method aborts if called on filters if with different time constants per input signal.

See also

get_time_constants_vector().

get_time_constants_vector(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[AutoDiffXd]) numpy.ndarray[numpy.float64[m, 1]]

Returns the vector of time constants for this filter.

set_initial_output_value(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[AutoDiffXd], arg0: pydrake.systems.framework.Context_[AutoDiffXd], arg1: numpy.ndarray[object[m, 1]]) None

Sets the initial conditions on the output value of the filtered signal.

Parameter context:

The current system context.

Parameter z0:

The vector on initial conditions on the output value.

class pydrake.systems.primitives.FirstOrderLowPassFilter_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

An element-wise first order low pass filter system that filters the i-th input uᵢ into the i-th output zᵢ. This system has one continuous state per filtered input signal. Therefore, the i-th state of the system zᵢ evolves according to:

Click to expand C++ code...
żᵢ = -1/τᵢ (zᵢ - uᵢ)

where τᵢ is the time constant of the i-th filter. The i-th output of the system is given by:

Click to expand C++ code...
yᵢ = zᵢ

The transfer function for the i-th filter corresponds to:

Click to expand C++ code...
H(s) = 1 / (1 + τᵢ s)

The Bode plot for the i-th filter exhibits a cutoff frequency (angular frequency) at 1/τᵢ and a gain of one. For frequencies higher than the cutoff frequency, the Bode plot approaches a 20 dB per decade negative slope. The Bode plot in phase exhibits a -90 degrees shift (lag) for frequencies much larger than the cutoff frequency and a zero shift for low frequencies.

u0→
FirstOrderLowPassFilter
→ y0
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[Expression], time_constant: float, size: int = 1) -> None

Constructs a FirstOrderLowPassFilter system that filters all input signals with the same time constant, i.e. τᵢ = τ, ∀ i.

Parameter time_constant:

the time constant τ of the filter. It must be a positive number.

Parameter size:

number of elements in the signal to be processed.

  1. __init__(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[Expression], time_constants: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a FirstOrderLowPassFilter so that the i-th component of the input signal vector is low pass filtered with a time constant given in the i-th component τᵢ of the input time_constants vector.

Parameter time_constants:

Vector of time constants. Each entry in this vector must be positive.

get_time_constant(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[Expression]) float

Returns the time constant of the filter for filters that have the same time constant τ for all signals. This method aborts if called on filters if with different time constants per input signal.

See also

get_time_constants_vector().

get_time_constants_vector(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[Expression]) numpy.ndarray[numpy.float64[m, 1]]

Returns the vector of time constants for this filter.

set_initial_output_value(self: pydrake.systems.primitives.FirstOrderLowPassFilter_[Expression], arg0: pydrake.systems.framework.Context_[Expression], arg1: numpy.ndarray[object[m, 1]]) None

Sets the initial conditions on the output value of the filtered signal.

Parameter context:

The current system context.

Parameter z0:

The vector on initial conditions on the output value.

pydrake.systems.primitives.FirstOrderTaylorApproximation(system: pydrake.systems.framework.System, context: pydrake.systems.framework.Context, input_port_index: Union[pydrake.systems.framework.InputPortSelection, pydrake.systems.framework.InputPortIndex] = <InputPortSelection.kUseFirstInputIfItExists: -2>, output_port_index: Union[pydrake.systems.framework.OutputPortSelection, pydrake.systems.framework.OutputPortIndex] = <OutputPortSelection.kUseFirstOutputIfItExists: -2>) pydrake.systems.primitives.AffineSystem

A first-order Taylor series approximation to a system in the neighborhood of an arbitrary point. When Taylor-expanding a system at a non-equilibrium point, it may be represented either of the form:

\[\dot{x} - \dot{x}_0 = A (x - x_0) + B (u - u_0),\]

for continuous time, or

\[x[n+1] - x_0[n+1] = A (x[n] - x_0[n]) + B (u[n] - u_0[n]),\]

for discrete time. As above, we denote \(x_0, u_0\) to be the nominal state and input at the provided context. The system description is affine when the terms \(\dot{x}_0 - A x_0 - B u_0\) and \(x_0[n+1] - A x_0[n] - B u_0[n]\) are nonzero.

More precisely, let x be a state and u be an input. This function returns an AffineSystem of the form:

\[\dot{x} = A x + B u + f_0,\]

(CT)

\[x[n+1] = A x[n] + B u[n] + f_0,\]

(DT) where \(f_0 = \dot{x}_0 - A x_0 - B u_0\) (CT) and \(f_0 = x_0[n+1] - A x[n] - B u[n]\) (DT).

This method currently supports approximating around at most a single vector input port and at most a single vector output port. For systems with more ports, use input_port_index and output_port_index to select the input for the newly constructed system. Any additional input ports will be treated as constants (fixed at the value specified in context).

Parameter system:

The system or subsystem to linearize.

Parameter context:

Defines the nominal operating point about which the system should be linearized.

Parameter input_port_index:

A valid input port index for system or InputPortSelection. $*Default:* kUseFirstInputIfItExists.

Parameter output_port_index:

A valid output port index for system or OutputPortSelection. $*Default:* kUseFirstOutputIfItExists.

Returns

An AffineSystem at this linearization point.

Raises
  • if any abstract inputs are connected, if any vector-valued inputs

  • are unconnected, if the system is not (only) continuous or not

  • (only) discrete time with a single periodic update.

Note

x, u and y are in the same coordinate system as the original system, since the terms involving \(x_0, u_0\) reside in \(f_0\).

Note

This method does not (yet) set the initial conditions (default nor random) of the AffineSystem based on system.

class pydrake.systems.primitives.Gain

Bases: pydrake.systems.framework.LeafSystem

An element-wise gain block with input u and output y = k * u with k a constant vector. The input to this system directly feeds through to its output.

u0→
Gain
→ y0

Note

This class is templated; see Gain_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Gain, k: float, size: int) -> None

Constructs a Gain system where the same gain is applied to every input value.

Parameter k:

the gain constant so that y = k * u.

Parameter size:

number of elements in the signal to be processed.

  1. __init__(self: pydrake.systems.primitives.Gain, k: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a Gain system where different gains can be applied to each input value.

Parameter k:

the gain vector constants so that y_i = k_i * u_i where subscript i indicates the i-th element of the vector.

template pydrake.systems.primitives.Gain_

Instantiations: Gain_[float], Gain_[AutoDiffXd], Gain_[Expression]

class pydrake.systems.primitives.Gain_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

An element-wise gain block with input u and output y = k * u with k a constant vector. The input to this system directly feeds through to its output.

u0→
Gain
→ y0
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Gain_[AutoDiffXd], k: float, size: int) -> None

Constructs a Gain system where the same gain is applied to every input value.

Parameter k:

the gain constant so that y = k * u.

Parameter size:

number of elements in the signal to be processed.

  1. __init__(self: pydrake.systems.primitives.Gain_[AutoDiffXd], k: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a Gain system where different gains can be applied to each input value.

Parameter k:

the gain vector constants so that y_i = k_i * u_i where subscript i indicates the i-th element of the vector.

class pydrake.systems.primitives.Gain_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

An element-wise gain block with input u and output y = k * u with k a constant vector. The input to this system directly feeds through to its output.

u0→
Gain
→ y0
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Gain_[Expression], k: float, size: int) -> None

Constructs a Gain system where the same gain is applied to every input value.

Parameter k:

the gain constant so that y = k * u.

Parameter size:

number of elements in the signal to be processed.

  1. __init__(self: pydrake.systems.primitives.Gain_[Expression], k: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a Gain system where different gains can be applied to each input value.

Parameter k:

the gain vector constants so that y_i = k_i * u_i where subscript i indicates the i-th element of the vector.

class pydrake.systems.primitives.Integrator

Bases: pydrake.systems.framework.LeafSystem

A continuous-time integrator for a vector input.

u0→
Integrator
→ y0

Note

This class is templated; see Integrator_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.Integrator, arg0: int) None

Constructs an Integrator system.

Parameter size:

number of elements in the signal to be processed.

set_integral_value(self: pydrake.systems.primitives.Integrator, context: pydrake.systems.framework.Context, value: numpy.ndarray[numpy.float64[m, 1]]) None

Sets the value of the integral modifying the state in the context. value must be a column vector of the appropriate size.

template pydrake.systems.primitives.Integrator_

Instantiations: Integrator_[float], Integrator_[AutoDiffXd], Integrator_[Expression]

class pydrake.systems.primitives.Integrator_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A continuous-time integrator for a vector input.

u0→
Integrator
→ y0
__init__(self: pydrake.systems.primitives.Integrator_[AutoDiffXd], arg0: int) None

Constructs an Integrator system.

Parameter size:

number of elements in the signal to be processed.

set_integral_value(self: pydrake.systems.primitives.Integrator_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], value: numpy.ndarray[object[m, 1]]) None

Sets the value of the integral modifying the state in the context. value must be a column vector of the appropriate size.

class pydrake.systems.primitives.Integrator_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A continuous-time integrator for a vector input.

u0→
Integrator
→ y0
__init__(self: pydrake.systems.primitives.Integrator_[Expression], arg0: int) None

Constructs an Integrator system.

Parameter size:

number of elements in the signal to be processed.

set_integral_value(self: pydrake.systems.primitives.Integrator_[Expression], context: pydrake.systems.framework.Context_[Expression], value: numpy.ndarray[object[m, 1]]) None

Sets the value of the integral modifying the state in the context. value must be a column vector of the appropriate size.

pydrake.systems.primitives.IsControllable(sys: pydrake.systems.primitives.LinearSystem, threshold: Optional[float] = None) bool

Returns true iff the controllability matrix is full row rank.

pydrake.systems.primitives.IsDetectable(sys: pydrake.systems.primitives.LinearSystem, threshold: Optional[float] = None) bool

Returns true iff the system is detectable.

pydrake.systems.primitives.IsObservable(sys: pydrake.systems.primitives.LinearSystem, threshold: Optional[float] = None) bool

Returns true iff the observability matrix is full column rank.

pydrake.systems.primitives.IsStabilizable(sys: pydrake.systems.primitives.LinearSystem, threshold: Optional[float] = None) bool

Returns true iff the system is stabilizable.

pydrake.systems.primitives.Linearize(system: pydrake.systems.framework.System, context: pydrake.systems.framework.Context, input_port_index: Union[pydrake.systems.framework.InputPortSelection, pydrake.systems.framework.InputPortIndex] = <InputPortSelection.kUseFirstInputIfItExists: -2>, output_port_index: Union[pydrake.systems.framework.OutputPortSelection, pydrake.systems.framework.OutputPortIndex] = <OutputPortSelection.kUseFirstOutputIfItExists: -2>, equilibrium_check_tolerance: float = 1e-06) pydrake.systems.primitives.LinearSystem

Takes the first-order Taylor expansion of a System around a nominal operating point (defined by the Context).

This method currently supports linearizing around at most a single vector input port and at most a single vector output port. For systems with more ports, use input_port_index and output_port_index to select the input for the newly constructed system. Any additional vector input ports will be treated as constants (fixed at the value specified in context). Abstract-valued input ports must be unconnected (i.e., the system must treat the port as optional and it must be unused).

Parameter system:

The system or subsystem to linearize.

Parameter context:

Defines the nominal operating point about which the system should be linearized. See note below.

Parameter input_port_index:

A valid input port index for system or InputPortSelection. All other inputs are assumed to be fixed to the value described by the context. $*Default:* kUseFirstInputIfItExists.

Parameter output_port_index:

A valid output port index for system or an OutputPortSelection. $*Default:* kUseFirstOutputIfItExists.

Parameter equilibrium_check_tolerance:

Specifies the tolerance on ensuring that the derivative vector isZero at the nominal operating point. $*Default:* 1e-6.

Returns

A LinearSystem that approximates the original system in the vicinity of the operating point. See note below.

Raises
  • RuntimeError if the operating point is not an equilibrium point of

  • the system (within the specified tolerance)

  • RuntimeError if the system is not (only) continuous or (only)

  • discrete time with a single periodic update.

Note

All vector inputs in the system must be connected, either to the output of some upstream System within a Diagram (e.g., if system is a reference to a subsystem in a Diagram), or to a constant value using, e.g. port.FixValue(context, default_input). Any abstract inputs in the system must be unconnected (the port must be both optional and unused).

Note

The inputs, states, and outputs of the returned system are NOT the same as the original system. Denote x0,u0 as the nominal state and input defined by the Context, and y0 as the value of the output at (x0,u0), then the created systems inputs are (u-u0), states are (x-x0), and outputs are (y-y0).

Note

This method does not (yet) set the initial conditions (default nor random) of the LinearSystem based on system.

class pydrake.systems.primitives.LinearSystem

Bases: pydrake.systems.primitives.AffineSystem

A discrete OR continuous linear system.

u0→
LinearSystem
→ y0

If time_period>0.0, then the linear system will have the following discrete- time state update:

\[x[n+1] = A x[n] + B u[n],\]

or if time_period==0.0, then the linear system will have the following continuous-time state update:

\[\dot{x} = A x + B u.\]

In both cases, the system will have the output:

\[y = C x + D u,\]

where u denotes the input vector, x denotes the state vector, and y denotes the output vector.

See also

AffineSystem

See also

MatrixGain

Note

This class is templated; see LinearSystem_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.LinearSystem, A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), time_period: float = 0.0) None

Constructs a LinearSystem with a fixed set of coefficient matrices A, B,``C``, and D. The coefficient matrices must obey the following dimensions: | Matrix | Num Rows | Num Columns | |:-------:|:———–:|:-----------:| | A | num states | num states | | B | num states | num inputs | | C | num outputs | num states | | D | num outputs | num inputs |

Empty matrices are treated as zero matrices with the appropriate number of rows and columns.

Subclasses must use the protected constructor, not this one.

template pydrake.systems.primitives.LinearSystem_

Instantiations: LinearSystem_[float], LinearSystem_[AutoDiffXd], LinearSystem_[Expression]

class pydrake.systems.primitives.LinearSystem_[AutoDiffXd]

Bases: pydrake.systems.primitives.AffineSystem_[AutoDiffXd]

A discrete OR continuous linear system.

u0→
LinearSystem
→ y0

If time_period>0.0, then the linear system will have the following discrete- time state update:

\[x[n+1] = A x[n] + B u[n],\]

or if time_period==0.0, then the linear system will have the following continuous-time state update:

\[\dot{x} = A x + B u.\]

In both cases, the system will have the output:

\[y = C x + D u,\]

where u denotes the input vector, x denotes the state vector, and y denotes the output vector.

See also

AffineSystem

See also

MatrixGain

__init__(self: pydrake.systems.primitives.LinearSystem_[AutoDiffXd], A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), time_period: float = 0.0) None

Constructs a LinearSystem with a fixed set of coefficient matrices A, B,``C``, and D. The coefficient matrices must obey the following dimensions: | Matrix | Num Rows | Num Columns | |:-------:|:———–:|:-----------:| | A | num states | num states | | B | num states | num inputs | | C | num outputs | num states | | D | num outputs | num inputs |

Empty matrices are treated as zero matrices with the appropriate number of rows and columns.

Subclasses must use the protected constructor, not this one.

class pydrake.systems.primitives.LinearSystem_[Expression]

Bases: pydrake.systems.primitives.AffineSystem_[Expression]

A discrete OR continuous linear system.

u0→
LinearSystem
→ y0

If time_period>0.0, then the linear system will have the following discrete- time state update:

\[x[n+1] = A x[n] + B u[n],\]

or if time_period==0.0, then the linear system will have the following continuous-time state update:

\[\dot{x} = A x + B u.\]

In both cases, the system will have the output:

\[y = C x + D u,\]

where u denotes the input vector, x denotes the state vector, and y denotes the output vector.

See also

AffineSystem

See also

MatrixGain

__init__(self: pydrake.systems.primitives.LinearSystem_[Expression], A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), B: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), C: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous] = array([], shape=(0, 0), dtype=float64), time_period: float = 0.0) None

Constructs a LinearSystem with a fixed set of coefficient matrices A, B,``C``, and D. The coefficient matrices must obey the following dimensions: | Matrix | Num Rows | Num Columns | |:-------:|:———–:|:-----------:| | A | num states | num states | | B | num states | num inputs | | C | num outputs | num states | | D | num outputs | num inputs |

Empty matrices are treated as zero matrices with the appropriate number of rows and columns.

Subclasses must use the protected constructor, not this one.

class pydrake.systems.primitives.LinearTransformDensity

Bases: pydrake.systems.framework.LeafSystem

Performs linear transformation on the random signal w_in as w_out = A*w_in + b. The user can obtain the probability density of w_out. When the class is instantiated with autodiff scalar, the user can also obtain the gradient of the probability density of w_out.

w_in→
A→
b→
LinearTransformDensity
→ w_out
→ w_out_density

The b port can remain disconnected, in which case it defaults to zero.

A should be a matrix using a column-major order.

The user should make sure that the input port w_in is connected from the output port of a RandomSource with the same distribution. A recommended way is to use AddRandomInputs().

Warning

The code cannot verify that the distribution type of w_in matches between where w_in comes from and the w_in input port of this system. This class will quietly produce incorrect behavior if the distribution types don’t match.

See also

stochastic_systems

Note

This class is templated; see LinearTransformDensity_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.LinearTransformDensity, distribution: pydrake.common.RandomDistribution, input_size: int, output_size: int) None
Parameter distribution:

The random input w_in should satisfy this distribution.

Parameter input_size:

The dimension of the input w_in.

Parameter output_size:

The dimension of the output w_out.

Note

The matrix A will have output_size columns and input_size rows. The vector b will have output_size columns.

CalcDensity(self: pydrake.systems.primitives.LinearTransformDensity, context: pydrake.systems.framework.Context) float

Compute the density (pdf) of a sampled output w_out.

When T=AutoDiffXd, this function computes the gradient of the function density(w_out_sample). Namely given an output sample, we want to know how the probability of drawing this sample would change, when the parameters of the distribution (like A and b) change. Such information is locally expressed in the gradient. Note this is different from computing the density of the input.

Raises

RuntimeError if A is not an invertible matrix.

FixConstantA(self: pydrake.systems.primitives.LinearTransformDensity, context: pydrake.systems.framework.Context, A: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) pydrake.systems.framework.FixedInputPortValue

Fix the input port A to a constant value in a given context.

Parameter context:

The context into which A’s value is set.

Parameter A:

The value to which the port is fixed. The matrix A has num_output rows and num_input columns, note that A is column-majored.

FixConstantB(self: pydrake.systems.primitives.LinearTransformDensity, context: pydrake.systems.framework.Context, b: numpy.ndarray[numpy.float64[m, 1]]) pydrake.systems.framework.FixedInputPortValue

Fix the input port b to a constant value in a given context.

Parameter context:

The context into which b’s value is set.

Parameter b:

The value to which the port is fixed. The vector b has num_output rows.

get_distribution(self: pydrake.systems.primitives.LinearTransformDensity) pydrake.common.RandomDistribution

Gets the random distribution type.

get_input_port_A(self: pydrake.systems.primitives.LinearTransformDensity) pydrake.systems.framework.InputPort

Gets the input port for A.

get_input_port_b(self: pydrake.systems.primitives.LinearTransformDensity) pydrake.systems.framework.InputPort

Gets the input port for b.

get_input_port_w_in(self: pydrake.systems.primitives.LinearTransformDensity) pydrake.systems.framework.InputPort

Gets the input port for w_in.

get_output_port_w_out(self: pydrake.systems.primitives.LinearTransformDensity) pydrake.systems.framework.OutputPort
get_output_port_w_out_density(self: pydrake.systems.primitives.LinearTransformDensity) pydrake.systems.framework.OutputPort
template pydrake.systems.primitives.LinearTransformDensity_

Instantiations: LinearTransformDensity_[float], LinearTransformDensity_[AutoDiffXd]

class pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

Performs linear transformation on the random signal w_in as w_out = A*w_in + b. The user can obtain the probability density of w_out. When the class is instantiated with autodiff scalar, the user can also obtain the gradient of the probability density of w_out.

w_in→
A→
b→
LinearTransformDensity
→ w_out
→ w_out_density

The b port can remain disconnected, in which case it defaults to zero.

A should be a matrix using a column-major order.

The user should make sure that the input port w_in is connected from the output port of a RandomSource with the same distribution. A recommended way is to use AddRandomInputs().

Warning

The code cannot verify that the distribution type of w_in matches between where w_in comes from and the w_in input port of this system. This class will quietly produce incorrect behavior if the distribution types don’t match.

See also

stochastic_systems

__init__(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd], distribution: pydrake.common.RandomDistribution, input_size: int, output_size: int) None
Parameter distribution:

The random input w_in should satisfy this distribution.

Parameter input_size:

The dimension of the input w_in.

Parameter output_size:

The dimension of the output w_out.

Note

The matrix A will have output_size columns and input_size rows. The vector b will have output_size columns.

CalcDensity(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.autodiffutils.AutoDiffXd

Compute the density (pdf) of a sampled output w_out.

When T=AutoDiffXd, this function computes the gradient of the function density(w_out_sample). Namely given an output sample, we want to know how the probability of drawing this sample would change, when the parameters of the distribution (like A and b) change. Such information is locally expressed in the gradient. Note this is different from computing the density of the input.

Raises

RuntimeError if A is not an invertible matrix.

FixConstantA(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], A: numpy.ndarray[object[m, n], flags.f_contiguous]) pydrake.systems.framework.FixedInputPortValue

Fix the input port A to a constant value in a given context.

Parameter context:

The context into which A’s value is set.

Parameter A:

The value to which the port is fixed. The matrix A has num_output rows and num_input columns, note that A is column-majored.

FixConstantB(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], b: numpy.ndarray[object[m, 1]]) pydrake.systems.framework.FixedInputPortValue

Fix the input port b to a constant value in a given context.

Parameter context:

The context into which b’s value is set.

Parameter b:

The value to which the port is fixed. The vector b has num_output rows.

get_distribution(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]) pydrake.common.RandomDistribution

Gets the random distribution type.

get_input_port_A(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]) pydrake.systems.framework.InputPort_[AutoDiffXd]

Gets the input port for A.

get_input_port_b(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]) pydrake.systems.framework.InputPort_[AutoDiffXd]

Gets the input port for b.

get_input_port_w_in(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]) pydrake.systems.framework.InputPort_[AutoDiffXd]

Gets the input port for w_in.

get_output_port_w_out(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]) pydrake.systems.framework.OutputPort_[AutoDiffXd]
get_output_port_w_out_density(self: pydrake.systems.primitives.LinearTransformDensity_[AutoDiffXd]) pydrake.systems.framework.OutputPort_[AutoDiffXd]
pydrake.systems.primitives.LogVectorOutput(*args, **kwargs)

Overloaded function.

  1. LogVectorOutput(src: pydrake.systems.framework.OutputPort, builder: pydrake.systems.framework.DiagramBuilder, publish_period: float = 0.0) -> pydrake.systems.primitives.VectorLogSink

LogVectorOutput provides a convenience function for adding a VectorLogSink, initialized to the correct size, and connected to an output in a DiagramBuilder. This overload supports the default set of publish triggers. See vector_log_sink_default_triggers “default triggers description”.

Parameter src:

the output port to attach logging to.

Parameter builder:

the diagram builder.

Parameter publish_period:

Period that messages will be published (optional). If the publish period is zero, VectorLogSink will use per-step publishing instead; see LeafSystem::DeclarePerStepPublishEvent().

Precondition:

publish_period is non-negative.

  1. LogVectorOutput(src: pydrake.systems.framework.OutputPort, builder: pydrake.systems.framework.DiagramBuilder, publish_triggers: set[pydrake.systems.framework.TriggerType], publish_period: float = 0.0) -> pydrake.systems.primitives.VectorLogSink

LogVectorOutput provides a convenience function for adding a VectorLogSink, initialized to the correct size, and connected to an output in a DiagramBuilder. This overload supports the full variety of publish trigger behavior.

Parameter src:

the output port to attach logging to.

Parameter builder:

the diagram builder.

Parameter publish_triggers:

Set of triggers that determine when messages will be published. Supported TriggerTypes are {kForced, kPeriodic, kPerStep}. Will throw an error if empty or if unsupported types are provided.

Parameter publish_period:

Period that messages will be published (optional). publish_period should only be non-zero if one of the publish_triggers is kPeriodic.

Precondition:

publish_period is non-negative.

Precondition:

publish_period > 0 if and only if publish_triggers contains kPeriodic.

  1. LogVectorOutput(src: pydrake.systems.framework.OutputPort_[AutoDiffXd], builder: pydrake.systems.framework.DiagramBuilder_[AutoDiffXd], publish_period: float = 0.0) -> pydrake.systems.primitives.VectorLogSink_[AutoDiffXd]

LogVectorOutput provides a convenience function for adding a VectorLogSink, initialized to the correct size, and connected to an output in a DiagramBuilder. This overload supports the default set of publish triggers. See vector_log_sink_default_triggers “default triggers description”.

Parameter src:

the output port to attach logging to.

Parameter builder:

the diagram builder.

Parameter publish_period:

Period that messages will be published (optional). If the publish period is zero, VectorLogSink will use per-step publishing instead; see LeafSystem::DeclarePerStepPublishEvent().

Precondition:

publish_period is non-negative.

  1. LogVectorOutput(src: pydrake.systems.framework.OutputPort_[AutoDiffXd], builder: pydrake.systems.framework.DiagramBuilder_[AutoDiffXd], publish_triggers: set[pydrake.systems.framework.TriggerType], publish_period: float = 0.0) -> pydrake.systems.primitives.VectorLogSink_[AutoDiffXd]

LogVectorOutput provides a convenience function for adding a VectorLogSink, initialized to the correct size, and connected to an output in a DiagramBuilder. This overload supports the full variety of publish trigger behavior.

Parameter src:

the output port to attach logging to.

Parameter builder:

the diagram builder.

Parameter publish_triggers:

Set of triggers that determine when messages will be published. Supported TriggerTypes are {kForced, kPeriodic, kPerStep}. Will throw an error if empty or if unsupported types are provided.

Parameter publish_period:

Period that messages will be published (optional). publish_period should only be non-zero if one of the publish_triggers is kPeriodic.

Precondition:

publish_period is non-negative.

Precondition:

publish_period > 0 if and only if publish_triggers contains kPeriodic.

  1. LogVectorOutput(src: pydrake.systems.framework.OutputPort_[Expression], builder: pydrake.systems.framework.DiagramBuilder_[Expression], publish_period: float = 0.0) -> pydrake.systems.primitives.VectorLogSink_[Expression]

LogVectorOutput provides a convenience function for adding a VectorLogSink, initialized to the correct size, and connected to an output in a DiagramBuilder. This overload supports the default set of publish triggers. See vector_log_sink_default_triggers “default triggers description”.

Parameter src:

the output port to attach logging to.

Parameter builder:

the diagram builder.

Parameter publish_period:

Period that messages will be published (optional). If the publish period is zero, VectorLogSink will use per-step publishing instead; see LeafSystem::DeclarePerStepPublishEvent().

Precondition:

publish_period is non-negative.

  1. LogVectorOutput(src: pydrake.systems.framework.OutputPort_[Expression], builder: pydrake.systems.framework.DiagramBuilder_[Expression], publish_triggers: set[pydrake.systems.framework.TriggerType], publish_period: float = 0.0) -> pydrake.systems.primitives.VectorLogSink_[Expression]

LogVectorOutput provides a convenience function for adding a VectorLogSink, initialized to the correct size, and connected to an output in a DiagramBuilder. This overload supports the full variety of publish trigger behavior.

Parameter src:

the output port to attach logging to.

Parameter builder:

the diagram builder.

Parameter publish_triggers:

Set of triggers that determine when messages will be published. Supported TriggerTypes are {kForced, kPeriodic, kPerStep}. Will throw an error if empty or if unsupported types are provided.

Parameter publish_period:

Period that messages will be published (optional). publish_period should only be non-zero if one of the publish_triggers is kPeriodic.

Precondition:

publish_period is non-negative.

Precondition:

publish_period > 0 if and only if publish_triggers contains kPeriodic.

class pydrake.systems.primitives.MatrixGain

Bases: pydrake.systems.primitives.LinearSystem

A system that specializes LinearSystem by setting coefficient matrices A, B, and C to all be zero. Thus, the only non-zero coefficient matrix is D. Specifically, given an input signal u and a state x, the output of this system, y, is:

\[y = D u\]

name: MatrixGain input_ports: - u0 output_ports: - y0

See also

AffineSystem

See also

LinearSystem

Note

This class is templated; see MatrixGain_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.MatrixGain, D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

A constructor where the gain matrix D is D.

template pydrake.systems.primitives.MatrixGain_

Instantiations: MatrixGain_[float], MatrixGain_[AutoDiffXd], MatrixGain_[Expression]

class pydrake.systems.primitives.MatrixGain_[AutoDiffXd]

Bases: pydrake.systems.primitives.LinearSystem_[AutoDiffXd]

A system that specializes LinearSystem by setting coefficient matrices A, B, and C to all be zero. Thus, the only non-zero coefficient matrix is D. Specifically, given an input signal u and a state x, the output of this system, y, is:

\[y = D u\]

name: MatrixGain input_ports: - u0 output_ports: - y0

See also

AffineSystem

See also

LinearSystem

__init__(self: pydrake.systems.primitives.MatrixGain_[AutoDiffXd], D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

A constructor where the gain matrix D is D.

class pydrake.systems.primitives.MatrixGain_[Expression]

Bases: pydrake.systems.primitives.LinearSystem_[Expression]

A system that specializes LinearSystem by setting coefficient matrices A, B, and C to all be zero. Thus, the only non-zero coefficient matrix is D. Specifically, given an input signal u and a state x, the output of this system, y, is:

\[y = D u\]

name: MatrixGain input_ports: - u0 output_ports: - y0

See also

AffineSystem

See also

LinearSystem

__init__(self: pydrake.systems.primitives.MatrixGain_[Expression], D: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

A constructor where the gain matrix D is D.

class pydrake.systems.primitives.MultilayerPerceptron

Bases: pydrake.systems.framework.LeafSystem

The MultilayerPerceptron (MLP) is one of the most common forms of neural networks used in reinforcement learning (RL) today. This implementation provides a System interface to distinguish between the network’s inputs and outputs (via ports), and the parameters, which are stored in the Context.

Each layer of the network is implemented as xₙ₊₁ = σ(Wₙxₙ+bₙ), where xₙ is the output of the preceding layer, W are the weights, b are the biases, and σ() is the activation function. We additionally use the shorthand x to denote the input layer and y to denote the output layer: y=xₘ for an m-layer network.

Note: For very large-scale neural network implementations, consider using a GPU-accelerated machine learning library like PyTorch, TensorFlow, or JAX. But most MLPs used in controls / RL are actually quite small. For those networks, the cost of transferring values/gradients from Drake to e.g. PyTorch is likely not worth the benefits. Another possible workflow might be to train a network in PyTorch, but then to copy the weights into an instance of this class for simulation.

x→
MultilayerPerceptron
→ y

Note

This class is templated; see MultilayerPerceptron_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron, layers: list[int], activation_type: pydrake.systems.primitives.PerceptronActivationType = <PerceptronActivationType.kTanh: 2>) -> None

Constructs the MLP with the same activation type for every layer (except the output).

Parameter layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the number of inputs, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies an activation function, σ(), used in every hidden layer of the network. kIdentity will be used for the output.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron, layers: list[int], activation_types: list[pydrake.systems.primitives.PerceptronActivationType]) -> None

Constructs the MLP with an activation_type specified for each non-input layer.

Parameter layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the number of inputs, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies the activation function, σ(), used in each non-input layer of the network (including the last layer).

activation_type should have one less element than layers.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron, use_sin_cos_for_input: list[bool], remaining_layers: list[int], activation_types: list[pydrake.systems.primitives.PerceptronActivationType]) -> None

Constructs the MLP with an additional option to transform the input vector so that the function is periodic in 2π.

For instance, for a rotary joint on a robot, this could be used to apply the transform [x, y] => [sin x, cos x, y]. This would be accomplished by passing use_sin_cos_for_input = [true, false].

Note that when this transformation is applied, num_inputs() != layers()[0]. num_inputs() == 2 != layers()[0] == 3.

Parameter use_sin_cos_for_input:

is a boolean vector that determines whether the sin/cos transform is applied to each element.

Parameter remaining_layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the size of the first hidden layer, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies the activation function, σ(), used in each non-input layer of the network (including the last layer).

activation_type should have the same number of elements as remaining_layers.

activation_type(self: pydrake.systems.primitives.MultilayerPerceptron, layer: int) pydrake.systems.primitives.PerceptronActivationType

Returns the type of the activation function, σ(), used in the MLP.

Backpropagation(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, X: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous], loss: Callable[[numpy.ndarray[numpy.float64[m, n], flags.f_contiguous], Optional[numpy.ndarray[numpy.float64[m, n], flags.writeable, flags.f_contiguous]]], float], dloss_dparams: Optional[numpy.ndarray[numpy.float64[m, 1], flags.writeable]]) float

Implements the Backpropagation algorithm for the MLP to compute the gradients of a scalar loss function with respect to the network parameters.

Note: The class uses the System Cache to minimize the number of dynamic memory allocations for repeated calls to this function with the same sized X. Changing the batch size between calls to this method or BatchOutput requires memory allocations.

Parameter X:

is a batch input, with one input per column.

Parameter loss:

is a scalar loss function, where Y is the columnwise batch output of the network. It should return the scalar loss and set dloss_dY, the derivatives of the loss with respect to Y, which is pre-allocated to be the same size as Y.

Parameter dloss_dparams:

are the gradients computed. We take the storage as an input argument to avoid memory allocations inside the algorithm.

Returns

the calculated loss.

Note: It is expected that this algorithm will be used with T=double. It uses analytical gradients; AutoDiffXd is not required.

BackpropagationMeanSquaredError(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, X: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous], Y_desired: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous], dloss_dparams: Optional[numpy.ndarray[numpy.float64[m, 1], flags.writeable]]) float

Calls Backpropagation with the mean-squared error loss function: loss = 1/N ∑ᵢ |yᵢ−yᵢᵈ|², where yᵈ is the desired values for y. See Backpropagation for details.

BatchOutput(*args, **kwargs)

Overloaded function.

  1. BatchOutput(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, X: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous], Y: Optional[numpy.ndarray[numpy.float64[m, n], flags.writeable, flags.f_contiguous]], dYdX: Optional[numpy.ndarray[numpy.float64[m, n], flags.writeable, flags.f_contiguous]] = None) -> None

Evaluates the batch output for the MLP with a batch input vector. Each column of X represents an input, and each column of Y will be assigned the corresponding output.

If the output layer of the network has size 1 (scalar output), and dYdX != nullptr, then dYdX is populated with the batch gradients of the scalar output Y relative to the input X: the (i,j)th element represents the gradient dY(0,j) / dX(i,j).

Note: In python, use numpy.asfortranarray() to allocate the writeable matrices Y and (if needed) dYdX.

This methods shares the cache with Backpropagation. If the size of X changes here or in Backpropagation, it may force dynamic memory allocations.

Raises
  • RuntimeError if dYdX != nullptr and the network has more than one

  • output.

  1. BatchOutput(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, X: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) -> numpy.ndarray[numpy.float64[m, n]]

Evaluates the batch output for the MLP with a batch input vector. See BatchOutput(context, X, Y) for a version that can avoid dynamic memory allocations of Y (e.g. if this is used inside an optimization loop).

GetBiases(*args, **kwargs)

Overloaded function.

  1. GetBiases(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, layer: int) -> numpy.ndarray[numpy.float64[m, 1]]

Returns the biases used in the mapping from layer to layer+1.

  1. GetBiases(self: pydrake.systems.primitives.MultilayerPerceptron, params: numpy.ndarray[numpy.float64[m, 1]], layer: int) -> numpy.ndarray[numpy.float64[m, 1]]

Returns the biases in params used in the mapping from layer to layer+1.

GetMutableParameters(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context) numpy.ndarray[numpy.float64[m, 1], flags.writeable]

Returns a mutable reference to all of the parameters (weights and biases) as a single vector.

GetParameters(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context) numpy.ndarray[numpy.float64[m, 1]]

Returns a reference to all of the parameters (weights and biases) as a single vector. Use GetWeights and GetBiases to extract the components.

GetWeights(*args, **kwargs)

Overloaded function.

  1. GetWeights(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, layer: int) -> numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]

Returns the weights used in the mapping from layer to layer+1.

  1. GetWeights(self: pydrake.systems.primitives.MultilayerPerceptron, params: numpy.ndarray[numpy.float64[m, 1]], layer: int) -> numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]

Returns the weights in params used in the mapping from layer to layer+1.

layers(self: pydrake.systems.primitives.MultilayerPerceptron) list[int]

Returns the number of elements in each layer of the network.

num_parameters(self: pydrake.systems.primitives.MultilayerPerceptron) int

Returns the total number of parameters in the network, including all weights and biases.

SetBiases(*args, **kwargs)

Overloaded function.

  1. SetBiases(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, layer: int, b: numpy.ndarray[numpy.float64[m, 1]]) -> None

Sets the biases in the context used in the mapping from layer to layer+1.

  1. SetBiases(self: pydrake.systems.primitives.MultilayerPerceptron, params: Optional[numpy.ndarray[numpy.float64[m, 1], flags.writeable]], layer: int, b: numpy.ndarray[numpy.float64[m, 1]]) -> None

Sets the biases in params used in the mapping from layer to layer+1.

SetParameters(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, params: numpy.ndarray[numpy.float64[m, 1]]) None

Sets all of the parameters in the network (weights and biases) using a single vector. Use SetWeights and SetBiases to extract the components.

SetWeights(*args, **kwargs)

Overloaded function.

  1. SetWeights(self: pydrake.systems.primitives.MultilayerPerceptron, context: pydrake.systems.framework.Context, layer: int, W: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) -> None

Sets the weights in the context used in the mapping from layer to layer+1.

  1. SetWeights(self: pydrake.systems.primitives.MultilayerPerceptron, params: Optional[numpy.ndarray[numpy.float64[m, 1], flags.writeable]], layer: int, W: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) -> None

Sets the weights in params used in the mapping from layer to layer+1.

template pydrake.systems.primitives.MultilayerPerceptron_

Instantiations: MultilayerPerceptron_[float], MultilayerPerceptron_[AutoDiffXd], MultilayerPerceptron_[Expression]

class pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

The MultilayerPerceptron (MLP) is one of the most common forms of neural networks used in reinforcement learning (RL) today. This implementation provides a System interface to distinguish between the network’s inputs and outputs (via ports), and the parameters, which are stored in the Context.

Each layer of the network is implemented as xₙ₊₁ = σ(Wₙxₙ+bₙ), where xₙ is the output of the preceding layer, W are the weights, b are the biases, and σ() is the activation function. We additionally use the shorthand x to denote the input layer and y to denote the output layer: y=xₘ for an m-layer network.

Note: For very large-scale neural network implementations, consider using a GPU-accelerated machine learning library like PyTorch, TensorFlow, or JAX. But most MLPs used in controls / RL are actually quite small. For those networks, the cost of transferring values/gradients from Drake to e.g. PyTorch is likely not worth the benefits. Another possible workflow might be to train a network in PyTorch, but then to copy the weights into an instance of this class for simulation.

x→
MultilayerPerceptron
→ y
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], layers: list[int], activation_type: pydrake.systems.primitives.PerceptronActivationType = <PerceptronActivationType.kTanh: 2>) -> None

Constructs the MLP with the same activation type for every layer (except the output).

Parameter layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the number of inputs, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies an activation function, σ(), used in every hidden layer of the network. kIdentity will be used for the output.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], layers: list[int], activation_types: list[pydrake.systems.primitives.PerceptronActivationType]) -> None

Constructs the MLP with an activation_type specified for each non-input layer.

Parameter layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the number of inputs, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies the activation function, σ(), used in each non-input layer of the network (including the last layer).

activation_type should have one less element than layers.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], use_sin_cos_for_input: list[bool], remaining_layers: list[int], activation_types: list[pydrake.systems.primitives.PerceptronActivationType]) -> None

Constructs the MLP with an additional option to transform the input vector so that the function is periodic in 2π.

For instance, for a rotary joint on a robot, this could be used to apply the transform [x, y] => [sin x, cos x, y]. This would be accomplished by passing use_sin_cos_for_input = [true, false].

Note that when this transformation is applied, num_inputs() != layers()[0]. num_inputs() == 2 != layers()[0] == 3.

Parameter use_sin_cos_for_input:

is a boolean vector that determines whether the sin/cos transform is applied to each element.

Parameter remaining_layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the size of the first hidden layer, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies the activation function, σ(), used in each non-input layer of the network (including the last layer).

activation_type should have the same number of elements as remaining_layers.

activation_type(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], layer: int) pydrake.systems.primitives.PerceptronActivationType

Returns the type of the activation function, σ(), used in the MLP.

Backpropagation(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], X: numpy.ndarray[object[m, n], flags.f_contiguous], loss: Callable[[numpy.ndarray[object[m, n], flags.f_contiguous], Optional[numpy.ndarray[object[m, n], flags.writeable, flags.f_contiguous]]], pydrake.autodiffutils.AutoDiffXd], dloss_dparams: Optional[numpy.ndarray[object[m, 1], flags.writeable]]) pydrake.autodiffutils.AutoDiffXd

Implements the Backpropagation algorithm for the MLP to compute the gradients of a scalar loss function with respect to the network parameters.

Note: The class uses the System Cache to minimize the number of dynamic memory allocations for repeated calls to this function with the same sized X. Changing the batch size between calls to this method or BatchOutput requires memory allocations.

Parameter X:

is a batch input, with one input per column.

Parameter loss:

is a scalar loss function, where Y is the columnwise batch output of the network. It should return the scalar loss and set dloss_dY, the derivatives of the loss with respect to Y, which is pre-allocated to be the same size as Y.

Parameter dloss_dparams:

are the gradients computed. We take the storage as an input argument to avoid memory allocations inside the algorithm.

Returns

the calculated loss.

Note: It is expected that this algorithm will be used with T=double. It uses analytical gradients; AutoDiffXd is not required.

BackpropagationMeanSquaredError(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], X: numpy.ndarray[object[m, n], flags.f_contiguous], Y_desired: numpy.ndarray[object[m, n], flags.f_contiguous], dloss_dparams: Optional[numpy.ndarray[object[m, 1], flags.writeable]]) pydrake.autodiffutils.AutoDiffXd

Calls Backpropagation with the mean-squared error loss function: loss = 1/N ∑ᵢ |yᵢ−yᵢᵈ|², where yᵈ is the desired values for y. See Backpropagation for details.

BatchOutput(*args, **kwargs)

Overloaded function.

  1. BatchOutput(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], X: numpy.ndarray[object[m, n], flags.f_contiguous], Y: Optional[numpy.ndarray[object[m, n], flags.writeable, flags.f_contiguous]], dYdX: Optional[numpy.ndarray[object[m, n], flags.writeable, flags.f_contiguous]] = None) -> None

Evaluates the batch output for the MLP with a batch input vector. Each column of X represents an input, and each column of Y will be assigned the corresponding output.

If the output layer of the network has size 1 (scalar output), and dYdX != nullptr, then dYdX is populated with the batch gradients of the scalar output Y relative to the input X: the (i,j)th element represents the gradient dY(0,j) / dX(i,j).

Note: In python, use numpy.asfortranarray() to allocate the writeable matrices Y and (if needed) dYdX.

This methods shares the cache with Backpropagation. If the size of X changes here or in Backpropagation, it may force dynamic memory allocations.

Raises
  • RuntimeError if dYdX != nullptr and the network has more than one

  • output.

  1. BatchOutput(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], X: numpy.ndarray[object[m, n], flags.f_contiguous]) -> numpy.ndarray[object[m, n]]

Evaluates the batch output for the MLP with a batch input vector. See BatchOutput(context, X, Y) for a version that can avoid dynamic memory allocations of Y (e.g. if this is used inside an optimization loop).

GetBiases(*args, **kwargs)

Overloaded function.

  1. GetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], layer: int) -> numpy.ndarray[object[m, 1]]

Returns the biases used in the mapping from layer to layer+1.

  1. GetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], params: numpy.ndarray[object[m, 1]], layer: int) -> numpy.ndarray[object[m, 1]]

Returns the biases in params used in the mapping from layer to layer+1.

GetMutableParameters(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) numpy.ndarray[object[m, 1], flags.writeable]

Returns a mutable reference to all of the parameters (weights and biases) as a single vector.

GetParameters(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) numpy.ndarray[object[m, 1]]

Returns a reference to all of the parameters (weights and biases) as a single vector. Use GetWeights and GetBiases to extract the components.

GetWeights(*args, **kwargs)

Overloaded function.

  1. GetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], layer: int) -> numpy.ndarray[object[m, n], flags.f_contiguous]

Returns the weights used in the mapping from layer to layer+1.

  1. GetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], params: numpy.ndarray[object[m, 1]], layer: int) -> numpy.ndarray[object[m, n], flags.f_contiguous]

Returns the weights in params used in the mapping from layer to layer+1.

layers(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd]) list[int]

Returns the number of elements in each layer of the network.

num_parameters(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd]) int

Returns the total number of parameters in the network, including all weights and biases.

SetBiases(*args, **kwargs)

Overloaded function.

  1. SetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], layer: int, b: numpy.ndarray[object[m, 1]]) -> None

Sets the biases in the context used in the mapping from layer to layer+1.

  1. SetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], params: Optional[numpy.ndarray[object[m, 1], flags.writeable]], layer: int, b: numpy.ndarray[object[m, 1]]) -> None

Sets the biases in params used in the mapping from layer to layer+1.

SetParameters(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], params: numpy.ndarray[object[m, 1]]) None

Sets all of the parameters in the network (weights and biases) using a single vector. Use SetWeights and SetBiases to extract the components.

SetWeights(*args, **kwargs)

Overloaded function.

  1. SetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], layer: int, W: numpy.ndarray[object[m, n], flags.f_contiguous]) -> None

Sets the weights in the context used in the mapping from layer to layer+1.

  1. SetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[AutoDiffXd], params: Optional[numpy.ndarray[object[m, 1], flags.writeable]], layer: int, W: numpy.ndarray[object[m, n], flags.f_contiguous]) -> None

Sets the weights in params used in the mapping from layer to layer+1.

class pydrake.systems.primitives.MultilayerPerceptron_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

The MultilayerPerceptron (MLP) is one of the most common forms of neural networks used in reinforcement learning (RL) today. This implementation provides a System interface to distinguish between the network’s inputs and outputs (via ports), and the parameters, which are stored in the Context.

Each layer of the network is implemented as xₙ₊₁ = σ(Wₙxₙ+bₙ), where xₙ is the output of the preceding layer, W are the weights, b are the biases, and σ() is the activation function. We additionally use the shorthand x to denote the input layer and y to denote the output layer: y=xₘ for an m-layer network.

Note: For very large-scale neural network implementations, consider using a GPU-accelerated machine learning library like PyTorch, TensorFlow, or JAX. But most MLPs used in controls / RL are actually quite small. For those networks, the cost of transferring values/gradients from Drake to e.g. PyTorch is likely not worth the benefits. Another possible workflow might be to train a network in PyTorch, but then to copy the weights into an instance of this class for simulation.

x→
MultilayerPerceptron
→ y
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], layers: list[int], activation_type: pydrake.systems.primitives.PerceptronActivationType = <PerceptronActivationType.kTanh: 2>) -> None

Constructs the MLP with the same activation type for every layer (except the output).

Parameter layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the number of inputs, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies an activation function, σ(), used in every hidden layer of the network. kIdentity will be used for the output.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], layers: list[int], activation_types: list[pydrake.systems.primitives.PerceptronActivationType]) -> None

Constructs the MLP with an activation_type specified for each non-input layer.

Parameter layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the number of inputs, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies the activation function, σ(), used in each non-input layer of the network (including the last layer).

activation_type should have one less element than layers.

  1. __init__(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], use_sin_cos_for_input: list[bool], remaining_layers: list[int], activation_types: list[pydrake.systems.primitives.PerceptronActivationType]) -> None

Constructs the MLP with an additional option to transform the input vector so that the function is periodic in 2π.

For instance, for a rotary joint on a robot, this could be used to apply the transform [x, y] => [sin x, cos x, y]. This would be accomplished by passing use_sin_cos_for_input = [true, false].

Note that when this transformation is applied, num_inputs() != layers()[0]. num_inputs() == 2 != layers()[0] == 3.

Parameter use_sin_cos_for_input:

is a boolean vector that determines whether the sin/cos transform is applied to each element.

Parameter remaining_layers:

is the number of elements in each layer of the network (the activation function does not count as an additional layer). The first element specifies the size of the first hidden layer, and the last layer specifies the number of outputs.

Parameter activation_type:

specifies the activation function, σ(), used in each non-input layer of the network (including the last layer).

activation_type should have the same number of elements as remaining_layers.

activation_type(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], layer: int) pydrake.systems.primitives.PerceptronActivationType

Returns the type of the activation function, σ(), used in the MLP.

Backpropagation(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], X: numpy.ndarray[object[m, n], flags.f_contiguous], loss: Callable[[numpy.ndarray[object[m, n], flags.f_contiguous], Optional[numpy.ndarray[object[m, n], flags.writeable, flags.f_contiguous]]], pydrake.symbolic.Expression], dloss_dparams: Optional[numpy.ndarray[object[m, 1], flags.writeable]]) pydrake.symbolic.Expression

Implements the Backpropagation algorithm for the MLP to compute the gradients of a scalar loss function with respect to the network parameters.

Note: The class uses the System Cache to minimize the number of dynamic memory allocations for repeated calls to this function with the same sized X. Changing the batch size between calls to this method or BatchOutput requires memory allocations.

Parameter X:

is a batch input, with one input per column.

Parameter loss:

is a scalar loss function, where Y is the columnwise batch output of the network. It should return the scalar loss and set dloss_dY, the derivatives of the loss with respect to Y, which is pre-allocated to be the same size as Y.

Parameter dloss_dparams:

are the gradients computed. We take the storage as an input argument to avoid memory allocations inside the algorithm.

Returns

the calculated loss.

Note: It is expected that this algorithm will be used with T=double. It uses analytical gradients; AutoDiffXd is not required.

BackpropagationMeanSquaredError(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], X: numpy.ndarray[object[m, n], flags.f_contiguous], Y_desired: numpy.ndarray[object[m, n], flags.f_contiguous], dloss_dparams: Optional[numpy.ndarray[object[m, 1], flags.writeable]]) pydrake.symbolic.Expression

Calls Backpropagation with the mean-squared error loss function: loss = 1/N ∑ᵢ |yᵢ−yᵢᵈ|², where yᵈ is the desired values for y. See Backpropagation for details.

BatchOutput(*args, **kwargs)

Overloaded function.

  1. BatchOutput(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], X: numpy.ndarray[object[m, n], flags.f_contiguous], Y: Optional[numpy.ndarray[object[m, n], flags.writeable, flags.f_contiguous]], dYdX: Optional[numpy.ndarray[object[m, n], flags.writeable, flags.f_contiguous]] = None) -> None

Evaluates the batch output for the MLP with a batch input vector. Each column of X represents an input, and each column of Y will be assigned the corresponding output.

If the output layer of the network has size 1 (scalar output), and dYdX != nullptr, then dYdX is populated with the batch gradients of the scalar output Y relative to the input X: the (i,j)th element represents the gradient dY(0,j) / dX(i,j).

Note: In python, use numpy.asfortranarray() to allocate the writeable matrices Y and (if needed) dYdX.

This methods shares the cache with Backpropagation. If the size of X changes here or in Backpropagation, it may force dynamic memory allocations.

Raises
  • RuntimeError if dYdX != nullptr and the network has more than one

  • output.

  1. BatchOutput(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], X: numpy.ndarray[object[m, n], flags.f_contiguous]) -> numpy.ndarray[object[m, n]]

Evaluates the batch output for the MLP with a batch input vector. See BatchOutput(context, X, Y) for a version that can avoid dynamic memory allocations of Y (e.g. if this is used inside an optimization loop).

GetBiases(*args, **kwargs)

Overloaded function.

  1. GetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], layer: int) -> numpy.ndarray[object[m, 1]]

Returns the biases used in the mapping from layer to layer+1.

  1. GetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], params: numpy.ndarray[object[m, 1]], layer: int) -> numpy.ndarray[object[m, 1]]

Returns the biases in params used in the mapping from layer to layer+1.

GetMutableParameters(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression]) numpy.ndarray[object[m, 1], flags.writeable]

Returns a mutable reference to all of the parameters (weights and biases) as a single vector.

GetParameters(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression]) numpy.ndarray[object[m, 1]]

Returns a reference to all of the parameters (weights and biases) as a single vector. Use GetWeights and GetBiases to extract the components.

GetWeights(*args, **kwargs)

Overloaded function.

  1. GetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], layer: int) -> numpy.ndarray[object[m, n], flags.f_contiguous]

Returns the weights used in the mapping from layer to layer+1.

  1. GetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], params: numpy.ndarray[object[m, 1]], layer: int) -> numpy.ndarray[object[m, n], flags.f_contiguous]

Returns the weights in params used in the mapping from layer to layer+1.

layers(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression]) list[int]

Returns the number of elements in each layer of the network.

num_parameters(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression]) int

Returns the total number of parameters in the network, including all weights and biases.

SetBiases(*args, **kwargs)

Overloaded function.

  1. SetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], layer: int, b: numpy.ndarray[object[m, 1]]) -> None

Sets the biases in the context used in the mapping from layer to layer+1.

  1. SetBiases(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], params: Optional[numpy.ndarray[object[m, 1], flags.writeable]], layer: int, b: numpy.ndarray[object[m, 1]]) -> None

Sets the biases in params used in the mapping from layer to layer+1.

SetParameters(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], params: numpy.ndarray[object[m, 1]]) None

Sets all of the parameters in the network (weights and biases) using a single vector. Use SetWeights and SetBiases to extract the components.

SetWeights(*args, **kwargs)

Overloaded function.

  1. SetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], context: pydrake.systems.framework.Context_[Expression], layer: int, W: numpy.ndarray[object[m, n], flags.f_contiguous]) -> None

Sets the weights in the context used in the mapping from layer to layer+1.

  1. SetWeights(self: pydrake.systems.primitives.MultilayerPerceptron_[Expression], params: Optional[numpy.ndarray[object[m, 1], flags.writeable]], layer: int, W: numpy.ndarray[object[m, n], flags.f_contiguous]) -> None

Sets the weights in params used in the mapping from layer to layer+1.

class pydrake.systems.primitives.Multiplexer

Bases: pydrake.systems.framework.LeafSystem

This system combines multiple vector-valued inputs into a vector-valued output. The input to this system directly feeds through to its output.

u0→
...→
u(N-1)→
Multiplexer
→ y0

Note

This class is templated; see Multiplexer_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Multiplexer, num_scalar_inputs: int) -> None

Constructs a Multiplexer with num_scalar_inputs scalar-valued input ports, and one vector-valued output port of size num_scalar_inputs.

u0→
...→
u(num_scalar_inputs - 1)→
Multiplexer
→ y0
  1. __init__(self: pydrake.systems.primitives.Multiplexer, input_sizes: list[int]) -> None

Constructs a Multiplexer with input_sizes.size() vector-valued input ports where the i-th input has size input_sizes[i], and one vector- valued output port of size sum(input_sizes).

u0→
...→
u(input_sizes.size() - 1)→
Multiplexer
→ y0
  1. __init__(self: pydrake.systems.primitives.Multiplexer, model_vector: pydrake.systems.framework.BasicVector) -> None

Constructs a Multiplexer with model_vector.size() scalar-valued inputs and one vector-valued output port whose size equals the size of model_vector. In addition, the output type derives from that of model_vector.

Note

Objects created using this constructor overload do not support system scalar conversion. See system_scalar_conversion.

template pydrake.systems.primitives.Multiplexer_

Instantiations: Multiplexer_[float], Multiplexer_[AutoDiffXd], Multiplexer_[Expression]

class pydrake.systems.primitives.Multiplexer_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

This system combines multiple vector-valued inputs into a vector-valued output. The input to this system directly feeds through to its output.

u0→
...→
u(N-1)→
Multiplexer
→ y0
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Multiplexer_[AutoDiffXd], num_scalar_inputs: int) -> None

Constructs a Multiplexer with num_scalar_inputs scalar-valued input ports, and one vector-valued output port of size num_scalar_inputs.

u0→
...→
u(num_scalar_inputs - 1)→
Multiplexer
→ y0
  1. __init__(self: pydrake.systems.primitives.Multiplexer_[AutoDiffXd], input_sizes: list[int]) -> None

Constructs a Multiplexer with input_sizes.size() vector-valued input ports where the i-th input has size input_sizes[i], and one vector- valued output port of size sum(input_sizes).

u0→
...→
u(input_sizes.size() - 1)→
Multiplexer
→ y0
  1. __init__(self: pydrake.systems.primitives.Multiplexer_[AutoDiffXd], model_vector: pydrake.systems.framework.BasicVector_[AutoDiffXd]) -> None

Constructs a Multiplexer with model_vector.size() scalar-valued inputs and one vector-valued output port whose size equals the size of model_vector. In addition, the output type derives from that of model_vector.

Note

Objects created using this constructor overload do not support system scalar conversion. See system_scalar_conversion.

class pydrake.systems.primitives.Multiplexer_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

This system combines multiple vector-valued inputs into a vector-valued output. The input to this system directly feeds through to its output.

u0→
...→
u(N-1)→
Multiplexer
→ y0
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Multiplexer_[Expression], num_scalar_inputs: int) -> None

Constructs a Multiplexer with num_scalar_inputs scalar-valued input ports, and one vector-valued output port of size num_scalar_inputs.

u0→
...→
u(num_scalar_inputs - 1)→
Multiplexer
→ y0
  1. __init__(self: pydrake.systems.primitives.Multiplexer_[Expression], input_sizes: list[int]) -> None

Constructs a Multiplexer with input_sizes.size() vector-valued input ports where the i-th input has size input_sizes[i], and one vector- valued output port of size sum(input_sizes).

u0→
...→
u(input_sizes.size() - 1)→
Multiplexer
→ y0
  1. __init__(self: pydrake.systems.primitives.Multiplexer_[Expression], model_vector: pydrake.systems.framework.BasicVector_[Expression]) -> None

Constructs a Multiplexer with model_vector.size() scalar-valued inputs and one vector-valued output port whose size equals the size of model_vector. In addition, the output type derives from that of model_vector.

Note

Objects created using this constructor overload do not support system scalar conversion. See system_scalar_conversion.

pydrake.systems.primitives.ObservabilityMatrix(arg0: pydrake.systems.primitives.LinearSystem) numpy.ndarray[numpy.float64[m, n]]

Returns the observability matrix: O = [ C; CA; …; CA^{n-1} ].

class pydrake.systems.primitives.PassThrough

Bases: pydrake.systems.framework.LeafSystem

A pass through system with input u and output y = u. This is mathematically equivalent to a Gain system with its gain equal to one. However this system incurs no computational cost. The input to this system directly feeds through to its output.

The system can also be used to provide default values for a port in any diagram. If the input port does not have a value, then the default value passed in the constructor is passed to the output.

This system is used, for instance, in PidController which is a Diagram composed of simple framework primitives. In this case a PassThrough is used to connect the exported input of the Diagram to the inputs of the Gain systems for the proportional and integral constants of the controller. This is necessary to provide an output port to which the internal Gain subsystems connect. In this case the PassThrough is effectively creating an output port that feeds through the input to the Diagram and that can now be connected to the inputs of the inner subsystems to the Diagram. A detailed discussion of the PidController can be found at https://github.com/RobotLocomotion/drake/pull/3132.

u→
PassThrough
→ y

Note

This class is templated; see PassThrough_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.PassThrough, vector_size: int) -> None

Constructs a pass-through system.

Parameter vector_size:

number of elements in the signal to be processed. When no input is connected, the output will be a vector of all zeros.

  1. __init__(self: pydrake.systems.primitives.PassThrough, value: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a pass-through system with vector-valued input/output ports.

Parameter value:

The model value, which defines the size of the ports and serves as the default when no input is connected.

  1. __init__(self: pydrake.systems.primitives.PassThrough, abstract_model_value: pydrake.common.value.AbstractValue) -> None

Constructs a pass-through system with abstract-valued input/output ports.

Parameter abstract_model_value:

A model value, which defines the type of the ports and serves as the default when no input is connected.

template pydrake.systems.primitives.PassThrough_

Instantiations: PassThrough_[float], PassThrough_[AutoDiffXd], PassThrough_[Expression]

class pydrake.systems.primitives.PassThrough_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A pass through system with input u and output y = u. This is mathematically equivalent to a Gain system with its gain equal to one. However this system incurs no computational cost. The input to this system directly feeds through to its output.

The system can also be used to provide default values for a port in any diagram. If the input port does not have a value, then the default value passed in the constructor is passed to the output.

This system is used, for instance, in PidController which is a Diagram composed of simple framework primitives. In this case a PassThrough is used to connect the exported input of the Diagram to the inputs of the Gain systems for the proportional and integral constants of the controller. This is necessary to provide an output port to which the internal Gain subsystems connect. In this case the PassThrough is effectively creating an output port that feeds through the input to the Diagram and that can now be connected to the inputs of the inner subsystems to the Diagram. A detailed discussion of the PidController can be found at https://github.com/RobotLocomotion/drake/pull/3132.

u→
PassThrough
→ y
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.PassThrough_[AutoDiffXd], vector_size: int) -> None

Constructs a pass-through system.

Parameter vector_size:

number of elements in the signal to be processed. When no input is connected, the output will be a vector of all zeros.

  1. __init__(self: pydrake.systems.primitives.PassThrough_[AutoDiffXd], value: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a pass-through system with vector-valued input/output ports.

Parameter value:

The model value, which defines the size of the ports and serves as the default when no input is connected.

  1. __init__(self: pydrake.systems.primitives.PassThrough_[AutoDiffXd], abstract_model_value: pydrake.common.value.AbstractValue) -> None

Constructs a pass-through system with abstract-valued input/output ports.

Parameter abstract_model_value:

A model value, which defines the type of the ports and serves as the default when no input is connected.

class pydrake.systems.primitives.PassThrough_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A pass through system with input u and output y = u. This is mathematically equivalent to a Gain system with its gain equal to one. However this system incurs no computational cost. The input to this system directly feeds through to its output.

The system can also be used to provide default values for a port in any diagram. If the input port does not have a value, then the default value passed in the constructor is passed to the output.

This system is used, for instance, in PidController which is a Diagram composed of simple framework primitives. In this case a PassThrough is used to connect the exported input of the Diagram to the inputs of the Gain systems for the proportional and integral constants of the controller. This is necessary to provide an output port to which the internal Gain subsystems connect. In this case the PassThrough is effectively creating an output port that feeds through the input to the Diagram and that can now be connected to the inputs of the inner subsystems to the Diagram. A detailed discussion of the PidController can be found at https://github.com/RobotLocomotion/drake/pull/3132.

u→
PassThrough
→ y
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.PassThrough_[Expression], vector_size: int) -> None

Constructs a pass-through system.

Parameter vector_size:

number of elements in the signal to be processed. When no input is connected, the output will be a vector of all zeros.

  1. __init__(self: pydrake.systems.primitives.PassThrough_[Expression], value: numpy.ndarray[numpy.float64[m, 1]]) -> None

Constructs a pass-through system with vector-valued input/output ports.

Parameter value:

The model value, which defines the size of the ports and serves as the default when no input is connected.

  1. __init__(self: pydrake.systems.primitives.PassThrough_[Expression], abstract_model_value: pydrake.common.value.AbstractValue) -> None

Constructs a pass-through system with abstract-valued input/output ports.

Parameter abstract_model_value:

A model value, which defines the type of the ports and serves as the default when no input is connected.

class pydrake.systems.primitives.PerceptronActivationType

Specifies one of the common activation functions in a neural network.

Members:

kIdentity :

kReLU :

kTanh :

__init__(self: pydrake.systems.primitives.PerceptronActivationType, value: int) None
kIdentity = <PerceptronActivationType.kIdentity: 0>
kReLU = <PerceptronActivationType.kReLU: 1>
kTanh = <PerceptronActivationType.kTanh: 2>
property name
property value
class pydrake.systems.primitives.PortSwitch

Bases: pydrake.systems.framework.LeafSystem

A simple system that passes through the value from just one of its input ports to the output. All inputs (except for the port_selector) must have the same data type as the output.

This system only evaluates the port_selector port and the input port that is indicated by port_selector at runtime. Because of the System framework’s “pull architecture”, this means that entire sub-diagrams can potentially be added with minimal runtime cost (their outputs will not be evaluated until they are selected). Just remember that their state dynamics will still be evaluated when the diagram’s dynamics are evaluated (e.g. during simulation), and their output ports could be evaluated via other connections.

port_selector→
(user assigned port name)→
...→
(user assigned port name)→
PortSwitch
→ value

Note

This class is templated; see PortSwitch_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.PortSwitch, vector_size: int) None

Constructs a vector-valued PortSwitch. All input ports declared via DeclareInputPort() will be vector-valued ports of size vector_size, which must be greater than zero.

DeclareInputPort(self: pydrake.systems.primitives.PortSwitch, name: str) pydrake.systems.framework.InputPort

Declares a new input port to the switch with port name name. The type of this port is already defined by the type of the output port. This must be called before any Context is allocated.

get_port_selector_input_port(self: pydrake.systems.primitives.PortSwitch) pydrake.systems.framework.InputPort

Returns the port-selector input port, which is an abstract-valued port of type InputPortIndex.

template pydrake.systems.primitives.PortSwitch_

Instantiations: PortSwitch_[float], PortSwitch_[AutoDiffXd], PortSwitch_[Expression]

class pydrake.systems.primitives.PortSwitch_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A simple system that passes through the value from just one of its input ports to the output. All inputs (except for the port_selector) must have the same data type as the output.

This system only evaluates the port_selector port and the input port that is indicated by port_selector at runtime. Because of the System framework’s “pull architecture”, this means that entire sub-diagrams can potentially be added with minimal runtime cost (their outputs will not be evaluated until they are selected). Just remember that their state dynamics will still be evaluated when the diagram’s dynamics are evaluated (e.g. during simulation), and their output ports could be evaluated via other connections.

port_selector→
(user assigned port name)→
...→
(user assigned port name)→
PortSwitch
→ value
__init__(self: pydrake.systems.primitives.PortSwitch_[AutoDiffXd], vector_size: int) None

Constructs a vector-valued PortSwitch. All input ports declared via DeclareInputPort() will be vector-valued ports of size vector_size, which must be greater than zero.

DeclareInputPort(self: pydrake.systems.primitives.PortSwitch_[AutoDiffXd], name: str) pydrake.systems.framework.InputPort_[AutoDiffXd]

Declares a new input port to the switch with port name name. The type of this port is already defined by the type of the output port. This must be called before any Context is allocated.

get_port_selector_input_port(self: pydrake.systems.primitives.PortSwitch_[AutoDiffXd]) pydrake.systems.framework.InputPort_[AutoDiffXd]

Returns the port-selector input port, which is an abstract-valued port of type InputPortIndex.

class pydrake.systems.primitives.PortSwitch_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A simple system that passes through the value from just one of its input ports to the output. All inputs (except for the port_selector) must have the same data type as the output.

This system only evaluates the port_selector port and the input port that is indicated by port_selector at runtime. Because of the System framework’s “pull architecture”, this means that entire sub-diagrams can potentially be added with minimal runtime cost (their outputs will not be evaluated until they are selected). Just remember that their state dynamics will still be evaluated when the diagram’s dynamics are evaluated (e.g. during simulation), and their output ports could be evaluated via other connections.

port_selector→
(user assigned port name)→
...→
(user assigned port name)→
PortSwitch
→ value
__init__(self: pydrake.systems.primitives.PortSwitch_[Expression], vector_size: int) None

Constructs a vector-valued PortSwitch. All input ports declared via DeclareInputPort() will be vector-valued ports of size vector_size, which must be greater than zero.

DeclareInputPort(self: pydrake.systems.primitives.PortSwitch_[Expression], name: str) pydrake.systems.framework.InputPort_[Expression]

Declares a new input port to the switch with port name name. The type of this port is already defined by the type of the output port. This must be called before any Context is allocated.

get_port_selector_input_port(self: pydrake.systems.primitives.PortSwitch_[Expression]) pydrake.systems.framework.InputPort_[Expression]

Returns the port-selector input port, which is an abstract-valued port of type InputPortIndex.

class pydrake.systems.primitives.RandomSource

Bases: pydrake.systems.framework.LeafSystem

A source block which generates random numbers at a fixed sampling interval, with a zero-order hold between samples. For continuous-time systems, this can be interpreted as a band-limited approximation of continuous white noise (with a power-spectral density of the form Ts * sinc^2( omega * Ts ), where Ts is the sampling interval.

RandomSource
→ output

This system exposes a parameter named seed for the pseudo-random number generator that determines the noise output. The seed parameter behaves as follows:

1. Each newly-created RandomSource chooses a new per_instance_seed member field value for itself. The value will be unique within the current executable process.

2. By default, source.CreateDefaultContext() will set the returned context’s seed parameter to per_instance_seed. Therefore, for a given instance of this system, the parameters, state, and outputs will be identical for all simulations that start from a default context.

3. By default, source.SetRandomContext() will choose a new, arbitrary value for the context’s seed parameter, which means that the system’s parameters, state, and outputs will (almost certainly) differ from their defaults.

4. The user may call source.set_fixed_seed(new_seed) on this system. When a new_seed value is provided, it is used by both CreateDefaultContext and SetRandomContext. Therefore, the system’s parameters, state, and outputs will be identical to any other instances that share the same new_seed value for their seed context parameter. Note that set_fixed_seed affects subsequently-created contexts; any pre-existing contexts are unaffected. The user may call source.set_fixed_seed(nullopt) to revert to the default the behaviors described in #2 and #3 again.

5. The context returned by source.AllocateContext() does not contain a valid seed parameter; that context should not be used until its values are populated via another Context.

Note

This system is only defined for the double scalar type.

Note

The exact distribution results may vary across multiple platforms or revisions of Drake, but will be consistent for all compilations on a given platform and Drake revision.

Note

The hard-coding of (default) distribution parameters is imposed intentionally to simplify analysis (by forcing systems taking noise inputs to implement the shifting/scaling, the system itself contains all of the necessary information for stochastic analysis).

See also

stochastic_systems

__init__(self: pydrake.systems.primitives.RandomSource, distribution: pydrake.common.RandomDistribution, num_outputs: int, sampling_interval_sec: float) None

Constructs the RandomSource system.

Parameter distribution:

The RandomDistribution used for each of the outputs.

Parameter num_outputs:

The dimension of the (single) vector output port.

Parameter sampling_interval_sec:

The sampling interval in seconds.

class pydrake.systems.primitives.Saturation

Bases: pydrake.systems.framework.LeafSystem

An element-wise hard saturation block with inputs signal u, saturation values \(u_{min}\) and/or \(u_{max}\), and output y respectively as in:

\[y = u, u_{min} < u < u_{max}\]
\[y = u_{min}, u \le u_{min}\]
\[y = u_{max}, u \ge u_{max}\]

The input to this system directly feeds through to its output.

Note that \(u_{min}\), and \(u_{max}\), and \(u\) are all vectors of same dimension, and the following condition holds elementwise in runtime.

\[u_{min} <= u_{max}\]

The quantities \(u_{min}\), and \(u_{max}\) can be supplied as inputs in separate ports or be initialised as constants using the appropriate constructor by passing their default value. If these quantities are not defined as constants but they are not connected to appropriate sources, their values are taken by default to be \(u_{min} = -\infty\), and \(u_{max} = \infty\) respectively. In this “variable” configuration, at least one of the input ports must be connected.

u0→
u1
u2
Saturation
→ y0

Ports show in <span style=”color:gray”>gray</span> may be absent, depending on how the system is constructed.

Note

This class is templated; see Saturation_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.Saturation, min_value: numpy.ndarray[numpy.float64[m, 1]], max_value: numpy.ndarray[numpy.float64[m, 1]]) None

Constructs a constant Saturation system where the upper and lower values are represented by vectors of identical size supplied via this constructor.

u0→
Saturation
→ y0
Parameter u_min:

the lower (vector) limit to the saturation.

Parameter u_max:

the upper (vector) limit to the saturation.

Please consult this class’s description for the requirements of u_min and u_max.

template pydrake.systems.primitives.Saturation_

Instantiations: Saturation_[float], Saturation_[AutoDiffXd], Saturation_[Expression]

class pydrake.systems.primitives.Saturation_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

An element-wise hard saturation block with inputs signal u, saturation values \(u_{min}\) and/or \(u_{max}\), and output y respectively as in:

\[y = u, u_{min} < u < u_{max}\]
\[y = u_{min}, u \le u_{min}\]
\[y = u_{max}, u \ge u_{max}\]

The input to this system directly feeds through to its output.

Note that \(u_{min}\), and \(u_{max}\), and \(u\) are all vectors of same dimension, and the following condition holds elementwise in runtime.

\[u_{min} <= u_{max}\]

The quantities \(u_{min}\), and \(u_{max}\) can be supplied as inputs in separate ports or be initialised as constants using the appropriate constructor by passing their default value. If these quantities are not defined as constants but they are not connected to appropriate sources, their values are taken by default to be \(u_{min} = -\infty\), and \(u_{max} = \infty\) respectively. In this “variable” configuration, at least one of the input ports must be connected.

u0→
u1
u2
Saturation
→ y0

Ports show in <span style=”color:gray”>gray</span> may be absent, depending on how the system is constructed.

__init__(self: pydrake.systems.primitives.Saturation_[AutoDiffXd], min_value: numpy.ndarray[object[m, 1]], max_value: numpy.ndarray[object[m, 1]]) None

Constructs a constant Saturation system where the upper and lower values are represented by vectors of identical size supplied via this constructor.

u0→
Saturation
→ y0
Parameter u_min:

the lower (vector) limit to the saturation.

Parameter u_max:

the upper (vector) limit to the saturation.

Please consult this class’s description for the requirements of u_min and u_max.

class pydrake.systems.primitives.Saturation_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

An element-wise hard saturation block with inputs signal u, saturation values \(u_{min}\) and/or \(u_{max}\), and output y respectively as in:

\[y = u, u_{min} < u < u_{max}\]
\[y = u_{min}, u \le u_{min}\]
\[y = u_{max}, u \ge u_{max}\]

The input to this system directly feeds through to its output.

Note that \(u_{min}\), and \(u_{max}\), and \(u\) are all vectors of same dimension, and the following condition holds elementwise in runtime.

\[u_{min} <= u_{max}\]

The quantities \(u_{min}\), and \(u_{max}\) can be supplied as inputs in separate ports or be initialised as constants using the appropriate constructor by passing their default value. If these quantities are not defined as constants but they are not connected to appropriate sources, their values are taken by default to be \(u_{min} = -\infty\), and \(u_{max} = \infty\) respectively. In this “variable” configuration, at least one of the input ports must be connected.

u0→
u1
u2
Saturation
→ y0

Ports show in <span style=”color:gray”>gray</span> may be absent, depending on how the system is constructed.

__init__(self: pydrake.systems.primitives.Saturation_[Expression], min_value: numpy.ndarray[object[m, 1]], max_value: numpy.ndarray[object[m, 1]]) None

Constructs a constant Saturation system where the upper and lower values are represented by vectors of identical size supplied via this constructor.

u0→
Saturation
→ y0
Parameter u_min:

the lower (vector) limit to the saturation.

Parameter u_max:

the upper (vector) limit to the saturation.

Please consult this class’s description for the requirements of u_min and u_max.

class pydrake.systems.primitives.SharedPointerSystem

Bases: pydrake.systems.framework.LeafSystem

SharedPointerSystem holds a single shared_ptr that will be released at System deletion time (i.e., the end of a Diagram lifespan). It has no input, output, state, nor parameters. This is useful for storing objects that will be pointed-to by other systems outside of the usual input/output port connections.

Scalar conversion is supported and will simply increment the reference count for the contained object. The contained object will not be scalar-converted, so should not depend on T.

Note

This class is templated; see SharedPointerSystem_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.SharedPointerSystem, value_to_hold: object) None

Creates a system holding the given value. The value is allowed to be nullptr.

Note

To immediately give up ownership at the call site, remember to use std::move on the value_to_hold.

Template parameter Held:

The type used to store the given value. Calls to get<>() must provide the same type for retrieval.

static AddToBuilder(builder: pydrake.systems.framework.DiagramBuilder, value_to_hold: object) object

Creates a system holding the given value and adds it to the builder. The value is allowed to be nullptr. Returns an alias to the value (or nullptr in case nullptr was passed in as the value_to_hold).

Note

To immediately give up ownership at the call site, remember to use std::move on the value_to_hold.

Template parameter Held:

The type used to store the given value. Calls to get<>() must provide the same type for retrieval.

Precondition:

builder is non-null

get(self: pydrake.systems.primitives.SharedPointerSystem) object

(Advanced) Retrieves an alias to the stored value. Returns nullptr in case nullptr was passed in as the value_to_hold.

Template parameter Held:

The type used to store the given value, per our constructor.

Raises

RuntimeError if Held doesn't match the type used at construction.

template pydrake.systems.primitives.SharedPointerSystem_

Instantiations: SharedPointerSystem_[float], SharedPointerSystem_[AutoDiffXd], SharedPointerSystem_[Expression]

class pydrake.systems.primitives.SharedPointerSystem_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

SharedPointerSystem holds a single shared_ptr that will be released at System deletion time (i.e., the end of a Diagram lifespan). It has no input, output, state, nor parameters. This is useful for storing objects that will be pointed-to by other systems outside of the usual input/output port connections.

Scalar conversion is supported and will simply increment the reference count for the contained object. The contained object will not be scalar-converted, so should not depend on T.

__init__(self: pydrake.systems.primitives.SharedPointerSystem_[AutoDiffXd], value_to_hold: object) None

Creates a system holding the given value. The value is allowed to be nullptr.

Note

To immediately give up ownership at the call site, remember to use std::move on the value_to_hold.

Template parameter Held:

The type used to store the given value. Calls to get<>() must provide the same type for retrieval.

static AddToBuilder(builder: pydrake.systems.framework.DiagramBuilder_[AutoDiffXd], value_to_hold: object) object

Creates a system holding the given value and adds it to the builder. The value is allowed to be nullptr. Returns an alias to the value (or nullptr in case nullptr was passed in as the value_to_hold).

Note

To immediately give up ownership at the call site, remember to use std::move on the value_to_hold.

Template parameter Held:

The type used to store the given value. Calls to get<>() must provide the same type for retrieval.

Precondition:

builder is non-null

get(self: pydrake.systems.primitives.SharedPointerSystem_[AutoDiffXd]) object

(Advanced) Retrieves an alias to the stored value. Returns nullptr in case nullptr was passed in as the value_to_hold.

Template parameter Held:

The type used to store the given value, per our constructor.

Raises

RuntimeError if Held doesn't match the type used at construction.

class pydrake.systems.primitives.SharedPointerSystem_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

SharedPointerSystem holds a single shared_ptr that will be released at System deletion time (i.e., the end of a Diagram lifespan). It has no input, output, state, nor parameters. This is useful for storing objects that will be pointed-to by other systems outside of the usual input/output port connections.

Scalar conversion is supported and will simply increment the reference count for the contained object. The contained object will not be scalar-converted, so should not depend on T.

__init__(self: pydrake.systems.primitives.SharedPointerSystem_[Expression], value_to_hold: object) None

Creates a system holding the given value. The value is allowed to be nullptr.

Note

To immediately give up ownership at the call site, remember to use std::move on the value_to_hold.

Template parameter Held:

The type used to store the given value. Calls to get<>() must provide the same type for retrieval.

static AddToBuilder(builder: pydrake.systems.framework.DiagramBuilder_[Expression], value_to_hold: object) object

Creates a system holding the given value and adds it to the builder. The value is allowed to be nullptr. Returns an alias to the value (or nullptr in case nullptr was passed in as the value_to_hold).

Note

To immediately give up ownership at the call site, remember to use std::move on the value_to_hold.

Template parameter Held:

The type used to store the given value. Calls to get<>() must provide the same type for retrieval.

Precondition:

builder is non-null

get(self: pydrake.systems.primitives.SharedPointerSystem_[Expression]) object

(Advanced) Retrieves an alias to the stored value. Returns nullptr in case nullptr was passed in as the value_to_hold.

Template parameter Held:

The type used to store the given value, per our constructor.

Raises

RuntimeError if Held doesn't match the type used at construction.

class pydrake.systems.primitives.Sine

Bases: pydrake.systems.framework.LeafSystem

A sine system which outputs y = a * sin(f * t + p) and first and second derivatives w.r.t. the time parameter t. The block parameters are: a the amplitude, f the frequency (radians/second), and p the phase (radians), all of which are constant vectors provided at construction time. This system has one or zero input ports and three vector valued output ports (y and its first two derivatives). The user can specify whether to use simulation time as the source of values for the time variable or an external source. If an external time source is specified, the system is created with an input port for the time source. Otherwise, the system is created with zero input ports.

u0
Sine
→ y0
→ y1
→ y2

Port u0 is present if and only if the constructor parameter is_time_based is false.

Port y0 emits the value y; port y1 emits the first derivative; port y2 emits the second derivative.

Note

This class is templated; see Sine_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Sine, amplitude: float, frequency: float, phase: float, size: int, is_time_based: bool = True) -> None

Constructs a Sine system where the amplitude, frequency, and phase is applied to every input.

Parameter amplitude:

the sine wave amplitude

Parameter frequency:

the sine wave frequency (radians/second)

Parameter phase:

the sine wave phase (radians)

Parameter size:

number of elements in the output signal.

Parameter is_time_based:

indicates whether to use the simulation time as the source for the sine wave time variable, or use an external source, in which case an input port of size size is created.

  1. __init__(self: pydrake.systems.primitives.Sine, amplitudes: numpy.ndarray[numpy.float64[m, 1]], frequencies: numpy.ndarray[numpy.float64[m, 1]], phases: numpy.ndarray[numpy.float64[m, 1]], is_time_based: bool = True) -> None

Constructs a Sine system where different amplitudes, frequencies, and phases can be applied to each sine wave.

Parameter amplitudes:

the sine wave amplitudes

Parameter frequencies:

the sine wave frequencies (radians/second)

Parameter phases:

the sine wave phases (radians)

Parameter is_time_based:

indicates whether to use the simulation time as the source for the sine wave time variable, or use an external source, in which case an input port is created.

template pydrake.systems.primitives.Sine_

Instantiations: Sine_[float], Sine_[AutoDiffXd], Sine_[Expression]

class pydrake.systems.primitives.Sine_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A sine system which outputs y = a * sin(f * t + p) and first and second derivatives w.r.t. the time parameter t. The block parameters are: a the amplitude, f the frequency (radians/second), and p the phase (radians), all of which are constant vectors provided at construction time. This system has one or zero input ports and three vector valued output ports (y and its first two derivatives). The user can specify whether to use simulation time as the source of values for the time variable or an external source. If an external time source is specified, the system is created with an input port for the time source. Otherwise, the system is created with zero input ports.

u0
Sine
→ y0
→ y1
→ y2

Port u0 is present if and only if the constructor parameter is_time_based is false.

Port y0 emits the value y; port y1 emits the first derivative; port y2 emits the second derivative.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Sine_[AutoDiffXd], amplitude: float, frequency: float, phase: float, size: int, is_time_based: bool = True) -> None

Constructs a Sine system where the amplitude, frequency, and phase is applied to every input.

Parameter amplitude:

the sine wave amplitude

Parameter frequency:

the sine wave frequency (radians/second)

Parameter phase:

the sine wave phase (radians)

Parameter size:

number of elements in the output signal.

Parameter is_time_based:

indicates whether to use the simulation time as the source for the sine wave time variable, or use an external source, in which case an input port of size size is created.

  1. __init__(self: pydrake.systems.primitives.Sine_[AutoDiffXd], amplitudes: numpy.ndarray[numpy.float64[m, 1]], frequencies: numpy.ndarray[numpy.float64[m, 1]], phases: numpy.ndarray[numpy.float64[m, 1]], is_time_based: bool = True) -> None

Constructs a Sine system where different amplitudes, frequencies, and phases can be applied to each sine wave.

Parameter amplitudes:

the sine wave amplitudes

Parameter frequencies:

the sine wave frequencies (radians/second)

Parameter phases:

the sine wave phases (radians)

Parameter is_time_based:

indicates whether to use the simulation time as the source for the sine wave time variable, or use an external source, in which case an input port is created.

class pydrake.systems.primitives.Sine_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A sine system which outputs y = a * sin(f * t + p) and first and second derivatives w.r.t. the time parameter t. The block parameters are: a the amplitude, f the frequency (radians/second), and p the phase (radians), all of which are constant vectors provided at construction time. This system has one or zero input ports and three vector valued output ports (y and its first two derivatives). The user can specify whether to use simulation time as the source of values for the time variable or an external source. If an external time source is specified, the system is created with an input port for the time source. Otherwise, the system is created with zero input ports.

u0
Sine
→ y0
→ y1
→ y2

Port u0 is present if and only if the constructor parameter is_time_based is false.

Port y0 emits the value y; port y1 emits the first derivative; port y2 emits the second derivative.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.Sine_[Expression], amplitude: float, frequency: float, phase: float, size: int, is_time_based: bool = True) -> None

Constructs a Sine system where the amplitude, frequency, and phase is applied to every input.

Parameter amplitude:

the sine wave amplitude

Parameter frequency:

the sine wave frequency (radians/second)

Parameter phase:

the sine wave phase (radians)

Parameter size:

number of elements in the output signal.

Parameter is_time_based:

indicates whether to use the simulation time as the source for the sine wave time variable, or use an external source, in which case an input port of size size is created.

  1. __init__(self: pydrake.systems.primitives.Sine_[Expression], amplitudes: numpy.ndarray[numpy.float64[m, 1]], frequencies: numpy.ndarray[numpy.float64[m, 1]], phases: numpy.ndarray[numpy.float64[m, 1]], is_time_based: bool = True) -> None

Constructs a Sine system where different amplitudes, frequencies, and phases can be applied to each sine wave.

Parameter amplitudes:

the sine wave amplitudes

Parameter frequencies:

the sine wave frequencies (radians/second)

Parameter phases:

the sine wave phases (radians)

Parameter is_time_based:

indicates whether to use the simulation time as the source for the sine wave time variable, or use an external source, in which case an input port is created.

class pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative

Bases: pydrake.systems.framework.Diagram

Supports the common pattern of combining a (feed-through) position with a velocity estimated with the DiscreteDerivative into a single output vector with positions and velocities stacked. This assumes that the velocities are equal to the time derivative of the positions.

Click to expand C++ code...
┌─────┐
position ───┬───────────────────>│     │
            │                    │ Mux ├──> state
            │   ┌────────────┐   │     │
            └──>│  Discrete  ├──>│     │
                │ Derivative │   └─────┘
                └────────────┘
position→
StateInterpolatorWithDiscreteDerivative
→ state

Note

This class is templated; see StateInterpolatorWithDiscreteDerivative_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative, num_positions: int, time_step: float, suppress_initial_transient: bool = True) None

Constructor taking num_positions, the size of the position vector to be differentiated, and time_step, the sampling interval. If suppress_initial_transient is true (the default), then the velocity output will be zero for the first two time steps (see the DiscreteDerivative class documentation for details and exceptions).

set_initial_position(*args, **kwargs)

Overloaded function.

  1. set_initial_position(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative, context: pydrake.systems.framework.Context, position: numpy.ndarray[numpy.float64[m, 1]]) -> None

Convenience method that sets the entire position history for the discrete-time derivative to a constant vector value (resulting in velocity estimate of zero). This is useful during initialization to avoid large derivative outputs. position must be the same size as the input/output ports. If suppress_initial_transient() is true, then also disables the suppression for this context.

Warning

This only changes the position history used for the velocity half of the output port; it has no effect on the feedthrough position.

  1. set_initial_position(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative, state: pydrake.systems.framework.State, position: numpy.ndarray[numpy.float64[m, 1]]) -> None

Convenience method that sets the entire position history for the discrete-time derivative to a constant vector value (resulting in velocity estimate of zero). This is useful during initialization to avoid large derivative outputs. position must be the same size as the input/output ports. If suppress_initial_transient() is true, then also disables the suppression for this state.

Warning

This only changes the position history used for the velocity half of the output port; it has no effect on the feedthrough position.

suppress_initial_transient(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative) bool

Returns the suppress_initial_transient passed to the constructor.

template pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_

Instantiations: StateInterpolatorWithDiscreteDerivative_[float], StateInterpolatorWithDiscreteDerivative_[AutoDiffXd], StateInterpolatorWithDiscreteDerivative_[Expression]

class pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[AutoDiffXd]

Bases: pydrake.systems.framework.Diagram_[AutoDiffXd]

Supports the common pattern of combining a (feed-through) position with a velocity estimated with the DiscreteDerivative into a single output vector with positions and velocities stacked. This assumes that the velocities are equal to the time derivative of the positions.

Click to expand C++ code...
┌─────┐
position ───┬───────────────────>│     │
            │                    │ Mux ├──> state
            │   ┌────────────┐   │     │
            └──>│  Discrete  ├──>│     │
                │ Derivative │   └─────┘
                └────────────┘
position→
StateInterpolatorWithDiscreteDerivative
→ state
__init__(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[AutoDiffXd], num_positions: int, time_step: float, suppress_initial_transient: bool = True) None

Constructor taking num_positions, the size of the position vector to be differentiated, and time_step, the sampling interval. If suppress_initial_transient is true (the default), then the velocity output will be zero for the first two time steps (see the DiscreteDerivative class documentation for details and exceptions).

set_initial_position(*args, **kwargs)

Overloaded function.

  1. set_initial_position(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd], position: numpy.ndarray[object[m, 1]]) -> None

Convenience method that sets the entire position history for the discrete-time derivative to a constant vector value (resulting in velocity estimate of zero). This is useful during initialization to avoid large derivative outputs. position must be the same size as the input/output ports. If suppress_initial_transient() is true, then also disables the suppression for this context.

Warning

This only changes the position history used for the velocity half of the output port; it has no effect on the feedthrough position.

  1. set_initial_position(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[AutoDiffXd], state: pydrake.systems.framework.State_[AutoDiffXd], position: numpy.ndarray[object[m, 1]]) -> None

Convenience method that sets the entire position history for the discrete-time derivative to a constant vector value (resulting in velocity estimate of zero). This is useful during initialization to avoid large derivative outputs. position must be the same size as the input/output ports. If suppress_initial_transient() is true, then also disables the suppression for this state.

Warning

This only changes the position history used for the velocity half of the output port; it has no effect on the feedthrough position.

suppress_initial_transient(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[AutoDiffXd]) bool

Returns the suppress_initial_transient passed to the constructor.

class pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[Expression]

Bases: pydrake.systems.framework.Diagram_[Expression]

Supports the common pattern of combining a (feed-through) position with a velocity estimated with the DiscreteDerivative into a single output vector with positions and velocities stacked. This assumes that the velocities are equal to the time derivative of the positions.

Click to expand C++ code...
┌─────┐
position ───┬───────────────────>│     │
            │                    │ Mux ├──> state
            │   ┌────────────┐   │     │
            └──>│  Discrete  ├──>│     │
                │ Derivative │   └─────┘
                └────────────┘
position→
StateInterpolatorWithDiscreteDerivative
→ state
__init__(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[Expression], num_positions: int, time_step: float, suppress_initial_transient: bool = True) None

Constructor taking num_positions, the size of the position vector to be differentiated, and time_step, the sampling interval. If suppress_initial_transient is true (the default), then the velocity output will be zero for the first two time steps (see the DiscreteDerivative class documentation for details and exceptions).

set_initial_position(*args, **kwargs)

Overloaded function.

  1. set_initial_position(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[Expression], context: pydrake.systems.framework.Context_[Expression], position: numpy.ndarray[object[m, 1]]) -> None

Convenience method that sets the entire position history for the discrete-time derivative to a constant vector value (resulting in velocity estimate of zero). This is useful during initialization to avoid large derivative outputs. position must be the same size as the input/output ports. If suppress_initial_transient() is true, then also disables the suppression for this context.

Warning

This only changes the position history used for the velocity half of the output port; it has no effect on the feedthrough position.

  1. set_initial_position(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[Expression], state: pydrake.systems.framework.State_[Expression], position: numpy.ndarray[object[m, 1]]) -> None

Convenience method that sets the entire position history for the discrete-time derivative to a constant vector value (resulting in velocity estimate of zero). This is useful during initialization to avoid large derivative outputs. position must be the same size as the input/output ports. If suppress_initial_transient() is true, then also disables the suppression for this state.

Warning

This only changes the position history used for the velocity half of the output port; it has no effect on the feedthrough position.

suppress_initial_transient(self: pydrake.systems.primitives.StateInterpolatorWithDiscreteDerivative_[Expression]) bool

Returns the suppress_initial_transient passed to the constructor.

class pydrake.systems.primitives.SymbolicVectorSystem

Bases: pydrake.systems.framework.LeafSystem

A LeafSystem that is defined by vectors of symbolic::Expression representing the dynamics and output. The resulting system has only zero or one vector input ports, zero or one vector of continuous or discrete state (depending on the specified time_period), zero or one vector of numeric parameters, and only zero or one vector output ports.

See SymbolicVectorSystemBuilder to make the construction a little nicer.

For example, to define the system: ẋ = -x + x³, y = x, we could write

Click to expand C++ code...
symbolic::Variable x("x");
  auto system = SymbolicVectorSystemBuilder().state(x)
                                             .dynamics(-x + pow(x,3))
                                             .output(x)
                                             .Build();

Note: This will not be as performant as writing your own LeafSystem. It is meant primarily for rapid prototyping.

u0
SymbolicVectorSystem
y0

Either port u0 or port y0 may be absent, depending on the values supplied at construction.

Note

This class is templated; see SymbolicVectorSystem_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.SymbolicVectorSystem, time: Optional[pydrake.symbolic.Variable] = None, state: numpy.ndarray[object[m, 1]] = array([], dtype=object), input: numpy.ndarray[object[m, 1]] = array([], dtype=object), dynamics: numpy.ndarray[object[m, 1]] = array([], dtype=object), output: numpy.ndarray[object[m, 1]] = array([], dtype=object), time_period: float = 0.0) -> None

Construct the SymbolicVectorSystem.

Parameter time:

an (optional) Variable used to represent time in the dynamics.

Parameter state:

an (optional) vector of Variables representing the state. The order in this vector will determine the order of the elements in the state vector. Each element must be unique.

Parameter input:

an (optional) vector of Variables representing the input. The order in this vector will determine the order of the elements in the vector-valued input port. Each element must be unique.

Parameter dynamics:

a vector of Expressions representing the dynamics of the system. If time_period == 0, then this describes the continuous time derivatives. If time_period > 0, then it defines the updates of the single discrete-valued state vector. The size of this vector must match the number of state variables.

Parameter output:

a vector of Expressions representing the output of the system. If empty, then no output port will be allocated.

Parameter time_period:

a scalar representing the period of a periodic update. time_period == 0.0 implies that the state variables will be declared as continuous state and the dynamics will be implemented as time derivatives. time_period > 0.0 implies the state variables will be declared as discrete state and the dynamics will be implemented as a dicraete variable update.

  1. __init__(self: pydrake.systems.primitives.SymbolicVectorSystem, time: Optional[pydrake.symbolic.Variable] = None, state: numpy.ndarray[object[m, 1]] = array([], dtype=object), input: numpy.ndarray[object[m, 1]] = array([], dtype=object), parameter: numpy.ndarray[object[m, 1]] = array([], dtype=object), dynamics: numpy.ndarray[object[m, 1]] = array([], dtype=object), output: numpy.ndarray[object[m, 1]] = array([], dtype=object), time_period: float = 0.0) -> None

Construct the SymbolicVectorSystem.

Parameter time:

an (optional) Variable used to represent time in the dynamics.

Parameter state:

an (optional) vector of Variables representing the state. The order in this vector will determine the order of the elements in the state vector. Each element must be unique.

Parameter input:

an (optional) vector of Variables representing the input. The order in this vector will determine the order of the elements in the vector-valued input port. Each element must be unique.

Parameter parameter:

an (optional) vector of Variables representing the numeric parameter. The order in this vector will determine the order of the elements in the vector-valued parameter. Each element must be unique.

Parameter dynamics:

a vector of Expressions representing the dynamics of the system. If time_period == 0, then this describes the continuous time derivatives. If time_period > 0, then it defines the updates of the single discrete-valued state vector. The size of this vector must match the number of state variables.

Parameter output:

a vector of Expressions representing the output of the system. If empty, then no output port will be allocated.

Parameter time_period:

a scalar representing the period of a periodic update. time_period == 0.0 implies that the state variables will be declared as continuous state and the dynamics will be implemented as time derivatives. time_period > 0.0 implies the state variables will be declared as discrete state and the dynamics will be implemented as a dicraete variable update.

dynamics_for_variable(self: pydrake.systems.primitives.SymbolicVectorSystem, var: pydrake.symbolic.Variable) pydrake.symbolic.Expression

Returns the dynamics for the variable var. That is, it returns the scalar expression corresponding to either \dot{var} (continuous case) or var[n+1] (discrete case).

Raises
  • RuntimeError if this system has no corresponding dynamics for the

  • variable var.

template pydrake.systems.primitives.SymbolicVectorSystem_

Instantiations: SymbolicVectorSystem_[float], SymbolicVectorSystem_[AutoDiffXd], SymbolicVectorSystem_[Expression]

class pydrake.systems.primitives.SymbolicVectorSystem_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A LeafSystem that is defined by vectors of symbolic::Expression representing the dynamics and output. The resulting system has only zero or one vector input ports, zero or one vector of continuous or discrete state (depending on the specified time_period), zero or one vector of numeric parameters, and only zero or one vector output ports.

See SymbolicVectorSystemBuilder to make the construction a little nicer.

For example, to define the system: ẋ = -x + x³, y = x, we could write

Click to expand C++ code...
symbolic::Variable x("x");
  auto system = SymbolicVectorSystemBuilder().state(x)
                                             .dynamics(-x + pow(x,3))
                                             .output(x)
                                             .Build();

Note: This will not be as performant as writing your own LeafSystem. It is meant primarily for rapid prototyping.

u0
SymbolicVectorSystem
y0

Either port u0 or port y0 may be absent, depending on the values supplied at construction.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.SymbolicVectorSystem_[AutoDiffXd], time: Optional[pydrake.symbolic.Variable] = None, state: numpy.ndarray[object[m, 1]] = array([], dtype=object), input: numpy.ndarray[object[m, 1]] = array([], dtype=object), dynamics: numpy.ndarray[object[m, 1]] = array([], dtype=object), output: numpy.ndarray[object[m, 1]] = array([], dtype=object), time_period: float = 0.0) -> None

Construct the SymbolicVectorSystem.

Parameter time:

an (optional) Variable used to represent time in the dynamics.

Parameter state:

an (optional) vector of Variables representing the state. The order in this vector will determine the order of the elements in the state vector. Each element must be unique.

Parameter input:

an (optional) vector of Variables representing the input. The order in this vector will determine the order of the elements in the vector-valued input port. Each element must be unique.

Parameter dynamics:

a vector of Expressions representing the dynamics of the system. If time_period == 0, then this describes the continuous time derivatives. If time_period > 0, then it defines the updates of the single discrete-valued state vector. The size of this vector must match the number of state variables.

Parameter output:

a vector of Expressions representing the output of the system. If empty, then no output port will be allocated.

Parameter time_period:

a scalar representing the period of a periodic update. time_period == 0.0 implies that the state variables will be declared as continuous state and the dynamics will be implemented as time derivatives. time_period > 0.0 implies the state variables will be declared as discrete state and the dynamics will be implemented as a dicraete variable update.

  1. __init__(self: pydrake.systems.primitives.SymbolicVectorSystem_[AutoDiffXd], time: Optional[pydrake.symbolic.Variable] = None, state: numpy.ndarray[object[m, 1]] = array([], dtype=object), input: numpy.ndarray[object[m, 1]] = array([], dtype=object), parameter: numpy.ndarray[object[m, 1]] = array([], dtype=object), dynamics: numpy.ndarray[object[m, 1]] = array([], dtype=object), output: numpy.ndarray[object[m, 1]] = array([], dtype=object), time_period: float = 0.0) -> None

Construct the SymbolicVectorSystem.

Parameter time:

an (optional) Variable used to represent time in the dynamics.

Parameter state:

an (optional) vector of Variables representing the state. The order in this vector will determine the order of the elements in the state vector. Each element must be unique.

Parameter input:

an (optional) vector of Variables representing the input. The order in this vector will determine the order of the elements in the vector-valued input port. Each element must be unique.

Parameter parameter:

an (optional) vector of Variables representing the numeric parameter. The order in this vector will determine the order of the elements in the vector-valued parameter. Each element must be unique.

Parameter dynamics:

a vector of Expressions representing the dynamics of the system. If time_period == 0, then this describes the continuous time derivatives. If time_period > 0, then it defines the updates of the single discrete-valued state vector. The size of this vector must match the number of state variables.

Parameter output:

a vector of Expressions representing the output of the system. If empty, then no output port will be allocated.

Parameter time_period:

a scalar representing the period of a periodic update. time_period == 0.0 implies that the state variables will be declared as continuous state and the dynamics will be implemented as time derivatives. time_period > 0.0 implies the state variables will be declared as discrete state and the dynamics will be implemented as a dicraete variable update.

dynamics_for_variable(self: pydrake.systems.primitives.SymbolicVectorSystem_[AutoDiffXd], var: pydrake.symbolic.Variable) pydrake.symbolic.Expression

Returns the dynamics for the variable var. That is, it returns the scalar expression corresponding to either \dot{var} (continuous case) or var[n+1] (discrete case).

Raises
  • RuntimeError if this system has no corresponding dynamics for the

  • variable var.

class pydrake.systems.primitives.SymbolicVectorSystem_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A LeafSystem that is defined by vectors of symbolic::Expression representing the dynamics and output. The resulting system has only zero or one vector input ports, zero or one vector of continuous or discrete state (depending on the specified time_period), zero or one vector of numeric parameters, and only zero or one vector output ports.

See SymbolicVectorSystemBuilder to make the construction a little nicer.

For example, to define the system: ẋ = -x + x³, y = x, we could write

Click to expand C++ code...
symbolic::Variable x("x");
  auto system = SymbolicVectorSystemBuilder().state(x)
                                             .dynamics(-x + pow(x,3))
                                             .output(x)
                                             .Build();

Note: This will not be as performant as writing your own LeafSystem. It is meant primarily for rapid prototyping.

u0
SymbolicVectorSystem
y0

Either port u0 or port y0 may be absent, depending on the values supplied at construction.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.SymbolicVectorSystem_[Expression], time: Optional[pydrake.symbolic.Variable] = None, state: numpy.ndarray[object[m, 1]] = array([], dtype=object), input: numpy.ndarray[object[m, 1]] = array([], dtype=object), dynamics: numpy.ndarray[object[m, 1]] = array([], dtype=object), output: numpy.ndarray[object[m, 1]] = array([], dtype=object), time_period: float = 0.0) -> None

Construct the SymbolicVectorSystem.

Parameter time:

an (optional) Variable used to represent time in the dynamics.

Parameter state:

an (optional) vector of Variables representing the state. The order in this vector will determine the order of the elements in the state vector. Each element must be unique.

Parameter input:

an (optional) vector of Variables representing the input. The order in this vector will determine the order of the elements in the vector-valued input port. Each element must be unique.

Parameter dynamics:

a vector of Expressions representing the dynamics of the system. If time_period == 0, then this describes the continuous time derivatives. If time_period > 0, then it defines the updates of the single discrete-valued state vector. The size of this vector must match the number of state variables.

Parameter output:

a vector of Expressions representing the output of the system. If empty, then no output port will be allocated.

Parameter time_period:

a scalar representing the period of a periodic update. time_period == 0.0 implies that the state variables will be declared as continuous state and the dynamics will be implemented as time derivatives. time_period > 0.0 implies the state variables will be declared as discrete state and the dynamics will be implemented as a dicraete variable update.

  1. __init__(self: pydrake.systems.primitives.SymbolicVectorSystem_[Expression], time: Optional[pydrake.symbolic.Variable] = None, state: numpy.ndarray[object[m, 1]] = array([], dtype=object), input: numpy.ndarray[object[m, 1]] = array([], dtype=object), parameter: numpy.ndarray[object[m, 1]] = array([], dtype=object), dynamics: numpy.ndarray[object[m, 1]] = array([], dtype=object), output: numpy.ndarray[object[m, 1]] = array([], dtype=object), time_period: float = 0.0) -> None

Construct the SymbolicVectorSystem.

Parameter time:

an (optional) Variable used to represent time in the dynamics.

Parameter state:

an (optional) vector of Variables representing the state. The order in this vector will determine the order of the elements in the state vector. Each element must be unique.

Parameter input:

an (optional) vector of Variables representing the input. The order in this vector will determine the order of the elements in the vector-valued input port. Each element must be unique.

Parameter parameter:

an (optional) vector of Variables representing the numeric parameter. The order in this vector will determine the order of the elements in the vector-valued parameter. Each element must be unique.

Parameter dynamics:

a vector of Expressions representing the dynamics of the system. If time_period == 0, then this describes the continuous time derivatives. If time_period > 0, then it defines the updates of the single discrete-valued state vector. The size of this vector must match the number of state variables.

Parameter output:

a vector of Expressions representing the output of the system. If empty, then no output port will be allocated.

Parameter time_period:

a scalar representing the period of a periodic update. time_period == 0.0 implies that the state variables will be declared as continuous state and the dynamics will be implemented as time derivatives. time_period > 0.0 implies the state variables will be declared as discrete state and the dynamics will be implemented as a dicraete variable update.

dynamics_for_variable(self: pydrake.systems.primitives.SymbolicVectorSystem_[Expression], var: pydrake.symbolic.Variable) pydrake.symbolic.Expression

Returns the dynamics for the variable var. That is, it returns the scalar expression corresponding to either \dot{var} (continuous case) or var[n+1] (discrete case).

Raises
  • RuntimeError if this system has no corresponding dynamics for the

  • variable var.

class pydrake.systems.primitives.TrajectoryAffineSystem

Bases: pydrake.systems.framework.LeafSystem

A continuous- or discrete-time Affine Time-Varying system with system matrices described by trajectories.

u0→
TrajectoryAffineSystem
→ y0

Note

This class is templated; see TrajectoryAffineSystem_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.TrajectoryAffineSystem, A: pydrake.trajectories.Trajectory, B: pydrake.trajectories.Trajectory, f0: pydrake.trajectories.Trajectory, C: pydrake.trajectories.Trajectory, D: pydrake.trajectories.Trajectory, y0: pydrake.trajectories.Trajectory, time_period: float = 0.0) None

Constructs a TrajectoryAffineSystem from trajectories of matrices.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

A(self: pydrake.systems.primitives.TrajectoryAffineSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]

@name Implementations of TimeVaryingAffineSystem<T>’s pure virtual methods.

B(self: pydrake.systems.primitives.TrajectoryAffineSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]
C(self: pydrake.systems.primitives.TrajectoryAffineSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]
configure_default_state(self: pydrake.systems.primitives.TrajectoryAffineSystem, x0: numpy.ndarray[numpy.float64[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.TrajectoryAffineSystem, covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.TrajectoryAffineSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]
f0(self: pydrake.systems.primitives.TrajectoryAffineSystem, arg0: float) numpy.ndarray[numpy.float64[m, 1]]
time_period(self: pydrake.systems.primitives.TrajectoryAffineSystem) float
y0(self: pydrake.systems.primitives.TrajectoryAffineSystem, arg0: float) numpy.ndarray[numpy.float64[m, 1]]
template pydrake.systems.primitives.TrajectoryAffineSystem_

Instantiations: TrajectoryAffineSystem_[float], TrajectoryAffineSystem_[AutoDiffXd]

class pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A continuous- or discrete-time Affine Time-Varying system with system matrices described by trajectories.

u0→
TrajectoryAffineSystem
→ y0
__init__(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], A: pydrake.trajectories.Trajectory, B: pydrake.trajectories.Trajectory, f0: pydrake.trajectories.Trajectory, C: pydrake.trajectories.Trajectory, D: pydrake.trajectories.Trajectory, y0: pydrake.trajectories.Trajectory, time_period: float = 0.0) None

Constructs a TrajectoryAffineSystem from trajectories of matrices.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

A(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]

@name Implementations of TimeVaryingAffineSystem<T>’s pure virtual methods.

B(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]
C(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]
configure_default_state(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], x0: numpy.ndarray[object[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]
f0(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, 1]]
time_period(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd]) float
y0(self: pydrake.systems.primitives.TrajectoryAffineSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, 1]]
class pydrake.systems.primitives.TrajectoryLinearSystem

Bases: pydrake.systems.framework.LeafSystem

A continuous- or discrete-time Linear Time-Varying system with system matrices described by trajectories.

u0→
TrajectoryLinearSystem
→ y0

Note

This class is templated; see TrajectoryLinearSystem_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.TrajectoryLinearSystem, A: pydrake.trajectories.Trajectory, B: pydrake.trajectories.Trajectory, C: pydrake.trajectories.Trajectory, D: pydrake.trajectories.Trajectory, time_period: float = 0.0) None

Constructs a PiecewisePolynomialLinearSystem from a LinearTimeVaryingData structure.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

A(self: pydrake.systems.primitives.TrajectoryLinearSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]

@name Implementations of PiecewisePolynomialLinearSystem<T>’s pure virtual methods.

B(self: pydrake.systems.primitives.TrajectoryLinearSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]
C(self: pydrake.systems.primitives.TrajectoryLinearSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]
configure_default_state(self: pydrake.systems.primitives.TrajectoryLinearSystem, x0: numpy.ndarray[numpy.float64[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.TrajectoryLinearSystem, covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.TrajectoryLinearSystem, arg0: float) numpy.ndarray[numpy.float64[m, n]]
time_period(self: pydrake.systems.primitives.TrajectoryLinearSystem) float
template pydrake.systems.primitives.TrajectoryLinearSystem_

Instantiations: TrajectoryLinearSystem_[float], TrajectoryLinearSystem_[AutoDiffXd]

class pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A continuous- or discrete-time Linear Time-Varying system with system matrices described by trajectories.

u0→
TrajectoryLinearSystem
→ y0
__init__(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], A: pydrake.trajectories.Trajectory, B: pydrake.trajectories.Trajectory, C: pydrake.trajectories.Trajectory, D: pydrake.trajectories.Trajectory, time_period: float = 0.0) None

Constructs a PiecewisePolynomialLinearSystem from a LinearTimeVaryingData structure.

Parameter time_period:

Defines the period of the discrete time system; use time_period=0.0 to denote a continuous time system. $*Default:* 0.0

A(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]

@name Implementations of PiecewisePolynomialLinearSystem<T>’s pure virtual methods.

B(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]
C(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]
configure_default_state(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], x0: numpy.ndarray[object[m, 1]]) None

Configures the value that will be assigned to the state vector in SetDefaultContext. x0 must be a vector of length num_states.

configure_random_state(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], covariance: numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]) None

Configures the Gaussian distribution over state vectors used in the SetRandomContext methods. The mean of the distribution will be the default state (

See also

configure_default_state()). covariance must have size num_states by num_states and must be symmetric and positive semi-definite.

D(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd], arg0: pydrake.autodiffutils.AutoDiffXd) numpy.ndarray[object[m, n]]
time_period(self: pydrake.systems.primitives.TrajectoryLinearSystem_[AutoDiffXd]) float
class pydrake.systems.primitives.TrajectorySource

Bases: pydrake.systems.framework.LeafSystem

Given a Trajectory, this System provides an output port with the value of the trajectory evaluated at the current time.

If the particular Trajectory is not available at the time the System / Diagram is being constructed, one can create a TrajectorySource with a placeholder trajectory (e.g. PiecewisePolynomimal(Eigen::VectorXd)) with the correct number of rows, and then use UpdateTrajectory().

TrajectorySource
→ y0

Note: Scalar conversion is supported from double to any other scalar, but the stored Trajectory is not automatically scalar converted. You must call UpdateTrajectory() with an updated Trajectory<T> in order to fully enable scalar-type support on the trajectory parameters/values.

Note

This class is templated; see TrajectorySource_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.TrajectorySource, trajectory: pydrake.trajectories.Trajectory, output_derivative_order: int = 0, zero_derivatives_beyond_limits: bool = True) None
Parameter trajectory:

Trajectory used by the system.

Parameter output_derivative_order:

The number of times to take the derivative. Must be greater than or equal to zero.

Parameter zero_derivatives_beyond_limits:

All derivatives will be zero before the start time or after the end time of trajectory. However, this clamping is ignored for T=Expression.

Precondition:

The value of trajectory is a column vector. More precisely, trajectory.cols() == 1.

UpdateTrajectory(self: pydrake.systems.primitives.TrajectorySource, trajectory: pydrake.trajectories.Trajectory) None

Updates the stored trajectory. trajectory must have the same number of rows as the trajectory passed to the constructor.

template pydrake.systems.primitives.TrajectorySource_

Instantiations: TrajectorySource_[float], TrajectorySource_[AutoDiffXd], TrajectorySource_[Expression]

class pydrake.systems.primitives.TrajectorySource_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

Given a Trajectory, this System provides an output port with the value of the trajectory evaluated at the current time.

If the particular Trajectory is not available at the time the System / Diagram is being constructed, one can create a TrajectorySource with a placeholder trajectory (e.g. PiecewisePolynomimal(Eigen::VectorXd)) with the correct number of rows, and then use UpdateTrajectory().

TrajectorySource
→ y0

Note: Scalar conversion is supported from double to any other scalar, but the stored Trajectory is not automatically scalar converted. You must call UpdateTrajectory() with an updated Trajectory<T> in order to fully enable scalar-type support on the trajectory parameters/values.

__init__(self: pydrake.systems.primitives.TrajectorySource_[AutoDiffXd], trajectory: pydrake.trajectories.Trajectory_[AutoDiffXd], output_derivative_order: int = 0, zero_derivatives_beyond_limits: bool = True) None
Parameter trajectory:

Trajectory used by the system.

Parameter output_derivative_order:

The number of times to take the derivative. Must be greater than or equal to zero.

Parameter zero_derivatives_beyond_limits:

All derivatives will be zero before the start time or after the end time of trajectory. However, this clamping is ignored for T=Expression.

Precondition:

The value of trajectory is a column vector. More precisely, trajectory.cols() == 1.

UpdateTrajectory(self: pydrake.systems.primitives.TrajectorySource_[AutoDiffXd], trajectory: pydrake.trajectories.Trajectory_[AutoDiffXd]) None

Updates the stored trajectory. trajectory must have the same number of rows as the trajectory passed to the constructor.

class pydrake.systems.primitives.TrajectorySource_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

Given a Trajectory, this System provides an output port with the value of the trajectory evaluated at the current time.

If the particular Trajectory is not available at the time the System / Diagram is being constructed, one can create a TrajectorySource with a placeholder trajectory (e.g. PiecewisePolynomimal(Eigen::VectorXd)) with the correct number of rows, and then use UpdateTrajectory().

TrajectorySource
→ y0

Note: Scalar conversion is supported from double to any other scalar, but the stored Trajectory is not automatically scalar converted. You must call UpdateTrajectory() with an updated Trajectory<T> in order to fully enable scalar-type support on the trajectory parameters/values.

__init__(self: pydrake.systems.primitives.TrajectorySource_[Expression], trajectory: pydrake.trajectories.Trajectory_[Expression], output_derivative_order: int = 0, zero_derivatives_beyond_limits: bool = True) None
Parameter trajectory:

Trajectory used by the system.

Parameter output_derivative_order:

The number of times to take the derivative. Must be greater than or equal to zero.

Parameter zero_derivatives_beyond_limits:

All derivatives will be zero before the start time or after the end time of trajectory. However, this clamping is ignored for T=Expression.

Precondition:

The value of trajectory is a column vector. More precisely, trajectory.cols() == 1.

UpdateTrajectory(self: pydrake.systems.primitives.TrajectorySource_[Expression], trajectory: pydrake.trajectories.Trajectory_[Expression]) None

Updates the stored trajectory. trajectory must have the same number of rows as the trajectory passed to the constructor.

class pydrake.systems.primitives.VectorLog

This utility class serves as an in-memory cache of time-dependent vector values. Note that this is a standalone class, not a Drake System. It is primarily intended to support the Drake System primitive VectorLogSink, but can be used independently.

When the log becomes full, adding more data will cause the allocated space to double in size. If avoiding memory allocation during some performance-critical phase is desired, clients can call Reserve() to pre-allocate log storage.

This object imposes no constraints on the stored data. For example, times passed to AddData() need not be increasing in order of insertion, values are allowed to be infinite, NaN, etc.

Note

This class is templated; see VectorLog_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.VectorLog, input_size: int) None

Constructs the vector log.

Parameter input_size:

Dimension of the per-time step data set.

AddData(self: pydrake.systems.primitives.VectorLog, time: float, sample: numpy.ndarray[numpy.float64[m, 1]]) None

Adds a sample to the data set with the associated time value. The new sample and time are added to the end of the log. No constraints are imposed on the values of`time` or sample.

Parameter time:

The time value for this sample.

Parameter sample:

A vector of data of the declared size for this log.

Clear(self: pydrake.systems.primitives.VectorLog) None

Clears the logged data.

data(self: pydrake.systems.primitives.VectorLog) numpy.ndarray[numpy.float64[m, n], flags.f_contiguous]

Accesses the logged data.

The InnerPanel parameter of the return type indicates that the compiler can assume aligned access to the data.

get_input_size(self: pydrake.systems.primitives.VectorLog) int

Reports the size of the log’s input vector.

kDefaultCapacity = 1000
num_samples(self: pydrake.systems.primitives.VectorLog) int

Returns the number of samples taken since construction or last Clear().

Reserve(self: pydrake.systems.primitives.VectorLog, arg0: int) None

Reserve storage for at least capacity samples. At construction, there will be at least kDefaultCapacity; use this method to reserve more.

sample_times(self: pydrake.systems.primitives.VectorLog) numpy.ndarray[numpy.float64[m, 1]]

Accesses the logged time stamps.

template pydrake.systems.primitives.VectorLog_

Instantiations: VectorLog_[float], VectorLog_[AutoDiffXd], VectorLog_[Expression]

class pydrake.systems.primitives.VectorLog_[AutoDiffXd]

This utility class serves as an in-memory cache of time-dependent vector values. Note that this is a standalone class, not a Drake System. It is primarily intended to support the Drake System primitive VectorLogSink, but can be used independently.

When the log becomes full, adding more data will cause the allocated space to double in size. If avoiding memory allocation during some performance-critical phase is desired, clients can call Reserve() to pre-allocate log storage.

This object imposes no constraints on the stored data. For example, times passed to AddData() need not be increasing in order of insertion, values are allowed to be infinite, NaN, etc.

__init__(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd], input_size: int) None

Constructs the vector log.

Parameter input_size:

Dimension of the per-time step data set.

AddData(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd], time: pydrake.autodiffutils.AutoDiffXd, sample: numpy.ndarray[object[m, 1]]) None

Adds a sample to the data set with the associated time value. The new sample and time are added to the end of the log. No constraints are imposed on the values of`time` or sample.

Parameter time:

The time value for this sample.

Parameter sample:

A vector of data of the declared size for this log.

Clear(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd]) None

Clears the logged data.

data(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd]) numpy.ndarray[object[m, n]]

Accesses the logged data.

The InnerPanel parameter of the return type indicates that the compiler can assume aligned access to the data.

get_input_size(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd]) int

Reports the size of the log’s input vector.

kDefaultCapacity = 1000
num_samples(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd]) int

Returns the number of samples taken since construction or last Clear().

Reserve(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd], arg0: int) None

Reserve storage for at least capacity samples. At construction, there will be at least kDefaultCapacity; use this method to reserve more.

sample_times(self: pydrake.systems.primitives.VectorLog_[AutoDiffXd]) numpy.ndarray[object[m, 1]]

Accesses the logged time stamps.

class pydrake.systems.primitives.VectorLog_[Expression]

This utility class serves as an in-memory cache of time-dependent vector values. Note that this is a standalone class, not a Drake System. It is primarily intended to support the Drake System primitive VectorLogSink, but can be used independently.

When the log becomes full, adding more data will cause the allocated space to double in size. If avoiding memory allocation during some performance-critical phase is desired, clients can call Reserve() to pre-allocate log storage.

This object imposes no constraints on the stored data. For example, times passed to AddData() need not be increasing in order of insertion, values are allowed to be infinite, NaN, etc.

__init__(self: pydrake.systems.primitives.VectorLog_[Expression], input_size: int) None

Constructs the vector log.

Parameter input_size:

Dimension of the per-time step data set.

AddData(self: pydrake.systems.primitives.VectorLog_[Expression], time: pydrake.symbolic.Expression, sample: numpy.ndarray[object[m, 1]]) None

Adds a sample to the data set with the associated time value. The new sample and time are added to the end of the log. No constraints are imposed on the values of`time` or sample.

Parameter time:

The time value for this sample.

Parameter sample:

A vector of data of the declared size for this log.

Clear(self: pydrake.systems.primitives.VectorLog_[Expression]) None

Clears the logged data.

data(self: pydrake.systems.primitives.VectorLog_[Expression]) numpy.ndarray[object[m, n]]

Accesses the logged data.

The InnerPanel parameter of the return type indicates that the compiler can assume aligned access to the data.

get_input_size(self: pydrake.systems.primitives.VectorLog_[Expression]) int

Reports the size of the log’s input vector.

kDefaultCapacity = 1000
num_samples(self: pydrake.systems.primitives.VectorLog_[Expression]) int

Returns the number of samples taken since construction or last Clear().

Reserve(self: pydrake.systems.primitives.VectorLog_[Expression], arg0: int) None

Reserve storage for at least capacity samples. At construction, there will be at least kDefaultCapacity; use this method to reserve more.

sample_times(self: pydrake.systems.primitives.VectorLog_[Expression]) numpy.ndarray[object[m, 1]]

Accesses the logged time stamps.

class pydrake.systems.primitives.VectorLogSink

Bases: pydrake.systems.framework.LeafSystem

A discrete sink block which logs its vector-valued input to per-context memory. This data is then retrievable outside of System operation, e.g. after a simulation. See the warning below.

The stored log (a VectorLog) holds a large, Eigen matrix for data storage, where each column corresponds to a data point. The VectorLogSink saves a data point and the context time whenever it samples its input.

Warning

The logged data MUST NOT be used to modify the behavior of a simulation. In technical terms, the log is not stored as System State, so should not be considered part of that state. This distinction allows the implementation to use Publish() as the event handler, rather than one of the state-modifying handlers.

By default, sampling is performed every time the Simulator completes a trajectory-advancing substep (that is, via a per-step Publish event), with the first sample occurring during Simulator::Initialize(). That means the samples will generally be unevenly spaced in time. If you prefer regular sampling, you may optionally specify a “publish period” in which case sampling occurs periodically, with the first sample occurring at time 0. Alternatively (not common), you can specify that logging should only occur at “forced publish” events, meaning at explicit calls to System::Publish(). The Simulator’s “publish every time step” option also results in forced publish events, so should be disabled (the default setting) if you want to control logging yourself.

See also

LogVectorOutput() for a convenient way to add logging to a Diagram.

data→
VectorLogSink

Note

This class is templated; see VectorLogSink_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.VectorLogSink, input_size: int, publish_period: float = 0.0) -> None

Constructs the vector log sink.

Sets the default set of publish triggers: if publish_period = 0, publishes on forced events and per step, if publish_period > 0, publishes on forced events and periodically.

Parameter input_size:

Dimension of the (single) input port. This corresponds to the number of rows of the data matrix.

Parameter publish_period:

Period that messages will be published (optional). If the publish period is zero or not supplied, VectorLogSink will use per-step publishing instead; see LeafSystem::DeclarePerStepPublishEvent().

Precondition:

publish_period is non-negative.

See also

LogVectorOutput() helper function for a convenient way to add logging.

  1. __init__(self: pydrake.systems.primitives.VectorLogSink, input_size: int, publish_triggers: set[pydrake.systems.framework.TriggerType], publish_period: float = 0.0) -> None

Constructs the vector log sink with a specified set of publish triggers.

Parameter input_size:

Dimension of the (single) input port. This corresponds to the number of rows of the data matrix.

Parameter publish_triggers:

Set of triggers that determine when messages will be published. Supported TriggerTypes are {kForced, kPeriodic, kPerStep}. Will throw an error if empty or if unsupported types are provided.

Parameter publish_period:

Period that messages will be published (optional). publish_period should only be non-zero if one of the publish_triggers is kPeriodic.

Precondition:

publish_period is non-negative.

Precondition:

publish_period > 0 if and only if publish_triggers contains kPeriodic.

See also

LogVectorOutput() helper function for a convenient way to add logging.

FindLog(self: pydrake.systems.primitives.VectorLogSink, context: pydrake.systems.framework.Context) pydrake.systems.primitives.VectorLog

Access the log within a containing root context.

Raises
  • RuntimeError if supplied context is not a root context, or was not

  • created for the containing diagram.

FindMutableLog(self: pydrake.systems.primitives.VectorLogSink, context: pydrake.systems.framework.Context) pydrake.systems.primitives.VectorLog

Access the log as a mutable object within a containing root context.

Raises
  • RuntimeError if supplied context is not a root context, or was not

  • created for the containing diagram.

GetLog(self: pydrake.systems.primitives.VectorLogSink, context: pydrake.systems.framework.Context) pydrake.systems.primitives.VectorLog

Access the log within this component’s context.

Raises

RuntimeError if context was not created for this system.

GetMutableLog(self: pydrake.systems.primitives.VectorLogSink, context: pydrake.systems.framework.Context) pydrake.systems.primitives.VectorLog

Access the log as a mutable object within this component’s context.

Raises

RuntimeError if context was not created for this system.

template pydrake.systems.primitives.VectorLogSink_

Instantiations: VectorLogSink_[float], VectorLogSink_[AutoDiffXd], VectorLogSink_[Expression]

class pydrake.systems.primitives.VectorLogSink_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A discrete sink block which logs its vector-valued input to per-context memory. This data is then retrievable outside of System operation, e.g. after a simulation. See the warning below.

The stored log (a VectorLog) holds a large, Eigen matrix for data storage, where each column corresponds to a data point. The VectorLogSink saves a data point and the context time whenever it samples its input.

Warning

The logged data MUST NOT be used to modify the behavior of a simulation. In technical terms, the log is not stored as System State, so should not be considered part of that state. This distinction allows the implementation to use Publish() as the event handler, rather than one of the state-modifying handlers.

By default, sampling is performed every time the Simulator completes a trajectory-advancing substep (that is, via a per-step Publish event), with the first sample occurring during Simulator::Initialize(). That means the samples will generally be unevenly spaced in time. If you prefer regular sampling, you may optionally specify a “publish period” in which case sampling occurs periodically, with the first sample occurring at time 0. Alternatively (not common), you can specify that logging should only occur at “forced publish” events, meaning at explicit calls to System::Publish(). The Simulator’s “publish every time step” option also results in forced publish events, so should be disabled (the default setting) if you want to control logging yourself.

See also

LogVectorOutput() for a convenient way to add logging to a Diagram.

data→
VectorLogSink
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.VectorLogSink_[AutoDiffXd], input_size: int, publish_period: float = 0.0) -> None

Constructs the vector log sink.

Sets the default set of publish triggers: if publish_period = 0, publishes on forced events and per step, if publish_period > 0, publishes on forced events and periodically.

Parameter input_size:

Dimension of the (single) input port. This corresponds to the number of rows of the data matrix.

Parameter publish_period:

Period that messages will be published (optional). If the publish period is zero or not supplied, VectorLogSink will use per-step publishing instead; see LeafSystem::DeclarePerStepPublishEvent().

Precondition:

publish_period is non-negative.

See also

LogVectorOutput() helper function for a convenient way to add logging.

  1. __init__(self: pydrake.systems.primitives.VectorLogSink_[AutoDiffXd], input_size: int, publish_triggers: set[pydrake.systems.framework.TriggerType], publish_period: float = 0.0) -> None

Constructs the vector log sink with a specified set of publish triggers.

Parameter input_size:

Dimension of the (single) input port. This corresponds to the number of rows of the data matrix.

Parameter publish_triggers:

Set of triggers that determine when messages will be published. Supported TriggerTypes are {kForced, kPeriodic, kPerStep}. Will throw an error if empty or if unsupported types are provided.

Parameter publish_period:

Period that messages will be published (optional). publish_period should only be non-zero if one of the publish_triggers is kPeriodic.

Precondition:

publish_period is non-negative.

Precondition:

publish_period > 0 if and only if publish_triggers contains kPeriodic.

See also

LogVectorOutput() helper function for a convenient way to add logging.

FindLog(self: pydrake.systems.primitives.VectorLogSink_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.systems.primitives.VectorLog_[AutoDiffXd]

Access the log within a containing root context.

Raises
  • RuntimeError if supplied context is not a root context, or was not

  • created for the containing diagram.

FindMutableLog(self: pydrake.systems.primitives.VectorLogSink_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.systems.primitives.VectorLog_[AutoDiffXd]

Access the log as a mutable object within a containing root context.

Raises
  • RuntimeError if supplied context is not a root context, or was not

  • created for the containing diagram.

GetLog(self: pydrake.systems.primitives.VectorLogSink_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.systems.primitives.VectorLog_[AutoDiffXd]

Access the log within this component’s context.

Raises

RuntimeError if context was not created for this system.

GetMutableLog(self: pydrake.systems.primitives.VectorLogSink_[AutoDiffXd], context: pydrake.systems.framework.Context_[AutoDiffXd]) pydrake.systems.primitives.VectorLog_[AutoDiffXd]

Access the log as a mutable object within this component’s context.

Raises

RuntimeError if context was not created for this system.

class pydrake.systems.primitives.VectorLogSink_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A discrete sink block which logs its vector-valued input to per-context memory. This data is then retrievable outside of System operation, e.g. after a simulation. See the warning below.

The stored log (a VectorLog) holds a large, Eigen matrix for data storage, where each column corresponds to a data point. The VectorLogSink saves a data point and the context time whenever it samples its input.

Warning

The logged data MUST NOT be used to modify the behavior of a simulation. In technical terms, the log is not stored as System State, so should not be considered part of that state. This distinction allows the implementation to use Publish() as the event handler, rather than one of the state-modifying handlers.

By default, sampling is performed every time the Simulator completes a trajectory-advancing substep (that is, via a per-step Publish event), with the first sample occurring during Simulator::Initialize(). That means the samples will generally be unevenly spaced in time. If you prefer regular sampling, you may optionally specify a “publish period” in which case sampling occurs periodically, with the first sample occurring at time 0. Alternatively (not common), you can specify that logging should only occur at “forced publish” events, meaning at explicit calls to System::Publish(). The Simulator’s “publish every time step” option also results in forced publish events, so should be disabled (the default setting) if you want to control logging yourself.

See also

LogVectorOutput() for a convenient way to add logging to a Diagram.

data→
VectorLogSink
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.VectorLogSink_[Expression], input_size: int, publish_period: float = 0.0) -> None

Constructs the vector log sink.

Sets the default set of publish triggers: if publish_period = 0, publishes on forced events and per step, if publish_period > 0, publishes on forced events and periodically.

Parameter input_size:

Dimension of the (single) input port. This corresponds to the number of rows of the data matrix.

Parameter publish_period:

Period that messages will be published (optional). If the publish period is zero or not supplied, VectorLogSink will use per-step publishing instead; see LeafSystem::DeclarePerStepPublishEvent().

Precondition:

publish_period is non-negative.

See also

LogVectorOutput() helper function for a convenient way to add logging.

  1. __init__(self: pydrake.systems.primitives.VectorLogSink_[Expression], input_size: int, publish_triggers: set[pydrake.systems.framework.TriggerType], publish_period: float = 0.0) -> None

Constructs the vector log sink with a specified set of publish triggers.

Parameter input_size:

Dimension of the (single) input port. This corresponds to the number of rows of the data matrix.

Parameter publish_triggers:

Set of triggers that determine when messages will be published. Supported TriggerTypes are {kForced, kPeriodic, kPerStep}. Will throw an error if empty or if unsupported types are provided.

Parameter publish_period:

Period that messages will be published (optional). publish_period should only be non-zero if one of the publish_triggers is kPeriodic.

Precondition:

publish_period is non-negative.

Precondition:

publish_period > 0 if and only if publish_triggers contains kPeriodic.

See also

LogVectorOutput() helper function for a convenient way to add logging.

FindLog(self: pydrake.systems.primitives.VectorLogSink_[Expression], context: pydrake.systems.framework.Context_[Expression]) pydrake.systems.primitives.VectorLog_[Expression]

Access the log within a containing root context.

Raises
  • RuntimeError if supplied context is not a root context, or was not

  • created for the containing diagram.

FindMutableLog(self: pydrake.systems.primitives.VectorLogSink_[Expression], context: pydrake.systems.framework.Context_[Expression]) pydrake.systems.primitives.VectorLog_[Expression]

Access the log as a mutable object within a containing root context.

Raises
  • RuntimeError if supplied context is not a root context, or was not

  • created for the containing diagram.

GetLog(self: pydrake.systems.primitives.VectorLogSink_[Expression], context: pydrake.systems.framework.Context_[Expression]) pydrake.systems.primitives.VectorLog_[Expression]

Access the log within this component’s context.

Raises

RuntimeError if context was not created for this system.

GetMutableLog(self: pydrake.systems.primitives.VectorLogSink_[Expression], context: pydrake.systems.framework.Context_[Expression]) pydrake.systems.primitives.VectorLog_[Expression]

Access the log as a mutable object within this component’s context.

Raises

RuntimeError if context was not created for this system.

class pydrake.systems.primitives.WrapToSystem

Bases: pydrake.systems.framework.LeafSystem

An element-wise wrapping block that transforms the specified indices of the input signal u into the interval [low, high). Precisely, the output element i is given the value:

Click to expand C++ code...
outputᵢ = inputᵢ + kᵢ*(highᵢ-lowᵢ)

for the unique integer value kᵢ that lands the output in the desired interval.

u0→
WrapToSystem
→ y0

Note

This class is templated; see WrapToSystem_ for the list of instantiations.

__init__(self: pydrake.systems.primitives.WrapToSystem, arg0: int) None

Constructs a system to pass through a fixed-size input vector to the output. Additional calls to set_interval() are required to produce any wrapping behavior.

set_interval(self: pydrake.systems.primitives.WrapToSystem, arg0: int, arg1: float, arg2: float) None

Sets the system to wrap the index element of the input vector to the interval [low, high). If this method is called multiple times for the same index, then only the last interval will be used. low and high should be finite, and low < high.

template pydrake.systems.primitives.WrapToSystem_

Instantiations: WrapToSystem_[float], WrapToSystem_[AutoDiffXd], WrapToSystem_[Expression]

class pydrake.systems.primitives.WrapToSystem_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

An element-wise wrapping block that transforms the specified indices of the input signal u into the interval [low, high). Precisely, the output element i is given the value:

Click to expand C++ code...
outputᵢ = inputᵢ + kᵢ*(highᵢ-lowᵢ)

for the unique integer value kᵢ that lands the output in the desired interval.

u0→
WrapToSystem
→ y0
__init__(self: pydrake.systems.primitives.WrapToSystem_[AutoDiffXd], arg0: int) None

Constructs a system to pass through a fixed-size input vector to the output. Additional calls to set_interval() are required to produce any wrapping behavior.

set_interval(self: pydrake.systems.primitives.WrapToSystem_[AutoDiffXd], arg0: int, arg1: pydrake.autodiffutils.AutoDiffXd, arg2: pydrake.autodiffutils.AutoDiffXd) None

Sets the system to wrap the index element of the input vector to the interval [low, high). If this method is called multiple times for the same index, then only the last interval will be used. low and high should be finite, and low < high.

class pydrake.systems.primitives.WrapToSystem_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

An element-wise wrapping block that transforms the specified indices of the input signal u into the interval [low, high). Precisely, the output element i is given the value:

Click to expand C++ code...
outputᵢ = inputᵢ + kᵢ*(highᵢ-lowᵢ)

for the unique integer value kᵢ that lands the output in the desired interval.

u0→
WrapToSystem
→ y0
__init__(self: pydrake.systems.primitives.WrapToSystem_[Expression], arg0: int) None

Constructs a system to pass through a fixed-size input vector to the output. Additional calls to set_interval() are required to produce any wrapping behavior.

set_interval(self: pydrake.systems.primitives.WrapToSystem_[Expression], arg0: int, arg1: pydrake.symbolic.Expression, arg2: pydrake.symbolic.Expression) None

Sets the system to wrap the index element of the input vector to the interval [low, high). If this method is called multiple times for the same index, then only the last interval will be used. low and high should be finite, and low < high.

class pydrake.systems.primitives.ZeroOrderHold

Bases: pydrake.systems.framework.LeafSystem

A zero order hold block with input u, which may be vector-valued (discrete or continuous) or abstract, and discrete output y, where the y is sampled from u with a fixed period (and optional offset).

u→
ZeroOrderHold
→ y

The discrete state space dynamics of ZeroOrderHold is:

Click to expand C++ code...
xₙ₊₁ = uₙ     // update
  yₙ   = xₙ     // output
  x₀   = xᵢₙᵢₜ  // initialize

where xᵢₙᵢₜ = 0 for vector-valued ZeroOrderHold, and xᵢₙᵢₜ is a given value for abstract-valued ZeroOrderHold. Use SetVectorState() to set xₙ in the context for vector-valued ZeroOrderHold.

See discrete_systems “Discrete Systems” for general information about discrete systems in Drake, including how they interact with continuous systems.

Note

This system defaults to a periodic update with zero offset, in which case the first update occurs at t=0. When used with a Simulator, the output port is equal to xᵢₙᵢₜ after simulator.Initialize(), but is immediately updated to u₀ at the start of the first step. If you want to force that initial update, use simulator.AdvanceTo(0.0).

Note

For an abstract-valued ZeroOrderHold, scalar-type conversion is not supported since AbstractValue does not support it.

Note

This class is templated; see ZeroOrderHold_ for the list of instantiations.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.ZeroOrderHold, period_sec: float, vector_size: int, offset_sec: float = 0.0) -> None

Constructs a ZeroOrderHold system with the given period_sec, over a vector-valued input of size vector_size. The default initial value for this system will be zero. The first update occurs at t=offset_sec, which must be >= 0.

  1. __init__(self: pydrake.systems.primitives.ZeroOrderHold, period_sec: float, abstract_model_value: pydrake.common.value.AbstractValue, offset_sec: float = 0.0) -> None

Constructs a ZeroOrderHold system with the given period_sec, over a abstract-valued input abstract_model_value. The default initial value for this system will be abstract_model_value. The first update occurs at t=offset_sec, which must be >= 0.

offset(self: pydrake.systems.primitives.ZeroOrderHold) float

Reports the first update time of this hold (in seconds).

period(self: pydrake.systems.primitives.ZeroOrderHold) float

Reports the period of this hold (in seconds).

SetVectorState(self: pydrake.systems.primitives.ZeroOrderHold, arg0: pydrake.systems.framework.Context, arg1: numpy.ndarray[numpy.float64[m, 1]]) None

Sets the value of the state by modifying it in the context. value must be a column vector of the appropriate size. This can only be used to initialize a vector-valued state.

template pydrake.systems.primitives.ZeroOrderHold_

Instantiations: ZeroOrderHold_[float], ZeroOrderHold_[AutoDiffXd], ZeroOrderHold_[Expression]

class pydrake.systems.primitives.ZeroOrderHold_[AutoDiffXd]

Bases: pydrake.systems.framework.LeafSystem_[AutoDiffXd]

A zero order hold block with input u, which may be vector-valued (discrete or continuous) or abstract, and discrete output y, where the y is sampled from u with a fixed period (and optional offset).

u→
ZeroOrderHold
→ y

The discrete state space dynamics of ZeroOrderHold is:

Click to expand C++ code...
xₙ₊₁ = uₙ     // update
  yₙ   = xₙ     // output
  x₀   = xᵢₙᵢₜ  // initialize

where xᵢₙᵢₜ = 0 for vector-valued ZeroOrderHold, and xᵢₙᵢₜ is a given value for abstract-valued ZeroOrderHold. Use SetVectorState() to set xₙ in the context for vector-valued ZeroOrderHold.

See discrete_systems “Discrete Systems” for general information about discrete systems in Drake, including how they interact with continuous systems.

Note

This system defaults to a periodic update with zero offset, in which case the first update occurs at t=0. When used with a Simulator, the output port is equal to xᵢₙᵢₜ after simulator.Initialize(), but is immediately updated to u₀ at the start of the first step. If you want to force that initial update, use simulator.AdvanceTo(0.0).

Note

For an abstract-valued ZeroOrderHold, scalar-type conversion is not supported since AbstractValue does not support it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.ZeroOrderHold_[AutoDiffXd], period_sec: float, vector_size: int, offset_sec: float = 0.0) -> None

Constructs a ZeroOrderHold system with the given period_sec, over a vector-valued input of size vector_size. The default initial value for this system will be zero. The first update occurs at t=offset_sec, which must be >= 0.

  1. __init__(self: pydrake.systems.primitives.ZeroOrderHold_[AutoDiffXd], period_sec: float, abstract_model_value: pydrake.common.value.AbstractValue, offset_sec: float = 0.0) -> None

Constructs a ZeroOrderHold system with the given period_sec, over a abstract-valued input abstract_model_value. The default initial value for this system will be abstract_model_value. The first update occurs at t=offset_sec, which must be >= 0.

offset(self: pydrake.systems.primitives.ZeroOrderHold_[AutoDiffXd]) float

Reports the first update time of this hold (in seconds).

period(self: pydrake.systems.primitives.ZeroOrderHold_[AutoDiffXd]) float

Reports the period of this hold (in seconds).

SetVectorState(self: pydrake.systems.primitives.ZeroOrderHold_[AutoDiffXd], arg0: pydrake.systems.framework.Context_[AutoDiffXd], arg1: numpy.ndarray[object[m, 1]]) None

Sets the value of the state by modifying it in the context. value must be a column vector of the appropriate size. This can only be used to initialize a vector-valued state.

class pydrake.systems.primitives.ZeroOrderHold_[Expression]

Bases: pydrake.systems.framework.LeafSystem_[Expression]

A zero order hold block with input u, which may be vector-valued (discrete or continuous) or abstract, and discrete output y, where the y is sampled from u with a fixed period (and optional offset).

u→
ZeroOrderHold
→ y

The discrete state space dynamics of ZeroOrderHold is:

Click to expand C++ code...
xₙ₊₁ = uₙ     // update
  yₙ   = xₙ     // output
  x₀   = xᵢₙᵢₜ  // initialize

where xᵢₙᵢₜ = 0 for vector-valued ZeroOrderHold, and xᵢₙᵢₜ is a given value for abstract-valued ZeroOrderHold. Use SetVectorState() to set xₙ in the context for vector-valued ZeroOrderHold.

See discrete_systems “Discrete Systems” for general information about discrete systems in Drake, including how they interact with continuous systems.

Note

This system defaults to a periodic update with zero offset, in which case the first update occurs at t=0. When used with a Simulator, the output port is equal to xᵢₙᵢₜ after simulator.Initialize(), but is immediately updated to u₀ at the start of the first step. If you want to force that initial update, use simulator.AdvanceTo(0.0).

Note

For an abstract-valued ZeroOrderHold, scalar-type conversion is not supported since AbstractValue does not support it.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pydrake.systems.primitives.ZeroOrderHold_[Expression], period_sec: float, vector_size: int, offset_sec: float = 0.0) -> None

Constructs a ZeroOrderHold system with the given period_sec, over a vector-valued input of size vector_size. The default initial value for this system will be zero. The first update occurs at t=offset_sec, which must be >= 0.

  1. __init__(self: pydrake.systems.primitives.ZeroOrderHold_[Expression], period_sec: float, abstract_model_value: pydrake.common.value.AbstractValue, offset_sec: float = 0.0) -> None

Constructs a ZeroOrderHold system with the given period_sec, over a abstract-valued input abstract_model_value. The default initial value for this system will be abstract_model_value. The first update occurs at t=offset_sec, which must be >= 0.

offset(self: pydrake.systems.primitives.ZeroOrderHold_[Expression]) float

Reports the first update time of this hold (in seconds).

period(self: pydrake.systems.primitives.ZeroOrderHold_[Expression]) float

Reports the period of this hold (in seconds).

SetVectorState(self: pydrake.systems.primitives.ZeroOrderHold_[Expression], arg0: pydrake.systems.framework.Context_[Expression], arg1: numpy.ndarray[object[m, 1]]) None

Sets the value of the state by modifying it in the context. value must be a column vector of the appropriate size. This can only be used to initialize a vector-valued state.