cwh#

class gym_socks.envs.cwh.BaseCWH[source]#

CWH base class.

This class holds the shared parameters for the CWH systems, which include:

  • orbital radius

  • gravitational constant

  • celestial body mass

  • chief mass

And provides methods to compute:

  • graviational parameter (\(\mu\))

  • angular velocity (n)

property celestial_body_mass#
property chief_mass#
compute_angular_velocity()[source]#
compute_mu()[source]#
property gravitational_constant#
property orbital_radius#
sampling_time = 20#
time_horizon = 600#
class gym_socks.envs.cwh.CWH4DEnv(*args, **kwargs)[source]#

4D Clohessy-Wiltshire-Hill (CWH) system.

Bases: gym_socks.envs.cwh.BaseCWH, gym_socks.envs.dynamical_system.DynamicalSystem

The 4D CWH system is a simplification of the 6D dynamics to operate within a plane. Essentially, it ignores the \(z\) component of the dynamics.

action_space = None#

The action (input) space of the system.

property celestial_body_mass#
property chief_mass#
close()[source]#

Override close in your subclass to perform any necessary cleanup.

Environments will automatically close() themselves when garbage collected or when the program exits.

compute_angular_velocity()[source]#
compute_input_matrix(sampling_time)[source]#
compute_mu()[source]#
compute_state_matrix(sampling_time)[source]#
cost(time, state, action)[source]#

Cost function for the system.

Warning

This function is typically not used in SOCKS, but is included here for compatibility with OpenAI gym, which returns the cost from the step() function.

dynamics(time, state, action, disturbance)[source]#

Dynamics for the system.

Attention

For this system, the scipy.solve_ivp function does not return the correct result for the dynamical equations, and will quickly run into numerical issues where the states explode. However, the CWH system has a closed-form solution for the equations of motion, so we use this instead to calculate the evolution of the system. See the step() function for additional details regarding how the next state is calculated.

generate_disturbance(time, state, action)[source]#

Generate a disturbance.

Note

Override generate_disturbance() in subclasses to modify the disturbance properties, such as the scale or distribution.

generate_observation(time, state, action)[source]#

Generate an observation from the system.

\[y = h(x, u, v)\]
Parameters
  • time – The time variable.

  • state – The state of the system at the current time step.

  • action – The control action applied at the current time step.

Returns

An observation of the system at the current time step.

Note

Override generate_observation() in subclasses if the system is partially observable. By default, the function returns the system state directly, meaning it is fully observable.

property gravitational_constant#
property np_random#

Random number generator.

observation_space = None#

The space of system observations.

Note

The observation space typically only differs from the state space if the system is partially observable. If this is the case, generate_observation() should be defined to return an element of the observation space.

property orbital_radius#
render(mode='human')[source]#

Renders the environment.

This method must be overridden in subclasses in order to enable rendering. Not all environments support rendering.

Parameters

mode – the mode to render with

reset(state=None)[source]#

Reset the system to a random initial condition.

sampling_time = 20#
seed(seed=None)[source]#

Sets the seed of the random number generator.

Parameters

seed – Integer value representing the random seed.

Returns

The seed of the RNG.

state_space = None#

The state space of the system.

Note

By convention, in controls theory the state space of the system is the set of all possible states that the system can have. OpenAI Gym’s convention is to ignore the underlying state space, opting to use only the observation_space.

step(action, time=0)[source]#

Advances the system forward one time step.

Parameters
  • time – Time of the simulation. Used primarily for time-varying systems.

  • action – Action (input) applied to the system at the current time step.

Returns

A tuple (obs, cost, done, info), where obs is the observation vector. Generally, it is the state of the system corrupted by some measurement noise. If the system is fully observable, this is the actual state of the system at the next time step. cost is the cost (reward) obtained by the system for taking action u in state x and transitioning to state y. In general, this is not typically used with DynamicalSystem models. done is a flag to indicate the simulation has terminated. Usually toggled by guard conditions, which terminates the simulation if the system violates certain operating constraints. info is a dictionary containing extra information.

time_horizon = 600#
class gym_socks.envs.cwh.CWH6DEnv(*args, **kwargs)[source]#

6D Clohessy-Wiltshire-Hill (CWH) system.

Bases: gym_socks.envs.dynamical_system.DynamicalSystem

action_space = None#

The action (input) space of the system.

property celestial_body_mass#
property chief_mass#
close()[source]#

Override close in your subclass to perform any necessary cleanup.

Environments will automatically close() themselves when garbage collected or when the program exits.

compute_angular_velocity()[source]#
compute_input_matrix(sampling_time)[source]#
compute_mu()[source]#
compute_state_matrix(sampling_time)[source]#
cost(time, state, action)[source]#

Cost function for the system.

Warning

This function is typically not used in SOCKS, but is included here for compatibility with OpenAI gym, which returns the cost from the step() function.

dynamics(time, state, action, disturbance)[source]#

Dynamics for the system.

Attention

For this system, the scipy.solve_ivp function does not return the correct result for the dynamical equations, and will quickly run into numerical issues where the states explode. However, the CWH system has a closed-form solution for the equations of motion, so we use this instead to calculate the evolution of the system. See the step() function for additional details regarding how the next state is calculated.

generate_disturbance(time, state, action)[source]#

Generate a disturbance.

Note

Override generate_disturbance() in subclasses to modify the disturbance properties, such as the scale or distribution.

generate_observation(time, state, action)[source]#

Generate an observation from the system.

\[y = h(x, u, v)\]
Parameters
  • time – The time variable.

  • state – The state of the system at the current time step.

  • action – The control action applied at the current time step.

Returns

An observation of the system at the current time step.

Note

Override generate_observation() in subclasses if the system is partially observable. By default, the function returns the system state directly, meaning it is fully observable.

property gravitational_constant#
property np_random#

Random number generator.

observation_space = None#

The space of system observations.

Note

The observation space typically only differs from the state space if the system is partially observable. If this is the case, generate_observation() should be defined to return an element of the observation space.

property orbital_radius#
render(mode='human')[source]#

Renders the environment.

This method must be overridden in subclasses in order to enable rendering. Not all environments support rendering.

Parameters

mode – the mode to render with

reset(state=None)[source]#

Reset the system to a random initial condition.

sampling_time = 20#
seed(seed=None)[source]#

Sets the seed of the random number generator.

Parameters

seed – Integer value representing the random seed.

Returns

The seed of the RNG.

state_space = None#

The state space of the system.

Note

By convention, in controls theory the state space of the system is the set of all possible states that the system can have. OpenAI Gym’s convention is to ignore the underlying state space, opting to use only the observation_space.

step(action, time=0)[source]#

Advances the system forward one time step.

Parameters
  • time – Time of the simulation. Used primarily for time-varying systems.

  • action – Action (input) applied to the system at the current time step.

Returns

A tuple (obs, cost, done, info), where obs is the observation vector. Generally, it is the state of the system corrupted by some measurement noise. If the system is fully observable, this is the actual state of the system at the next time step. cost is the cost (reward) obtained by the system for taking action u in state x and transitioning to state y. In general, this is not typically used with DynamicalSystem models. done is a flag to indicate the simulation has terminated. Usually toggled by guard conditions, which terminates the simulation if the system violates certain operating constraints. info is a dictionary containing extra information.

time_horizon = 600#