cleave.impl package

Submodules

cleave.impl.inverted_pendulum module

cleave.impl.inverted_pendulum.G_CONST = Vec2d(0, -9.8)

Gravity constants

cleave.impl.inverted_pendulum.visualization_loop(input_q: Queue, shutdown_event: Event, window_w: int, window_h: int, caption: str, ppm: float = 200.0) None

Utility function that executes a Pyglet GUI loop to graphically visualize the inverted pendulum. Should always be called from a separate Process.

Parameters
  • input_q – Input queue which holds dictionaries describing the figures to be drawn on screen.

  • shutdown_event – Event to signal a shutdown of the Plant.

  • window_w – Window width.

  • window_h – Window height.

  • caption – Window caption.

  • ppm – Factor relating number of pixels per meter.

class cleave.impl.inverted_pendulum.InvPendulumState(fail_angle_rad: float = 0.34, ground_friction: float = 0.1, cart_mass: float = 0.5, cart_dims: Vec2d = Vec2d(0.3, 0.2), pend_length: float = 1.2, pend_mass: float = 0.2, pend_moment: float = 0.001)

Bases: State

Implementation of a discrete-time simulation of an inverted pendulum.

Parameters
  • fail_angle_rad – Angle at which the pendulum is considered unrecoverable. Negative values disable this check.

  • ground_friction – Friction factor to apply for the ground.

  • cart_mass – Mass of the pendulum cart in Kg.

  • cart_dims – Dimensions of the cart in meters.

  • pend_length – Length of the pendulum arm.

  • pend_mass – Mass of the pendulum in Kg.

  • pend_moment – Moment of the pendulum.

advance(delta_t: float) None

Called by the plant on every time step to advance the emulation. Needs to be implemented by subclasses.

Parameters

delta_t – Time elapsed since the previous call to this method. This value will be 0 the first time this method is called.

class cleave.impl.inverted_pendulum.InvPendulumStateWithViz(fail_angle_rad: float = 0.34, ground_friction: float = 0.1, cart_mass: float = 0.5, cart_dims: Vec2d = Vec2d(0.3, 0.2), pend_length: float = 1.2, pend_mass: float = 0.2, pend_moment: float = 0.001, window_w: int = 1000, window_h: int = 700, caption: str = 'Inverted Pendulum Simulation', ppm: float = 200.0)

Bases: InvPendulumState

Implementation of a discrete-time simulation of an inverted pendulum, with a graphical visualization using Pyglet.

Parameters
  • fail_angle_rad – Angle at which the pendulum is considered unrecoverable. Negative values disable this check.

  • ground_friction – Friction factor to apply for the ground.

  • cart_mass – Mass of the pendulum cart in Kg.

  • cart_dims – Dimensions of the cart in meters.

  • pend_length – Length of the pendulum arm.

  • pend_mass – Mass of the pendulum in Kg.

  • pend_moment – Moment of the pendulum.

initialize() None

Called by the plant at the beginning of the emulation.

shutdown() None

Called by the plant on shutdown.

advance(delta_t: float) None

Called by the plant on every time step to advance the emulation. Needs to be implemented by subclasses.

Parameters

delta_t – Time elapsed since the previous call to this method. This value will be 0 the first time this method is called.

class cleave.impl.inverted_pendulum.InvPendulumController(ref: float = 0.0, max_force: float = 25)

Bases: Controller

Proportional-differential controller for the Inverted Pendulum.

Parameters
  • ref – Position on the X-axis around which to balance the pendulum.

  • max_force – Maximum force, in Newtons, allowed to apply to the pendulum.

K = [-57.38901804, -36.24133932, 118.51380879, 28.97241832]

Pendulum parameters

process(sensor_values: Mapping[str, Union[int, float, bool]]) Mapping[str, Union[int, float, bool]]

Processes samples and produces a control command.

Samples arrive in the form of a dictionary of mappings from sensor property name to measured value. Actuator commands should be returned in the same fashion, in a dictionary of mappings from actuated property name to actuated value.

This method needs to be implemented by extending subclasses with their respective logic.

Parameters

sensor_values – A mapping of sensor property names to measured values.

Returns

A mapping of actuated property names to desired values.

Return type

PhyPropMapping