pytrebuchet.differential_equations.sling_phase module

Ordinary differential equations (ODEs) for the unconstrained sling phase.

class pytrebuchet.differential_equations.sling_phase.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.sling_phase.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_phase._get_ode_matrix(y: tuple[float, float, float, float, float, float], trebuchet: Trebuchet, environment: EnvironmentConfig, sling_phase: SlingPhases) tuple[ndarray, ndarray]

Construct the A and B matrices for the ODEs in the form Ax = B.

Parameters:
  • 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:

A, B: matrices for the ODEs in the form Ax = B

pytrebuchet.differential_equations.sling_phase._add_constraint_equations_to_ode_matrix(A_unconstrained: ndarray[tuple[Any, ...], dtype[floating]], B_unconstrained: ndarray[tuple[Any, ...], dtype[floating]], constraint_eqs_a: list[ndarray[tuple[Any, ...], dtype[floating]]], constraint_eqs_b: list[float]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]

Add constraint equations to the unconstrained ODE matrix.

Parameters:
  • A_unconstrained – Unconstrained A matrix from the ODEs

  • B_unconstrained – Unconstrained B matrix from the ODEs

  • constraint_eqs_a – List of constraint equations coefficients for A matrix

  • constraint_eqs_b – List of constraint equations constants for B matrix

Returns:

A, B: matrices for the ODEs in the form Ax = B with constraints added

pytrebuchet.differential_equations.sling_phase.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

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

Event function to determine when to terminate the ODE integration.

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

Parameters:
  • 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

Returns:

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

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

Calculate lagrange multiplier for the ground separation event.

When the lagrange multiplier becomes zero, the projectile separates from the ground.

Parameters:
  • 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

Returns:

lambd: the lagrange multiplier

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

Event function that determines when the projectile separates from the arm.

The projectile separates when the unconstrained angular accelerations of the projectile and arm result in an increasing angle between them.

Parameters:
  • 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

Returns:

lambd: the lagrange multiplier, representing the normal force at the ground contact point.

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

Event function that determines weight separation.

The weight separates when the unconstrained angular accelerations of the weight and arm result in an increasing angle between them. This event function returns the difference in angular accelerations (ddphi - ddtheta).

Parameters:
  • 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

Returns:

lambd: the lagrange multiplier, representing the normal force at the ground contact point.