The state object

Contents

The state object#

class c4dynamics.states.state.state(**kwargs)[source]#

Custom state object.

A state object represents a state vector and other attributes that form an entity of a physical (dynamic) system.

A custom state object means any set of state variables is possible, while pre-defined states from the state library are ready to use out of the box.

Keyword Arguments:

**kwargs (float or int) – Keyword arguments representing the variables and their initial conditions. Each key is a variable name and each value is its initial condition. For example: s = c4d.state(x = 0, theta = 3.14)

See also

states

Examples

Pendulum

>>> s = c4d.state(theta = 10 * c4d.d2r, omega = 0) 
[ θ  ω ]

Strapdown navigation system

>>> s = c4d.state(x = 0, y = 0, z = 0, vx = 0, vy = 0, vz = 0, q0 = 0, q1 = 0, q2 = 0, q3 = 0, bax = 0, bay = 0, baz = 0)   
[ x  y  z  vx  vy  vz  q0  q1  q2  q3  bax  bay  baz ]

Objects tracker

>>> s = c4d.state(x = 960, y = 540, w = 20, h = 10)   
[ x  y  w  h ]

Aircraft

>>> s = c4d.state(x = 0, y = 0, z = 0, vx = 0, vy = 0, vz = 0, phi = 0, theta = 0, psi = 0, p = 0, q = 0, r = 0)   
[ x  y  z  vx  vy  vz  φ  θ  Ψ  p  q  r ]

Self-driving car

>>> s = c4d.state(x = 0, y = 0, v = 0, theta = 0, omega = 0)   
[ x  y  v  θ  ω ]

Robot arm

>>> s = c4d.state(theta1 = 0, theta2 = 0, omega1 = 0, omega2 = 0)   
[ θ1  θ2  ω1  ω2 ]

Operations

The following properties and methods are categorized into two main types: mathematical operations and data management operations.

Mathematical operations

Operations that involve direct manipulation of the state vector using mathematical methods. These operations include normalization, norm calculation, and other operations assume cartesian coordinates.

Properties

state.X

Gets and sets the state vector variables.

state.X0

Returns the initial conditions of the state vector.

state.norm

Returns the Euclidean norm of the state vector.

state.normalize

Returns a unit vector representation of the state vector.

state.position

Returns a vector of position coordinates.

state.velocity

Returns a vector of velocity coordinates.

Methods

state.addvars(**kwargs)

Add state variables.

state.P([state2])

Euclidean distance.

state.V()

Velocity Magnitude.

Data management operations

Operations that involve managing the state vector data, such as storing and retrieving states at different times or handling time series data.

Methods

state.store([t])

Stores the current state.

state.storeparams(params[, t])

Stores parameters.

state.data([var, scale])

Returns arrays of stored time and data.

state.timestate(t)

Returns the state as stored at time t.

state.plot(var[, scale, ax, filename, darkmode])

Draws plots of variable evolution over time.