swarmsim.agent.StaticAgent#
An Agent Class and Config for a non-moving agent.
- class swarmsim.agent.StaticAgent.StaticAgentConfig(position: tuple[float, ...] | numpy.ndarray = (0, 0), angle: float | typing.Any = 0.0, name: str | typing.Any = None, controller: typing.Any | None = None, grounded: bool = False, collides: bool | int = True, sensors: list = <factory>, team: str | None = None, seed: int | None | str = 'unspecified', agent_radius: float = 0.0, body_color: tuple[int, int, int] = (255, 255, 255), body_filled: bool = False, points: list[tuple[float, float]] | numpy.ndarray | str = <factory>, anchor_point: None | tuple[float, float] | str = None, debug: bool = False)[source]#
- Attributes:
- anchor_point
- controller
- name
- team
Methods
as_config_dict
as_dict
as_generator
asdict
attach_world_config
from_dict
- class swarmsim.agent.StaticAgent.StaticAgent(config: StaticAgentConfig, world: RectangularWorld, name=None, initialize=True)[source]#
-
Methods
copy
()Create a copy of this agent.
from_config
(config, world)Returns a new agent instance from the given config and world.
Alias for
pos
.Alias for
dpos
.get_aabb
()Get the agent's
AABB
.Alias for
sensors
.Return the Bounding Box of the agent
orientation_uvec
([offset])Returns the agent's 2D orientation matrix.
set_heading
(new_heading)Set the agent's heading (radians).
set_name
(new_name)Set the name of the agent.
set_pos_vec
(vec)Set the
x
,y
, andangle
of the agent.Creates and adds the
AgentConfig.controller
to the agent.Creates and adds sensors from the
AgentConfig.sensors
to the agent.attach_agent_to_sensors
build_collider
debug_draw
draw
draw_direction
getFrontalPoint
get_heading
get_name
get_simple_poly_radius
get_x_pos
get_y_pos
on_key_press
rotmat2d
rotmat2dT
rotmat3d
set_seed
set_x_pos
set_y_pos
step
- controller[source]#
The
Controller
for this agent.
- copy()[source]#
Create a copy of this agent.
- Returns:
The new agent has the same type as the class/instance it was called from.
- Return type:
Almost all attributes are deep-copied from this agent. However, some attributes do not get recursively deep-copied, such as the
world
attribute.The
Agent._always_shallow_copy
attribute is a list of agent attribute names which determines which attributes do not get deep-copied. By default, this is['world']
.On the new agent, Attributes of this agent not in this list will be a deep-copy of those in the original agent.
Attributes of this agent in this list will share the same reference as the original agent.
Examples
>>> agent = Agent(config, world) >>> agent.copy().world is agent.world True >>> copy.deepcopy(agent).world is agent.world False
- classmethod from_config(config, world)[source]#
Returns a new agent instance from the given config and world.
- grounded[source]#
If True, the agent should never change position or be pushed during collision resolution.
- orientation_uvec(offset=0.0)[source]#
Returns the agent’s 2D orientation matrix.
This is a unit vector pointing in the direction of the agent’s heading plus an offset.
Equivalent to
np.array([ math.cos(self.angle + offset), math.sin(self.angle + offset) ], dtype=np.float64)
- Parameters:
offset (float, default=0) – The offset to add to the agent’s heading (radians).
- Returns:
The 2D orientation matrix.
- Return type:
numpy.ndarray (2,)
- set_name(new_name: str | None | Any)[source]#
Set the name of the agent.
- Parameters:
new_name (str | None | Any) – The new name of the agent. Strongly recommended to use
str
.
- set_pos_vec(vec)[source]#
Set the
x
,y
, andangle
of the agent.- Parameters:
vec (tuple[float, float, float] | numpy.ndarray) – A vector with
len()
of3
containing thex, y, angle
- setup_controller_from_config()[source]#
Creates and adds the
AgentConfig.controller
to the agent.If
config.controller
is a dict with atype
key, then it is created through the Configuration System and set as the agent’scontroller
.AbstractController
instances copied and added to the list.The controller is also given a back-reference to this agent via its
set_agent()
.- Raises:
TypeError – if the
element
is not a dict orAbstractSensor
instance.
- setup_sensors_from_config()[source]#
Creates and adds sensors from the
AgentConfig.sensors
to the agent.For each
element
ofconfig.sensors
, if theelement
is a dict with atype
key, then it is created through the Configuration System and then added to the agent’ssensors
list.AbstractSensor
instances copied and added to the list.The new sensor instances are also given a back-reference to this agent via their
set_agent()
.- Raises:
TypeError – if the
element
is not a dict orAbstractSensor
instance.
Classes
|
|
|