pfh.glidersim.simulator#

Models for simulating flight trajectories.

FIXME: explain state dynamics models

Functions

prettyprint_state(state[, header, footer])

Pretty-print a single instance of a StateDynamics.state_dtype

recompute_derivatives(model, times, states)

Re-run the dynamics to access the state derivatives (accelerations).

simulate(model, state0, T, dt[, t0])

Generate a state trajectory using the model's state derivatives.

Classes

ParagliderStateDynamics6a(paraglider[, ...])

State dynamics for a 6 DoF paraglider model.

ParagliderStateDynamics9a(paraglider[, ...])

State dynamics for a 9 DoF paraglider model.

StateDynamics(*args, **kwargs)

Interface for classes that implement a StateDynamics model.

class pfh.glidersim.simulator.StateDynamics(*args, **kwargs)#

Bases: Protocol

Interface for classes that implement a StateDynamics model.

StateDynamics are used to simulate state trajectories.

Methods

cleanup(t, state)

Perform any necessary cleanup after each integration step.

derivatives(t, state, *args)

Compute the state derivatives given a specific state at time t.

extra_arguments()

Any additional arguments used to compute the state derivatives.

state_dtype: Any#
abstract classmethod extra_arguments()#

Any additional arguments used to compute the state derivatives.

Returns
tuple

Additional arguments that the integrator should pass to the StateDynamics.derivatives method.

abstract cleanup(t: float, state) None#

Perform any necessary cleanup after each integration step.

NOTE: mutating state will modify the integrator’s internal state

Parameters
tfloat [s]

The timestamp of the completed integration step.

statemodel.state_dtype

The state_dtype of the state dynamics model.

abstract derivatives(t: float, state, *args)#

Compute the state derivatives given a specific state at time t.

The inputs to the system at time t are given the by the control functions internal to the model.

Parameters
tfloat [s]

The current time

statemodel.state_dtype

The current state

argstuple

Extra arguments for computing the derivatives as defined by StateDynamics.extra_arguments.

Returns
state_dotmodel.state_dtype

The state derivatives

__init__(*args, **kwargs)#
class pfh.glidersim.simulator.ParagliderStateDynamics6a(paraglider: ParagliderSystemDynamics6a, delta_a: float | Callable = 0, delta_bl: float | Callable = 0, delta_br: float | Callable = 0, delta_w: float | Callable = 0, rho_air: float | Callable = 1.225, v_W2e=(0, 0, 0))#

Bases: pfh.glidersim.simulator.StateDynamics

State dynamics for a 6 DoF paraglider model.

Implements the choice of state variables and their associated dynamics outlined in .

Methods

cleanup(t, state)

Perform any necessary cleanup after each integration step.

derivatives(t, state, params)

Compute the state derivatives given a specific state at time t.

extra_arguments()

Any additional arguments used to compute the state derivatives.

starting_equilibrium()

Compute the equilibrium state at t = 0 assuming uniform local wind.

state_dtype: Any = [('q_b2e', <class 'float'>, (4,)), ('omega_b2e', <class 'float'>, (3,)), ('r_RM2O', <class 'float'>, (3,)), ('v_RM2e', <class 'float'>, (3,))]#
__init__(paraglider: ParagliderSystemDynamics6a, delta_a: float | Callable = 0, delta_bl: float | Callable = 0, delta_br: float | Callable = 0, delta_w: float | Callable = 0, rho_air: float | Callable = 1.225, v_W2e=(0, 0, 0))#
extra_arguments()#

Any additional arguments used to compute the state derivatives.

Returns
tuple

Additional arguments that the integrator should pass to the StateDynamics.derivatives method.

cleanup(t: float, state)#

Perform any necessary cleanup after each integration step.

NOTE: mutating state will modify the integrator’s internal state

Parameters
tfloat [s]

The timestamp of the completed integration step.

statemodel.state_dtype

The state_dtype of the state dynamics model.

derivatives(t, state, params)#

Compute the state derivatives given a specific state at time t.

The inputs to the system at time t are given the by the control functions internal to the model.

Parameters
tfloat [s]

The current time

statemodel.state_dtype

The current state

argstuple

Extra arguments for computing the derivatives as defined by StateDynamics.extra_arguments.

Returns
state_dotmodel.state_dtype

The state derivatives

starting_equilibrium()#

Compute the equilibrium state at t = 0 assuming uniform local wind.

In this case, “equilibrium” means “non-accelerating and no sideslip”. In a uniform wind field, this steady-state definition requires symmetric brakes and no weight shift.

Equilibrium is first calculated assuming zero wind. Steady-state is established by relative wind, so the local wind vector is merely an offset from the zero-wind steady-state. The non-zero local wind is included by adding it to the equilibrium v_RM2e.

Returns
gsim.simulator.ParagliderStateDynamics6a.state_dtype

The equilibrium state

class pfh.glidersim.simulator.ParagliderStateDynamics9a(paraglider: ParagliderSystemDynamics9a, delta_a: float | Callable = 0, delta_bl: float | Callable = 0, delta_br: float | Callable = 0, delta_w: float | Callable = 0, rho_air: float | Callable = 1.225, v_W2e=(0, 0, 0))#

Bases: pfh.glidersim.simulator.StateDynamics

State dynamics for a 9 DoF paraglider model.

Implements the choice of state variables and their associated dynamics outlined in .

Methods

cleanup(t, state)

Perform any necessary cleanup after each integration step.

derivatives(t, state, params)

Compute the state derivatives given a specific state at time t.

extra_arguments()

Any additional arguments used to compute the state derivatives.

starting_equilibrium()

Compute the equilibrium state at t = 0 assuming uniform local wind.

state_dtype: Any = [('q_b2e', <class 'float'>, (4,)), ('q_p2e', <class 'float'>, (4,)), ('omega_b2e', <class 'float'>, (3,)), ('omega_p2e', <class 'float'>, (3,)), ('r_RM2O', <class 'float'>, (3,)), ('v_RM2e', <class 'float'>, (3,))]#
__init__(paraglider: ParagliderSystemDynamics9a, delta_a: float | Callable = 0, delta_bl: float | Callable = 0, delta_br: float | Callable = 0, delta_w: float | Callable = 0, rho_air: float | Callable = 1.225, v_W2e=(0, 0, 0))#
extra_arguments()#

Any additional arguments used to compute the state derivatives.

Returns
tuple

Additional arguments that the integrator should pass to the StateDynamics.derivatives method.

cleanup(t, state)#

Perform any necessary cleanup after each integration step.

NOTE: mutating state will modify the integrator’s internal state

Parameters
tfloat [s]

The timestamp of the completed integration step.

statemodel.state_dtype

The state_dtype of the state dynamics model.

derivatives(t, state, params)#

Compute the state derivatives given a specific state at time t.

The inputs to the system at time t are given the by the control functions internal to the model.

Parameters
tfloat [s]

The current time

statemodel.state_dtype

The current state

argstuple

Extra arguments for computing the derivatives as defined by StateDynamics.extra_arguments.

Returns
state_dotmodel.state_dtype

The state derivatives

starting_equilibrium()#

Compute the equilibrium state at t = 0 assuming uniform local wind.

In this case, “equilibrium” means “non-accelerating and no sideslip”. In a uniform wind field, this steady-state definition requires symmetric brakes and no weight shift.

Equilibrium is first calculated assuming zero wind. Steady-state is established by relative wind, so the local wind vector is merely an offset from the zero-wind steady-state. The non-zero local wind is included by adding it to the equilibrium v_RM2e.

Returns
gsim.simulator.ParagliderStateDynamics9a.state_dtype

The equilibrium state

pfh.glidersim.simulator.simulate(model: pfh.glidersim.simulator.StateDynamics, state0, T: float, dt: float, t0: float = 0.0)#

Generate a state trajectory using the model’s state derivatives.

Parameters
modelStateDynamics

The model that provides state_dtype and derivatives

state0model.state_dtype

The initial state

Tfloat [seconds]

The total simulation time

dtfloat [seconds]

The simulation step size. This determines the time separation of each point in the state trajectory, but the RK4 integrator is free to use a different step size internally.

t0float [seconds], optional

The start time of the simulation. Useful for models with time varying behavior (eg, wind fields).

Returns
timesarray of float, shape (K+1,) [seconds]

The timestamp of each solution

statesarray of model.state_dtype, shape (K+1,)

The state trajectory.

pfh.glidersim.simulator.prettyprint_state(state, header: Optional[str] = None, footer: Optional[str] = None) None#

Pretty-print a single instance of a StateDynamics.state_dtype

Parameters
stateStateDynamics.state_dtype

The state to pretty-print.

headerstring, optional

A string to print on a separate line preceding the states.

footerstring, optional

A string to print on a separate line after the states.

Notes

Don’t rely on this function. It’s here because I currently find it useful in some scripting, but overall I’m not a fan of hard-coding this information. Then again, I’m in crunch mode, so…

pfh.glidersim.simulator.recompute_derivatives(model: pfh.glidersim.simulator.StateDynamics, times, states)#

Re-run the dynamics to access the state derivatives (accelerations).

In simulate the derivatives are internal, but it can be helpful to know the accelerations at each time step. This is a bit of a kludge, but it’s fast so good enough for now.

Parameters
modelStateDynamics

The state dynamics model that generated the derivatives.

timesarray of float

The time value at each step.

statesarray of model.state_dtype

The state of the simulation at each step.

Returns
derivativesarray of model.state_dtype

The derivatives of the state variables at each step.