symaware.simulators.pymunk package

Submodules

symaware.simulators.pymunk.dynamical_model module

class symaware.simulators.pymunk.dynamical_model.DynamicalModel(ID, control_input)[source]

Bases: DynamicalModel

Abstract class for the dynamical models using the Pymunk physics engine.

Parameters:
  • ID (int) – Identifier of the agent this model belongs to

  • control_input (ndarray) – Initial control input of the agent. It also used to validate the size of future control inputs

initialise(entity)[source]

Initialise the dynamical model. Called by the associated entity when it is added to the environment.

Parameters:
  • args – Additional arguments

  • kwargs – Additional keyword arguments

abstract step()[source]

Run a simulation step of the dynamical model. Called by the associated entity at each simulation step.

Parameters:
  • args – Additional arguments

  • kwargs – Additional keyword arguments

class symaware.simulators.pymunk.dynamical_model.ForceModel(ID, max_force=2.0)[source]

Bases: DynamicalModel

Pymunk dynamical model. It applies an impulse force to the entity.

Parameters:
  • ID (int) – Identifier of the agent this model belongs to

  • control_input – Initial control input of the agent. It also used to validate the size of future control inputs

  • max_force (float, default: 2.0) – Maximum force that can be applied to the wheels

  • steering_links – Tuple of the two links that are used to steer the car

  • motorized_wheels – Tuple of the two links that are used to drive the car

step()[source]

Run a simulation step of the dynamical model. Called by the associated entity at each simulation step.

Parameters:
  • args – Additional arguments

  • kwargs – Additional keyword arguments

property subinputs_dict: ForceModelSubinputs

The input of a system is the composition of subinputs.

Example

A car input [vx, vy, vz, s] is composed by the velocity and the steering angle.

>>> from symaware.base import DynamicalModel
>>> class CarModel(DynamicalModel):
...     @property
...     def subinputs_dict(self):
...         return {
...             "velocity": self._control_input[:3],
...             "steering_angle": self._control_input[3]
...         }
...

Important

The order of the subinputs in the list must be the same as the order of the subinputs in the input vector

class symaware.simulators.pymunk.dynamical_model.ForceModelSubinputs[source]

Bases: TypedDict

force: ndarray
class symaware.simulators.pymunk.dynamical_model.VelocityModel(ID, max_force=40.0)[source]

Bases: DynamicalModel

Pymunk dynamical model. It sets the velocity of the entity.

Parameters:
  • ID (int) – Identifier of the agent this model belongs to

  • control_input – Initial control input of the agent. It also used to validate the size of future control inputs

  • max_force (float, default: 40.0) – Maximum force that can be applied to the wheels

  • steering_links – Tuple of the two links that are used to steer the car

  • motorized_wheels – Tuple of the two links that are used to drive the car

step()[source]

Run a simulation step of the dynamical model. Called by the associated entity at each simulation step.

Parameters:
  • args – Additional arguments

  • kwargs – Additional keyword arguments

property subinputs_dict: VelocityModelSubinputs

The input of a system is the composition of subinputs.

Example

A car input [vx, vy, vz, s] is composed by the velocity and the steering angle.

>>> from symaware.base import DynamicalModel
>>> class CarModel(DynamicalModel):
...     @property
...     def subinputs_dict(self):
...         return {
...             "velocity": self._control_input[:3],
...             "steering_angle": self._control_input[3]
...         }
...

Important

The order of the subinputs in the list must be the same as the order of the subinputs in the input vector

class symaware.simulators.pymunk.dynamical_model.VelocityModelSubinputs[source]

Bases: TypedDict

velocity: ndarray

symaware.simulators.pymunk.entities module

class symaware.simulators.pymunk.entities.BoxEntity(id=-1, model=<factory>, position=<factory>, angle=0.0, body=<factory>, color=None, mass=1, friction=0.7, elasticity=0, _shape=None, sizes=<factory>)[source]

Bases: Entity

sizes: ndarray
class symaware.simulators.pymunk.entities.Entity(id=-1, model=<factory>, position=<factory>, angle=0.0, body=<factory>, color=None, mass=1, friction=0.7, elasticity=0, _shape=None)[source]

Bases: Entity

Abstract class for the entities using the Pymunk physics engine.

Parameters:
  • model (DynamicalModel, default: <factory>) – Dynamical model of the entity. Must be a subclass of PymunkDynamicalModel

  • position (ndarray, default: <factory>) – Initial position of the entity

  • angle (float, default: 0.0) – Initial angle of the entity

  • body (Body, default: <factory>) – Pymunk body of the entity. It is automatically created

  • shape – Pymunk shape of the entity. It is automatically created

  • color (Color | None, default: None) – Color of the entity used for visualisation

  • mass (float, default: 1) – Mass of the entity

  • friction (float, default: 0.7) – Friction of the entity

  • elasticity (float, default: 0) – Elasticity of the entity

_shape: pymunk.Shape = None
angle: float = 0.0
body: pymunk.Body
color: pygame.Color | None = None
elasticity: float = 0
friction: float = 0.7
initialise(space)[source]
mass: float = 1
model: DynamicalModel
position: ndarray
property shape: Shape
class symaware.simulators.pymunk.entities.SphereEntity(id=-1, model=<factory>, position=<factory>, angle=0.0, body=<factory>, color=None, mass=1, friction=0.7, elasticity=0, _shape=None, radius=1.0)[source]

Bases: Entity

radius: float = 1.0

symaware.simulators.pymunk.environment module

class symaware.simulators.pymunk.environment.Environment(real_time_interval=0, visualise=True, async_loop_lock=None)[source]

Bases: Environment

Environment based on the Pymunk physics engine.

Parameters:
  • connection_method – Method used to connect to the pymunk server. See the pymunk documentation for more information.

  • real_time_interval (float, default: 0) – If set to a strictly positive value, pymunk will run the simulation in real time. Otherwise, the simulation will run when step() is called.

  • async_loop_lock (AsyncLoopLock | None, default: None) – Async loop lock to use for the environment

__LOGGER = <Logger symaware.simulators.pymunk.PymunkEnvironment (WARNING)>
_add_entity(entity)[source]

Add an entity to the environment, initialising it. The actual implementation should be done in the derived class, based on the simulated environment API. The entity’s initialise_entity() function should be called within this function with the appropriate arguments.

Parameters:

entity (Entity) – entity to initialise

get_entity_state(entity)[source]

Get the state of an entity in the environment. The actual implementation should be done in the derived class, based on the simulated environment API.

Parameters:

entity (Entity) – entity to get the state of

Returns:

ndarray – State of the entity within the environment

initialise()[source]

Initialise the simulation, allocating the required resources. Should be called when the simulation has been set up and is ready to be run. Some environment implementations may call it automatically when the environment is created. It is their responsibility to ensure that the method is idempotent.

step()[source]

It can be called repeatedly step the environment forward in time, updating the state of all the entities.

stop()[source]

Terminate the simulation, releasing the resources. Should be called when the simulation has been running manually and needs to be stopped. Some environment implementations may call it automatically when the environment is destroyed. It is their responsibility to ensure that the method is idempotent.

Warning

Depending on the simulator implementation, calling this method may invalidate all the entities previously added to the environment. In that case, entities and the environment should be recreated from scratch.

Module contents