pytrebuchet.differential_equations package

Module containing differential equations that describe trebuchet motion.

class pytrebuchet.differential_equations.SlingPhases(*values)

Bases: StrEnum

Enumeration for the different sling phases.

ALL = 'ALL'
SLIDING_OVER_GROUND = 'SLIDING_OVER_GROUND'
PROJECTILE_AND_COUNTERWEIGHT_CONTACT_ARM = 'PROJECTILE_AND_COUNTERWEIGHT_CONTACT_ARM'
PROJECTILE_CONTACT_ARM = 'PROJECTILE_CONTACT_ARM'
UNCONSTRAINED = 'UNCONSTRAINED'
static _generate_next_value_(name, start, count, last_values)

Return the lower-cased version of the member name.

pytrebuchet.differential_equations.ballistic_ode(t: float, y: tuple[float, float, float, float], environment: EnvironmentConfig, projectile: Projectile) tuple[float, float, float, float]

Ordinary differential equations (ODEs) for a ballistic projectile.

Parameters:
  • t – time variable (not used in this function but required for ODE solvers)

  • y – tuple containing the state variables: (px, py, vx, vy) where: px: x position of the projectile py: y position of the projectile vx: x velocity of the projectile vy: y velocity of the projectile

  • environment – EnvironmentConfig object containing environment parameters

  • projectile – Projectile object containing properties of the projectile

Returns:

derivatives: tuple containing the derivatives of the state variables: (vx, vy, ax, ay)

pytrebuchet.differential_equations.projectile_hits_ground_event(t: float, y: tuple[float, float, float, float], environment: EnvironmentConfig, projectile: Projectile) float

Event function to determine when the projectile hits the ground.

The event occurs when the vertical position of the projectile (py) reaches zero.

Parameters:
  • t – time variable (not used in this function but required for ODE solvers)

  • y – tuple containing the state variables: (px, py, vx, vy) where: px: x position of the projectile py: y position of the projectile vx: x velocity of the projectile vy: y velocity of the projectile

  • args – additional parameters required for the equations: (wind_speed, rho, nu, g, projectile) where: wind_speed: wind speed rho: air density nu: kinematic viscosity of the air g: gravitational acceleration projectile: Projectile object containing properties of the projectile

Returns:

py: vertical position of the projectile

pytrebuchet.differential_equations.sling_ode(t: float, y: tuple[float, float, float, float, float, float], trebuchet: Trebuchet, environment: EnvironmentConfig, sling_phase: SlingPhases) tuple[float, float, float, float, float, float]

Solves the ODEs for a projectile that is still in the sling.

Parameters:
  • t – time variable (not used in this function but required for ODE solvers)

  • y – tuple containing the state variables: (theta, phi, psi, dtheta, dphi, dpsi) where: theta: angle of the arm phi: angle of the weight psi: angle of the projectile dtheta: angular velocity of the arm dphi: angular velocity of the weight dpsi: angular velocity of the projectile

  • trebuchet – Trebuchet object containing trebuchet parameters

  • environment – EnvironmentConfig object containing environmental parameters

  • sling_phase – current phase of the sling (from SlingPhases enum) This determines the additional constraints to apply to the ODEs.

Returns:

derivatives: tuple containing the derivatives of the state variables: (dtheta, dphi, dpsi, ddtheta, ddphi, ddpsi)

pytrebuchet.differential_equations.sling_terminate_event(t: float, y: tuple[float, float, float, float, float, float], trebuchet: Trebuchet, environment: EnvironmentConfig, sling_phase: SlingPhases) float

Event function to determine when to terminate the ODE integration.

Release happens when the velocity angle matches the desired release angle.

Parameters:
  • t – time variable (not used in this function but required for ODE solvers)

  • y – tuple containing the state variables: (theta, phi, psi, dtheta, dphi, dpsi) where: theta: angle of the arm phi: angle of the weight psi: angle of the projectile dtheta: angular velocity of the arm dphi: angular velocity of the weight dpsi: angular velocity of the projectile

  • trebuchet – Trebuchet object containing trebuchet parameters

  • environment – EnvironmentConfig object containing environmental parameters

  • sling_phase – current phase of the sling (from SlingPhases enum) This parameter is used to determine the correct event function.

Returns:

event_value: difference between the current velocity angle and the desired release angle

Submodules