swarmsim.agent.MazeAgent#
MazeAgent has Unicycle Dynamics and can move based on sensor info.
- class swarmsim.agent.MazeAgent.MazeAgentConfig(position: tuple[float, ...] | numpy.ndarray = (0, 0), angle: float | typing.Any = 0.0, name: str | typing.Any = None, controller: swarmsim.agent.control.Controller.Controller | 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, sensing_avg: int = 1, stop_on_collision: bool = False, stop_at_goal: bool = False, catastrophic_collisions: bool = False, trace_length: int | None = 0, trace_color: tuple[int, int, int] = (255, 255, 255), track_io: bool = False, idiosyncrasies: Any = False, delay: str | int | float = 0)[source]#
- Attributes:
- anchor_point
- controller
- name
- team
Methods
as_config_dict
as_dict
as_generator
asdict
attach_world_config
create
from_dict
rescale
- controller: Controller | None = None[source]#
The controller used by the agent. Zero controller by default.
- Type:
- class swarmsim.agent.MazeAgent.MazeAgent(config: MazeAgentConfig, world, 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, andangleof the agent.Creates and adds the
AgentConfig.controllerto the agent.Creates and adds sensors from the
AgentConfig.sensorsto the agent.attach_agent_to_sensors
build_collider
debug_draw
draw
draw_direction
getFrontalPoint
get_heading
get_name
get_random_color
get_simple_poly_radius
get_x_pos
get_y_pos
handle_collisions
on_key_press
rotmat2d
rotmat2dT
rotmat3d
set_color_by_id
set_seed
set_x_pos
set_y_pos
step
- controller[source]#
The
Controllerfor 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
worldattribute.The
Agent._always_shallow_copyattribute 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, andangleof the agent.- Parameters:
vec (tuple[float, float, float] | numpy.ndarray) – A vector with
len()of3containing thex, y, angle
- setup_controller_from_config()[source]#
Creates and adds the
AgentConfig.controllerto the agent.If
config.controlleris a dict with atypekey, then it is created through the Configuration System and set as the agent’scontroller.AbstractControllerinstances 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
elementis not a dict orAbstractSensorinstance.
- setup_sensors_from_config()[source]#
Creates and adds sensors from the
AgentConfig.sensorsto the agent.For each
elementofconfig.sensors, if theelementis a dict with atypekey, then it is created through the Configuration System and then added to the agent’ssensorslist.AbstractSensorinstances 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
elementis not a dict orAbstractSensorinstance.
- class swarmsim.agent.MazeAgent.State[source]#
A
typing.NamedTuplefor recording the state of the agent.- Args:
- xfloat
The agent’s x position in the world.
- yfloat
The agent’s y position in the world.
- anglefloat
The agent’s heading. (radians)
- class swarmsim.agent.MazeAgent.SPA[source]#
A
collections.namedtuple()for recording the State, Perception, Action of the agent.- Args:
- stateState | tuple[float, …] | np.ndarray
The agent’s position and heading.
- perceptiontuple[Any, …] | np.ndarray
The sensor readings.
- actiontuple[float, …] | np.ndarray
The action to take.
Classes
|
|
|
|
|
|
|