pendulum#

Pendulum dynamics model for physics-based simulation.

Classes#

class prt_rl.model_based.models.dynamics.pendulum.PendulumDynamics(g: float = 10.0, l: float = 1.0, m: float = 1.0, dt: float = 0.05)[source]#

Physics-based dynamics model for a simple pendulum system.

This class implements the equations of motion for a simple pendulum with torque control. The dynamics are based on the physical parameters of the pendulum (mass, length, gravity) and use Euler integration for time stepping.

Note: Assumes zero theta corresponds to the pendulum straight up, and positive theta / torque is counterclockwise.

Variables:
  • g (float) – Gravitational acceleration constant (m/s²). Defaults to 10.0.

  • l (float) – Length of the pendulum (m).

  • m (float) – Mass of the pendulum bob (kg).

  • dt (float) – Time step for Euler integration (s).

Initialize the pendulum dynamics model.

Parameters:
  • g – Gravitational acceleration constant in m/s². Defaults to 10.0.

  • l – Length of the pendulum in meters. Defaults to 1.0.

  • m – Mass of the pendulum bob in kg. Defaults to 1.0.

  • dt – Time step for Euler integration in seconds. Defaults to 0.05.

__init__(g: float = 10.0, l: float = 1.0, m: float = 1.0, dt: float = 0.05) None[source]#

Initialize the pendulum dynamics model.

Parameters:
  • g – Gravitational acceleration constant in m/s². Defaults to 10.0.

  • l – Length of the pendulum in meters. Defaults to 1.0.

  • m – Mass of the pendulum bob in kg. Defaults to 1.0.

  • dt – Time step for Euler integration in seconds. Defaults to 0.05.

derivative(theta: Tensor, thetad: Tensor, tau: Tensor) Tensor[source]#

Compute the time derivatives of the pendulum state.

Uses the equations of motion for a simple pendulum with torque input: θ̈ = (3g)/(2l) * sin(θ) + 3/(ml²) * τ

Parameters:
  • theta – Pendulum angle in radians. Shape: [B, 1] where B is batch size.

  • thetad – Pendulum angular velocity in rad/s. Shape: [B, 1].

  • tau – Applied torque in N⋅m. Shape: [B, 1].

Returns:

[B, 2].

Return type:

Time derivatives [θ̇, θ̈]. Shape

step(theta: Tensor, thetad: Tensor, tau: Tensor) Tensor[source]#

Perform one time step of the pendulum dynamics using Euler integration.

Parameters:
  • theta – Pendulum angle in radians. Shape: [B, 1] where B is batch size.

  • thetad – Pendulum angular velocity in rad/s. Shape: [B, 1].

  • tau – Applied torque in N⋅m. Shape: [B, 1].

Returns:

[B, 2].

Return type:

Next state [theta, thetad] after one time step. Shape