simworld.communicator package

Submodules

simworld.communicator.communicator module

Communicator module for interfacing with Unreal Engine.

This module provides a high-level communication interface with Unreal Engine through the UnrealCV client, handling vehicle, pedestrian, and traffic signal management.

class simworld.communicator.communicator.Communicator(unrealcv: UnrealCV | None = None)

Bases: object

Class 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.

simworld.communicator.unrealcv module

UnrealCV communication module.

This module provides a client interface for communicating with Unreal Engine, allowing for various operations such as object spawning, movement, and image capture.

class simworld.communicator.unrealcv.UnrealCV(port=9000, ip='127.0.0.1', resolution=(1280, 720))

Bases: object

Interface 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_location_multicam(camera_ids: list)

Get camera location batch.

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, and VehicleCollision.

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.

v_set_states(manager_object_name, states: str)

Batch set vehicle states.

Args:

manager_object_name: Manager object name. states: States string.

Module contents

Communication modules for interfacing with Unreal Engine.

This package provides the necessary classes and functions for communicating with Unreal Engine through the UnrealCV interface.