simworld package
Subpackages
- simworld.agent package
- simworld.assets_rp package
- simworld.citygen package
- simworld.communicator package
- Submodules
- simworld.communicator.communicator module
CommunicatorCommunicator.add_traffic_signal()Communicator.clean_traffic_only()Communicator.clear_env()Communicator.disconnect()Communicator.generate_world()Communicator.get_atmosphere()Communicator.get_camera_observation()Communicator.get_camera_observation_multicam()Communicator.get_collision_number()Communicator.get_fog()Communicator.get_humanoid_name()Communicator.get_pedestrian_name()Communicator.get_position_and_direction()Communicator.get_scooter_name()Communicator.get_sun_direction()Communicator.get_sun_intensity()Communicator.get_traffic_signal_name()Communicator.get_vehicle_name()Communicator.get_waypoint_mark_name()Communicator.get_weather_info()Communicator.humanoid_get_off_scooter()Communicator.humanoid_get_on_scooter()Communicator.humanoid_move_forward()Communicator.humanoid_pick_up_object()Communicator.humanoid_rotate()Communicator.humanoid_set_speed()Communicator.humanoid_sit_down()Communicator.humanoid_stand_up()Communicator.humanoid_step_forward()Communicator.humanoid_stop()Communicator.p_set_waypoints()Communicator.pedestrian_move_forward()Communicator.pedestrian_rotate()Communicator.pedestrian_stop()Communicator.set_atmosphere()Communicator.set_fog()Communicator.set_pedestrian_speed()Communicator.set_scooter_attributes()Communicator.set_sun_direction()Communicator.set_sun_intensity()Communicator.show_img()Communicator.spawn_agent()Communicator.spawn_intersection()Communicator.spawn_object()Communicator.spawn_pedestrians()Communicator.spawn_scooter()Communicator.spawn_traffic_signals()Communicator.spawn_ue_manager()Communicator.spawn_vehicles()Communicator.spawn_waypoint_mark()Communicator.spawn_weather_manager()Communicator.traffic_signal_set_duration()Communicator.traffic_signal_start_simulation()Communicator.traffic_signal_switch_to()Communicator.update_objects()Communicator.update_pedestrians()Communicator.update_vehicle()Communicator.update_vehicles()Communicator.vehicle_make_u_turn()
- simworld.communicator.unrealcv module
UnrealCVUnrealCV.add_pedestrian_signal()UnrealCV.add_vehicle_signal()UnrealCV.check_connection()UnrealCV.clean_garbage()UnrealCV.destroy()UnrealCV.disconnect()UnrealCV.dog_look_down()UnrealCV.dog_look_up()UnrealCV.dog_move()UnrealCV.dog_rotate()UnrealCV.enable_controller()UnrealCV.get_atmosphere()UnrealCV.get_camera_fov()UnrealCV.get_camera_location()UnrealCV.get_camera_location_multicam()UnrealCV.get_camera_resolution()UnrealCV.get_camera_rotation()UnrealCV.get_cameras()UnrealCV.get_collision_num()UnrealCV.get_fog()UnrealCV.get_image()UnrealCV.get_informations()UnrealCV.get_location()UnrealCV.get_location_batch()UnrealCV.get_objects()UnrealCV.get_orientation()UnrealCV.get_orientation_batch()UnrealCV.get_sun_direction()UnrealCV.get_sun_intensity()UnrealCV.humanoid_argue()UnrealCV.humanoid_directing_path()UnrealCV.humanoid_discuss()UnrealCV.humanoid_drop_object()UnrealCV.humanoid_enter_vehicle()UnrealCV.humanoid_exit_vehicle()UnrealCV.humanoid_follow_path()UnrealCV.humanoid_get_off_scooter()UnrealCV.humanoid_get_on_scooter()UnrealCV.humanoid_listen()UnrealCV.humanoid_move_forward()UnrealCV.humanoid_pick_up_object()UnrealCV.humanoid_rotate()UnrealCV.humanoid_set_path()UnrealCV.humanoid_set_speed()UnrealCV.humanoid_sit_down()UnrealCV.humanoid_stand_up()UnrealCV.humanoid_step_forward()UnrealCV.humanoid_stop()UnrealCV.humanoid_stop_current_action()UnrealCV.humanoid_wave_to_dog()UnrealCV.ini_unrealcv()UnrealCV.p_move_forward()UnrealCV.p_movement_simulation()UnrealCV.p_rotate()UnrealCV.p_set_speed()UnrealCV.p_set_states()UnrealCV.p_set_waypoints()UnrealCV.p_stop()UnrealCV.s_set_state()UnrealCV.set_atmosphere()UnrealCV.set_camera_fov()UnrealCV.set_camera_location()UnrealCV.set_camera_resolution()UnrealCV.set_camera_rotation()UnrealCV.set_collision()UnrealCV.set_color()UnrealCV.set_fog()UnrealCV.set_fps()UnrealCV.set_location()UnrealCV.set_mode()UnrealCV.set_movable()UnrealCV.set_object_name()UnrealCV.set_orientation()UnrealCV.set_physics()UnrealCV.set_scale()UnrealCV.set_sun_direction()UnrealCV.set_sun_intensity()UnrealCV.set_tick_interval()UnrealCV.show_img()UnrealCV.spawn()UnrealCV.spawn_bp_asset()UnrealCV.tick()UnrealCV.tl_set_duration()UnrealCV.tl_set_pedestrian_walk()UnrealCV.tl_set_vehicle_green()UnrealCV.traffic_signal_start_simulation()UnrealCV.update_objects()UnrealCV.update_ue_manager()UnrealCV.v_make_u_turn()UnrealCV.v_set_state()UnrealCV.v_set_states()
- Module contents
- simworld.config package
- simworld.llm package
- simworld.local_planner package
- simworld.map package
- Submodules
- simworld.map.map module
EdgeMapMap.add_edge()Map.add_node()Map.get_adjacency_list()Map.get_adjacent_points()Map.get_closest_node()Map.get_nodes_by_type()Map.get_random_node()Map.get_road_at_position()Map.get_road_info_at_position()Map.get_shortest_path()Map.has_edge()Map.initialize_map_from_file()Map.sample_cycle()Map.visualize_by_type()Map.visualize_path()
NodeRoad
- Module contents
- simworld.traffic package
- simworld.utils package
- Submodules
- simworld.utils.bbox_utils module
- simworld.utils.data_exporter module
- simworld.utils.data_importer module
- simworld.utils.get_bbox module
- simworld.utils.load_json module
- simworld.utils.logger module
- simworld.utils.math_utils module
MathUtilsMathUtils.add_points()MathUtils.angle_between()MathUtils.angle_difference()MathUtils.cross_product()MathUtils.do_line_segments_intersect()MathUtils.dot_product()MathUtils.get_direction_description_for_points()MathUtils.interpolate_point()MathUtils.length()MathUtils.length_v()MathUtils.min_degree_difference()MathUtils.point_segment_distance()MathUtils.rotate_point()MathUtils.subtract_points()
- simworld.utils.priority_queue module
- simworld.utils.quadtree module
- simworld.utils.road_utils module
- simworld.utils.traffic_utils module
- simworld.utils.vector module
- simworld.utils.video_recorder module
- Module contents
Module contents
SimWorld package for simulation of urban environments and traffic.
This package provides tools for city generation, traffic simulation, and visualization in Unreal Engine.
- class simworld.BaseAgent(position: Vector, direction: Vector)
Bases:
objectBase 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.
- class simworld.BaseLLM(model_name: str, url: str | None = None, provider: str | None = 'openai')
Bases:
objectBase class for interacting with language models through OpenAI-compatible APIs.
- generate_text(system_prompt: str, user_prompt: str, max_tokens: int = 2048, temperature: float = 0.5, top_p: float = None, **kwargs) str | None
Generate text using the language model.
- Args:
system_prompt: System prompt to guide model behavior. user_prompt: User input prompt. max_tokens: Maximum number of tokens to generate. temperature: Sampling temperature. top_p: Top p sampling parameter.
- Returns:
Generated text response or None if generation fails.
- class simworld.CityFunctionCall(config: Config, seed: int | None = None, num_segments: int | None = None, generate_element: bool | None = None, generate_route: bool | None = None)
Bases:
objectFunction call interface for city generation operations.
- add_road(start: List[float], end: List[float]) int
Add a road segment to the city.
- Args:
start: Starting coordinates [x, y] of the road. end: Ending coordinates [x, y] of the road.
- Returns:
ID of the newly added road segment.
- export_city(output_dir: str | None = None)
Export city data to JSON files.
- Args:
output_dir: Directory path where the city data will be exported.
- generate_building_alone_road(road_id: int)
Generate buildings along a single road.
- Args:
road_id: ID of the road to generate buildings along.
- generate_building_alone_roads()
Generate buildings along all roads in the city.
- generate_city()
Generate city randomly with roads, buildings and elements.
- generate_element_alone_road(road_id: int)
Generate elements along a single road.
- Args:
road_id: ID of the road to generate elements along.
- generate_element_alone_roads()
Generate elements along all roads in the city.
- generate_element_around_buildings()
Generate elements around all buildings in the city.
- generate_road_network()
Generate a procedural road network.
- Args:
num_segments: Target number of road segments to generate.
- modify_road(id: int, start: List[float], end: List[float]) bool
Modify an existing road segment.
- Args:
id: ID of the road segment to modify. start: New starting coordinates [x, y] of the road. end: New ending coordinates [x, y] of the road.
- Returns:
True if the road was successfully modified, False otherwise.
- class simworld.CityGenerator(config, seed: int | None = None, num_segments: int | None = None, generate_element: bool | None = None, generate_route: bool | None = None)
Bases:
objectManages the complete city generation process including roads, buildings, and elements.
- property building_manager
Get the building manager.
- Returns:
BuildingManager: Manager for building operations.
- property building_quadtree
Get the building quadtree.
- Returns:
Quadtree: Quadtree for efficient building queries.
- property buildings
Get all buildings.
- Returns:
list: List of buildings.
- property city_quadtrees
Get all city quadtrees.
- Returns:
list: List of road, building, and element quadtrees.
- property element_manager
Get the element manager.
- Returns:
ElementManager: Manager for element operations.
- property element_quadtree
Get the element quadtree.
- Returns:
Quadtree: Quadtree for efficient element queries.
- property elements
Get all elements.
- Returns:
list: List of elements.
- generate()
Generate the city.
- property intersections
Get all intersections.
- Returns:
list: List of road intersections.
- is_generation_complete() bool
Check if city generation is complete.
- Returns:
bool: True if generation is complete.
- property road_manager
Get the road manager.
- Returns:
RoadManager: Manager for road operations.
- property road_quadtree
Get the road quadtree.
- Returns:
Quadtree: Quadtree for efficient road queries.
- property roads
Get all roads.
- Returns:
list: List of road segments.
- property route_manager
Get the route manager.
- Returns:
RouteManager: Manager for route operations.
- property routes
Get all routes.
- Returns:
list: List of routes.
- class simworld.Communicator(unrealcv: UnrealCV | None = None)
Bases:
objectClass for communicating with Unreal Engine through UnrealCV.
This class is responsible for handling communication with Unreal Engine, including the management of vehicles, pedestrians, and traffic signals.
- add_traffic_signal(intersection_name, traffic_signal)
Add traffic signal.
- Args:
intersection_name: Name of the intersection to add the traffic signal to. traffic_signal: Traffic signal object.
- clean_traffic_only(vehicles, pedestrians, traffic_signals)
Clean traffic objects only.
- Args:
vehicles: List of vehicles. pedestrians: List of pedestrians. traffic_signals: List of traffic signals.
- clear_env(keep_roads=False)
Clear all objects in the environment.
- disconnect()
Disconnect from Unreal Engine.
- generate_world(world_json, ue_asset_path, run_time=True)
Generate world.
- Args:
world_json: World configuration JSON file path. ue_asset_path: Unreal Engine asset path. run_time: Whether to run the world generation in real time.
- Returns:
set: A set of generated object IDs.
- get_atmosphere(weather_manager_name)
Get atmosphere parameters.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
tuple: (rayleigh_scattering_scale, mie_scattering_scale), or (None, None) if parsing fails.
- get_camera_observation(cam_id, viewmode, mode='direct')
Get camera observation.
- Args:
cam_id: Camera ID. viewmode: View mode. Possible values are ‘lit’, ‘depth’, ‘object_mask’. mode: Mode, possible values are ‘direct’, ‘file’, ‘fast’.
- Returns:
Image data.
- get_camera_observation_multicam(cam_ids, viewmode, mode='direct')
Get camera observation batch.
- get_collision_number(humanoid_id)
Get collision number.
- Args:
humanoid_id: Humanoid ID.
- Returns:
Human collision number, object collision number, building collision number, vehicle collision number.
- get_fog(weather_manager_name)
Get fog parameters.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
tuple: (density, distance, falloff), or (None, None, None) if parsing fails.
- get_humanoid_name(humanoid_id)
Get humanoid name.
- Args:
humanoid_id: humanoid ID.
- Returns:
str: The formatted humanoid name.
- get_pedestrian_name(pedestrian_id)
Get pedestrian name.
- Args:
pedestrian_id: Pedestrian ID.
- Returns:
Pedestrian name.
- get_position_and_direction(vehicle_ids=[], pedestrian_ids=[], traffic_signal_ids=[], humanoid_ids=[], scooter_ids=[])
Get position and direction of vehicles, pedestrians, and traffic signals.
- Args:
vehicle_ids: List of vehicle IDs. pedestrian_ids: List of pedestrian IDs. traffic_signal_ids: List of traffic signal IDs. humanoid_ids: Optional list of humanoid IDs to get their positions and directions. scooter_ids: Optional list of scooter IDs to get their positions and directions.
- Returns:
Dictionary containing position and direction information for all objects.
- get_scooter_name(scooter_id)
Get scooter name.
- Args:
scooter_id: Scooter ID.
- get_sun_direction(weather_manager_name)
Get sun direction.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
tuple: (pitch, yaw) in degrees, or (None, None) if parsing fails.
- get_sun_intensity(weather_manager_name)
Get sun intensity.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
float: Sun intensity value, or 0.0 if parsing fails.
- get_traffic_signal_name(traffic_signal_id)
Get traffic signal name.
- Args:
traffic_signal_id: Traffic signal ID.
- Returns:
Traffic signal name.
- get_vehicle_name(vehicle_id)
Get vehicle name.
- Args:
vehicle_id: Vehicle ID.
- Returns:
Vehicle name.
- get_waypoint_mark_name(waypoint_mark_id)
Get waypoint mark name.
- Args:
waypoint_mark_id: Waypoint mark ID.
- Returns:
Waypoint mark name.
- get_weather_info(weather_manager_name)
Get all weather information.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
dict: Dictionary containing all weather parameters, or None if any parsing fails.
- humanoid_get_off_scooter(humanoid_id, scooter_id)
Get off scooter.
- Args:
humanoid_id: humanoid ID. scooter_id: Scooter ID of the humanoid to get off.
- humanoid_get_on_scooter(humanoid_id)
Get on scooter.
- Args:
humanoid_id: humanoid ID.
- humanoid_move_forward(humanoid_id)
Move humanoid forward.
- Args:
humanoid_id: The unique identifier of the humanoid to move forward.
- humanoid_pick_up_object(humanoid_id, object_name)
Pick up object.
- Args:
humanoid_id: humanoid ID. object_name: Object name.
- humanoid_rotate(humanoid_id, angle, direction)
Rotate humanoid.
- Args:
humanoid_id: humanoid ID. angle: Rotation angle. direction: Rotation direction.
- humanoid_set_speed(humanoid_id, speed)
Set humanoid speed.
- Args:
humanoid_id: humanoid ID. speed: Speed.
- humanoid_sit_down(humanoid_id)
Sit down.
- Args:
humanoid_id: humanoid ID.
- humanoid_stand_up(humanoid_id)
Stand up.
- Args:
humanoid_id: humanoid ID.
- humanoid_step_forward(humanoid_id, duration, direction=0)
Step forward.
- Args:
humanoid_id: humanoid ID. duration: Duration. direction: Direction.
- humanoid_stop(humanoid_id)
Stop humanoid.
- Args:
humanoid_id: humanoid ID.
- p_set_waypoints(pedestrian_id, waypoints)
Set pedestrian waypoints.
- Args:
pedestrian_id: Pedestrian ID. waypoints: List of waypoints (Vector).
- pedestrian_move_forward(pedestrian_id)
Move pedestrian forward.
- Args:
pedestrian_id: Pedestrian ID.
- pedestrian_rotate(pedestrian_id, angle, direction)
Rotate pedestrian.
- Args:
pedestrian_id: Pedestrian ID. angle: Rotation angle. direction: Rotation direction.
- pedestrian_stop(pedestrian_id)
Stop pedestrian movement.
- Args:
pedestrian_id: Pedestrian ID.
- set_atmosphere(weather_manager_name, rayleigh, mie)
Set atmosphere parameters.
- Args:
weather_manager_name: Name of the weather manager. rayleigh: Rayleigh scattering scale. Range: 0-2. mie: Mie scattering scale. Range: 0-5.
- set_fog(weather_manager_name, density, distance, falloff)
Set fog parameters.
- Args:
weather_manager_name: Name of the weather manager. density: Fog density. Range: 0-100. distance: Fog distance in cm. Range: 0-5000. falloff: Fog falloff. Range: 0-2.
- set_pedestrian_speed(pedestrian_id, speed)
Set pedestrian speed.
- Args:
pedestrian_id: Pedestrian ID. speed: Pedestrian speed.
- set_scooter_attributes(scooter_id, throttle, brake, steering)
Set scooter attributes.
- Args:
scooter_id: Scooter ID. throttle: Throttle. brake: Brake. steering: Steering.
- set_sun_direction(weather_manager_name, pitch, yaw)
Set sun direction.
- Args:
weather_manager_name: Name of the weather manager. pitch: Pitch of the sun. Range: -89 to 89 degrees. yaw: Yaw of the sun. Range: 0 to 360 degrees.
- set_sun_intensity(weather_manager_name, intensity)
Set sun intensity.
- Args:
weather_manager_name: Name of the weather manager. intensity: Intensity of the sun. 0 - 100
- show_img(image)
Show image.
- Args:
image: Image data.
- spawn_agent(agent, name, position=None, model_path='/Game/TrafficSystem/Pedestrian/Base_User_Agent.Base_User_Agent_C', type='humanoid')
Spawn agent.
- Args:
agent: Agent object. name: Agent name. position: Position. If None, use agent’s position. model_path: Model path. type: Agent type, possible values: ‘humanoid’, ‘dog’, …
- spawn_intersection(intersection_name, model_path)
Spawn intersection.
- Args:
intersection_name: Name of the intersection to spawn. model_path: Model path.
- spawn_object(object_name, model_path, position, direction)
Spawn object.
- Args:
object_name: Object name. model_path: Model path. position: Position. Tuple (x, y, z). direction: Direction. Tuple (pitch, yaw, roll).
- spawn_pedestrians(pedestrians, model_path='/Game/TrafficSystem/Pedestrian/Base_Pedestrian.Base_Pedestrian_C')
Spawn pedestrians.
- Args:
pedestrians: List of pedestrian objects. model_path: Pedestrian model path.
- spawn_scooter(scooter, model_path)
Spawn scooter.
- Args:
scooter: Scooter object. model_path: Model path.
- spawn_traffic_signals(traffic_signals, traffic_light_model_path='/Game/city_props/BP/props/street_light/BP_street_light.BP_street_light_C', pedestrian_light_model_path='/Game/city_props/BP/props/street_light/BP_street_light_ped.BP_street_light_ped_C')
Spawn traffic signals.
- Args:
traffic_signals: List of traffic signal objects to spawn. traffic_light_model_path: Path to the traffic light model asset. pedestrian_light_model_path: Path to the pedestrian signal light model asset.
- spawn_ue_manager(ue_manager_path)
Spawn UE manager.
- Args:
ue_manager_path: Path to the UE manager asset in the content browser.
- spawn_vehicles(vehicles)
Spawn vehicles.
- Args:
vehicles: List of vehicle objects.
- spawn_waypoint_mark(waypoints, model_path)
Spawn waypoint marks.
- Args:
waypoints: List of waypoint objects. model_path: Waypoint mark model path.
- spawn_weather_manager(weather_manager_name, weather_manager_model_path='/Game/Weather/BP_WeatherManager.BP_WeatherManager_C')
Spawn weather manager.
- Args:
weather_manager_name: Name of the weather manager. weather_manager_model_path: Path to the weather manager model.
- traffic_signal_set_duration(traffic_signal_id, green_duration, yellow_duration, pedestrian_green_duration)
Set traffic signal duration.
- Args:
traffic_signal_id: Traffic signal ID. green_duration: Green duration. yellow_duration: Yellow duration. pedestrian_green_duration: Pedestrian green duration.
- traffic_signal_start_simulation(intersection_name)
Start traffic signal simulation.
- Args:
intersection_name: Name of the intersection to start simulation for.
- traffic_signal_switch_to(traffic_signal_id, state='green')
Switch traffic signal state.
- Args:
traffic_signal_id: Traffic signal ID. state: Target state, possible values: ‘green’ or ‘pedestrian walk’.
- update_objects()
Update objects.
- update_pedestrians(states)
Batch update multiple pedestrian states.
- Args:
- states: Dictionary containing multiple pedestrian states,
where keys are pedestrian IDs and values are states.
- update_vehicle(vehicle_id, throttle, brake, steering)
Update vehicle state.
- Args:
vehicle_id: Vehicle ID. throttle: Throttle value. brake: Brake value. steering: Steering value.
- update_vehicles(states)
Batch update multiple vehicle states.
- Args:
- states: Dictionary containing multiple vehicle states,
where keys are vehicle IDs and values are state tuples.
- vehicle_make_u_turn(vehicle_id)
Make vehicle perform a U-turn.
- Args:
vehicle_id: Vehicle ID.
- class simworld.Config(path: str | None = None)
Bases:
objectConfiguration manager for the simulation.
Loads configuration values from YAML files and provides methods to access them through dot-notation paths.
- get(key_path: str, default=None)
Get a configuration value by its dot-notation path.
- Args:
key_path: Dot-notation path to the configuration value (e.g., ‘traffic.num_lanes’). default: Value to return if the key is not found.
- Returns:
The configuration value at the specified path, or the default value if not found.
- Raises:
ValueError: If the key is not found and no default value is provided.
- class simworld.Edge(node1: Node, node2: Node, type: str = 'sidewalk')
Bases:
objectUndirected weighted edge between two nodes.
- class simworld.IntersectionManager(intersections: List[Intersection], config)
Bases:
objectManages intersections and traffic signals in the simulation.
This class handles the initialization of intersections, traffic signal state management, and routing of vehicles and pedestrians through intersections.
- get_intersection_by_lane(lane: TrafficLane)
Find the intersection that contains a specific lane.
- Args:
lane: The traffic lane to find the intersection for.
- Returns:
The intersection containing the lane, or None if not found.
- get_intersection_by_sidewalk(sidewalk: Sidewalk, current_waypoint: Vector)
Find the closest intersection that contains a specific sidewalk.
- Args:
sidewalk: The sidewalk to find the intersection for. current_waypoint: The current position to determine closest intersection.
- Returns:
The closest intersection containing the sidewalk, or None if not found.
- get_next_lane_for_vehicle(lane: TrafficLane)
Determine the next lane for a vehicle to follow at an intersection.
This method chooses the next lane based on a weighted random selection, with straight paths given higher probability.
- Args:
lane: The current lane the vehicle is on.
- Returns:
A tuple of (intersection, next_lane) or (None, None) if no valid next lane.
- get_waypoints_for_pedestrian(sidewalk: Sidewalk, current_waypoint: Vector)
Get the next sidewalk, crosswalk and waypoints for a pedestrian.
- Args:
sidewalk: The current sidewalk the pedestrian is on. current_waypoint: The current position of the pedestrian.
- Returns:
A tuple of (next_sidewalk, crosswalk, waypoints, intersection) or (None, None, None, None).
- get_waypoints_for_vehicle(lane: TrafficLane)
Generate waypoints for a vehicle to navigate through an intersection.
- Args:
lane: The current lane the vehicle is on.
- Returns:
A tuple of (next_lane, waypoints, intersection, is_u_turn) or (None, None, None, None).
- init_intersections()
Initialize all intersections with their configuration.
Sets up lanes, sidewalks, and traffic lights for each intersection.
- set_traffic_signal_duration(communicator: Communicator)
Set the duration of all traffic signals.
- Args:
communicator: Interface for communicating with the simulation environment.
- spawn_traffic_signals(communicator: Communicator)
Spawn all traffic signals in the simulation environment.
- Args:
communicator: Interface for communicating with the simulation environment.
- update_intersections(communicator: Communicator)
Control the traffic lights at intersections.
Manages the cycle of traffic signals, switching between vehicle and pedestrian phases.
- Args:
communicator: Interface for communicating with the simulation environment.
- class simworld.Logger
Bases:
objectSingleton logger class for the simulation application.
This class provides a centralized logging mechanism with configurable options for enabling/disabling logging and console output.
- classmethod configure(logging_enabled=True, log_to_console=True, log_to_file=False)
Configure global logging settings.
- Args:
logging_enabled: Whether logging is enabled globally. log_to_console: Whether to output logs to console. log_to_file: Whether to output logs to file.
- static get_logger(name=None)
Get a logger instance, optionally as a child logger with the specified name.
- Args:
name: Optional name for child logger.
- Returns:
A configured logger instance.
- property logger
Delay creating logger instance.
- class simworld.Map(config: Config, traffic_signals: list | None = None)
Bases:
objectGraph of nodes and edges supporting path queries and random access.
- get_adjacent_points(node: Node) List[Vector]
Get neighboring node positions for a given node.
- Args:
node: Node to get neighbors for.
- Returns:
List of neighboring node positions.
- get_closest_node(position: Vector) Node
Find the node nearest to a given position.
- Args:
position: Position to find nearest node to.
- Returns:
Nearest node.
- get_nodes_by_type(type: str) List[Node]
Get all nodes of a given type.
- Args:
type: Node type.
- Returns:
List of nodes of the given type.
- get_random_node(type: str | None = None, exclude: List[Node] | None = None) Node
Get a random node from the map.
- Args:
type: Node type. exclude: List of nodes to exclude.
- Returns:
A random node from the map.
- get_road_at_position(position: Vector) Road
Find the road that contains the given position.
- Args:
position: Position vector to check.
- Returns:
The Road object if position is on any road.
- get_road_info_at_position(position: Vector) dict
Get detailed information about the road at the given position.
- Args:
position: Position vector to check.
- Returns:
Dictionary containing road information and distance, or None if no road found.
- get_shortest_path(start: Node, end: Node)
Get the shortest path between two nodes using A* algorithm. Include the start node and end node in the path.
- Args:
start: Start node. end: End node.
- Returns:
List of nodes in the shortest path.
- has_edge(edge: Edge) bool
Check if an edge exists in the map.
- Args:
edge: Edge to check.
- Returns:
True if the edge exists, False otherwise.
- initialize_map_from_file(roads_file: str | None = None, sidewalk_offset: float | None = None, fine_grained: bool = False, num_waypoints_normal: int = 3, waypoints_distance: float = 900, waypoints_normal_distance: float = 150)
Initialize the map from the input roads file.
- Args:
roads_file: Path to the roads file. sidewalk_offset: Sidewalk offset. fine_grained: Whether to use fine-grained map. num_waypoints_normal: Number of waypoints in the normal direction. waypoints_distance: Waypoints distance. waypoints_normal_distance: Waypoints normal distance.
- sample_cycle(start_node, min_len=3, max_len=6, max_attempts=1000)
Randomly sample a cycle starting and ending at start_node within [min_len, max_len] length.
- Args:
start_node: The starting node. min_len: The minimum length of the cycle. max_len: The maximum length of the cycle. max_attempts: The maximum number of attempts to sample a cycle.
- Returns:
A list of Node instances representing the cycle, or None if not found.
- visualize_by_type()
Visualize the map by node type.
- visualize_path(path)
Visualize the path.
- Args:
path: Path to visualize. A list of Node instances.
- class simworld.Node(position: Vector, direction: Vector, type: str = 'sidewalk')
Bases:
objectGraph node with a position and type (‘sidewalk’, ‘crosswalk’, or ‘intersection’).
- class simworld.PedestrianManager(roads, num_pedestrians, config)
Bases:
objectManages pedestrians in the traffic simulation.
This class handles spawning pedestrians on sidewalks, updating their positions and states, and managing their interactions with intersections and traffic signals.
- init_pedestrians()
Initialize the pedestrians and place them on the sidewalks.
Pedestrians are randomly placed on sidewalks, ensuring they maintain safe distances from other pedestrians and intersections.
- set_pedestrians_max_speed(communicator)
Set the maximum speed for each pedestrian in the simulation.
- Args:
communicator: Communication interface to the simulation environment.
- spawn_pedestrians(communicator)
Spawn pedestrians in the simulation environment.
- Args:
communicator: Communication interface to the simulation environment.
- stop_pedestrians(communicator)
Stop all pedestrians in the simulation.
- update_pedestrians(communicator, intersection_controller)
Update pedestrian states and movements based on environment conditions.
This method handles pedestrian movement logic, including waypoint following, intersection crossing, and traffic signal compliance.
- Args:
communicator: Interface for sending updates to the simulation. intersection_controller: Controller for managing intersection logic.
- class simworld.TrafficController(config: Config, num_vehicles: int | None = None, num_pedestrians: int | None = None, map: str | None = None, seed: int | None = None, dt: float | None = None)
Bases:
objectMain controller class for the traffic simulation system.
Coordinates all aspects of the traffic simulation including road network, vehicles, pedestrians, and traffic signals.
- property crosswalks
Get all crosswalks in the simulation.
- Returns:
List of all crosswalk objects.
- disconnect_communicator()
Disconnect the communication interface from the simulation environment.
- init_communicator(communicator=None)
Initialize the communication interface with the simulation environment.
- Args:
communicator: Optional communicator instance. If None, a new one is created.
- init_roadnet_from_file(file_path)
Initialize the road network from a JSON file.
- Args:
file_path: Path to the JSON file containing road network data.
- Raises:
ValueError: If the file path is not absolute.
- property lanes
Get all traffic lanes in the simulation.
- Returns:
List of all traffic lane objects.
- property pedestrians
Get all pedestrians in the simulation.
- Returns:
List of all pedestrian objects.
- reset(num_vehicles: int, num_pedestrians: int, map: str)
Reset the simulation with new parameters.
- Args:
num_vehicles: New number of vehicles to spawn. num_pedestrians: New number of pedestrians to spawn. map: Path to the new map file to use.
- property sidewalks
Get all sidewalks in the simulation.
- Returns:
List of all sidewalk objects.
- simulation(physical_update_function: Callable, exit_event: Event | None = None, signal_event: Event | None = None)
Run the traffic simulation continuously.
Continuously updates the state of all simulation components at fixed time intervals.
- Args:
physical_update_function: Function to update the physical state of the simulation. exit_event: Event to signal the end of the simulation. signal_event: Event to signal the end of the simulation.
- spawn_objects_in_unreal_engine()
Spawn all traffic-related objects in the Unreal Engine simulation.
- spawn_pedestrians()
Spawn pedestrians in the simulation environment.
- spawn_traffic_signals()
Spawn traffic signals in the simulation environment.
- spawn_vehicles()
Spawn vehicles in the simulation environment.
- stop_simulation()
Stop the traffic simulation.
- property traffic_signals
Get all traffic signals in the simulation.
- Returns:
List of all traffic signal objects.
- update_states()
Update the states of all traffic components from the simulation.
- property vehicles
Get all vehicles in the simulation.
- Returns:
List of all vehicle objects.
- class simworld.UnrealCV(port=9000, ip='127.0.0.1', resolution=(1280, 720))
Bases:
objectInterface class for communication with Unreal Engine.
This class provides various functionalities for communicating with Unreal Engine, including basic operations and traffic system operations.
- add_pedestrian_signal(intersection_name, pedestrian_signal_name)
Add pedestrian signal.
- Args:
intersection_name: Name of the intersection to add pedestrian signal to. pedestrian_signal_name: Name of the pedestrian signal to add.
- add_vehicle_signal(intersection_name, vehicle_signal_name)
Add vehicle signal.
- Args:
intersection_name: Name of the intersection to add traffic signal to. vehicle_signal_name: Name of the vehicle signal to add.
- check_connection()
Check connection status, attempt to reconnect if not connected.
- clean_garbage()
Clean garbage objects.
- destroy(actor_name)
Destroy an object.
- Args:
actor_name: Actor name.
- disconnect()
Disconnect from Unreal Engine.
- dog_look_down(robot_name)
Apply look down action.
- Args:
robot_name: Robot name.
- dog_look_up(robot_name)
Apply look up action.
- Args:
robot_name: Robot name.
- dog_move(robot_name, action)
Apply transition action.
- Args:
robot_name: Robot name. action: Action in the form [speed, duration, direction].
- dog_rotate(robot_name, action)
Apply rotation action.
- Args:
robot_name: Robot name. action: Action in the form [duration, angle, direction].
- enable_controller(name, enable_controller)
Enable or disable controller.
- Args:
name: Object name. enable_controller: Whether to enable controller.
- get_atmosphere(weather_manager_name)
Get atmosphere.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
Atmosphere.
- get_camera_fov(camera_id: int)
Get camera field of view.
- Args:
camera_id: ID of the camera to get field of view.
- Returns:
Horizontal field of view of the camera.
- get_camera_location(camera_id: int)
Get camera location.
- Args:
camera_id: ID of the camera to get location.
- Returns:
Location (x, y, z) of the camera.
- get_camera_resolution(camera_id: int)
Get camera resolution.
- Args:
camera_id: ID of the camera to get resolution.
- Returns:
Resolution (width, height) of the camera.
- get_camera_rotation(camera_id: int)
Get camera rotation.
- Args:
camera_id: ID of the camera to get rotation.
- Returns:
Rotation (yaw, pitch, roll) of the camera.
- get_cameras()
Get all cameras.
- Returns:
List of camera names.
- get_collision_num(actor_name)
Get collision number.
- Args:
actor_name: Actor name.
- Returns:
dict: Collision counts keyed by
HumanCollision,ObjectCollision,BuildingCollision, andVehicleCollision.
- get_fog(weather_manager_name)
Get fog.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
Fog.
- get_image(cam_id, viewmode, mode='direct', img_path=None)
Get image.
- Args:
cam_id: Camera ID. viewmode: View mode. Possible values are ‘lit’, ‘depth’, ‘object_mask’. mode: Mode. img_path: Image path.
- get_informations(manager_object_name)
Get information.
- Args:
manager_object_name: Name of the manager object to get information from.
- Returns:
str: Information string containing the current state of the environment.
- get_location(actor_name)
Get object location.
- Args:
actor_name: Actor name.
- Returns:
Location coordinates array.
- get_location_batch(actor_names)
Batch get object locations.
- Args:
actor_names: List of actor names.
- Returns:
List of location coordinate arrays.
- get_objects()
Get all objects.
- Returns:
List of objects.
- get_orientation(actor_name)
Get object orientation.
- Args:
actor_name: Actor name.
- Returns:
Orientation array.
- get_orientation_batch(actor_names)
Batch get object orientations.
- Args:
actor_names: List of actor names.
- Returns:
List of orientation arrays.
- get_sun_direction(weather_manager_name)
Get sun direction.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
Sun direction.
- get_sun_intensity(weather_manager_name)
Get sun intensity.
- Args:
weather_manager_name: Name of the weather manager.
- Returns:
Sun intensity.
- humanoid_argue(humanoid_name, argue_type)
Argue.
- Args:
humanoid_name: Name of the humanoid to argue. argue_type: Type of arguing. Can be [0, 1]
- humanoid_directing_path(humanoid_name)
Directing path.
- Args:
humanoid_name: Name of the humanoid to directing path.
- humanoid_discuss(humanoid_name, discuss_type)
Discuss.
- Args:
humanoid_name: Name of the humanoid to discuss. discuss_type: Type of discussion. Can be [0, 1]
- humanoid_drop_object(humanoid_name)
Drop object.
- Args:
humanoid_name: Name of the humanoid to drop object.
- humanoid_enter_vehicle(humanoid_name, vehicle_name)
Enter vehicle.
- Args:
humanoid_name: Name of the humanoid to enter vehicle. vehicle_name: Name of the vehicle to enter.
- humanoid_exit_vehicle(humanoid_name, vehicle_name)
Exit vehicle.
- Args:
humanoid_name: Name of the humanoid to enter vehicle. vehicle_name: Name of the vehicle to exit.
- humanoid_follow_path(object_name)
Follow path.
- Args:
object_name: Name of the humanoid object.
- humanoid_get_off_scooter(object_name)
Get off scooter.
- Args:
object_name: Name of the humanoid object to get off scooter.
- humanoid_get_on_scooter(object_name)
Get on scooter.
- Args:
object_name: Name of the humanoid object to get on scooter.
- humanoid_listen(humanoid_name)
Listen.
- Args:
humanoid_name: Name of the humanoid to discuss.
- humanoid_move_forward(object_name)
Move humanoid forward.
- Args:
object_name: Name of the humanoid object to move forward.
- humanoid_pick_up_object(humanoid_name, object_name)
Pick up object.
- Args:
humanoid_name: Name of the humanoid to pick up object. object_name: Name of the object to pick up.
- humanoid_rotate(object_name, angle, direction='left')
Rotate humanoid.
- Args:
object_name: Name of the humanoid object to rotate. angle: Rotation angle in degrees. direction: Direction of rotation, either ‘left’ or ‘right’. Defaults to ‘left’.
- humanoid_set_path(object_name, path)
Set humanoid path.
- Args:
object_name: Name of the humanoid object. path: String of path. Use semicolon to separate waypoints and use comma to separate coordinates. Example: “100,100;200,200;300,300”
- humanoid_set_speed(object_name, speed)
Set humanoid speed.
- Args:
object_name: Name of the humanoid object to set speed. speed: Speed to set.
- humanoid_sit_down(object_name)
Sit down.
- Args:
object_name: Name of the humanoid object to sit down.
- humanoid_stand_up(object_name)
Stand up.
- Args:
object_name: Name of the humanoid object to sit down.
- humanoid_step_forward(object_name, duration, direction=0)
Step forward.
- Args:
object_name: Name of the humanoid object to step forward. duration: Duration of the step forward movement in seconds. direction: Direction of the step forward movement.
- humanoid_stop(object_name)
Stop humanoid.
- Args:
object_name: Name of the humanoid object to stop.
- humanoid_stop_current_action(humanoid_name)
Stop current action.
- Args:
humanoid_name: Name of the humanoid to stop current action.
- humanoid_wave_to_dog(humanoid_name)
Wave to dog.
- Args:
humanoid_name: Name of the humanoid to wave to dog.
- ini_unrealcv(resolution=(320, 240))
Initialize UnrealCV settings.
- Args:
resolution: Resolution, defaults to (320, 240).
- p_move_forward(object_name)
Move pedestrian forward.
- Args:
object_name: Object name.
- p_movement_simulation(object_name)
Start pedestrian movement simulation.
- Args:
object_name: Object name.
- p_rotate(object_name, angle, direction='left')
Rotate pedestrian.
- Args:
object_name: Object name. angle: Angle. direction: Direction, defaults to ‘left’.
- p_set_speed(object_name, speed)
Set pedestrian speed.
- Args:
object_name: Object name. speed: Speed.
- p_set_states(manager_object_name, states: str)
Batch set pedestrian states.
- Args:
manager_object_name: Manager object name. states: States string.
- p_set_waypoints(object_name, waypoints)
Set pedestrian waypoints.
- Args:
object_name: Object name. waypoints: String of waypoints. Use semicolon to separate waypoints and use comma to separate coordinates. Example: “100,100;200,200;300,300”
- p_stop(object_name)
Stop pedestrian movement.
- Args:
object_name: Object name.
- s_set_state(object_name, throttle, brake, steering)
Set scooter state.
- Args:
object_name: Name of the scooter object. throttle: Throttle value. brake: Brake value. steering: Steering value.
- set_atmosphere(weather_manager_name, rayleigh, mie)
Set atmosphere.
- Args:
weather_manager_name: Name of the weather manager. rayleigh: RayleighScatteringScale of the atmosphere. 0 - 2. mie: MieScatteringScale of the atmosphere. 0 - 5.
- set_camera_fov(camera_id: int, fov: float)
Set camera field of view.
- Args:
camera_id: ID of the camera to set field of view. fov: Horizontal field of view of the camera.
- set_camera_location(camera_id: int, location: tuple)
Set camera location.
- Args:
camera_id: ID of the camera to set location. location: Location (x, y, z) of the camera.
- set_camera_resolution(camera_id: int, resolution: tuple)
Set camera resolution.
- Args:
camera_id: ID of the camera to set resolution. resolution: Resolution (width, height) of the camera.
- set_camera_rotation(camera_id: int, rotation: tuple)
Set camera rotation.
- Args:
camera_id: ID of the camera to set rotation. rotation: Rotation (pitch, yaw, roll) of the camera.
- set_collision(actor_name, hasCollision)
Set collision properties.
- Args:
actor_name: Actor name. hasCollision: Whether to enable collision.
- set_color(actor_name, color)
Set object color.
- Args:
actor_name: Object name. color: Color in the form [R, G, B].
- set_fog(weather_manager_name, density, distance, falloff)
Set fog.
- Args:
weather_manager_name: Name of the weather manager. density: Density of the fog. 0 - 100 distance: Distance of the fog. 0 - 5000, cm falloff: Falloff of the fog. 0 - 2
- set_fps(fps)
Set FPS.
- Args:
fps: FPS.
- set_location(loc, name)
Set object location.
- Args:
loc: Location coordinates in the form [x, y, z]. name: Object name.
- set_mode(mode='async', tick_interval=0.05)
Set asynchronous or synchronous mode.
- Args:
mode: Mode. tick_interval: Tick interval if synchronous mode.
- set_movable(actor_name, isMovable)
Set movable properties.
- Args:
actor_name: Actor name. isMovable: Whether the object is movable.
- set_object_name(name, new_name)
Set object name.
- Args:
name: Object name. new_name: New object name.
- set_orientation(orientation, name)
Set object orientation.
- Args:
orientation: Orientation in the form [pitch, yaw, roll]. name: Object name.
- set_physics(actor_name, hasPhysics)
Set physics properties.
- Args:
actor_name: Actor name. hasPhysics: Whether to enable physics.
- set_scale(scale, name)
Set object scale.
- Args:
scale: Scale in the form [x, y, z]. name: Object name.
- set_sun_direction(weather_manager_name, pitch, yaw)
Set sun direction.
- Args:
weather_manager_name: Name of the weather manager. pitch: Pitch of the sun. -89 - 89 yaw: Yaw of the sun. 0 - 360
- set_sun_intensity(weather_manager_name, intensity)
Set sun intensity.
- Args:
weather_manager_name: Name of the weather manager. intensity: Intensity of the sun. 0 - 100
- set_tick_interval(interval)
Set tick interval.
- show_img(img, title='raw_img')
Display an image.
- Args:
img: Image. title: Title, defaults to “raw_img”.
- spawn(prefab, name)
Spawn an object (deprecated).
- Args:
prefab: Prefab. name: Object name.
- spawn_bp_asset(prefab_path, name)
Spawn a blueprint asset.
- Args:
prefab_path: Prefab path. name: Object name.
- tick()
Tick.
- tl_set_duration(object_name: str, green_duration: float, yellow_duration: float, pedestrian_green_duration: float)
Set traffic light duration.
- Args:
object_name: Object name. green_duration: Green duration. yellow_duration: Yellow duration. pedestrian_green_duration: Pedestrian green duration.
- tl_set_pedestrian_walk(object_name: str)
Set pedestrian traffic light to walk.
- Args:
object_name: Object name.
- tl_set_vehicle_green(object_name: str)
Set vehicle traffic light to green.
- Args:
object_name: Object name.
- traffic_signal_start_simulation(intersection_name)
Start traffic signal simulation.
- update_objects(object_name)
Update objects.
- Args:
object_name: UE_Manager object name.
- update_ue_manager(manager_object_name)
Update UE manager.
- Args:
manager_object_name: Name of the manager object to update.
- v_make_u_turn(object_name)
Make vehicle U-turn.
- Args:
object_name: Object name.
- v_set_state(object_name, throttle, brake, steering)
Set vehicle state.
- Args:
object_name: Object name. throttle: Throttle value. brake: Brake value. steering: Steering value.
- class simworld.VehicleManager(roads, num_vehicles, config)
Bases:
objectManages vehicles in the traffic simulation.
This class handles spawning vehicles on roads, updating their positions and states, and managing their interactions with other elements in the simulation.
- init_vehicles()
Initialize the vehicles and place them on the roads.
Vehicles are randomly placed on lanes, ensuring they maintain safe distances from other vehicles and intersections.
- spawn_vehicles(communicator)
Spawn vehicles in the simulation environment.
- Args:
communicator: Communication interface to the simulation environment.
- stop_vehicles(communicator)
Stop all vehicles in the simulation.
- update_vehicles(communicator, intersection_controller, pedestrians)
Update vehicle states and movements based on environment conditions.
This method handles vehicle movement logic, including waypoint following, intersection crossing, obstacle avoidance, and traffic signal compliance.
- Args:
communicator: Interface for sending updates to the simulation. intersection_controller: Controller for managing intersection logic. pedestrians: List of pedestrians to check for collision avoidance.