skydy.rigidbody package¶
Submodules¶
skydy.rigidbody.Body module¶
- class skydy.rigidbody.Body.Body(name=None)[source]¶
Bases:
skydy.configuration.Configuration.Configuration- __init__(name=None)[source]¶
A Body is a collection of particles. It has a mass, and some dimensions (length, width and height), and by default has six degrees of freedom (DOFs). As such, it extends the Configuration class, with the addition of the inertial properties (InertiaMatrix and MassMatrix) and some dimensions (DimensionSymbols).
We also instantite two empty lists for the forces and torques that might be applied to the body.
- Parameters
name (int, float or string) – the name of the body.
- Returns
None
Example
>>> from skydy.rigidbody import Body >>> # Empty initializer >>> b_1 = Body() >>> # Define name by a number >>> b_2 = Body(2) >>> # Empty initializer >>> b_3 = Body("car")
- add_force(force_vector, force_location)[source]¶
Add, or apply a force to the body. For a force to do anything, the force must have a direction AND a location.
- Parameters
force_vector (BodyForce) – the force direction, as defined in the body’s coordinate frame.
force_location (BodyCoordinate) – the location of the force, as define in the body’s coordinate frame.
- Returns
None
Examples
>>> from skydy.Body import Body, BodyForce, BodyCoordinate >>> # Define the body >>> b = Body() >>> # Apply a force in the x-direction >>> f_1 = BodyForce("1", x_dir=True) >>> # Apply the force at the origin of the Body >>> f_loc = BodyCoordinate("PF1") >>> # We can now apply the force >>> b.apply_force(f_1, f_loc)
- add_torque(torque_vector, torque_location)[source]¶
Add, or apply a torque to the body. For a torque to f do anything, the torque must have a direction AND a location.
- Parameters
torque_vector (BodyTorque) – the torque direction, as defined in the body’s coordinate frame.
torque_location (BodyCoordinate) – the location of the torque, as define in the body’s coordinate frame.
- Returns
None
Examples
>>> from skydy.Body import Body, BodyTorque, BodyCoordinate >>> # Define the body >>> b = Body() >>> # Apply a torque in the x-direction >>> t_1 = BodyTorque("1", x_dir=True) >>> # Apply the torque at the origin of the Body >>> t_loc = BodyCoordinate("PT1") >>> # We can now apply the torque >>> b.apply_torque(t_1, t_loc)
- body_twists()[source]¶
Calculate the body twists to ultimately determine the translational and rotational velocities.
omega is the body rotational velocity. v_body is the body translational velocity.
Mathematical expressions are:
Let r in R^3 be the position of the COM, and R in SO(3) the body orientation.
Then,
omega_hat = R^(-1) @ (d/dt) R, omega = unhat_map(omega_hat), v_body = (d/dt) r.
Refer to Bullo and Lewis for more information.
- Parameters
None –
- Returns
the body translational velocities omega_body (sympy.matrix): the body rotational velocities
- Return type
v_body (sympy.matrix)
- draw(ax=None, ref_body=None, ref_joint=None, sub_vals=None)[source]¶
Draw the body.
- Parameters
ax (matplotlib.axes._subplots.AxesSubplot) – the axis to plot the connection on.
ref_body (None or Body) – the reference Body to propagate dimensions, coordinates etc.
ref_joint (None or numpy.ndarray) – the location of the joint the body is connected to.
sub_vals (dict) – symbol-value pairs required to go from symbolic to numeric expression. It is important to note, that all symbols each body is dependent on, for example, for upstream bodies and joints, are included.
- Returns
updated axes, with plots.
- Return type
ax (matplotlib.axes._subplots.AxesSubplot)
Example
>>> import matplotlib.pyplot as plt >>> from skydy.rigidbody import Body >>> # Define the body >>> b = Body() >>> # Define the axes >>> fig = plt.figure() >>> ax = fig.add_subplot(111, projection='3d') >>> ax = b.draw(ax) >>> plt.show()
- id_counter = 1¶
- kinetic_energy()[source]¶
Determine the kinetic energy of the body.
Let v_body in R^3, w_body in R^3 be the translational and rotational velocities, M in R^(3x3), I in R^(3x3) be the mass and inertia matrices, then,
KE_trans = (1/2) * v_vody^(T) @ M @ v_body KE_rot = (1/2) * w_vody^(T) @ I @ w_body
KE_tot = KE_trans + KE_rot.
- Parameters
None –
- Returns
the symbol expression of the kinetic energy.
- Return type
KE_tot (sympy.symbol)
- potential_energy(gravity)[source]¶
Determine the potential energy of the body.
The PE is the component of the position of the body in the z-coordinate (height), times gravity (g), times mass, i.e.,
PE = m * dot(g, r)
- Parameters
gravity (sympy.matrix) – the gravity vector in the global coordinte frame, typically [0, 0, g]
- Returns
the symbol expression of the potential energy
- Return type
potential_energy (sympy.symbols)
Examples
>>> from skydy.rigidbody import Body >>> b = Body() >>> # Define the gravity vector >>> g = sym.Matrix([0, 0, sym.Symbol('g')]) >>> # Calculate the potential energy >>> b.potential_energy(g)
- class skydy.rigidbody.Body.Ground[source]¶
Bases:
skydy.rigidbody.Body.Body
skydy.rigidbody.BodyCoordinate module¶
- class skydy.rigidbody.BodyCoordinate.BodyCoordinate(name, x=0, y=0, z=0)[source]¶
Bases:
skydy.configuration.BaseSymbols.DimensionSymbols- __init__(name, x=0, y=0, z=0)[source]¶
A coordinate of a point on a body. Inherits from DimensionSymbols.
- Parameters
name (int, float or string) – the name of the body or object we want to
for. (generate dimensions) –
x (int or float) – the x-coordinate to a point from the body’s COM
y (int or float) – the y-coordinate to a point from the body’s COM
z (int or float) – the z-coordinate to a point from the body’s COM
- Returns
None
Example
>>> from skydy.configuration import BodyCoordinate >>> # Create a set of symbols >>> body_name = 1 >>> # Default constructor >>> body_coord = BodyCoordinate(body_name) >>> # Assign some distances >>> body_coord = BodyCoordinate(body_name, 1, 2, 3) >>> body_coord = BodyCoordinate(body_name, 3, -4, 4)
skydy.rigidbody.BodyForce module¶
- class skydy.rigidbody.BodyForce.BodyForce(name, x_dir=False, y_dir=False, z_dir=False)[source]¶
Bases:
skydy.configuration.BaseSymbols.ForceSymbols- __init__(name, x_dir=False, y_dir=False, z_dir=False)[source]¶
Define a force that acts on a Body. The direction of the force is defined the the relevant body’s coordinate frame.
By default, a force is assgined a default value of 1, if the force is defined in that direction, or 0 otherwise.
- Parameters
name (int or str) – the name for the force.
x_dir (bool) – if the defined force acts in the body x-direction
y_dir (bool) – if the defined force acts in the body y-direction
z_dir (bool) – if the defined force acts in the body z-direction
- Returns
None
Example
>>> from skydy.rigidbody import BodyForce >>> # Instantiate a force in the body x-direction >>> f_1 = BodyForce("1", x_dir=True) >>> # Instantiate another force in the body y-direction >>> f_2 = BodyForce("2", y_dir=True) >>> # Instantiate another force in all directions >>> f_3 = BodyForce("3", True, True, True)
- class skydy.rigidbody.BodyForce.BodyTorque(name, x_dir=False, y_dir=False, z_dir=False)[source]¶
Bases:
skydy.configuration.BaseSymbols.TorqueSymbols- __init__(name, x_dir=False, y_dir=False, z_dir=False)[source]¶
Define a torque that acts on a Body. The direction of the torque is defined the the relevant body’s coordinate frame, and a rotation ABOUT that coordinate direction (as per the right hand rule).
By default, a torque is assgined a default value of 1, if the torque is defined in that direction, or 0 otherwise.
- Parameters
name (int or str) – the name for the torque.
x_dir (bool) – if the defined torque acts around the body x-direction
y_dir (bool) – if the defined torque acts around the body y-direction
z_dir (bool) – if the defined torque acts around the body z-direction
- Returns
None
Example
>>> from skydy.rigidbody import BodyTorque >>> # Instantiate a torque about the body x-direction >>> t_1 = BodyTorque("1", x_dir=True) >>> # Instantiate another torque about the body y-direction >>> t_2 = BodyTorque("2", y_dir=True) >>> # Instantiate another torque about all directions >>> t_3 = BodyTorque("3", True, True, True)