simworld.agent package

Submodules

simworld.agent.base_agent module

Base agent class for all agents in the simulation.

class simworld.agent.base_agent.BaseAgent(position: Vector, direction: Vector)

Bases: object

Base class for all agents in the simulation.

property direction

Get the direction of the agent.

Returns:

Vector: The direction of the agent.

property position

Get the position of the agent.

Returns:

Vector: The position of the agent.

property yaw

Get the yaw of the agent.

Returns:

float: The yaw of the agent.

simworld.agent.humanoid module

Humanoid agent class.

class simworld.agent.humanoid.Humanoid(position: Vector, direction: Vector, map: Map | None = None, communicator: Communicator | None = None, config: Config | None = None)

Bases: BaseAgent

Humanoid agent class.

simworld.agent.pedestrian module

Pedestrian agent module for simulating pedestrians in traffic.

class simworld.agent.pedestrian.Pedestrian(position: Vector, direction: Vector, current_sidewalk: Sidewalk | None = None, speed: float = 100)

Bases: BaseAgent

Pedestrian agent for traffic simulation.

add_waypoint(waypoints: list[simworld.utils.vector.Vector])

Add waypoints to the pedestrian’s path.

Args:

waypoints: List of waypoint vectors to add.

change_to_next_sidewalk(next_sidewalk)

Change the pedestrian’s current sidewalk to the next sidewalk.

Args:

next_sidewalk: The sidewalk to change to.

complete_turn()

Check if the pedestrian has completed turning around.

Returns:

bool: True if the turn is completed.

compute_control(waypoint: Vector)

Compute control values for pedestrian movement.

Args:

waypoint: Target waypoint to move towards.

Returns:

tuple: Angle to turn and direction to turn (‘left’, ‘right’, or None).

is_close_to_end(waypoint_distance_threshold: float)

Check if the pedestrian is close to the end of the sidewalk.

Args:

waypoint_distance_threshold: Distance threshold to consider close to waypoint.

Returns:

bool: True if pedestrian is close to end of the sidewalk.

pop_waypoint()

Remove and return the first waypoint.

Returns:

Vector: The first waypoint.

classmethod reset_id_counter()

Reset the pedestrian ID counter to zero.

class simworld.agent.pedestrian.PedestrianState(value)

Bases: Enum

Enumeration of possible pedestrian states.

MOVE_FORWARD = 2
STOP = 1
TURN_AROUND = 3

simworld.agent.scooter module

Scooter agent module.

class simworld.agent.scooter.Scooter(position: Vector, direction: Vector)

Bases: BaseAgent

Scooter agent for traffic simulation.

get_attributes()

Get the attributes of the scooter.

set_attributes(throttle: float, brake: float, steering: float)

Set the attributes of the scooter.

simworld.agent.vehicle module

Vehicle agent module for simulating vehicles in traffic.

class simworld.agent.vehicle.Vehicle(position: Vector, direction: Vector, current_lane, vehicle_reference: str, config, length: float = 500, width: float = 200)

Bases: BaseAgent

Vehicle agent for traffic simulation.

add_waypoint(waypoint: list[simworld.utils.vector.Vector])

Add waypoints to the vehicle’s path.

Args:

waypoint: List of waypoint vectors to add.

change_to_next_lane(next_lane)

Change the vehicle’s current lane to the next lane.

Args:

next_lane: The lane to change to.

completed_u_turn()

Check if the vehicle has completed a U-turn.

Returns:

bool: True if the U-turn is completed.

compute_control(waypoint, dt)

Compute throttle, brake, steering.

Args:

waypoint: Target waypoint to calculate control values. dt: Time delta for PID controller.

Returns:

tuple: Throttle, brake, steering values, and a boolean indicating control change.

get_attributes()

Get the vehicle’s current control attributes.

Returns:

tuple: Current throttle, brake, and steering values.

is_close_to_end()

Check if the vehicle is close to the end of the current lane.

Returns:

bool: True if vehicle is close to the end of the lane.

is_close_to_object(vehicles, pedestrians)

Detect objects in the vehicle’s path.

Args:

vehicles: List of vehicles to check for proximity. pedestrians: List of pedestrians to check for proximity.

Returns:

bool: True if the vehicle is close to any object.

pop_waypoint()

Remove and return the first waypoint.

Returns:

Vector: The first waypoint.

classmethod reset_id_counter()

Reset the vehicle ID counter to zero.

set_attributes(throttle: float, brake: float, steering: float)

Set the vehicle’s control attributes.

Args:

throttle: Throttle value. brake: Brake value. steering: Steering value.

class simworld.agent.vehicle.VehicleState(value)

Bases: Enum

Enumeration of possible vehicle states.

MAKING_U_TURN = 2
MOVING = 3
STOPPED = 4
WAITING = 1

Module contents

Agent module for managing agents in the city.