Pendulum

Description

Environment to simulate a simple Pendulum.

Equation

\[M_t = l m g \sin{\theta_t} + l^2 m \ddot{\theta_t}\]

Parameters

\(l\): Length of the pendulum
\(m\): Mass of the pendulum tip
\(g\): Gravitational acceleration

Action

Num

Term in Equation

Term in Class

0

\(M_t\)

torque

States

Num

Term in Equation

Term in Class

0

\(\theta_t\)

theta

1

\(\dot{\theta_t}\)

omega

Class

class exciting_environments.pendulum.pendulum_env.Pendulum(batch_size=8, l=1, m=1, max_torque=20, reward_func=None, g=9.81, tau=0.0001, constraints=[10])[source]
State Variables:

['theta' , 'omega']

Action Variable:

['torque']''

Observation Space (State Space):

Box(low=[-1, -1], high=[1, 1])

Action Space:

Box(low=-1, high=1)

Initial State:

Unless chosen otherwise, theta equals 1(normalized to pi) and omega is set to zero.

Example

>>> import jax
>>> import exciting_environments as excenvs
>>>
>>> # Create the environment
>>> env= excenvs.make('Pendulum-v0',batch_size=2,l=2,m=4)
>>>
>>> # Reset the environment with default initial values
>>> env.reset()
>>>
>>> # Sample a random action
>>> action = env.action_space.sample(jax.random.PRNGKey(6))
>>>
>>> # Perform step
>>> obs,reward,terminated,truncated,info= env.step(action)
>>>
Parameters
  • batch_size (int) – Number of training examples utilized in one iteration. Default: 8

  • l (float) – Length of the pendulum. Default: 1

  • m (float) – Mass of the pendulum tip. Default: 1

  • max_torque (float) – Maximum torque that can be applied to the system as action. Default: 20

  • reward_func (function) – Reward function for training. Needs Observation-Matrix and Action as Parameters. Default: None (default_reward_func from class)

  • g (float) – Gravitational acceleration. Default: 9.81

  • tau (float) – Duration of one control step in seconds. Default: 1e-4.

  • constraints (array) – Constraints for state [‘omega’] (list with length 1). Default: [10]

Note: l,m and max_torque can also be passed as lists with the length of the batch_size to set different parameters per batch. In addition to that constraints can also be passed as a list of lists with length 1 to set different constraints per batch.