cartpole#

Functions#

_tensorize_cfg_cached

cartpole_step

Compute the next state of the inverted pendulum given the current state and action using the equations of motion.

prt_rl.model_based.models.dynamics.cartpole._tensorize_cfg_cached(config, device: device, dtype: dtype) Dict[str, Tensor][source]#
prt_rl.model_based.models.dynamics.cartpole.cartpole_step(config: CartPoleConfig, state: Tensor, action: Tensor) Tensor[source]#

Compute the next state of the inverted pendulum given the current state and action using the equations of motion.

Parameters:
  • config (CartPoleConfig) – Configuration parameters for the cart-pole system.

  • state (torch.Tensor) – Current state tensor of shape (batch_size, 4) where each state is [x, theta, x_dot, theta_dot].

  • action (torch.Tensor) – Action tensor of shape (batch_size, 1) representing the force applied to the cart.

Returns:

Next state tensor of shape (batch_size, 4).

Return type:

torch.Tensor

Classes#

class prt_rl.model_based.models.dynamics.cartpole.CartPoleConfig(M: float = 10.472, m: float = 5.019, l: float = 1.0, I: float = 0.153, b_cart: float = 1.0, b_pole: float = 1.0, g: float = 9.81, dt: float = 0.02, F_scale: float = 100.0)[source]#

Configuration parameters for the Inverted Pendulum model. The default parameters are modeled after the InvertedPendulum-v5 environment from Gymnasium.

Variables:
  • M (float) – Mass of the cart (kg).

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

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

  • I (float) – Moment of inertia of the pendulum (kg*m^2).

  • b_cart (float) – Coefficient of friction for the cart linear damping (Nm/s).

  • b_pole (float) – Coefficient of friction for the pendulum rotational damping (Nm/s).

  • g (float) – Acceleration due to gravity (m/s^2).

  • dt (float) – Time step for simulation (s).

  • F_scale (float) – Scaling factor for the applied force.