Source code for aerosandbox.dynamics.rigid_body.rigid_2D.body

from aerosandbox.dynamics.rigid_body.rigid_3D.body_euler import (
    DynamicsRigidBody3DBodyEuler,
)
from aerosandbox.weights.mass_properties import MassProperties
import aerosandbox.numpy as np
from typing import Union, Dict


[docs]class DynamicsRigidBody2DBody(DynamicsRigidBody3DBodyEuler): """ Dynamics instance: * simulating a rigid body * in 2D * with velocity parameterized in body axes State variables: x_e: x-position, in Earth axes. [meters] z_e: z-position, in Earth axes. [meters] u_b: x-velocity, in body axes. [m/s] w_b: z-velocity, in body axes. [m/s] theta: pitch angle. [rad] q: y-angular-velocity, in body axes. [rad/sec] Control variables: Fx_b: Force along the body-x axis. [N] Fz_b: Force along the body-z axis. [N] My_b: Moment about the body-y axis. [Nm] """ def __init__( self, mass_props: MassProperties = None, x_e: Union[float, np.ndarray] = 0, z_e: Union[float, np.ndarray] = 0, u_b: Union[float, np.ndarray] = 0, w_b: Union[float, np.ndarray] = 0, theta: Union[float, np.ndarray] = 0, q: Union[float, np.ndarray] = 0, ): # Initialize state variables
[docs] self.mass_props = MassProperties() if mass_props is None else mass_props
[docs] self.x_e = x_e
[docs] self.y_e = 0
[docs] self.z_e = z_e
[docs] self.u_b = u_b
[docs] self.v_b = 0
[docs] self.w_b = w_b
[docs] self.phi = 0
[docs] self.theta = theta
[docs] self.psi = 0
[docs] self.p = 0
[docs] self.q = q
[docs] self.r = 0
# Initialize control variables
[docs] self.Fx_b = 0
[docs] self.Fy_b = 0
[docs] self.Fz_b = 0
[docs] self.Mx_b = 0
[docs] self.My_b = 0
[docs] self.Mz_b = 0
[docs] self.hx_b = 0
[docs] self.hy_b = 0
[docs] self.hz_b = 0
@property
[docs] def state(self): return { "x_e": self.x_e, "z_e": self.z_e, "u_b": self.u_b, "w_b": self.w_b, "theta": self.theta, "q": self.q, }
@property
[docs] def control_variables(self): return { "Fx_b": self.Fx_b, "Fz_b": self.Fz_b, "My_b": self.My_b, }
[docs] def state_derivatives(self) -> Dict[str, Union[float, np.ndarray]]: derivatives = super().state_derivatives() return {k: derivatives[k] for k in self.state.keys()}
if __name__ == "__main__":
[docs] dyn = DynamicsRigidBody2DBody()