diff --git a/CHANGELOG.md b/CHANGELOG.md index 0475512ba..138f015a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Latest Changes + * Fixed a bug that caused navigation information not to be loaded when switching maps * Prevent from segfault on failing SignalReference identification when loading OpenDrive files * Added vehicle doors to the recorder * Added functions to get actor' components transform @@ -14,6 +15,12 @@ * Added possibility to change gravity variable in imui sensor for the accelerometer * Fixed ROS2 native extension build error when ROS2 is installed in the system. * ROS2Native: Force fast-dds dependencies download to avoid build crash when boost_asio and tinyxml2 are not installed in Linux. + * Added API function `get_telemetry_data` to the vehicle actor. + * PythonAPI `Sensor.is_listening` was defined twice (property and method), cleaned and clarified it as a method. + * Added V2X sensors for cooperative awareness message and custom user-defined messages to support vehicle-to-vehicle communication + * Added named tuples for BasicAgent.py's detection result to allow for type-hints and better semantics. + * Added type-hint support for the PythonAPI + ## CARLA 0.9.15 diff --git a/Docs/adv_cpp_client.md b/Docs/adv_cpp_client.md new file mode 100644 index 000000000..e1eb0b163 --- /dev/null +++ b/Docs/adv_cpp_client.md @@ -0,0 +1,142 @@ +# C++ client example + +To build the C++ client example you will need `make` installed. Before building a C++ client, you will need to build CARLA, follow the relevant [build instructions](build_carla.md) for your platform. + +Navigate to the `Examples/CppClient` folder in the CARLA repository and open a terminal. You will find a Makefile in this directory. To build and run it in Linux execute `make run` at the command prompt. In Windows, create a file named `CMakeLists.txt` in the same directory and add the contents in [this file](cpp_client_cmake_windows.md), then run `cmake`. + +This C++ example will connect to the server, spawn a vehicle and apply a command to the vehicle before destroying it and terminating. + +### Include the relevant header files + +For this example, we will be using several different CARLA classes, so we need to include the relevant header files from the CARLA library and include any standard libraries we will use: + +```cpp +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +``` + +### Connecting the C++ client to the server + +Include `carla/client/Client.h` and then connect the client: + +```cpp +... +#include +... +int main(int argc, const char *argv[]) { + + std::string host; + uint16_t port; + std::tie(host, port) = ParseArguments(argc, argv); + ... + // Connect the client to the server + auto client = cc::Client(host, port); + client.SetTimeout(40s); +``` + +### Load a map + +Now let's load a randomly chosen map: + +```cpp +// Initialize random number generator +std::mt19937_64 rng((std::random_device())()); +... +auto town_name = RandomChoice(client.GetAvailableMaps(), rng); +std::cout << "Loading world: " << town_name << std::endl; +auto world = client.LoadWorld(town_name); +``` + +### Spawn a randomly chosen vehicle + +Next we will fetch the blueprint library, filter for vehicles and choose a random vehicle blueprint: + +```cpp +auto blueprint_library = world.GetBlueprintLibrary(); +auto vehicles = blueprint_library->Filter("vehicle"); +auto blueprint = RandomChoice(*vehicles, rng); +``` + +Now we need to find a location to spawn the vehicle from a spawn point in the map. We will get a pointer reference to the map object and then choose a random spawn point (ensure you have initialized the random number generator): + +```cpp +auto map = world.GetMap(); +auto transform = RandomChoice(map->GetRecommendedSpawnPoints(), rng); +``` + +Now we have the blueprint and spawn location, we can now spawn the vehicle using the `world.SpawnActor(...)` method: + +```cpp +auto actor = world.SpawnActor(blueprint, transform); +std::cout << "Spawned " << actor->GetDisplayId() << '\n'; +// Retrieve a pointer to the vehicle object +auto vehicle = boost::static_pointer_cast(actor); +``` + +### Apply a control + +Let's now apply some control to the vehicle to move it using the `ApplyControl(...)` method: + +```cpp +cc::Vehicle::Control control; +control.throttle = 1.0f; +vehicle->ApplyControl(control); +``` + +Now we will relocate the spectator so that we can see our newly spawned vehicle in the map: + +```cpp +auto spectator = world.GetSpectator(); +// Adjust the transform to look +transform.location += 32.0f * transform.GetForwardVector(); +transform.location.z += 2.0f; +transform.rotation.yaw += 180.0f; +transform.rotation.pitch = -15.0f; +// Now set the spectator transform +spectator->SetTransform(transform); +``` + +We'll also sleep the process for 10 seconds to observe the simulation shortly, before the client closes: + + +```cpp +std::this_thread::sleep_for(10s); + +``` + +If you wish to keep the client open while other commands are executed, create a game loop. Now you have loaded a map and spawned a vehicle. To further explore the C++ API [build the Doxygen documentation](ref_cpp.md#c-documentation) and open it in a browser. + +To build the C++ client in another location outside of the CARLA repository, edit the first 5 lines of the Makefile to reference the correct locations for the `/build` directory and the CARLA build location: + +```make +CARLADIR=$(CURDIR)/../.. +BUILDDIR=$(CURDIR)/build +BINDIR=$(CURDIR)/bin +INSTALLDIR=$(CURDIR)/libcarla-install +TOOLCHAIN=$(CURDIR)/ToolChain.cmake +``` + + + + + + + diff --git a/Docs/adv_digital_twin.md b/Docs/adv_digital_twin.md index 41c271b6a..4857e1d98 100644 --- a/Docs/adv_digital_twin.md +++ b/Docs/adv_digital_twin.md @@ -15,6 +15,8 @@ The __Digital Twin Tool__ enables procedural generation of unique 3D environments based on road networks derived from the [OpenStreetMap](https://www.openstreetmap.org) (OSM) service. Through the Digital Twin Tool interface in CARLA's Unreal Engine editor a user can select a region of map from OSM and download the road network as the basis for a new CARLA map. The tool then fills the spaces between the roads with procedurally generated 3D buildings that adjust to the layout of the road, creating a realistic 3D road environment with high variability. + + ## Building the OSM renderer If you are using Linux, you have the option of using the OSM renderer in the CARLA interface to navigate a large OSM map region that you have downloaded. You first need to build the OSM renderer before proceeding to build CARLA. Run `make osmrenderer` inside the CARLA root directory. You may need to upgrade your version of CMake to v3.2 or above in order for this to work. This will create two folders in your build directory called `libosmcout-source` and `libosmcout-build`. Before proceeding to build CARLA, you need to then edit the `Build.sh` file in the directory `$CARLA_ROOT/Build/libosmcout-source/maps` like so, to ensure the executable is found: diff --git a/Docs/build_carla.md b/Docs/build_carla.md index 1ac943002..d0e1fed62 100644 --- a/Docs/build_carla.md +++ b/Docs/build_carla.md @@ -9,7 +9,10 @@ Build instructions are available for Linux and Windows. You can also build CARLA * [__Docker__](build_docker.md) * [__Docker with Unreal__](build_docker_unreal.md) * [__Updating CARLA__](build_update.md) -* [__Build system__](build_system.md) +* [__Build system__](build_system.md) + +* [__Linux build with Unreal Engine 5.3__](build_linux_ue5.md) +* [__Windows build with Unreal Engine 5.3__](build_windows_ue5.md) * [__FAQ__](build_faq.md) diff --git a/Docs/build_docker_unreal.md b/Docs/build_docker_unreal.md index 6a43c1b92..b15f3dc58 100644 --- a/Docs/build_docker_unreal.md +++ b/Docs/build_docker_unreal.md @@ -52,10 +52,10 @@ The following steps will each take a long time. __1. Build the CARLA prerequisites image.__ -The following command will build an image called `carla-prerequisites` using `Prerequisites.Dockerfile`. In this build we install the compiler and required tools, download the Unreal Engine 4.26 fork and compile it. You will need to provide your login details as build arguments for the download of Unreal Engine to be successful: +The following command will build an image called `carla-prerequisites` using `Prerequisites.Dockerfile`. In this build we install the compiler and required tools, download the Unreal Engine 4.26 fork and compile it. You will need to provide your login details (use a Github Personal Access Token instead of a password) as build arguments for the download of Unreal Engine to be successful: ```sh -docker build --build-arg EPIC_USER= --build-arg EPIC_PASS= -t carla-prerequisites -f Prerequisites.Dockerfile . +docker build --build-arg EPIC_USER= --build-arg EPIC_PASS= -t carla-prerequisites -f Prerequisites.Dockerfile . ``` __2. Build the final CARLA image.__ diff --git a/Docs/build_linux.md b/Docs/build_linux.md index 704aa8447..e292a71d5 100644 --- a/Docs/build_linux.md +++ b/Docs/build_linux.md @@ -129,7 +129,7 @@ pip3 install --user -Iv setuptools==47.3.1 && pip install --user distro && pip3 install --user distro && pip install --user wheel && -pip3 install --user wheel auditwheel +pip3 install --user wheel auditwheel==4.0.0 ``` --- diff --git a/Docs/build_linux_ue5.md b/Docs/build_linux_ue5.md new file mode 100644 index 000000000..54de572a3 --- /dev/null +++ b/Docs/build_linux_ue5.md @@ -0,0 +1,95 @@ +!!! warning + This is a work in progress!! This version of CARLA is not considered a stable release. Over the following months many significant changes may be made to this branch which could break any modifications you make. We advise you to treat this branch as experimental. + +# Building CARLA in Linux with Unreal Engine 5.3 + +!!! note + This build process is implemented and tested for Ubuntu 22.04. We recommend to use this Ubuntu version. + +## Set up the environment + +This guide details how to build CARLA from source on Linux with Unreal Engine 5.3. + +Clone the `ue5-dev` branch of CARLA on your local machine: + +```sh +git clone -b ue5-dev https://github.com/carla-simulator/carla.git CarlaUE5 +``` + +Run the setup script: + +```sh +cd CarlaUE5 +bash -x Setup.sh +``` + +The Setup.sh script installs all the required packages, including Cmake, debian packages, Python packages and Unreal Engine 5.3. It also downloads the CARLA content and builds CARLA. This script can therefore take a long time to complete. + +!!! note + * This version of CARLA requires the **CARLA fork of Unreal Engine 5.3**. You need to link your GitHub account to Epic Games in order to gain permission to clone the UE repository. If you have not already linked your accounts, follow [this guide](https://www.unrealengine.com/en-US/ue4-on-github) + * For using CARLA Unreal Engine 5 previous builds, **ensure CARLA_UNREAL_ENGINE_PATH environment variable is defined** pointing to the CARLA Unreal Engine 5.3 absolute path. If this variable is not defined, the Setup.sh script will download and build CARLA Unreal Engine 5 and **this takes more than 1 extra hour of build and 225Gb of disk space**. + * The Setup.sh script checks if there is any Python installed at the top of the PATH variable, and installs Python otherwise. **To use your own version of Python, ensure that the PATH variable is properly set for Python before running the script**. + * CARLA cannot be built on an external disk, Ubuntu is not giving the required read/write/execution permissions for builds. + + +## Build and Run CARLA UE5 + +The setup script launches the following commands itself, you will need to use the following commands once you modify the code and wish to relaunch: + +* Configure: + +```sh +cmake -G Ninja -S . -B Build --toolchain=$PWD/CMake/LinuxToolchain.cmake \ +-DLAUNCH_ARGS="-prefernvidia" -DCMAKE_BUILD_TYPE=Release -DENABLE_ROS2=ON \ +-DBUILD_CARLA_UNREAL=ON -DCARLA_UNREAL_ENGINE_PATH=$CARLA_UNREAL_ENGINE_PATH +``` + +* Build CARLA: + +```sh +cmake --build Build +``` + +* Build and install the Python API: + +```sh +cmake --build Build --target carla-python-api-install +``` + +* Launch the editor: + +```sh +cmake --build Build --target launch +``` + +## Build a package with CARLA UE5 + +```sh +cmake --build Build --target package +``` + +The package will be generated in the directory `$CARLA_PATH/Build/Package` + +## Run the package + +Run the package with the following command. + +```sh +./CarlaUnreal.sh +``` + +If you want to run the native ROS2 interface, add the `--ros2` argument + +```sh +./CarlaUnreal.sh --ros2 +``` + +If you want to install the Python API corresponding to the package you have built: + +```sh +pip3 install PythonAPI/carla/dist/carla-*.whl +``` + +## Additional build targets + +The procedure outlined above will download all necessary components to build CARLA, you may not want to \ No newline at end of file diff --git a/Docs/build_windows_ue5.md b/Docs/build_windows_ue5.md new file mode 100644 index 000000000..70b1eeb9e --- /dev/null +++ b/Docs/build_windows_ue5.md @@ -0,0 +1,79 @@ +!!! warning + This is a work in progress!! This version of CARLA is not considered a stable release. Over the following months many significant changes may be made to this branch which could break any modifications you make. We advise you to treat this branch as experimental. + +# Building CARLA in Windowswith Unreal Engine 5.3 + +## Set up the environment + +This guide details how to build CARLA from source on Windows with Unreal Engine 5.3. + +Clone the `ue5-dev` branch of CARLA on your local machine: + +```sh +git clone -b ue5-dev https://github.com/carla-simulator/carla.git CarlaUE5 +``` + +Run the setup script: + +```sh +cd CarlaUE5 +Setup.bat +``` + +The Setup.bat script installs all the required packages, including Visual Studio 2022, Cmake, Python packages and Unreal Engine 5. It also downloads the CARLA content and builds CARLA. This batch file can therefore take a long time to complete. + +!!! note + * This version of CARLA requires the **CARLA fork of Unreal Engine 5.3**. You need to link your GitHub account to Epic Games in order to gain permission to clone the UE repository. If you have not already linked your accounts, follow [this guide](https://www.unrealengine.com/en-US/ue4-on-github) + * For using CARLA Unreal Engine 5 previous builds, ensure CARLA_UNREAL_ENGINE_PATH environment variable is defined pointing to the CARLA Unreal Engine 5 absolute path. If this variable is not defined, Setup.bat script will download and build CARLA Unreal Engine 5 and **this takes more than 1 extra hour of build and a 225Gb of disk space**. + * Setup.bat script checks if there is any Python version installed at the top of the PATH variable, and installs Python otherwise. **To use your own version of Python, ensure that the PATH variable is properly set for Python before running the script**. + * **Windows Developer Mode should be active**, otherwise build will fail. Please see [here](https://learn.microsoft.com/en-us/gaming/game-bar/guide/developer-mode) for instructions on how to activate Developer Mode. + * **CARLA cannot be built on an external disk**, Windows does not give the required read/write/execution permissions for builds. + + +## Build and Run CARLA UE5 + +The Setup.bat file launches the following commands itself, you will need to use the following commands once you modify the code and wish to relaunch: + +!!! warning + Ensure CARLA_UNREAL_ENGINE_PATH environment variable is defined pointing to the CARLA Unreal Engine 5.3 absolute path. Setup.bat sets this variable, but I may not be set if another approach was followed to install the requirements. + +* **Configure**. Open x64 Native Tools Command Prompt for VS 2022 at the CarlaUE5 folder and runn the following command: + +```sh +cmake -G Ninja -S . -B Build -DCMAKE_BUILD_TYPE=Release -DBUILD_CARLA_UNREAL=ON -DCARLA_UNREAL_ENGINE_PATH=%CARLA_UNREAL_ENGINE_PATH% +``` + +* **Build CARLA**. Open the x64 Native Tools Command Prompt for VS 2022 at the CarlaUE5 folder and run the following command: + +```sh +cmake --build Build +``` + +* **Build and install the Python API**. Open the x64 Native Tools Command Prompt for VS 2022 at the CarlaUE5 folder and run the following command:: + +```sh +cmake --build Build --target carla-python-api-install +``` + +* **Launch the editor**. Open the x64 Native Tools Command Prompt for VS 2022 at the CarlaUE5 folder and run the following command: + +```sh +cmake --build Build --target launch +``` + +## Build a package with CARLA UE5 + +!!! warning + The package build for Carla UE5 is not yet fully tested for Windows. + +Open the x64 Native Tools Command Prompt for VS 2022 at the CarlaUE5 folder and run the following command: + +```sh +cmake --build Build --target package +``` + +The package will be generated in the directory `Build/Package` + +## Run the package + +The package build is not yet tested for Windows diff --git a/Docs/core_sensors.md b/Docs/core_sensors.md index 4ca9c1603..0a3ab237c 100644 --- a/Docs/core_sensors.md +++ b/Docs/core_sensors.md @@ -96,7 +96,8 @@ Sensor data differs a lot between sensor types. Take a look at the [sensors refe !!! Important - `is_listening` is a __sensor attribute__ that enables/disables data listening at will. + `is_listening()` is a __sensor method__ to check whether the sensor has a callback registered by `listen`. + `stop()` is a __sensor method__ to stop the sensor from listening. `sensor_tick` is a __blueprint attribute__ that sets the simulation time between data received. --- diff --git a/Docs/cpp_client_cmake_windows.md b/Docs/cpp_client_cmake_windows.md new file mode 100644 index 000000000..e4af27c83 --- /dev/null +++ b/Docs/cpp_client_cmake_windows.md @@ -0,0 +1,68 @@ +```make +cmake_minimum_required(VERSION 3.5.1) +project(example) + +link_directories( + ${RPCLIB_LIB_PATH}) + +file(GLOB example_sources "*.cpp" "*.h") + +file(GLOB example_client_sources "") + +set(carla_config client) +list(APPEND build_targets example_${carla_config}_debug) + +# Create targets for debug and release in the same build type. +foreach(target ${build_targets}) + + add_executable(${target} ${example_sources}) + + target_compile_definitions(${target} PUBLIC + -DLIBCARLA_ENABLE_PROFILER) + + target_include_directories(${target} SYSTEM PRIVATE + "../../LibCarla/source" + "../../Build/boost-1.80.0-install/include" + "../../Build/rpclib-install/include/" + "../../Build/recast-22dfcb-install/include/" + "../../Build/zlib-install/include/" + "../../Build/libpng-1.2.37-install/include/" + "../../LibCarla/source/third-party/") + + target_link_directories(${target} SYSTEM PRIVATE + "../../Build/boost-1.80.0-install/lib" + "../../Build/rpclib-install/lib/" + "../../Build/recast-22dfcb-install/lib/" + "../../Build/zlib-install/lib/" + "../../Build/libcarla-visualstudio/LibCarla/cmake/client/Release/" + "../../Build/libpng-1.2.37-install/lib/") + + target_include_directories(${target} PRIVATE + "${libcarla_source_path}/test") + + if (WIN32) + target_link_libraries(${target} "rpc.lib") + target_link_libraries(${target} "carla_client.lib") + target_link_libraries(${target} "DebugUtils.lib") + target_link_libraries(${target} "Detour.lib") + target_link_libraries(${target} "DetourCrowd.lib") + target_link_libraries(${target} "DetourTileCache.lib") + target_link_libraries(${target} "Recast.lib") + target_link_libraries(${target} "Shlwapi.lib") + else() + target_link_libraries(${target} "-lrpc") + endif() + + install(TARGETS ${target} DESTINATION test OPTIONAL) +endforeach(target) + +if (LIBCARLA_BUILD_DEBUG) + # Specific options for debug. + set_target_properties(example_${carla_config}_debug PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") + target_link_libraries(example_${carla_config}_debug "carla_${carla_config}${carla_target_postfix}_debug") + target_compile_definitions(example_${carla_config}_debug PUBLIC -DBOOST_ASIO_ENABLE_BUFFER_DEBUGGING) + if (CMAKE_BUILD_TYPE STREQUAL "Client") + target_link_libraries(example_${carla_config}_debug "${BOOST_LIB_PATH}/libboost_filesystem.a") + endif() +endif() +``` diff --git a/Docs/python_api.md b/Docs/python_api.md index 3cf5203b7..a7ab163a2 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -419,6 +419,43 @@ Parses the location and extent of the bounding box to string. --- +## carla.CAMData +Inherited from _[carla.SensorData](#carla.SensorData)_
+This is the data type for cooperative awareness message reception, contained in a [CAMEvent](#carlacamevent). + +### Instance Variables +- **power** (_float - dBm_) +Received power. + +### Methods +- **get**(**self**) +Get the CAM data. Returns a nested dictionary containing the message following the ETSI standard: - `Header`: dict - `Message`: dict. + - **Return:** _dict_ + +##### Dunder methods +- **\__str__**(**self**) + +--- + +## carla.CAMEvent +Inherited from _[carla.SensorData](#carla.SensorData)_
+Class that defines the data provided by a **sensor.other.v2x**. This is a collection type to combine returning several [CAMData](#carlacamdata). + +### Methods + +##### Getters +- **get_message_count**(**self**) +Get the number of received CAM's. + - **Return:** _int_ + +##### Dunder methods +- **\__get_item__**(**self**, **pos**=int) +- **\__iter__**(**self**) +Iterate over the [CAMData](#carlacamdata) retrieved as data. +- **\__len__**(**self**) + +--- + ## carla.CityObjectLabel Enum declaration that contains the different tags available to filter the bounding boxes returned by [carla.World.get_level_bbs](#carla.World.get_level_bbs)(). These values correspond to the [semantic tag](ref_sensors.md#semantic-segmentation-camera) that the elements in the scene have. @@ -576,8 +613,8 @@ Returns the client libcarla version by consulting it in the "Version.h" file. Bo - **get_required_files**(**self**, **folder**, **download**=True) Asks the server which files are required by the client to use the current map. Option to download files automatically if they are not already in the cache. - **Parameters:** - - `folder` (_str_) - Folder where files required by the client will be downloaded to. - - `download` (_bool_) - If True, downloads files that are not already in cache. + - `folder` (_str_) - Specifies a folder to look through on the server maps. Leaving this blank will search recursively through all map folders in the server, which is recommended if you're unfamiliar with the server map folder structure. + - `download` (_bool_) - If True, downloads files that are not already in cache. The cache can be found at "HOME\carlaCache" or "USERPROFILE\carlaCache", depending on OS. - **get_server_version**(**self**) Returns the server libcarla version by consulting it in the "Version.h" file. Both client and server should use the same libcarla version. - **Return:** _str_ @@ -669,6 +706,43 @@ No changes applied to the image. Used by the [RGB camera](ref_sensors.md#rgb-cam --- +## carla.CustomV2XData +Inherited from _[carla.SensorData](#carla.SensorData)_
+This is the data type defining a custom V2X message. Received as part of a [CustomV2XEvent](#carlacustomv2xevent). + +### Instance Variables +- **power** (_float - dBm_) +Received power. + +### Methods +- **get**(**self**) +Get the custom message. Returns a nested dictionary containing the message. It has two primary keys: - `Header` : dict - `Message`: str. + - **Return:** _dict_ + +##### Dunder methods +- **\__str__**(**self**) + +--- + +## carla.CustomV2XEvent +Inherited from _[carla.SensorData](#carla.SensorData)_
+Class that defines the data provided by a **sensor.other.v2x_custom**. This is a collection type to combine returning several [CustomV2XData](#carlacustomv2xdata). + +### Methods + +##### Getters +- **get_message_count**(**self**) +Get the number of received CAM's. + - **Return:** _int_ + +##### Dunder methods +- **\__get_item__**(**self**, **pos**=int) +- **\__iter__**(**self**) +Iterate over the [CustomV2XData](#carlacustomv2xdata) retrieved as data. +- **\__len__**(**self**) + +--- + ## carla.DVSEvent Class that defines a DVS event. An event is a quadruple, so a tuple of 4 elements, with `x`, `y` pixel coordinate location, timestamp `t` and polarity `pol` of the event. Learn more about them [here](ref_sensors.md). @@ -857,7 +931,7 @@ Initializes a color, black by default. --- ## carla.GBufferTextureID -Defines the identifiers of each GBuffer texture (See the method `[carla.Sensor.listen_to_gbuffer](#carla.Sensor.listen_to_gbuffer)`). +Defines the of each GBuffer texture (See the method `[carla.Sensor.listen_to_gbuffer](#carla.Sensor.listen_to_gbuffer)`). ### Instance Variables - **SceneColor** @@ -2230,25 +2304,26 @@ Iterate over the [carla.SemanticLidarDetection](#carla.SemanticLidarDetection) r Inherited from _[carla.Actor](#carla.Actor)_
Sensors compound a specific family of actors quite diverse and unique. They are normally spawned as attachment/sons of a vehicle (take a look at [carla.World](#carla.World) to learn about actor spawning). Sensors are thoroughly designed to retrieve different types of data that they are listening to. The data they receive is shaped as different subclasses inherited from [carla.SensorData](#carla.SensorData) (depending on the sensor). - Most sensors can be divided in two groups: those receiving data on every tick (cameras, point clouds and some specific sensors) and those who only receive under certain circumstances (trigger detectors). CARLA provides a specific set of sensors and their blueprint can be found in [carla.BlueprintLibrary](#carla.BlueprintLibrary). All the information on their preferences and settlement can be found [here](ref_sensors.md), but the list of those available in CARLA so far goes as follow. -
Receive data on every tick. - - [Depth camera](ref_sensors.md#depth-camera). - - [Gnss sensor](ref_sensors.md#gnss-sensor). - - [IMU sensor](ref_sensors.md#imu-sensor). - - [Lidar raycast](ref_sensors.md#lidar-raycast-sensor). - - [SemanticLidar raycast](ref_sensors.md#semanticlidar-raycast-sensor). - - [Radar](ref_sensors.md#radar-sensor). - - [RGB camera](ref_sensors.md#rgb-camera). - - [RSS sensor](ref_sensors.md#rss-sensor). - - [Semantic Segmentation camera](ref_sensors.md#semantic-segmentation-camera). -
Only receive data when triggered. - - [Collision detector](ref_sensors.md#collision-detector). - - [Lane invasion detector](ref_sensors.md#lane-invasion-detector). - - [Obstacle detector](ref_sensors.md#obstacle-detector). + Most sensors can be divided in two groups: those receiving data on every tick (cameras, point clouds and some specific sensors) and those who only receive under certain circumstances (trigger detectors). CARLA provides a specific set of sensors and their blueprint can be found in [carla.BlueprintLibrary](#carla.BlueprintLibrary). All the information on their preferences and settlement can be found [here](ref_sensors.md), but the list of those available in CARLA so far goes as follows:
+
Receive data on every tick
+ - [Depth camera](ref_sensors.md#depth-camera)
+ - [Gnss sensor](ref_sensors.md#gnss-sensor)
+ - [IMU sensor](ref_sensors.md#imu-sensor)
+ - [Lidar raycast](ref_sensors.md#lidar-raycast-sensor)
+ - [SemanticLidar raycast](ref_sensors.md#semanticlidar-raycast-sensor)
+ - [Radar](ref_sensors.md#radar-sensor)
+ - [RGB camera](ref_sensors.md#rgb-camera)
+ - [RSS sensor](ref_sensors.md#rss-sensor)
+ - [Semantic Segmentation camera](ref_sensors.md#semantic-segmentation-camera)
+
Only receive data when triggered.
+ - [Collision detector](ref_sensors.md#collision-detector)
+ - [Lane invasion detector](ref_sensors.md#lane-invasion-detector)
+ - [Obstacle detector](ref_sensors.md#obstacle-detector)
+ - [V2X sensor](ref_sensors.md#v2x-sensor). ### Instance Variables - **is_listening** (_boolean_) -When True the sensor will be waiting for data. +When **True** the sensor will be waiting for data. ### Methods - **disable_for_ros**(**self**) @@ -2257,12 +2332,15 @@ Commands the sensor to not be processed for publishing in ROS2 if there is no an Commands the sensor to be processed to be able to publish in ROS2 without any listen to it. - **is_enabled_for_ros**(**self**) Returns if the sensor is enabled or not to publish in ROS2 if there is no any listen to it. + - **Return:** _bool_ - **is_listening**(**self**) Returns whether the sensor is in a listening state. + - **Return:** _bool_ - **is_listening_gbuffer**(**self**, **gbuffer_id**) Returns whether the sensor is in a listening state for a specific GBuffer texture. - **Parameters:** - `gbuffer_id` (_[carla.GBufferTextureID](#carla.GBufferTextureID)_) - The ID of the target Unreal Engine GBuffer texture. + - **Return:** _bool_ - **listen**(**self**, **callback**) The function the sensor will be calling to every time a new measurement is received. This function needs for an argument containing an object type [carla.SensorData](#carla.SensorData) to work with. - **Parameters:** @@ -2272,6 +2350,10 @@ The function the sensor will be calling to every time the desired GBuffer textur - **Parameters:** - `gbuffer_id` (_[carla.GBufferTextureID](#carla.GBufferTextureID)_) - The ID of the target Unreal Engine GBuffer texture. - `callback` (_function_) - The called function with one argument containing the received GBuffer texture. +- **send**(**self**, **message**) +Instructs the sensor to send the string given by `message` to all other CustomV2XSensors on the next tick. + - **Parameters:** + - `message` (_string_) - The data to send. Note: maximum string length is 100 chars. - **stop**(**self**) Commands the sensor to stop listening for data. - **stop_gbuffer**(**self**, **gbuffer_id**) @@ -2295,7 +2377,9 @@ Base class for all the objects containing data generated by a [carla.Sensor](#ca - Obstacle detector: [carla.ObstacleDetectionEvent](#carla.ObstacleDetectionEvent).
- Radar sensor: [carla.RadarMeasurement](#carla.RadarMeasurement).
- RSS sensor: [carla.RssResponse](#carla.RssResponse).
- - Semantic LIDAR sensor: [carla.SemanticLidarMeasurement](#carla.SemanticLidarMeasurement). + - Semantic LIDAR sensor: [carla.SemanticLidarMeasurement](#carla.SemanticLidarMeasurement).
+ - Cooperative awareness messages V2X sensor: [carla.CAMEvent](#carla.CAMEvent).
+ - Custom V2X messages V2X sensor: [carla.CustomV2XEvent](#carla.CustomV2XEvent). ### Instance Variables - **frame** (_int_) diff --git a/Docs/ref_cpp.md b/Docs/ref_cpp.md index 075b97a7d..41e03c99c 100644 --- a/Docs/ref_cpp.md +++ b/Docs/ref_cpp.md @@ -1,4 +1,15 @@ # C++ Reference + +## C++ client + +The C++ client can be built with `make` on Linux and `cmake` in Windows. An C++ client example is provided in the repository in `CARLA_ROOT/Examples/CppClient/main.cpp`. This example shows how to connect the C++ client to the CARLA server and use the API for some simple tasks. + +To build the example C++ client, open a terminal in the `CARLA_ROOT/Examples/CppClient` directory in the repository. Run `make` in this folder and then execute `./bin/cpp_client` to run the example. The example will choose a random map from those available then load it. It will then spawn a vehicle and apply a control to the vehicle. + +Please see the [C++ client example](adv_cpp_client.md) for more details on this example script. + +## C++ documentation + We use Doxygen to generate the documentation of our C++ code: [Libcarla/Source](http://carla.org/Doxygen/html/dir_b9166249188ce33115fd7d5eed1849f2.html)
diff --git a/Docs/ref_sensors.md b/Docs/ref_sensors.md index 477d16c51..142798920 100644 --- a/Docs/ref_sensors.md +++ b/Docs/ref_sensors.md @@ -15,6 +15,9 @@ - [__Instance segmentation camera__](#instance-segmentation-camera) - [__DVS camera__](#dvs-camera) - [__Optical Flow camera__](#optical-flow-camera) +- [__V2X sensor__](#v2x-sensor) + - [Cooperative awareness](#cooperative-awareness-message) + - [Custom message](#custom-v2x-message) !!! Important All the sensors use the UE coordinate system (__x__-*forward*, __y__-*right*, __z__-*up*), and return coordinates in local space. When using any visualization software, pay attention to its coordinate system. Many invert the Y-axis, so visualizing the sensor data directly may result in mirrored outputs. @@ -183,10 +186,11 @@ Provides measures that accelerometer, gyroscope and compass would retrieve for t | `timestamp` | double | Simulation time of the measurement in seconds since the beginning of the episode. | | `transform` | [carla.Transform](<../python_api#carlatransform>) | Location and rotation in world coordinates of the sensor at the time of the measurement. | | `accelerometer` | [carla.Vector3D](<../python_api#carlavector3d>) | Measures linear acceleration in `m/s^2`. | -| `gyroscope` | [carla.Vector3D](<../python_api#carlavector3d>) | Measures angular velocity in `rad/sec`. | -| `compass` | float | Orientation in radians. North is `(0.0, -1.0, 0.0)` in UE. | - +| `gyroscope` | [carla.Vector3D](<../python_api#carlavector3d>) | Measures angular velocity in `rad/s`. | +| `compass` | float | Orientation in radians. North is 0 radians. | +!!! note + For the compass, North is 0 radians. East is *pi*/2 radians, South is *pi* radians, West is 3*pi*/2 radians. North is in the direction of decreasing Y in CARLA's global coordinate system. East is in the direction of increasing X. The compass value converted to degrees is equal to 90 - yaw. --- ## Lane invasion detector @@ -904,3 +908,102 @@ The Optical Flow camera captures the motion perceived from the point of view of | `raw_data` | bytes | Array of BGRA 64-bit pixels containing two float values. |
+ +--- + +## V2X sensor + +Vehicle-to-everything (V2X) communication is an important aspect for future applications of cooperative intelligent transportation systems. In real vehicles, this requires a dedicated onboard unit (OBU) in each vehicle, that is able to send and receive information over wireless channels. Depending on the region (Europe, China, USA), different physical technologies, protocols and application messaging formats are used. + +CARLA currently supports simulation of a simple broadcast wireless channel and two application messages. Protocols for network access and forwarding are not supported yet. The two implemented messages are the [*Cooperative Awarness Message*](#cooperative-awareness-message) according to the European standard ETSI, and a [*custom message*](#custom-v2x-message) type, that can be used to transmit arbitrary string data (e.g. JSON). There are two distinct sensors for V2X communication, that can be used separately, one for each application message type. + +Basically, the wireless channel incorporates the following calculation for both sensors: + + ReceivedPower = OtherTransmitPower + combined_antenna_gain - loss + + IF (ReceivedPower >= receiver_sensitivity) + THEN message is received + +To simulate V2X communication, at least two V2X sensors of the same type need to be spawned (at least one sender-receiver pair). Because the received power is calculated on the receiver-side V2X sensor, only the antenna gain that is specified on the receiver-side sensor is incorporated in this calculation. Transmission power and receiver sensitivity can be configured (see [Blueprint attributes](#v2x-sensors-blueprint-attributes)). + +The *loss* calculation depends on +- the visbility condition between sender and receiver: line of sight (no obstacles), non-line of sight obstructed by buildings, or non-line of sight obstructed by vehicles, and +- the scenario: highway, rural, or urban environment + +While the visibility is simulated within CARLA, the scenario can be configured by the user (see [Blueprint attributes](#v2x-sensors-blueprint-attributes)), as well as several other attributes of the wireless channel. + +### Sensor (sub)types + +#### Cooperative Awareness Message + +* __Blueprint:__ sensor.other.v2x +* __Output:__ [carla.CAMData](python_api.md#carla.CAMData), triggered according to the ETSI CAM standard, unless configured otherwise + +Triggering conditions according to ETSI standard: +- Heading angle change > $4$° +- Position difference > $4$ m +- Speed change > $5$ m/s +- Time elapsed > CAM Generation time (configurable) +- Low Frequency Container Time Elapsed $> 500$ ms + +For the CAM V2X sensor, additional blueprint attributes apply: + +| Blueprint attribute | Type | Default | Description | +|-------------------------|--------|-------------------------|------------------------------------| +| Message generation | +| gen\_cam\_min | float | $0.1$ | Minimum elapsed time between two successive CAMs in seconds (s) | +| gen\_cam\_max | float | $1.0$ | Maximum elapsed time between two successive CAMs in seconds (s) | +| fixed\_rate | bool | false [true] | Generate a CAM in every CARLA tick (only for debug purposes, will result in slowdown) | +| Data generation | +| `noise_vel_stddev_x` | float | 0\.0 | Standard deviation parameter in the noise model for velocity (X axis). | +| `noise_accel_stddev_x` | float | 0\.0 | Standard deviation parameter in the noise model for acceleration (X axis). | +| `noise_accel_stddev_y` | float | 0\.0 | Standard deviation parameter in the noise model for acceleration (Y axis). | +| `noise_accel_stddev_z` | float | 0\.0 | Standard deviation parameter in the noise model for acceleration (Z axis). | +| `noise_yawrate_bias` | float | 0\.0 | Mean parameter in the noise model for yaw rate. | +| `noise_yawrate_stddev` | float | 0\.0 | Standard deviation parameter in the noise model for yaw rate. | +| `noise_alt_bias` | float | 0\.0 | Mean parameter in the noise model for altitude. | +| `noise_alt_stddev` | float | 0\.0 | Standard deviation parameter in the noise model for altitude. | +| `noise_lat_bias` | float | 0\.0 | Mean parameter in the noise model for latitude. | +| `noise_lat_stddev` | float | 0\.0 | Standard deviation parameter in the noise model for latitude. | +| `noise_lon_bias` | float | 0\.0 | Mean parameter in the noise model for longitude. | +| `noise_lon_stddev` | float | 0\.0 | Standard deviation parameter in the noise model for longitude. | +| `noise_head_bias` | float | 0\.0 | Mean parameter in the noise model for heading. | +| `noise_head_stddev` | float | 0\.0 | Standard deviation parameter in the noise model for heading. | + +#### Custom V2X Message + +* __Blueprint:__ sensor.other.v2x_custom +* __Output:__ [carla.CustomV2XData](python_api.md#carla.CustomV2XData), triggered with next tick after a *send()* was called + +##### Methods +- **send**(**self**, **callback**) +The function the user has to call every time to send a message. This function needs for an argument containing an object type [carla.SensorData](#carla.SensorData) to work with. + - **Parameters:** + - `data` (_function_) - The called function with one argument containing the sensor data. + +The custom V2X message sensor works a little bit different than other sensors, because it has the *send* function in addition to the *listen* function, that needs to be called, before another sensor of this type will receive anything. The transmission of a custom message is only triggered, when *send* is called. Each message given to the *send* function is only transmitted once to all Custom V2X Message sensors currently spawned. + +Example: + + bp = world.get_blueprint_library().find('sensor.other.v2x_custom') + sensor = world.spawn_actor(bp, carla.Transform(), attach_to=parent) + sensor.send("Hello CARLA") + +### V2X sensors blueprint attributes + +| Blueprint attribute | Type | Default | Description | +|-------------------------|--------|-------------------------|------------------------------------| +| transmit\_power | float | $21.5$ | Sender transmission power in dBm | +| receiver\_sensitivity | float | $-99$ | Receiver sensitivity in dBm | +| frequency\_ghz | float | $5.9$ | Transmission frequency in GHz. 5.9 GHz is standard for several physical channels. | +| noise\_seed | int | $0$ | Random parameter for initialization of noise | +| filter\_distance | float | $500$ | Maximum transmission distance in meter, path loss calculations above are skipped for simulation speed | +| __Path loss model parameters__ | +| combined\_antenna\_gain | float | $10.0$ | Combined gain of sender and receiver antennas in dBi, parameter for radiation efficiency and directivity | +| d\_ref | float | $ 1.0 $ | reference distance for Log-distance path loss model in meter | +| path\_loss\_exponent | float | 2.7 | Loss parameter for non-line of sight due to building obstruction | +| scenario | string | urban | Options: [urban, rural, highway], defines the fading noise parameters | +| path\_loss\_model | string | geometric | general path loss model to be used. Options: [geometric, winner] | +| use\_etsi\_fading | bool | true | Use the fading params as mentioned in the ETSI publication (true), or use the custom fading standard deviation | +| custom\_fading\_stddev | float | 0.0 | Custom value for fading standard deviation, only used if `use_etsi_fading` is set to `false` | + diff --git a/Jenkinsfile b/Jenkinsfile index b7352cac9..2eb130419 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,7 +17,7 @@ pipeline //{ stage('ubuntu') { - agent { label "gpu" } + agent { label "ubuntu_20_04" } environment { UE4_ROOT = '/home/jenkins/UnrealEngine_4.26' @@ -132,7 +132,7 @@ pipeline dir('doc_repo') { checkout scmGit( - branches: [[name: '*/master']], + branches: [[name: '*/dev']], extensions: [ cleanBeforeCheckout(), checkoutOption(120), @@ -207,6 +207,7 @@ pipeline { stage('ubuntu smoke tests') { + agent { label "gpu_20_04" } steps { unstash name: 'ubuntu_eggs' @@ -315,7 +316,7 @@ pipeline tar -xvzf carla_doc.tar.gz git add Doxygen git commit -m "Updated c++ docs" || true - git push --set-upstream origin ruben/jenkins_migration + git push --set-upstream origin dev ''' } } diff --git a/LibCarla/source/carla/client/ServerSideSensor.cpp b/LibCarla/source/carla/client/ServerSideSensor.cpp index 19ec11c1a..30803b172 100644 --- a/LibCarla/source/carla/client/ServerSideSensor.cpp +++ b/LibCarla/source/carla/client/ServerSideSensor.cpp @@ -55,6 +55,16 @@ namespace client { listening_mask.reset(0); } + void ServerSideSensor::Send(std::string message) { + log_debug("calling sensor Send() ", GetDisplayId()); + if (GetActorDescription().description.id != "sensor.other.v2x_custom") + { + log_warning("Send methods are not supported on non-V2x sensors (sensor.other.v2x_custom)."); + return; + } + GetEpisode().Lock()->Send(*this,message); + } + void ServerSideSensor::ListenToGBuffer(uint32_t GBufferId, CallbackFunctionType callback) { log_debug(GetDisplayId(), ": subscribing to gbuffer stream"); RELEASE_ASSERT(GBufferId < GBufferTextureCount); diff --git a/LibCarla/source/carla/client/ServerSideSensor.h b/LibCarla/source/carla/client/ServerSideSensor.h index fae320aba..288f0e235 100644 --- a/LibCarla/source/carla/client/ServerSideSensor.h +++ b/LibCarla/source/carla/client/ServerSideSensor.h @@ -56,6 +56,9 @@ namespace client { /// Return if the sensor is publishing for ROS2 bool IsEnabledForROS(); + /// Send data via this sensor + void Send(std::string message); + /// @copydoc Actor::Destroy() /// /// Additionally stop listening. diff --git a/LibCarla/source/carla/client/Vehicle.cpp b/LibCarla/source/carla/client/Vehicle.cpp index 4a0c2ebd4..b24347e07 100644 --- a/LibCarla/source/carla/client/Vehicle.cpp +++ b/LibCarla/source/carla/client/Vehicle.cpp @@ -44,6 +44,10 @@ namespace client { } } + Vehicle::TelemetryData Vehicle::GetTelemetryData() const { + return GetEpisode().Lock()->GetVehicleTelemetryData(*this); + } + void Vehicle::ShowDebugTelemetry(bool enabled) { GetEpisode().Lock()->ShowVehicleDebugTelemetry(*this, enabled); } diff --git a/LibCarla/source/carla/client/Vehicle.h b/LibCarla/source/carla/client/Vehicle.h index 2fb7c2925..b9fe883a0 100644 --- a/LibCarla/source/carla/client/Vehicle.h +++ b/LibCarla/source/carla/client/Vehicle.h @@ -14,6 +14,7 @@ #include "carla/rpc/VehicleDoor.h" #include "carla/rpc/VehicleLightState.h" #include "carla/rpc/VehiclePhysicsControl.h" +#include "carla/rpc/VehicleTelemetryData.h" #include "carla/rpc/VehicleWheels.h" #include "carla/trafficmanager/TrafficManager.h" @@ -35,6 +36,7 @@ namespace client { using Control = rpc::VehicleControl; using AckermannControl = rpc::VehicleAckermannControl; using PhysicsControl = rpc::VehiclePhysicsControl; + using TelemetryData = rpc::VehicleTelemetryData; using LightState = rpc::VehicleLightState::LightState; using TM = traffic_manager::TrafficManager; using VehicleDoor = rpc::VehicleDoor; @@ -46,6 +48,11 @@ namespace client { /// Switch on/off this vehicle's autopilot. void SetAutopilot(bool enabled = true, uint16_t tm_port = TM_DEFAULT_PORT); + /// Return the telemetry data for this vehicle. + /// + /// @warning This function does call the simulator. + TelemetryData GetTelemetryData() const; + /// Switch on/off this vehicle's autopilot. void ShowDebugTelemetry(bool enabled = true); diff --git a/LibCarla/source/carla/client/detail/Client.cpp b/LibCarla/source/carla/client/detail/Client.cpp index fe5c327f0..49cf59e00 100644 --- a/LibCarla/source/carla/client/detail/Client.cpp +++ b/LibCarla/source/carla/client/detail/Client.cpp @@ -481,6 +481,11 @@ namespace detail { _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled); } + rpc::VehicleTelemetryData Client::GetVehicleTelemetryData( + rpc::ActorId vehicle) const { + return _pimpl->CallAndWait("get_telemetry_data", vehicle); + } + void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) { _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled); } @@ -670,6 +675,10 @@ namespace detail { return _pimpl->CallAndWait("is_sensor_enabled_for_ros", thisToken.get_stream_id()); } + void Client::Send(rpc::ActorId ActorId, std::string message) { + _pimpl->AsyncCall("send", ActorId, message); + } + void Client::SubscribeToGBuffer( rpc::ActorId ActorId, uint32_t GBufferId, diff --git a/LibCarla/source/carla/client/detail/Client.h b/LibCarla/source/carla/client/detail/Client.h index 73f8cdb85..ffd3c8fba 100644 --- a/LibCarla/source/carla/client/detail/Client.h +++ b/LibCarla/source/carla/client/detail/Client.h @@ -29,6 +29,7 @@ #include "carla/rpc/VehicleLightStateList.h" #include "carla/rpc/VehicleLightState.h" #include "carla/rpc/VehiclePhysicsControl.h" +#include "carla/rpc/VehicleTelemetryData.h" #include "carla/rpc/VehicleWheels.h" #include "carla/rpc/WeatherParameters.h" #include "carla/rpc/Texture.h" @@ -285,6 +286,8 @@ namespace detail { rpc::ActorId vehicle, bool enabled); + rpc::VehicleTelemetryData GetVehicleTelemetryData(rpc::ActorId vehicle) const; + void ShowVehicleDebugTelemetry( rpc::ActorId vehicle, bool enabled); @@ -430,6 +433,8 @@ namespace detail { rpc::ActorId ActorId, uint32_t GBufferId); + void Send(rpc::ActorId ActorId, std::string message); + void DrawDebugShape(const rpc::DebugShape &shape); void ApplyBatch( diff --git a/LibCarla/source/carla/client/detail/Simulator.cpp b/LibCarla/source/carla/client/detail/Simulator.cpp index 28eb8be68..5083dd378 100644 --- a/LibCarla/source/carla/client/detail/Simulator.cpp +++ b/LibCarla/source/carla/client/detail/Simulator.cpp @@ -88,6 +88,12 @@ namespace detail { const auto id = GetCurrentEpisode().GetId(); _client.LoadEpisode(std::move(map_name), reset_settings, map_layers); + // delete the pointer to _episode so that the Navigation information + // will be loaded for the correct map + assert(_episode.use_count() == 1); + _episode.reset(); + GetReadyCurrentEpisode(); + // We are waiting 50ms for the server to reload the episode. // If in this time we have not detected a change of episode, we try again // 'number_of_attempts' times. @@ -441,6 +447,10 @@ EpisodeProxy Simulator::GetCurrentEpisode() { _client.FreezeAllTrafficLights(frozen); } + void Simulator::Send(const Sensor &sensor, std::string message) { + _client.Send(sensor.GetId(), message); + } + // ========================================================================= /// -- Texture updating operations // ========================================================================= diff --git a/LibCarla/source/carla/client/detail/Simulator.h b/LibCarla/source/carla/client/detail/Simulator.h index 6f5d950c3..0ff8f3c17 100644 --- a/LibCarla/source/carla/client/detail/Simulator.h +++ b/LibCarla/source/carla/client/detail/Simulator.h @@ -525,6 +525,10 @@ namespace detail { _client.SetActorAutopilot(vehicle.GetId(), enabled); } + rpc::VehicleTelemetryData GetVehicleTelemetryData(const Vehicle &vehicle) const { + return _client.GetVehicleTelemetryData(vehicle.GetId()); + } + void ShowVehicleDebugTelemetry(Vehicle &vehicle, bool enabled = true) { _client.ShowVehicleDebugTelemetry(vehicle.GetId(), enabled); } @@ -695,6 +699,8 @@ namespace detail { Actor & sensor, uint32_t gbuffer_id); + void Send(const Sensor &sensor, std::string message); + /// @} // ========================================================================= /// @name Operations with traffic lights diff --git a/LibCarla/source/carla/road/MeshFactory.cpp b/LibCarla/source/carla/road/MeshFactory.cpp index 8d7019ebb..b01828915 100644 --- a/LibCarla/source/carla/road/MeshFactory.cpp +++ b/LibCarla/source/carla/road/MeshFactory.cpp @@ -206,23 +206,33 @@ namespace geom { size_t PosToAdd = it - redirections.begin(); Mesh out_mesh; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving ){ - out_mesh += *GenerateTesselated(lane_pair.second); - }else{ - out_mesh += *GenerateSidewalk(lane_pair.second); + switch(lane_pair.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + out_mesh += *GenerateTesselated(lane_pair.second); + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + out_mesh += *GenerateSidewalk(lane_pair.second); + break; + } + default: + { + out_mesh += *GenerateTesselated(lane_pair.second); + break; + } } if( result[lane_pair.second.GetType()].size() <= PosToAdd ){ result[lane_pair.second.GetType()].push_back(std::make_unique(out_mesh)); } else { - uint32_t verticesinwidth = 0; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving) { - verticesinwidth = vertices_in_width; - }else if(lane_pair.second.GetType() == road::Lane::LaneType::Sidewalk){ - verticesinwidth = 6; - }else{ - verticesinwidth = 2; - } + uint32_t verticesinwidth = SelectVerticesInWidth(vertices_in_width, lane_pair.second.GetType()); (result[lane_pair.second.GetType()][PosToAdd])->ConcatMesh(out_mesh, verticesinwidth); } } @@ -548,12 +558,28 @@ std::map>> MeshFactory: for (auto &&lane_pair : lane_section.GetLanes()) { Mesh lane_section_mesh; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving ){ - lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_until); - }else{ - lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_until); + switch(lane_pair.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_until); + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_until); + break; + } + default: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_until); + break; + } } - auto it = std::find(redirections.begin(), redirections.end(), lane_pair.first); if (it == redirections.end()) { redirections.push_back(lane_pair.first); @@ -564,14 +590,7 @@ std::map>> MeshFactory: if (mesh_uptr_list[lane_pair.second.GetType()].size() <= PosToAdd) { mesh_uptr_list[lane_pair.second.GetType()].push_back(std::make_unique(lane_section_mesh)); } else { - uint32_t verticesinwidth = 0; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving) { - verticesinwidth = vertices_in_width; - }else if(lane_pair.second.GetType() == road::Lane::LaneType::Sidewalk){ - verticesinwidth = 6; - }else{ - verticesinwidth = 2; - } + uint32_t verticesinwidth = SelectVerticesInWidth(vertices_in_width, lane_pair.second.GetType()); (mesh_uptr_list[lane_pair.second.GetType()][PosToAdd])->ConcatMesh(lane_section_mesh, verticesinwidth); } } @@ -580,10 +599,27 @@ std::map>> MeshFactory: if (s_end - s_current > EPSILON) { for (auto &&lane_pair : lane_section.GetLanes()) { Mesh lane_section_mesh; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving ){ - lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_end); - }else{ - lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_end); + switch(lane_pair.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_end); + break; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + lane_section_mesh += *GenerateSidewalk(lane_pair.second, s_current, s_end); + break; + } + default: + { + lane_section_mesh += *GenerateTesselated(lane_pair.second, s_current, s_end); + break; + } } auto it = std::find(redirections.begin(), redirections.end(), lane_pair.first); @@ -597,14 +633,6 @@ std::map>> MeshFactory: if (mesh_uptr_list[lane_pair.second.GetType()].size() <= PosToAdd) { mesh_uptr_list[lane_pair.second.GetType()].push_back(std::make_unique(lane_section_mesh)); } else { - uint32_t verticesinwidth = 0; - if(lane_pair.second.GetType() == road::Lane::LaneType::Driving) { - verticesinwidth = vertices_in_width; - }else if(lane_pair.second.GetType() == road::Lane::LaneType::Sidewalk){ - verticesinwidth = 6; - }else{ - verticesinwidth = 2; - } *(mesh_uptr_list[lane_pair.second.GetType()][PosToAdd]) += lane_section_mesh; } } @@ -725,9 +753,16 @@ std::map>> MeshFactory: for (auto&& lane_section : road.GetLaneSections()) { for (auto&& lane : lane_section.GetLanes()) { if (lane.first != 0) { - if(lane.second.GetType() == road::Lane::LaneType::Driving ){ - GenerateLaneMarksForNotCenterLine(lane_section, lane.second, inout, outinfo); - outinfo.push_back("white"); + switch(lane.second.GetType()) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + GenerateLaneMarksForNotCenterLine(lane_section, lane.second, inout, outinfo); + outinfo.push_back("white"); + break; + } } } else { if(lane.second.GetType() == road::Lane::LaneType::None ){ @@ -1131,6 +1166,29 @@ std::map>> MeshFactory: return std::make_unique(out_mesh); } + uint32_t MeshFactory::SelectVerticesInWidth(uint32_t default_num_vertices, road::Lane::LaneType type) + { + switch(type) + { + case road::Lane::LaneType::Driving: + case road::Lane::LaneType::Parking: + case road::Lane::LaneType::Bidirectional: + { + return default_num_vertices; + } + case road::Lane::LaneType::Shoulder: + case road::Lane::LaneType::Sidewalk: + case road::Lane::LaneType::Biking: + { + return 6; + } + default: + { + return 2; + } + } + } + std::pair MeshFactory::ComputeEdgesForLanemark( const road::LaneSection& lane_section, const road::Lane& lane, diff --git a/LibCarla/source/carla/road/MeshFactory.h b/LibCarla/source/carla/road/MeshFactory.h index 42bc60ea1..aacb07584 100644 --- a/LibCarla/source/carla/road/MeshFactory.h +++ b/LibCarla/source/carla/road/MeshFactory.h @@ -129,6 +129,7 @@ namespace geom { const road::Lane& lane, std::vector>& inout, std::vector& outinfo ) const; + // ========================================================================= // -- Generation parameters ------------------------------------------------ // ========================================================================= @@ -148,6 +149,12 @@ namespace geom { RoadParameters road_param; + + // ========================================================================= + // -- Helper functions ------------------------------------------------ + // ========================================================================= + + static uint32_t SelectVerticesInWidth(uint32_t default_num_vertices, road::Lane::LaneType type); private: // Calculate the points on both sides of the lane mark for the specified s_current diff --git a/LibCarla/source/carla/rpc/ActorAttributeType.h b/LibCarla/source/carla/rpc/ActorAttributeType.h index dda52939f..9ecf822b6 100644 --- a/LibCarla/source/carla/rpc/ActorAttributeType.h +++ b/LibCarla/source/carla/rpc/ActorAttributeType.h @@ -12,11 +12,11 @@ namespace carla { namespace rpc { enum class ActorAttributeType : uint8_t { - Bool, - Int, - Float, - String, - RGBColor, + Bool = 1u, + Int = 2u, + Float = 3u, + String = 4u, + RGBColor = 5u, SIZE, INVALID diff --git a/LibCarla/source/carla/rpc/VehicleTelemetryData.h b/LibCarla/source/carla/rpc/VehicleTelemetryData.h new file mode 100644 index 000000000..7be84e8a3 --- /dev/null +++ b/LibCarla/source/carla/rpc/VehicleTelemetryData.h @@ -0,0 +1,123 @@ +// Copyright (c) 2022 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/MsgPack.h" +#include "carla/rpc/WheelTelemetryData.h" + +#include + +namespace carla { +namespace rpc { + class VehicleTelemetryData { + public: + + VehicleTelemetryData() = default; + + VehicleTelemetryData( + float speed, + float steer, + float throttle, + float brake, + float engine_rpm, + int32_t gear, + float drag, + std::vector wheels) + : speed(speed), + steer(steer), + throttle(throttle), + brake(brake), + engine_rpm(engine_rpm), + gear(gear), + drag(drag), + wheels(wheels) {} + + const std::vector &GetWheels() const { + return wheels; + } + + void SetWheels(std::vector &in_wheels) { + wheels = in_wheels; + } + + float speed = 0.0f; + float steer = 0.0f; + float throttle = 0.0f; + float brake = 0.0f; + float engine_rpm = 0.0f; + int32_t gear = 0.0f; + float drag = 0.0f; + std::vector wheels; + + bool operator!=(const VehicleTelemetryData &rhs) const { + return + speed != rhs.speed || + steer != rhs.steer || + throttle != rhs.throttle || + brake != rhs.brake || + engine_rpm != rhs.engine_rpm || + gear != rhs.gear || + drag != rhs.drag || + wheels != rhs.wheels; + } + + bool operator==(const VehicleTelemetryData &rhs) const { + return !(*this != rhs); + } + +#ifdef LIBCARLA_INCLUDED_FROM_UE4 + + VehicleTelemetryData(const FVehicleTelemetryData &TelemetryData) { + speed = TelemetryData.Speed; + steer = TelemetryData.Steer; + throttle = TelemetryData.Throttle; + brake = TelemetryData.Brake; + engine_rpm = TelemetryData.EngineRPM; + gear = TelemetryData.Gear; + drag = TelemetryData.Drag; + + // Wheels Setup + wheels = std::vector(); + for (const auto &Wheel : TelemetryData.Wheels) { + wheels.push_back(WheelTelemetryData(Wheel)); + } + } + + operator FVehicleTelemetryData() const { + FVehicleTelemetryData TelemetryData; + + TelemetryData.Speed = speed; + TelemetryData.Steer = steer; + TelemetryData.Throttle = throttle; + TelemetryData.Brake = brake; + TelemetryData.EngineRPM = engine_rpm; + TelemetryData.Gear = gear; + TelemetryData.Drag = drag; + + TArray Wheels; + for (const auto &wheel : wheels) { + Wheels.Add(FWheelTelemetryData(wheel)); + } + TelemetryData.Wheels = Wheels; + + return TelemetryData; + } + +#endif + + MSGPACK_DEFINE_ARRAY(speed, + steer, + throttle, + brake, + engine_rpm, + gear, + drag, + wheels); + }; + +} // namespace rpc +} // namespace carla diff --git a/LibCarla/source/carla/rpc/WheelTelemetryData.h b/LibCarla/source/carla/rpc/WheelTelemetryData.h new file mode 100644 index 000000000..ce7df7b10 --- /dev/null +++ b/LibCarla/source/carla/rpc/WheelTelemetryData.h @@ -0,0 +1,120 @@ +// Copyright (c) 2022 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/MsgPack.h" + +namespace carla { +namespace rpc { + + class WheelTelemetryData { + public: + + WheelTelemetryData() = default; + + WheelTelemetryData( + float tire_friction, + float lat_slip, + float long_slip, + float omega, + float tire_load, + float normalized_tire_load, + float torque, + float long_force, + float lat_force, + float normalized_long_force, + float normalized_lat_force) + : tire_friction(tire_friction), + lat_slip(lat_slip), + long_slip(long_slip), + omega(omega), + tire_load(tire_load), + normalized_tire_load(normalized_tire_load), + torque(torque), + long_force(long_force), + lat_force(lat_force), + normalized_long_force(normalized_long_force), + normalized_lat_force(normalized_lat_force) {} + + float tire_friction = 0.0f; + float lat_slip = 0.0f; + float long_slip = 0.0f; + float omega = 0.0f; + float tire_load = 0.0f; + float normalized_tire_load = 0.0f; + float torque = 0.0f; + float long_force = 0.0f; + float lat_force = 0.0f; + float normalized_long_force = 0.0f; + float normalized_lat_force = 0.0f; + + bool operator!=(const WheelTelemetryData &rhs) const { + return + tire_friction != rhs.tire_friction || + lat_slip != rhs.lat_slip || + long_slip != rhs.long_slip || + omega != rhs.omega || + tire_load != rhs.tire_load || + normalized_tire_load != rhs.normalized_tire_load || + torque != rhs.torque || + long_force != rhs.long_force || + lat_force != rhs.lat_force || + normalized_long_force != rhs.normalized_long_force || + normalized_lat_force != rhs.normalized_lat_force; + } + + bool operator==(const WheelTelemetryData &rhs) const { + return !(*this != rhs); + } +#ifdef LIBCARLA_INCLUDED_FROM_UE4 + + WheelTelemetryData(const FWheelTelemetryData &TelemetryData) + : tire_friction(TelemetryData.TireFriction), + lat_slip(TelemetryData.LatSlip), + long_slip(TelemetryData.LongSlip), + omega(TelemetryData.Omega), + tire_load(TelemetryData.TireLoad), + normalized_tire_load(TelemetryData.NormalizedTireLoad), + torque(TelemetryData.Torque), + long_force(TelemetryData.LongForce), + lat_force(TelemetryData.LatForce), + normalized_long_force(TelemetryData.NormalizedLongForce), + normalized_lat_force(TelemetryData.NormalizedLatForce) {} + + operator FWheelTelemetryData() const { + FWheelTelemetryData TelemetryData; + TelemetryData.TireFriction = tire_friction; + TelemetryData.LatSlip = lat_slip; + TelemetryData.LongSlip = long_slip; + TelemetryData.Omega = omega; + TelemetryData.TireLoad = tire_load; + TelemetryData.NormalizedTireLoad = normalized_tire_load; + TelemetryData.Torque = torque; + TelemetryData.LongForce = long_force; + TelemetryData.LatForce = lat_force; + TelemetryData.NormalizedLongForce = normalized_long_force; + TelemetryData.NormalizedLatForce = normalized_lat_force; + + return TelemetryData; + } +#endif + + MSGPACK_DEFINE_ARRAY(tire_friction, + lat_slip, + long_slip, + omega, + tire_load, + normalized_tire_load, + torque, + long_force, + lat_force, + normalized_long_force, + normalized_lat_force) + }; + +} // namespace rpc +} // namespace carla diff --git a/LibCarla/source/carla/sensor/SensorRegistry.h b/LibCarla/source/carla/sensor/SensorRegistry.h index 901a47dfd..6f7c21745 100644 --- a/LibCarla/source/carla/sensor/SensorRegistry.h +++ b/LibCarla/source/carla/sensor/SensorRegistry.h @@ -29,6 +29,7 @@ #include "carla/sensor/s11n/SemanticLidarSerializer.h" #include "carla/sensor/s11n/GBufferUint8Serializer.h" #include "carla/sensor/s11n/GBufferFloatSerializer.h" +#include "carla/sensor/s11n/V2XSerializer.h" // 2. Add a forward-declaration of the sensor here. class ACollisionSensor; @@ -50,6 +51,8 @@ class ARssSensor; class FWorldObserver; struct FCameraGBufferUint8; struct FCameraGBufferFloat; +class AV2XSensor; +class ACustomV2XSensor; namespace carla { namespace sensor { @@ -80,7 +83,11 @@ namespace sensor { std::pair, std::pair, std::pair, - std::pair + std::pair, + std::pair, + std::pair + + >; } // namespace sensor @@ -108,5 +115,7 @@ namespace sensor { #include "Carla/Sensor/SemanticSegmentationCamera.h" #include "Carla/Sensor/InstanceSegmentationCamera.h" #include "Carla/Sensor/WorldObserver.h" +#include "Carla/Sensor/V2XSensor.h" +#include "Carla/Sensor/CustomV2XSensor.h" #endif // LIBCARLA_SENSOR_REGISTRY_WITH_SENSOR_INCLUDES diff --git a/LibCarla/source/carla/sensor/data/LibITS.h b/LibCarla/source/carla/sensor/data/LibITS.h new file mode 100644 index 000000000..b3f419b6a --- /dev/null +++ b/LibCarla/source/carla/sensor/data/LibITS.h @@ -0,0 +1,771 @@ +#pragma once +#include +#include +#include + +class ITSContainer +{ + +public: + + typedef bool OptionalValueAvailable_t; + + /* Latitude Dependencies*/ + typedef enum Latitude + { + Latitude_oneMicroDegreeNorth = 10, + Latitude_oneMicroDegreeSouth = -10, + Latitude_unavailable = 900000001 + } e_Latitude; + + /* Latitude */ + typedef long Latitude_t; + + /* Longitude Dependencies */ + typedef enum Longitude + { + Longitude_oneMicroDegreeEast = 10, + Longitude_oneMicroDegreeWest = -10, + Longitude_unavailable = 1800000001 + } e_Longitude; + + /* Longitude */ + typedef long Longitude_t; + + /* SemiAxisLength Dependencies */ + typedef enum SemiAxisLength + { + SemiAxisLength_oneCentimeter = 1, + SemiAxisLength_outOfRange = 4094, + SemiAxisLength_unavailable = 4095 + } e_SemiAxisLength; + + /* SemiAxisLength*/ + typedef long SemiAxisLength_t; + + /* HeadingValue Dependencies */ + typedef enum HeadingValue + { + HeadingValue_wgs84North = 0, + HeadingValue_wgs84East = 900, + HeadingValue_wgs84South = 1800, + HeadingValue_wgs84West = 2700, + HeadingValue_unavailable = 3601 + } e_HeadingValue; + + /* HeadingValue */ + typedef long HeadingValue_t; + + /* HeadingConfidence Dependencies */ + typedef enum HeadingConfidence { + HeadingConfidence_equalOrWithinZeroPointOneDegree = 1, + HeadingConfidence_equalOrWithinOneDegree = 10, + HeadingConfidence_outOfRange = 126, + HeadingConfidence_unavailable = 127 + } e_HeadingConfidence; + + /* HeadingConfidence */ + typedef long HeadingConfidence_t; + + /* PosConfidenceEllipse*/ + typedef struct PosConfidenceEllipse + { + SemiAxisLength_t semiMajorConfidence; + SemiAxisLength_t semiMinorConfidence; + HeadingValue_t semiMajorOrientation; + } PosConfidenceEllipse_t; + + /* AltitudeValue Dependencies */ + typedef enum AltitudeValue + { + AltitudeValue_referenceEllipsoidSurface = 0, + AltitudeValue_oneCentimeter = 1, + AltitudeValue_unavailable = 800001 + } e_AltitudeValue; + + /* AltitudeValue */ + typedef long AltitudeValue_t; + + /* AltitudeConfidence Dependencies */ + typedef enum AltitudeConfidence + { + AltitudeConfidence_alt_000_01 = 0, + AltitudeConfidence_alt_000_02 = 1, + AltitudeConfidence_alt_000_05 = 2, + AltitudeConfidence_alt_000_10 = 3, + AltitudeConfidence_alt_000_20 = 4, + AltitudeConfidence_alt_000_50 = 5, + AltitudeConfidence_alt_001_00 = 6, + AltitudeConfidence_alt_002_00 = 7, + AltitudeConfidence_alt_005_00 = 8, + AltitudeConfidence_alt_010_00 = 9, + AltitudeConfidence_alt_020_00 = 10, + AltitudeConfidence_alt_050_00 = 11, + AltitudeConfidence_alt_100_00 = 12, + AltitudeConfidence_alt_200_00 = 13, + AltitudeConfidence_outOfRange = 14, + AltitudeConfidence_unavailable = 15 + }e_AltitudeConfidence; + + /* AltitudeConfidence */ + typedef long AltitudeConfidence_t; + + /* Altitude */ + typedef struct Altitude + { + AltitudeValue_t altitudeValue; + AltitudeConfidence_t altitudeConfidence; + }Altitude_t; + + /* ReferencePosition */ + typedef struct ReferencePosition + { + Latitude_t latitude; + Longitude_t longitude; + PosConfidenceEllipse_t positionConfidenceEllipse; + Altitude_t altitude; + } ReferencePosition_t; + + /* StationType Dependencies */ + typedef enum StationType + { + StationType_unknown = 0, + StationType_pedestrian = 1, + StationType_cyclist = 2, + StationType_moped = 3, + StationType_motorcycle = 4, + StationType_passengerCar = 5, + StationType_bus = 6, + StationType_lightTruck = 7, + StationType_heavyTruck = 8, + StationType_trailer = 9, + StationType_specialVehicles = 10, + StationType_tram = 11, + StationType_roadSideUnit = 15 + } e_StationType; + + /* StationType */ + typedef long StationType_t; + + /* StationID*/ + typedef long StationID_t; + // typedef unsigned long StationID_t; + + /* Dependencies */ + typedef enum protocolVersion + { + protocolVersion_currentVersion = 1 + } e_protocolVersion; + + typedef enum messageID + { + messageID_custom = 0, + messageID_denm = 1, + messageID_cam = 2, + messageID_poi = 3, + messageID_spat = 4, + messageID_map = 5, + messageID_ivi = 6, + messageID_ev_rsr = 7 + } e_messageID; + + typedef struct ItsPduHeader + { + long protocolVersion; + long messageID; + StationID_t stationID; + } ItsPduHeader_t; + + /* Heading */ + typedef struct Heading + { + HeadingValue_t headingValue; + HeadingConfidence_t headingConfidence; + } Heading_t; + + /* SpeedValue Dependencies */ + typedef enum SpeedValue + { + SpeedValue_standstill = 0, + SpeedValue_oneCentimeterPerSec = 1, + SpeedValue_unavailable = 16383 + } e_SpeedValue; + + /* SpeedValue */ + typedef long SpeedValue_t; + + /* SpeedConfidence Dependencies */ + typedef enum SpeedConfidence + { + SpeedConfidence_equalOrWithInOneCentimerterPerSec = 1, + SpeedConfidence_equalOrWithinOneMeterPerSec = 100, + SpeedConfidence_outOfRange = 126, + SpeedConfidence_unavailable = 127 + } e_SpeedConfidence; + + /* SpeedConfidence */ + typedef long SpeedConfidence_t; + + /* Speed */ + typedef struct speed + { + SpeedValue_t speedValue; + SpeedConfidence_t speedConfidence; + } Speed_t; + + /* DriveDirection Dependencies */ + typedef enum DriveDirection + { + DriveDirection_forward = 0, + DriveDirection_backward = 1, + DriveDirection_unavailable = 2 + } e_DriveDirection; + + /* DriveDirection */ + typedef long DriveDirection_t; + + /* VehicleLength Dependencies */ + typedef enum VehicleLengthValue + { + VehicleLengthValue_tenCentimeters = 1, + VehicleLengthValue_outOfRange = 1022, + VehicleLengthValue_unavailable = 1023 + } e_VehicleLengthValue; + + /* VehicleLengthValue */ + typedef long VehicleLengthValue_t; + + /* VehicleLengthConfidenceIndication Dependencies */ + typedef enum VehicleLengthConfidenceIndication + { + VehicleLengthConfidenceIndication_noTrailerPresent = 0, + VehicleLengthConfidenceIndication_trailerPresentWithKnownLength = 1, + VehicleLengthConfidenceIndication_trailerPresentWithUnknownLength = 2, + VehicleLengthConfidenceIndication_trailerPresenceIsUnknown = 3, + VehicleLengthConfidenceIndication_unavailable = 4 + } e_VehicleLengthConfidenceIndication; + + /* VehicleLengthConfidenceIndication */ + typedef long VehicleLengthConfidenceIndication_t; + + /* VehicleLength */ + typedef struct VehicleLength + { + VehicleLengthValue_t vehicleLengthValue; + VehicleLengthConfidenceIndication_t vehicleLengthConfidenceIndication; + } VehicleLength_t; + + /* VehicleWidth Dependencies */ + typedef enum VehicleWidth + { + VehicleWidth_tenCentimeters = 1, + VehicleWidth_outOfRange = 61, + VehicleWidth_unavailable = 62 + } e_VehicleWidth; + + /* VehicleWidth */ + typedef long VehicleWidth_t; + + /* LongitudinalAcceleration Dependencies */ + typedef enum LongitudinalAcceletationValue + { + LongitudinalAccelerationValue_pointOneMeterPerSecSquaredForward = 1, + LongitudinalAccelerationValue_pointOneMeterPerSecSquaredBackWard = -1, + LongitudinalAccelerationValue_unavailable = 161 + } e_LongitudinalAccelerationValue; + + /* LongitudinalAcclerationValue */ + typedef long LongitudinalAccelerationValue_t; + + /* AccelerationConfidence Dependencies */ + typedef enum AccelerationConfidence + { + AccelerationConfindence_pointOneMeterPerSecSquared = 1, + AccelerationConfidence_outOfRange = 101, + AccelerationConfidence_unavailable = 102 + } e_AccelerationConfidence; + + /* AccelerationConfidence*/ + typedef long AccelerationConfidence_t; + + /* LongitudinalAcceleration */ + typedef struct LongitudinalAcceleration + { + LongitudinalAccelerationValue_t longitudinalAccelerationValue; + AccelerationConfidence_t longitudinalAccelerationConfidence; + } LongitudinalAcceleration_t; + + /* CurvatureValue Dependencies */ + typedef enum CurvatureValue + { + CurvatureValue_straight = 0, + CurvatureValue_reciprocalOf1MeterRadiusToRight = -30000, + CurvatureValue_reciprocalOf1MeterRadiusToLeft = 30000, + CurvatureValue_unavailable = 30001 + } e_CurvatureValue; + + /* CurvatureValue */ + typedef long CurvatureValue_t; + + /* CurvatureConfidence Dependencies*/ + typedef enum CurvatureConfidence + { + CurvatureConfidence_onePerMeter_0_00002 = 0, + CurvatureConfidence_onePerMeter_0_0001 = 1, + CurvatureConfidence_onePerMeter_0_0005 = 2, + CurvatureConfidence_onePerMeter_0_002 = 3, + CurvatureConfidence_onePerMeter_0_01 = 4, + CurvatureConfidence_onePerMeter_0_1 = 5, + CurvatureConfidence_outOfRange = 6, + CurvatureConfidence_unavailable = 7 + } e_CurvatureConfidence; + + /* CurvatureConfidence */ + typedef long CurvatureConfidence_t; + + /* Curvature */ + typedef struct Curvature + { + CurvatureValue_t curvatureValue; + CurvatureConfidence_t curvatureConfidence; + } Curvature_t; + + /* CurvatureCalculationMode Dependencies */ + typedef enum CurvatureCalculationMode + { + CurvatureCalculationMode_yarRateUsed = 0, + CurvatureCalculationMode_yarRateNotUsed = 1, + CurvatureCalculationMode_unavailable = 2 + } e_CurvatureCalculationMode; + + /* CurvatureCalculationMode */ + typedef long CurvatureCalculationMode_t; + + /* YawRateValue Dependencies */ + typedef enum YawRateValue + { + YawRateValue_straight = 0, + YawRateValue_degSec_000_01ToRight = -1, + YawRateValue_degSec_000_01ToLeft = 1, + YawRateValue_unavailable = 32767 + } e_YawRateValue; + + /* YawRateValue */ + typedef long YawRateValue_t; + + /* YawRateConfidence Dependencies */ + typedef enum YawRateConfidence { + YawRateConfidence_degSec_000_01 = 0, + YawRateConfidence_degSec_000_05 = 1, + YawRateConfidence_degSec_000_10 = 2, + YawRateConfidence_degSec_001_00 = 3, + YawRateConfidence_degSec_005_00 = 4, + YawRateConfidence_degSec_010_00 = 5, + YawRateConfidence_degSec_100_00 = 6, + YawRateConfidence_outOfRange = 7, + YawRateConfidence_unavailable = 8 + } e_YawRateConfidence; + + /* YawRateConfidence */ + typedef long YawRateConfidence_t; + + /* YawRate */ + typedef struct YawRate + { + YawRateValue_t yawRateValue; + YawRateConfidence_t yawRateConfidence; + } YawRate_t; + + /* AccelerationControl Dependencies */ + typedef enum AccelerationControl { + AccelerationControl_brakePedalEngaged = 0, + AccelerationControl_gasPedalEngaged = 1, + AccelerationControl_emergencyBrakeEngaged = 2, + AccelerationControl_collisionWarningEngaged = 3, + AccelerationControl_accEngaged = 4, + AccelerationControl_cruiseControlEngaged = 5, + AccelerationControl_speedLimiterEngaged = 6 + } e_AccelerationControl; + + /* AccelerationControl */ + typedef uint8_t AccelerationControl_t; + + /* LanePosition Dependencies */ + typedef enum LanePosition { + LanePosition_offTheRoad = -1, + LanePosition_hardShoulder = 0, + LanePosition_outermostDrivingLane = 1, + LanePosition_secondLaneFromOutside = 2 + } e_LanePosition; + + /* LanePosition */ + typedef long LanePosition_t; + + /* SteeringWheelAngleValue Dependencies */ + typedef enum SteeringWheelAngleValue { + SteeringWheelAngleValue_straight = 0, + SteeringWheelAngleValue_onePointFiveDegreesToRight = -1, + SteeringWheelAngleValue_onePointFiveDegreesToLeft = 1, + SteeringWheelAngleValue_unavailable = 512 + } e_SteeringWheelAngleValue; + + /* SteeringWheelAngleValue */ + typedef long SteeringWheelAngleValue_t; + + /* SteeringWheelAngleConfidence Dependencies */ + typedef enum SteeringWheelAngleConfidence { + SteeringWheelAngleConfidence_equalOrWithinOnePointFiveDegree = 1, + SteeringWheelAngleConfidence_outOfRange = 126, + SteeringWheelAngleConfidence_unavailable = 127 + } e_SteeringWheelAngleConfidence; + + /* SteeringWheelAngleConfidence */ + typedef long SteeringWheelAngleConfidence_t; + + /* SteeringWheelAngle */ + typedef struct SteeringWheelAngle + { + SteeringWheelAngleValue_t steeringWheelAngleValue; + SteeringWheelAngleConfidence_t steeringWheelAngleConfidence; + } SteeringWheelAngle_t; + + /* LateralAccelerationValue Dependencies */ + typedef enum LateralAccelerationValue { + LateralAccelerationValue_pointOneMeterPerSecSquaredToRight = -1, + LateralAccelerationValue_pointOneMeterPerSecSquaredToLeft = 1, + LateralAccelerationValue_unavailable = 161 + } e_LateralAccelerationValue; + + /* LateralAccelerationValue */ + typedef long LateralAccelerationValue_t; + + /* LateralAcceleration */ + typedef struct LateralAcceleration + { + LateralAccelerationValue_t lateralAccelerationValue; + AccelerationConfidence_t lateralAccelerationConfidence; + } LateralAcceleration_t; + + /* VerticalAccelerationValue Dependencies */ + typedef enum VerticalAccelerationValue { + VerticalAccelerationValue_pointOneMeterPerSecSquaredUp = 1, + VerticalAccelerationValue_pointOneMeterPerSecSquaredDown = -1, + VerticalAccelerationValue_unavailable = 161 + } e_VerticalAccelerationValue; + + /* VerticalAccelerationValue */ + typedef long VerticalAccelerationValue_t; + + /* VerticalAcceleration */ + typedef struct VerticalAcceleration + { + VerticalAccelerationValue_t verticalAccelerationValue; + AccelerationConfidence_t verticalAccelerationConfidence; + } VerticalAcceleration_t; + + /* PerformanceClass Dependencies */ + typedef enum PerformanceClass { + PerformanceClass_unavailable = 0, + PerformanceClass_performanceClassA = 1, + PerformanceClass_performanceClassB = 2 + } e_PerformanceClass; + + /* PerformanceClass */ + typedef long PerformanceClass_t; + + /* ProtectedZoneID */ + typedef long ProtectedZoneID_t; + + /* CenDsrcTollingZoneID */ + typedef ProtectedZoneID_t CenDsrcTollingZoneID_t; + + /* CenDsrcTollingZone */ + typedef struct CenDsrcTollingZone { + Latitude_t protectedZoneLatitude; + Longitude_t protectedZoneLongitude; + CenDsrcTollingZoneID_t cenDsrcTollingZoneID; /* OPTIONAL */ + OptionalValueAvailable_t cenDsrcTollingZoneIDAvailable; + } CenDsrcTollingZone_t; + + /* ProtectedZoneType Dependencies */ + typedef enum ProtectedZoneType { + ProtectedZoneType_cenDsrcTolling = 0 + + } e_ProtectedZoneType; + + /* ProtectedZoneType */ + typedef long ProtectedZoneType_t; + + /* TimestampIts Dependencies */ + typedef enum TimestampIts { + TimestampIts_utcStartOf2004 = 0, + TimestampIts_oneMillisecAfterUTCStartOf2004 = 1 + } e_TimestampIts; + + + + /* TimestampIts */ + typedef long TimestampIts_t; + + /* ProtectedZoneRadius Dependencies */ + typedef enum ProtectedZoneRadius { + ProtectedZoneRadius_oneMeter = 1 + } e_ProtectedZoneRadius; + + /* ProtectedZoneRadius */ + typedef long ProtectedZoneRadius_t; + + /* ProtectedCommunicationZone */ + typedef struct ProtectedCommunicationZone { + ProtectedZoneType_t protectedZoneType; + TimestampIts_t expiryTime /* OPTIONAL */; + OptionalValueAvailable_t expiryTimeAvailable; + Latitude_t protectedZoneLatitude; + Longitude_t protectedZoneLongitude; + ProtectedZoneRadius_t protectedZoneRadius /* OPTIONAL */; + OptionalValueAvailable_t protectedZoneRadiusAvailable; + ProtectedZoneID_t protectedZoneID /* OPTIONAL */; + OptionalValueAvailable_t protectedZoneIDAvailable; + } ProtectedCommunicationZone_t; + + /* ProtectedCommunicationZonesRSU */ + typedef struct ProtectedCommunicationZonesRSU { + long ProtectedCommunicationZoneCount; + std::vector list; + } ProtectedCommunicationZonesRSU_t; + + /* VehicleRole Dependencies */ + typedef enum VehicleRole { + VehicleRole_default = 0, + VehicleRole_publicTransport = 1, + VehicleRole_specialTransport = 2, + VehicleRole_dangerousGoods = 3, + VehicleRole_roadWork = 4, + VehicleRole_rescue = 5, + VehicleRole_emergency = 6, + VehicleRole_safetyCar = 7, + VehicleRole_agriculture = 8, + VehicleRole_commercial = 9, + VehicleRole_military = 10, + VehicleRole_roadOperator = 11, + VehicleRole_taxi = 12, + VehicleRole_reserved1 = 13, + VehicleRole_reserved2 = 14, + VehicleRole_reserved3 = 15 + } e_VehicleRole; + + /* VehicleRole */ + typedef long VehicleRole_t; + + /* ExteriorLights Dependencies */ + typedef enum ExteriorLights { + ExteriorLights_lowBeamHeadlightsOn = 0, + ExteriorLights_highBeamHeadlightsOn = 1, + ExteriorLights_leftTurnSignalOn = 2, + ExteriorLights_rightTurnSignalOn = 3, + ExteriorLights_daytimeRunningLightsOn = 4, + ExteriorLights_reverseLightOn = 5, + ExteriorLights_fogLightOn = 6, + ExteriorLights_parkingLightsOn = 7 + } e_ExteriorLights; + + /* ExteriorLights */ + typedef uint8_t ExteriorLights_t; + /* DeltaLatitude Dependencies */ + typedef enum DeltaLatitude { + DeltaLatitude_oneMicrodegreeNorth = 10, + DeltaLatitude_oneMicrodegreeSouth = -10, + DeltaLatitude_unavailable = 131072 + } e_DeltaLatitude; + + /* DeltaLatitude */ + typedef long DeltaLatitude_t; + + /* DeltaLongitude Dependencies */ + typedef enum DeltaLongitude { + DeltaLongitude_oneMicrodegreeEast = 10, + DeltaLongitude_oneMicrodegreeWest = -10, + DeltaLongitude_unavailable = 131072 + } e_DeltaLongitude; + + /* DeltaLongitude */ + typedef long DeltaLongitude_t; + + /* DeltaAltitude Dependencies */ + typedef enum DeltaAltitude { + DeltaAltitude_oneCentimeterUp = 1, + DeltaAltitude_oneCentimeterDown = -1, + DeltaAltitude_unavailable = 12800 + } e_DeltaAltitude; + + /* DeltaAltitude */ + typedef long DeltaAltitude_t; + + /* DeltaReferencePosition */ + typedef struct DeltaReferencePosition { + DeltaLatitude_t deltaLatitude; + DeltaLongitude_t deltaLongitude; + DeltaAltitude_t deltaAltitude; + } DeltaReferencePosition_t; + + /* PathDeltaTime Dependencies */ + typedef enum PathDeltaTime { + PathDeltaTime_tenMilliSecondsInPast = 1 + } e_PathDeltaTime; + + /* PathDeltaTime */ + typedef long PathDeltaTime_t; + + /* PathPoint */ + typedef struct PathPoint { + DeltaReferencePosition_t pathPosition; + PathDeltaTime_t *pathDeltaTime /* OPTIONAL */; + + } PathPoint_t; + + /* PathHistory */ + typedef struct PathHistory { + long NumberOfPathPoint; + std::vector data; + } PathHistory_t; +}; + +class CAMContainer +{ +public: + + /* GenerationDeltaTime Dependencies*/ + typedef enum GenerationDeltaTime + { + GenerationDeltaTime_oneMilliSec = 1 + } e_GenerationDeltaTime; + + /* GenerationDeltaTime */ + typedef long GenerationDeltaTime_t; + + /* BasicContainer */ + typedef struct BasicContainer + { + ITSContainer::StationType_t stationType; + ITSContainer::ReferencePosition_t referencePosition; + } BasicContainer_t; + + /* HighFrequencyContainer Dependencies */ + typedef enum HighFrequencyContainer_PR : long + { + HighFrequencyContainer_PR_NOTHING, /* No components present */ + HighFrequencyContainer_PR_basicVehicleContainerHighFrequency, + HighFrequencyContainer_PR_rsuContainerHighFrequency + } HighFrequencyContainer_PR; + + typedef bool OptionalStructAvailable_t; + + /* BasicVehicleContainerHighFrequency*/ + typedef struct BasicVehicleContainerHighFrequency + { + ITSContainer::Heading_t heading; + ITSContainer::Speed_t speed; + ITSContainer::DriveDirection_t driveDirection; + ITSContainer::VehicleLength_t vehicleLength; + ITSContainer::VehicleWidth_t vehicleWidth; + ITSContainer::LongitudinalAcceleration_t longitudinalAcceleration; + ITSContainer::Curvature_t curvature; + ITSContainer::CurvatureCalculationMode_t curvatureCalculationMode; + ITSContainer::YawRate_t yawRate; + + OptionalStructAvailable_t accelerationControlAvailable; + ITSContainer::AccelerationControl_t accelerationControl /* OPTIONAL */; + + OptionalStructAvailable_t lanePositionAvailable; + ITSContainer::LanePosition_t lanePosition /* OPTIONAL */; + + OptionalStructAvailable_t steeringWheelAngleAvailable; + ITSContainer::SteeringWheelAngle_t steeringWheelAngle /* OPTIONAL */; + + OptionalStructAvailable_t lateralAccelerationAvailable; + ITSContainer::LateralAcceleration_t lateralAcceleration /* OPTIONAL */; + + OptionalStructAvailable_t verticalAccelerationAvailable; + ITSContainer::VerticalAcceleration_t verticalAcceleration /* OPTIONAL */; + + OptionalStructAvailable_t performanceClassAvailable; + ITSContainer::PerformanceClass_t performanceClass /* OPTIONAL */; + + OptionalStructAvailable_t cenDsrcTollingZoneAvailable; + ITSContainer::CenDsrcTollingZone_t cenDsrcTollingZone /* OPTIONAL */; + + } BasicVehicleContainerHighFrequency_t; + + /* RsuContainerHighFrequency */ + typedef struct RSUContainerHighFrequency + { + ITSContainer::ProtectedCommunicationZonesRSU_t protectedCommunicationZonesRSU; + } RSUContainerHighFrequency_t; + + /* HighFrequencyContainer */ + typedef struct HighFrequencyContainer + { + HighFrequencyContainer_PR present; + + BasicVehicleContainerHighFrequency_t basicVehicleContainerHighFrequency; + RSUContainerHighFrequency_t rsuContainerHighFrequency; + + } HighFrequencyContainer_t; + + /* Dependencies */ + typedef enum LowFrequencyContainer_PR : long + { + LowFrequencyContainer_PR_NOTHING, /* No components present */ + LowFrequencyContainer_PR_basicVehicleContainerLowFrequency, + /* Extensions may appear below */ + + } LowFrequencyContainer_PR; + + /* BasicVehicleContainerLowFrequency */ + typedef struct BasicVehicleContainerLowFrequency { + ITSContainer::VehicleRole_t vehicleRole; + ITSContainer::ExteriorLights_t exteriorLights; + ITSContainer::PathHistory_t pathHistory; + } BasicVehicleContainerLowFrequency_t; + + /* LowFrequencyContainer */ + typedef struct LowFrequencyContainer + { + LowFrequencyContainer_PR present; + // Since only option is available + BasicVehicleContainerLowFrequency_t basicVehicleContainerLowFrequency; + + } LowFrequencyContainer_t; + + /* CamParameters */ + typedef struct CamParameters + { + BasicContainer_t basicContainer; + HighFrequencyContainer_t highFrequencyContainer; + LowFrequencyContainer_t lowFrequencyContainer; /* OPTIONAL */ + // Optional TODO: SpecialVehicleContainer *specialVehicleContainer + } CamParameters_t; + + /* CoopAwareness*/ + typedef struct CoopAwareness + { + GenerationDeltaTime_t generationDeltaTime; + CamParameters_t camParameters; + } CoopAwareness_t; + + +}; + + /* CoopAwareness */ + typedef struct CAM + { + ITSContainer::ItsPduHeader_t header; + CAMContainer::CoopAwareness_t cam; + } CAM_t; + + + typedef struct CustomV2XM + { + ITSContainer::ItsPduHeader_t header; + char message[100]; + } CustomV2XM_t; diff --git a/LibCarla/source/carla/sensor/data/V2XData.h b/LibCarla/source/carla/sensor/data/V2XData.h new file mode 100644 index 000000000..4747b5ef8 --- /dev/null +++ b/LibCarla/source/carla/sensor/data/V2XData.h @@ -0,0 +1,106 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . +#pragma once + +#include +#include +#include +#include "LibITS.h" + +namespace carla +{ + namespace sensor + { + + namespace s11n + { + class CAMDataSerializer; + class CustomV2XDataSerializer; + } + + namespace data + { + class CAMData + { + public: + float Power; + CAM_t Message; + }; + + class CustomV2XData + { + public: + float Power; + CustomV2XM Message; + }; + + class CAMDataS + { + + public: + explicit CAMDataS() = default; + + CAMDataS &operator=(CAMDataS &&) = default; + + // Returns the number of current received messages. + size_t GetMessageCount() const + { + return MessageList.size(); + } + + // Deletes the current messages. + void Reset() + { + MessageList.clear(); + } + + // Adds a new detection. + void WriteMessage(CAMData message) + { + MessageList.push_back(message); + } + + private: + std::vector MessageList; + + friend class s11n::CAMDataSerializer; + }; + + class CustomV2XDataS + { + + public: + explicit CustomV2XDataS() = default; + + CustomV2XDataS &operator=(CustomV2XDataS &&) = default; + + // Returns the number of current received messages. + size_t GetMessageCount() const + { + return MessageList.size(); + } + + // Deletes the current messages. + void Reset() + { + MessageList.clear(); + } + + // Adds a new detection. + void WriteMessage(CustomV2XData message) + { + MessageList.push_back(message); + } + + private: + std::vector MessageList; + + friend class s11n::CustomV2XDataSerializer; + }; + + } // namespace s11n + } // namespace sensor +} // namespace carla diff --git a/LibCarla/source/carla/sensor/data/V2XEvent.h b/LibCarla/source/carla/sensor/data/V2XEvent.h new file mode 100644 index 000000000..f146bffb1 --- /dev/null +++ b/LibCarla/source/carla/sensor/data/V2XEvent.h @@ -0,0 +1,61 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/Debug.h" +#include "carla/sensor/data/Array.h" +#include "carla/sensor/s11n/V2XSerializer.h" +#include "carla/sensor/data/V2XData.h" + +namespace carla +{ + namespace sensor + { + namespace data + { + + class CAMEvent : public Array + { + using Super = Array; + + protected: + using Serializer = s11n::CAMDataSerializer; + + friend Serializer; + + explicit CAMEvent(RawData &&data) + : Super(0u, std::move(data)) {} + + public: + Super::size_type GetMessageCount() const + { + return Super::size(); + } + }; + + class CustomV2XEvent : public Array + { + using Super = Array; + + protected: + using Serializer = s11n::CustomV2XDataSerializer; + + friend Serializer; + + explicit CustomV2XEvent(RawData &&data) + : Super(0u, std::move(data)) {} + + public: + Super::size_type GetMessageCount() const + { + return Super::size(); + } + }; + + } // namespace data + } // namespace sensor +} // namespace carla diff --git a/LibCarla/source/carla/sensor/s11n/V2XSerializer.cpp b/LibCarla/source/carla/sensor/s11n/V2XSerializer.cpp new file mode 100644 index 000000000..7853afac7 --- /dev/null +++ b/LibCarla/source/carla/sensor/s11n/V2XSerializer.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "carla/sensor/s11n/V2XSerializer.h" + +#include "carla/sensor/data/V2XEvent.h" + +namespace carla +{ + namespace sensor + { + namespace s11n + { + + SharedPtr CAMDataSerializer::Deserialize(RawData &&data) + { + return SharedPtr(new data::CAMEvent(std::move(data))); + } + + SharedPtr CustomV2XDataSerializer::Deserialize(RawData &&data) + { + return SharedPtr(new data::CustomV2XEvent(std::move(data))); + } + + } // namespace s11n + } // namespace sensor +} // namespace carla diff --git a/LibCarla/source/carla/sensor/s11n/V2XSerializer.h b/LibCarla/source/carla/sensor/s11n/V2XSerializer.h new file mode 100644 index 000000000..4c38aed47 --- /dev/null +++ b/LibCarla/source/carla/sensor/s11n/V2XSerializer.h @@ -0,0 +1,79 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/Memory.h" +#include "carla/sensor/RawData.h" +#include "carla/sensor/data/V2XData.h" + +#include +#include +class CAMContainer; +namespace carla +{ + namespace sensor + { + + class SensorData; + + namespace s11n + { + + // =========================================================================== + // -- V2XSerializer -------------------------------------------------------- + // =========================================================================== + + /// Serializes the data generated by V2X sensors. + // CAM + class CAMDataSerializer + { + public: + template + static Buffer Serialize( + const Sensor &sensor, + const data::CAMDataS &data, + Buffer &&output); + + static SharedPtr Deserialize(RawData &&data); + }; + + template + inline Buffer CAMDataSerializer::Serialize( + const Sensor &, + const data::CAMDataS &data, + Buffer &&output) + { + output.copy_from(data.MessageList); + return std::move(output); + } + + // Custom message + class CustomV2XDataSerializer + { + public: + template + static Buffer Serialize( + const Sensor &sensor, + const data::CustomV2XDataS &data, + Buffer &&output); + + static SharedPtr Deserialize(RawData &&data); + }; + + template + inline Buffer CustomV2XDataSerializer::Serialize( + const Sensor &, + const data::CustomV2XDataS &data, + Buffer &&output) + { + output.copy_from(data.MessageList); + return std::move(output); + } + + } // namespace s11n + } // namespace sensor +} // namespace carla diff --git a/PythonAPI/carla/agents/navigation/basic_agent.py b/PythonAPI/carla/agents/navigation/basic_agent.py index 44e6d0351..2d0b9b91a 100644 --- a/PythonAPI/carla/agents/navigation/basic_agent.py +++ b/PythonAPI/carla/agents/navigation/basic_agent.py @@ -18,6 +18,8 @@ from agents.tools.misc import (get_speed, is_within_distance, get_trafficlight_trigger_location, compute_distance) +from agents.tools.hints import ObstacleDetectionResult, TrafficLightDetectionResult + class BasicAgent(object): """ @@ -137,30 +139,37 @@ class BasicAgent(object): def get_global_planner(self): """Get method for protected member local planner""" return self._global_planner - - def set_destination(self, end_location, start_location=None): + + def set_destination(self, end_location, start_location=None, clean_queue=True): + # type: (carla.Location, carla.Location | None, bool) -> None """ This method creates a list of waypoints between a starting and ending location, based on the route returned by the global router, and adds it to the local planner. - If no starting location is passed, the vehicle local planner's target location is chosen, - which corresponds (by default), to a location about 5 meters in front of the vehicle. + If no starting location is passed and `clean_queue` is True, the vehicle local planner's + target location is chosen, which corresponds (by default), to a location about 5 meters + in front of the vehicle. + If `clean_queue` is False the newly planned route will be appended to the current route. :param end_location (carla.Location): final location of the route :param start_location (carla.Location): starting location of the route + :param clean_queue (bool): Whether to clear or append to the currently planned route """ if not start_location: - start_location = self._local_planner.target_waypoint.transform.location - clean_queue = True - else: - start_location = self._vehicle.get_location() - clean_queue = False - + if clean_queue and self._local_planner.target_waypoint: + # Plan from the waypoint in front of the vehicle onwards + start_location = self._local_planner.target_waypoint.transform.location + elif not clean_queue and self._local_planner._waypoints_queue: + # Append to the current plan + start_location = self._local_planner._waypoints_queue[-1][0].transform.location + else: + # no target_waypoint or _waypoints_queue empty, use vehicle location + start_location = self._vehicle.get_location() start_waypoint = self._map.get_waypoint(start_location) end_waypoint = self._map.get_waypoint(end_location) - + route_trace = self.trace_route(start_waypoint, end_waypoint) self._local_planner.set_global_plan(route_trace, clean_queue=clean_queue) - + def set_global_plan(self, plan, stop_waypoint_creation=True, clean_queue=True): """ Adds a specific plan to the agent. @@ -265,7 +274,7 @@ class BasicAgent(object): If None, the base threshold value is used """ if self._ignore_traffic_lights: - return (False, None) + return TrafficLightDetectionResult(False, None) if not lights_list: lights_list = self._world.get_actors().filter("*traffic_light*") @@ -277,7 +286,7 @@ class BasicAgent(object): if self._last_traffic_light.state != carla.TrafficLightState.Red: self._last_traffic_light = None else: - return (True, self._last_traffic_light) + return TrafficLightDetectionResult(True, self._last_traffic_light) ego_vehicle_location = self._vehicle.get_location() ego_vehicle_waypoint = self._map.get_waypoint(ego_vehicle_location) @@ -308,9 +317,9 @@ class BasicAgent(object): if is_within_distance(trigger_wp.transform, self._vehicle.get_transform(), max_distance, [0, 90]): self._last_traffic_light = traffic_light - return (True, traffic_light) + return TrafficLightDetectionResult(True, traffic_light) - return (False, None) + return TrafficLightDetectionResult(False, None) def _vehicle_obstacle_detected(self, vehicle_list=None, max_distance=None, up_angle_th=90, low_angle_th=0, lane_offset=0): """ @@ -347,12 +356,12 @@ class BasicAgent(object): return Polygon(route_bb) if self._ignore_vehicles: - return (False, None, -1) + return ObstacleDetectionResult(False, None, -1) if vehicle_list is None: vehicle_list = self._world.get_actors().filter("*vehicle*") if len(vehicle_list) == 0: - return (False, None, -1) + return ObstacleDetectionResult(False, None, -1) if not max_distance: max_distance = self._base_vehicle_threshold @@ -395,7 +404,7 @@ class BasicAgent(object): target_polygon = Polygon(target_list) if route_polygon.intersects(target_polygon): - return (True, target_vehicle, compute_distance(target_vehicle.get_location(), ego_location)) + return ObstacleDetectionResult(True, target_vehicle, compute_distance(target_vehicle.get_location(), ego_location)) # Simplified approach, using only the plan waypoints (similar to TM) else: @@ -416,9 +425,9 @@ class BasicAgent(object): ) if is_within_distance(target_rear_transform, ego_front_transform, max_distance, [low_angle_th, up_angle_th]): - return (True, target_vehicle, compute_distance(target_transform.location, ego_transform.location)) + return ObstacleDetectionResult(True, target_vehicle, compute_distance(target_transform.location, ego_transform.location)) - return (False, None, -1) + return ObstacleDetectionResult(False, None, -1) def _generate_lane_change_path(self, waypoint, direction='left', distance_same_lane=10, distance_other_lane=25, lane_change_distance=25, diff --git a/PythonAPI/carla/agents/tools/hints.py b/PythonAPI/carla/agents/tools/hints.py new file mode 100644 index 000000000..475d93d3d --- /dev/null +++ b/PythonAPI/carla/agents/tools/hints.py @@ -0,0 +1,34 @@ +""" +Module to add high-level semantic return types for obstacle and traffic light detection results via named tuples. + +The code is compatible with Python 2.7, <3.6 and >=3.6. The later uses the typed version of named tuples. +""" + + +import sys +if sys.version_info < (3, 6): + from collections import namedtuple + ObstacleDetectionResult = namedtuple('ObstacleDetectionResult', ['obstacle_was_found', 'obstacle', 'distance']) + TrafficLightDetectionResult = namedtuple('TrafficLightDetectionResult', ['traffic_light_was_found', 'traffic_light']) +else: + from typing import NamedTuple, Union, TYPE_CHECKING + from carla import Actor, TrafficLight + """ + # Python 3.6+, incompatible with Python 2.7 syntax + class ObstacleDetectionResult(NamedTuple): + obstacle_was_found : bool + obstacle : Union[Actor, None] + distance : float + # distance : Union[float, Literal[-1]] # Python 3.8+ only + + class TrafficLightDetectionResult(NamedTuple): + traffic_light_was_found : bool + traffic_light : Union[TrafficLight, None] + """ + if TYPE_CHECKING: + from typing import Literal + ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', Union[float, Literal[-1]])]) + else: + ObstacleDetectionResult = NamedTuple('ObstacleDetectionResult', [('obstacle_was_found', bool), ('obstacle', Union[Actor, None]), ('distance', float)]) + + TrafficLightDetectionResult = NamedTuple('TrafficLightDetectionResult', [('traffic_light_was_found', bool), ('traffic_light', Union[TrafficLight, None])]) diff --git a/PythonAPI/carla/source/carla/libcarla.pyi b/PythonAPI/carla/source/carla/libcarla.pyi new file mode 100644 index 000000000..b8691681f --- /dev/null +++ b/PythonAPI/carla/source/carla/libcarla.pyi @@ -0,0 +1,5749 @@ +from enum import Enum, Flag, IntFlag +import sys +from typing import (Callable, Iterable, Iterator, Union, Optional, overload, ClassVar, Any, TypeVar, + type_check_only) + +if sys.version_info >= (3, 11): + from typing import Self +else: + from typing_extensions import Self + +if sys.version_info >= (3, 9): + from typing import Annotated +else: + from typing_extensions import Annotated + +if sys.version_info >= (3, 8): + from typing import Literal +else: + from typing_extensions import Literal + + +# Note: __protected_variables are not part of the carla module, they are helpers to complete the stubs. + +__SensorData = TypeVar("__SensorData", bound=SensorData) +"""Generic that allows subclassing.""" + +@type_check_only +class __CarlaEnum(Enum): + """ + CARLA's Enums have a `values` and `names` attribute that are not part of the python `enum.Enum` + class. This abstract stub class adds these attributes. + """ + + values : ClassVar[dict[int, Self]] + names : ClassVar[dict[str, Self]] + + def __init_subclass__(cls): + cls.values : dict[int, cls] + cls.names : dict[str, cls] + + +class AckermannControllerSettings(): + """Manages the settings of the Ackermann PID controller.""" + + # region Instance Variables + @property + def speed_kp(self) -> float: + """Proportional term of the speed PID controller.""" + ... + + @property + def speed_ki(self) -> float: + """Integral term of the speed PID controller.""" + ... + + @property + def speed_kd(self) -> float: + """Derivative term of the speed PID controller.""" + ... + + @property + def accel_kp(self) -> float: + """Proportional term of the acceleration PID controller.""" + ... + + @property + def accel_ki(self) -> float: + """Integral term of the acceleration PID controller.""" + ... + + @property + def accel_kd(self) -> float: + """Derivative term of the acceleration PID controller.""" + ... + # endregion + + # region Methods + def __init__(self, + speed_kp: float = 0.15, + speed_ki: float = 0.0, + speed_kd: float = 0.25, + accel_kp: float = 0.01, + accel_ki: float = 0.0, + accel_kd: float = 0.01): + """Manages the settings of the Ackermann PID controller. + """ + # endregion + + # region Dunder Methods + def __eq__(self, __value: AckermannControllerSettings) -> bool: ... + + def __ne__(self, __value: AckermannControllerSettings) -> bool: ... + + def __str__(self) -> str: ... + # endregion + + +class Actor(): + """CARLA defines actors as anything that plays a role in the simulation or can be moved around. + + That includes: pedestrians, vehicles, sensors and traffic signs (considering traffic lights as part of these). Actors are spawned in the simulation by `carla.World` and they need for a `carla.ActorBlueprint` to be created. These blueprints belong into a library provided by CARLA, find more about them here. + https://carla.readthedocs.io/en/latest/bp_library/ + """ + + # region Instance Variables + @property + def attributes(self) -> dict: + """A dictionary containing the attributes of the blueprint this actor was based on. + """ + ... + + @property + def id(self) -> int: + """Identifier for this actor. Unique during a given episode. + """ + ... + + @property + def type_id(self) -> str: + """The identifier of the blueprint this actor was based on, + + e.g., `vehicle.ford.mustang.`""" + ... + + @property + def is_alive(self) -> bool: + """Returns whether this object was destroyed using this actor handle.""" + ... + + @property + def is_active(self) -> bool: + """Returns whether this actor is active (`True`) or not (`False`).""" + ... + + @property + def is_dormant(self) -> bool: + """Returns whether this actor is dormant (`True`) or not (`False`) - the opposite of `is_active`.""" + ... + + @property + def parent(self) -> Actor | None: + """Actors may be attached to a parent actor that they will follow around. This is said actor.""" + ... + + @property + def semantic_tags(self) -> list[int]: + """A list of semantic tags provided by the blueprint listing components for this actor. + + E.g. a traffic light could be tagged with `Pole` and `TrafficLight`. These tags are used by the semantic segmentation sensor. Find more about this and other sensors here + https://carla.readthedocs.io/en/latest/ref_sensors/#semantic-segmentation-camera + """ + + @property + def actor_state(self) -> ActorState: + """Returns the carla.ActorState, which can identify if the actor is Active, Dormant or Invalid.""" + ... + + @property + def bounding_box(self) -> BoundingBox: + """Bounding box containing the geometry of the actor. Its location and rotation are relative to the actor it is attached to.""" + # endregion + + # region Methods + def add_angular_impulse(self, angular_impulse: Vector3D): + """Applies an angular impulse at the center of mass of the actor. + + This method should be used for instantaneous torques, usually applied once. Use `add_torque()` to apply rotation forces over a period of time. + + Args: + `angular_impulse (Vector3D - degrees*s)`: Angular impulse vector in global coordinates.\n + """ + ... + + def add_force(self, force: Vector3D): + """Applies a force at the center of mass of the actor. + + This method should be used for forces that are applied over a certain period of time. Use `add_impulse()` to apply an impulse that only lasts an instant. + + Args: + `force (Vector3D - N)`: Force vector in global coordinates.\n + """ + ... + + def add_impulse(self, impulse: Vector3D): + """Applies an impulse at the center of mass of the actor. + + This method should be used for instantaneous forces, usually applied once. Use `add_force()` to apply forces over a period of time. + + Args: + `impulse (Vector3D - N*s)`: Impulse vector in global coordinates.\n + """ + ... + + def add_torque(self, torque: Vector3D): + """Applies a torque at the center of mass of the actor. + + This method should be used for torques that are applied over a certain period of time. Use `add_angular_impulse()` to apply a torque that only lasts an instant. + + Args: + `torque (Vector3D - degrees)`: Torque vector in global coordinates.\n + """ + ... + + def destroy(self) -> bool: + """Tells the simulator to destroy this actor and returns True if it was successful. + + It has no effect if it was already destroyed. + + + Warning: This method blocks the script until the destruction is completed by the simulator. + """ + ... + + def disable_constant_velocity(self): + """Disables any constant velocity previously set for a `carla.Vehicle` actor. + """ + ... + + def enable_constant_velocity(self, velocity: Vector3D): + """Sets a vehicle's velocity vector to a constant value over time. + + The resulting velocity will be approximately the `velocity` being set, as with set_target_velocity(). + + + Note: Only `carla.Vehicle` actors can use this method. + + + Warning: Enabling a constant velocity for a vehicle managed by the `Traffic Manager` may cause conflicts. This method overrides any changes in velocity by the TM. + + Args: + `velocity (Vector3D - m/s)`: Velocity vector in local space.\n + """ + ... + # endregion + + # region Getters + def get_acceleration(self) -> Vector3D: + """Returns the actor's 3D acceleration vector the client received during last tick. + + The method does not call the simulator. + + Returns: + `Vector3D`: m/s^2\n + """ + ... + + def get_angular_velocity(self) -> Vector3D: + """Returns the actor's angular velocity vector the client received during last tick. + + The method does not call the simulator. + + Returns: + `Vector3D`: deg/s\n + """ + ... + + def get_location(self) -> Location: + """Returns the actor's location the client received during last tick. + + The method does not call the simulator. + + + Setter: `carla.Actor.set_location` + + Returns: + `Location`: - meters\n + """ + ... + + def get_transform(self) -> Transform: + """Returns the actor's transform (location and rotation) the client received during last tick. + + The method does not call the simulator. + + + Setter: `carla.Actor.set_transform` + + Returns: + `Transform`\n + """ + + def get_velocity(self) -> Vector3D: + """Returns the actor's velocity vector the client received during last tick. + + The method does not call the simulator. + + Returns: + `Vector3D`: m/s\n + """ + ... + + def get_world(self) -> World: + """Returns the world this actor belongs to. + + Returns: + `World`\n + """ + ... + # endregion + + # region Setters + def set_enable_gravity(self, enabled: bool): + """Enables or disables gravity for the actor. + Default is `True`. + + Args: + `enabled (bool)`\n + """ + ... + + def set_location(self, location: Location): + """Teleports the actor to a given location. + + + Getter: `carla.Actor.get_location` + + Args: + `location (Location)`: meters\n + """ + ... + + def set_simulate_physics(self, enabled=True): + """Enables or disables the simulation of physics on this actor. + + Args: + `enabled (bool, optional)`: Defaults to True.\n + """ + ... + + def set_target_angular_velocity(self, angular_velocity: Vector3D): + """_summary_Sets the actor's angular velocity vector. + + This is applied before the physics step so the resulting angular velocity will be affected by external forces such as friction. + + Args: + `angular_velocity (Vector3D)`: deg/s\n + """ + ... + + def set_target_velocity(self, velocity: Vector3D): + """Sets the actor's velocity vector. + + This is applied before the physics step so the resulting angular velocity will be affected by external forces such as friction. + + Args: + `velocity (Vector3D)`\n + """ + ... + + def set_transform(self, transform: Transform): + """Teleports the actor to a given transform (location and rotation). + + + Getter: `carla.Actor.get_transform` + + Args: + `transform (Transform)`\n + """ + ... + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class ActorAttribute(): + """CARLA provides a library of blueprints for actors that can be accessed as `carla.BlueprintLibrary`. Each of these blueprints has a series of attributes defined internally. Some of these are modifiable, others are not. A list of recommended values is provided for those that can be set. + """ + + # region Instance Variables + @property + def id(self) -> str: + """The attribute's name and identifier in the library. + """ + @property + def is_modifiable(self) -> bool: + """It is True if the attribute's value can be modified.""" + @property + def recommended_values(self) -> list[str]: + """A list of values suggested by those who designed the blueprint.""" + @property + def type(self) -> ActorAttributeType: + """The attribute's parameter type.""" + # endregion + + # region Methods + def as_bool(self) -> bool: + """Reads the attribute as boolean value.""" + ... + + def as_color(self) -> Color: + """Reads the attribute as `carla.Color`.""" + ... + + def as_float(self) -> float: + """Reads the attribute as float.""" + ... + + def as_int(self) -> int: + """Reads the attribute as int.""" + ... + + def as_str(self) -> str: + """Reads the attribute as string.""" + ... + # endregion + + # region Dunder Methods + def __bool__(self) -> bool: ... + def __eq__(self, __value: Union[bool, int, float, str, Color, ActorAttribute]) -> bool: ... + def __float__(self) -> float: ... + def __int__(self) -> int: ... + def __ne__(self, __value: Union[bool, int, float, str, Color, ActorAttribute]) -> bool: ... + def __nonzero__(self) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class ActorAttributeType(int, __CarlaEnum): + """CARLA provides a library of blueprints for actors in `carla.BlueprintLibrary` with different attributes each. This class defines the types those at `carla.ActorAttribute` can be as a series of enum. All this information is managed internally and listed here for a better comprehension of how CARLA works. + """ + # region Instance Variables + Bool = 0 + Int = 1 + Float = 2 + String = 3 + RGBColor = 4 + # endregion + + +class ActorBlueprint(): + """CARLA provides a blueprint library for actors that can be consulted through `carla.BlueprintLibrary`. Each of these consists of an identifier for the blueprint and a series of attributes that may be modifiable or not. This class is the intermediate step between the library and the actor creation. Actors need an actor blueprint to be spawned. These store the information for said blueprint in an object with its attributes and some tags to categorize them. The user can then customize some attributes and eventually spawn the actors through `carla.World`. + """ + + # region Instance Variables + @property + def id(self) -> str: + """The identifier of said blueprint inside the library. + + E.g. `walker.pedestrian.0001`.""" + + @property + def tags(self) -> list[str]: + """A list of tags each blueprint has that helps describing them. + + E.g. `['0001', 'pedestrian', 'walker']`. + """ + ... + # endregion + + # region Methods + def has_attribute(self, id: str) -> bool: + """Returns `True` if the blueprint contains the attribute `id`. + + Args: + `id (str)`: e.g. `gender` would return True for pedestrians' blueprints.\n + + Returns: + `bool`\n + """ + ... + + def has_tag(self, tag: str) -> bool: + """Returns `True` if the blueprint has the specified `tag` listed. + + Args: + `tag (str)`: e.g. `'walker'`\n + + Returns: + `bool`\n + """ + ... + + def match_tags(self, wildcard_pattern: str) -> bool: + """Returns `True` if any of the tags listed for this blueprint matches `wildcard_pattern`. + + Matching follows `fnmatch` standard. https://docs.python.org/3.12/library/fnmatch.html + + Args: + `wildcard_pattern (str)`\n + + Returns: + `bool`\n + """ + # endregion + + # region Getters + def get_attribute(self, id: str) -> ActorAttribute: + """Returns the actor's attribute with `id` as identifier if existing. + + + Setter: `carla.ActorBlueprint.set_attribute` + + Args: + `id (str)`\n + + Returns: + `ActorAttribute`\n + """ + ... + # endregion + + # region Setters + def set_attribute(self, id: str, value: str) -> None: + """If the `id` attribute is modifiable, changes its value to `value`. + + Args: + `id (str)`: The identifier for the attribute that is intended to be changed.\n + `value (str)`: The new value for said attribute.\n + """ + # endregion + + # region Dunder Methods + def __iter__(self) -> Iterator[ActorAttribute]: + """Iterate over the `carla.ActorAttribute` that this blueprint has. + """ + ... + + def __len__(self) -> int: + """Returns the amount of attributes for this blueprint.""" + ... + + def __str__(self) -> str: ... + # endregion + + +class ActorList(): + """ + A class that contains every actor present on the scene and provides access to them. + The list is automatically created and updated by the server and it can be returned using `carla.World`. + """ + + # region Methods + def filter(self, wildcard_pattern: str) -> ActorList: + """Filters a list of Actors matching wildcard_pattern against their variable `type_id` (which identifies the blueprint used to spawn them). Matching follows fnmatch standard. + + Args: + `wildcard_pattern (str)`\n + + Returns: + `ActorList`\n + """ + ... + + def find(self, actor_id: int) -> Actor: + """Finds an actor using its identifier and returns it or None if it is not present. + + Args: + `actor_id (int)`\n + + Returns: + `Actor`\n + """ + ... + # endregion + + # region Dunder methods + def __getitem__(self, pos: int) -> Actor: + """Returns the actor corresponding to pos position in the list.""" + ... + + def __iter__(self) -> Iterator[Actor]: + """Iterate over the `carla.Actor` contained in the list.""" + ... + + def __len__(self) -> int: + """Returns the amount of actors listed.""" + ... + + def __str__(self) -> str: + """Parses to the ID for every actor listed.""" + ... + # endregion + + +class ActorSnapshot(): + """A class that comprises all the information for an actor at a certain moment in time. These objects are contained in a `carla.WorldSnapshot` and sent to the client once every tick. + """ + + # region Instance Variables + @property + def id(self) -> int: + """An identifier for the snapshot itself.""" + ... + # endregion + + # region Getters + def get_acceleration(self) -> Vector3D: + """Returns the acceleration vector registered for an actor in that tick. + + Returns: + `Vector3D`: m/s^2\n + """ + ... + + def get_angular_velocity(self) -> Vector3D: + """Returns the angular velocity vector registered for an actor in that tick. + + Returns: + `Vector3D`: rad/s\n + """ + ... + + def get_transform(self) -> Transform: + """Returns the actor's transform (location and rotation) for an actor in that tick. + + Returns: + `Transform`\n + """ + ... + + def get_velocity(self) -> Vector3D: + """Returns the velocity vector registered for an actor in that tick. + + Returns: + `Vector3D`: m/s\n + """ + ... + # endregion + + +class ActorState(int, __CarlaEnum): + """Class that defines the state of an actor.""" + # region Instance Variables + Invalid = 0 + """An actor is Invalid if a problem has occurred.""" + Active = 1 + """An actor is Active when it visualized and can affect other actors.""" + Dormant = 2 + """An actor is Dormant when it is not visualized and will not affect other actors through physics. For example, actors are dormant if they are on an unloaded tile in a large map.""" + # endregion + + +class AttachmentType(int, __CarlaEnum): + """ + Class that defines attachment options between an actor and its parent. + When spawning actors, these can be attached to another actor so their + position changes accordingly. This is specially useful for sensors. + The snippet in `carla.World.spawn_actor` shows some sensors being + attached to a car when spawned. + + + Note that the attachment type is declared as an enum within the class.""" + + # region Instance Variables + Rigid = 0 + """With this fixed attachment the object follow its parent position strictly. + This is the recommended attachment to retrieve precise data from the simulation.""" + + SpringArm = 1 + """ + An attachment that expands or retracts the position of the actor, + depending on its parent. This attachment is only recommended to record + videos from the simulation where a smooth movement is needed. SpringArms + are an Unreal Engine component so check the UE docs to learn more about + them. + + https://docs.unrealengine.com/5.3/en-US/using-spring-arm-components-in-unreal-engine/ + + + Warning: The `SpringArm` attachment presents weird behaviors when an + actor is spawned with a relative translation in the Z-axis (e.g. `child_location = Location(0,0,2)`). + """ + + SpringArmGhost = 2 + """ + An attachment like the previous one but that does not make the collision test, + and that means that it does not expands or retracts the position of the actor. + The term ghost is because then the camera can cross walls and other geometries. + This attachment is only recommended to record videos from the simulation where + a smooth movement is needed. SpringArms are an Unreal Engine component so + check the UE docs to learn more about them. + + https://docs.unrealengine.com/5.3/en-US/using-spring-arm-components-in-unreal-engine/ + + + Warning: The `SpringArm` attachment presents weird behaviors when an actor is + spawned with a relative translation in the Z-axis (e.g. `child_location = Location(0,0,2)`). + """ + # endregion + + +class BlueprintLibrary(): + """A class that contains the blueprints provided for actor spawning. Its main application is to return `carla.ActorBlueprint` objects needed to spawn actors. Each blueprint has an identifier and attributes that may or may not be modifiable. The library is automatically created by the server and can be accessed through `carla.World`. + + Here is a reference containing every available blueprint and its specifics. + """ + + # region Methods + def filter(self, wildcard_pattern: str) -> BlueprintLibrary: + """Filters a list of blueprints matching the `wildcard_pattern` against the id and tags of every blueprint contained in this library and returns the result as a new one. Matching follows fnmatch standard. + + Args: + `wildcard_pattern (str)`\n + + Returns: + `BlueprintLibrary`\n + """ + + def filter_by_attribute(self, name: str, value: str) -> BlueprintLibrary: + """Filters a list of blueprints with a given attribute matching the `value` against every blueprint contained in this library and returns the result as a new one. Matching follows fnmatch standard. + + Args: + `name (str)`\n + `value (str)`\n + + Returns: + `ActorBlueprint`\n + """ + + def find(self, id: str) -> ActorBlueprint: + """Returns the blueprint corresponding to that identifier. + + Args: + `id (str)`\n + + Returns: + `ActorBlueprint`\n + """ + # endregion + + # region Dunder Methods + def __getitem__(self, pos: int) -> ActorBlueprint: + """Returns the blueprint stored in `pos` position inside the data structure containing them. + """ + + def __iter__(self) -> Iterator[ActorBlueprint]: + """Iterate over the `carla.ActorBlueprint` stored in the library.""" + + def __len__(self): + """Returns the amount of blueprints comprising the library.""" + + def __str__(self) -> str: + """Parses the identifiers for every blueprint to string.""" + ... + # endregion + + +class BoundingBox(): + """Bounding boxes contain the geometry of an actor or an element in the scene. They can be used by `carla.DebugHelper` or a `carla.Client` to draw their shapes for debugging. Check out the snippet in `carla.DebugHelper.draw_box` where a snapshot of the world is used to draw bounding boxes for traffic lights. + """ + + # region Instance Variables + @property + def extent(self) -> Vector3D: + """Vector from the center of the box to one vertex. The value in each axis equals half the size of the box for that axis. `extent.x * 2` would return the size of the box in the X-axis. + + Returns: + `Vector3D`: meters\n + """ + @property + def location(self) -> Location: + """The center of the bounding box. + + Returns: + `Location`: meters\n + """ + + @property + def rotation(self) -> Rotation: + """The orientation of the bounding box.""" + # endregion + + # region Methods + def __init__(self, location: Location, extent: Vector3D): + """Bounding boxes contain the geometry of an actor or an element in the scene. They can be used by `carla.DebugHelper` or a `carla.Client` to draw their shapes for debugging. Check out the snippet in `carla.DebugHelper.draw_box` where a snapshot of the world is used to draw bounding boxes for traffic lights. + + Args: + `location (Location)`: Center of the box, relative to its parent.\n + `extent (Vector3D)`: Vector containing half the size of the box for every axis.\n + """ + ... + + def contains(self, world_point: Location, transform: Transform) -> bool: + """Returns `True` if a point passed in world space is inside this bounding box. + + + Args: + `world_point (Location)`: meters. The point in world space to be checked.\n + `transform (Transform)`: Contains location and rotation needed to convert this object's local space to world space.\n + + Returns: + `bool`\n + """ + # endregion + + # region Getters + def get_local_vertices(self) -> list[Location]: + """Returns a list containing the locations of this object's vertices in local space.""" + ... + + def get_world_vertices(self, transform: Transform) -> list[Location]: + """Returns a list containing the locations of this object's vertices in world space. + + Args: + `transform (Transform)`: Contains location and rotation needed to convert this object's local space to world space.\n + """ + ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: BoundingBox) -> bool: + """Returns true if both location and extent are equal for this and `other`.""" + + def __ne__(self, __value: BoundingBox) -> bool: + """Returns true if either location or extent are different for this and `other`.""" + + def __str__(self) -> str: + """Parses the location and extent of the bounding box to string.""" + # endregion + + +class CityObjectLabel(int, __CarlaEnum): + """Enum declaration that contains the different tags available to filter the bounding boxes returned by carla.World.get_level_bbs(). These values correspond to the semantic tag that the elements in the scene have.""" + NONE = 0 + Buildings = 3 + Fences = 5 + Other = 22 + Pedestrians = 12 + Poles = 6 + RoadLines = 24 + Roads = 1 + Sidewalks = 2 + TrafficSigns = 8 + Vegetation = 9 + Car = 14 + Walls = 4 + Sky = 11 + Ground = 25 + Bridge = 26 + RailTrack = 27 + GuardRail = 28 + TrafficLight = 7 + Static = 20 + Dynamic = 21 + Water = 23 + Terrain = 10 + Truck = 15 + Motorcycle = 18 + Bicycle = 19 + Bus = 16 + Rider = 13 + Train = 17 + Any = 255 + + +class Client(): + """The Client connects CARLA to the server which runs the simulation. Both server and client contain a CARLA library (libcarla) with some differences that allow communication between them. Many clients can be created and each of these will connect to the RPC server inside the simulation to send commands. The simulation runs server-side. Once the connection is established, the client will only receive data retrieved from the simulation. Walkers are the exception. The client is in charge of managing pedestrians so, if you are running a simulation with multiple clients, some issues may arise. For example, if you spawn walkers through different clients, collisions may happen, as each client is only aware of the ones it is in charge of. + + The client also has a recording feature that saves all the information of a simulation while running it. This allows the server to replay it at will to obtain information and experiment with it. Here is some information about how to use this recorder. + + https://carla.readthedocs.io/en/latest/adv_recorder/ + """ + # region Methods + + def __init__(self, host="127.0.0.1", port=2000, worker_threads=0): + """Client constructor. + + Args: + `host (str, optional)`: IP address where a CARLA Simulator instance is running. Defaults to "127.0.0.1".\n + `port (int, optional)`: TCP port where the CARLA Simulator instance is running. Defaults to 2000 and the subsequent 2001.\n + `worker_threads (int, optional)`: Number of working threads used for background updates. If 0, use all available concurrency. Defaults to 0.\n + """ + + def apply_batch(self, commands: list[command]): + """Executes a list of commands on a single simulation step and retrieves no information. + + If you need information about the response of each command, use the `apply_batch_sync()` method. Here is an example on how to delete the actors that appear in `carla.ActorList` all at once. + + https://github.com/carla-simulator/carla/blob/master/PythonAPI/examples/generate_traffic.py + + Args: + `commands (list)`: A list of commands to execute in batch. Each command is different and has its own parameters. \n + """ + + def apply_batch_sync(self, commands: list[command], due_tick_cue=False) -> list[command.Response]: + """Executes a list of commands on a single simulation step, blocks until the commands are linked, and returns a list of command.Response that can be used to determine whether a single command succeeded or not. Here is an example of it being used to spawn actors. + + https://github.com/carla-simulator/carla/blob/master/PythonAPI/examples/generate_traffic.py + + Args: + `commands (list[command])`: A list of commands to execute in batch. The commands available are listed right above, in the method `apply_batch()`.\n + `due_tick_cue (bool, optional)`: A boolean parameter to specify whether or not to perform a `carla.World.tick` after applying the batch in synchronous mode. Defaults to False.\n + + Returns: + `list[command.Response]`\n + """ + + def generate_opendrive_world(self, opendrive: str, parameters: OpendriveGenerationParameters = OpendriveGenerationParameters(2.0, 50.0, 1.0, 0.6, True, True), reset_settings=True): + """Loads a new world with a basic 3D topology generated from the content of an OpenDRIVE file. This content is passed as a `string` parameter. It is similar to `client.load_world(map_name)` but allows for custom OpenDRIVE maps in server side. Cars can drive around the map, but there are no graphics besides the road and sidewalks. + + Args: + `opendrive (str)`: Content of an OpenDRIVE file as `string`, not the path to the `.xodr`.\n + `parameters (OpendriveGenerationParameters, optional)`: Additional settings for the mesh generation. Defaults to (2.0, 50.0, 1.0, 0.6, True, True).\n + `reset_settings (bool, optional)`: Option to reset the episode setting to default values, set to false to keep the current settings. This is useful to keep sync mode when changing map and to keep deterministic scenarios. Defaults to True.\n + """ + + def load_world(self, map_name: str, reset_settings=True, map_layers=MapLayer.All) -> World: + """Creates a new world with default settings using `map_name` map. All actors in the current world will be destroyed. + + + Warning: `map_layers` are only available for "Opt" maps + + Args: + `map_name (str)`: Name of the map to be used in this world. Accepts both full paths and map names,e.g. `'/Game/Carla/Maps/Town01'` or `'Town01'`. Remember that these paths are dynamic.\n + `reset_settings (bool, optional)`: Option to reset the episode setting to default values, set to false to keep the current settings. This is useful to keep sync mode when changing map and to keep deterministic scenarios. Defaults to True.\n + `map_layers (MapLayer, optional)`: Layers of the map that will be loaded. This parameter works like a flag mask. Defaults to MapLayer.All.\n + + Returns: + `World`\n + """ + + def reload_world(self, reset_settings=True) -> World: + """Reload the current world, note that a new world is created with default settings using the same map. All actors present in the world will be destroyed, but traffic manager instances will stay alive. + + Args: + `reset_settings (bool, optional)`: Option to reset the episode setting to default values, set to false to keep the current settings. This is useful to keep sync mode when changing map and to keep deterministic scenarios. Defaults to True.\n + + Raises: + `RuntimeError` when corresponding. + + Returns: + `World`\n + """ + + def load_world_if_different(self, map_name: str, reset_settings=True, map_layers=MapLayer.All): + """" + Creates a new world with default settings using `map_name` map only if it is a different map + from the currently loaded map. + Otherwise this function returns `None`. All actors in the current world will be destroyed. + + Args: + `map_name (str)`: Name of the map to be used in this world. Accepts both full paths and map names, + e.g.'/Game/Carla/Maps/Town01' or 'Town01'. Remember that these paths are dynamic.\n + `reset_settings (bool, optional)`: Option to reset the episode setting to default values, set to false to keep the current settings. + This is useful to keep sync mode when changing map and to keep deterministic scenarios. + Defaults to True.\n + `map_layers (MapLayer, optional)`: Layers of the map that will be loaded. This parameter works like a flag mask. + Defaults to MapLayer.All.\n + + Returns: + None + """ + + def replay_file(self, name: str, start: float, duration: float, follow_id: int, replay_sensors: bool): + """Load a new world with default settings using `map_name` map. All actors present in the current world will be destroyed, but traffic manager instances will stay alive. + + Args: + `name (str)`: Name of the file containing the information of the simulation.\n + `start (float - seconds)`: Time where to start playing the simulation. Negative is read as beginning from the end, being -10 just 10 seconds before the recording finished.\n + `duration (float - seconds)`: Time that will be reenacted using the information `name` file. If the end is reached, the simulation will continue.\n + `follow_id (int)`: ID of the actor to follow. If this is 0 then camera is disabled.\n + `replay_sensors (bool)`: Flag to enable or disable the spawn of sensors during playback.\n + """ + + def request_file(self, name: str): + """Requests one of the required files returned by `carla.Client.get_required_files`. + + Args: + `name (str)`: Name of the file you are requesting.\n + """ + + def show_recorder_actors_blocked(self, filename: str, min_time: float, min_distance: float) -> str: + """The terminal will show the information registered for actors considered blocked. An actor is considered blocked when it does not move a minimum distance in a period of time, being these `min_distance` and `min_time`. + + Args: + `filename (str)`: Name of the recorded file to load.\n + `min_time (float - seconds)`: Minimum time the actor has to move a minimum distance before being considered blocked. Default is 60 seconds.\n + `min_distance (float - centimeters)`: Minimum distance the actor has to move to not be considered blocked. Default is 100 centimeters.\n + + Returns: + `str`\n + """ + + def show_recorder_collisions(self, filename: str, category1: str, category2: str) -> str: + """The terminal will show the collisions registered by the recorder. These can be filtered by specifying the type of actor involved. The categories will be specified in `category1` and `category2` as follows: 'h' = Hero, the one vehicle that can be controlled manually or managed by the user. 'v' = Vehicle 'w' = Walker 't' = Traffic light 'o' = Other 'a' = Any If you want to see only collisions between a vehicles and a walkers, use for `category1` as 'v' and `category2` as 'w' or vice versa. If you want to see all the collisions (filter off) you can use 'a' for both parameters. + + Args: + `filename (str)`: Name or absolute path of the file recorded, depending on your previous choice.\n + `category1 (str)`: Character variable specifying a first type of actor involved in the collision.\n + `category2 (str)`: Character variable specifying the second type of actor involved in the collision.\n + + Returns: + `str`\n + """ + + def show_recorder_file_info(self, filename: str, show_all: bool) -> str: + """The information saved by the recorder will be parsed and shown in your terminal as text (frames, times, events, state, positions...). The information shown can be specified by using the `show_all` parameter. Here is some more information about how to read the recorder file. + + https://carla.readthedocs.io/en/latest/ref_recorder_binary_file_format/ + + Args: + `filename (str)`: Name or absolute path of the file recorded, depending on your previous choice.\n + `show_all (bool)`: If `True`, returns all the information stored for every frame (traffic light states, positions of all actors, orientation and animation data...). If `False`, returns a summary of key events and frames.\n + + Returns: + `str`\n + """ + + def start_recorder(self, filename: str, additional_data=False): + """Enables the recording feature, which will start saving every information possible needed by the server to replay the simulation. + + Args: + `filename (str)`: Name of the file to write the recorded data. A simple name will save the recording in 'CarlaUE4/Saved/recording.log'. Otherwise, if some folder appears in the name, it will be considered an absolute path.\n + `additional_data (bool, optional)`: Enables or disable recording non-essential data for reproducing the simulation (bounding box location, physics control parameters, etc). Defaults to False.\n + """ + + def stop_recorder(self): + """Stops the recording in progress. If you specified a path in `filename`, the recording will be there. If not, look inside `CarlaUE4/Saved/`.""" + + def stop_replayer(self, keep_actors: bool): + """Stop current replayer. + + Args: + `keep_actors (bool)`: `True` if you want autoremove all actors from the replayer, or `False` to keep them.\n + """ + # endregion + + # region Getters + def get_available_maps(self) -> list[str]: + """Returns a list of strings containing the paths of the maps available on server. These paths are dynamic, they will be created during the simulation and so you will not find them when looking up in your files. One of the possible returns for this method would be: + + >>> ['/Game/Carla/Maps/Town01', '/Game/Carla/Maps/Town02', '/Game/Carla/Maps/Town03', '/Game/Carla/Maps/Town04', '/Game/Carla/Maps/Town05', '/Game/Carla/Maps/Town06', '/Game/Carla/Maps/Town07'] + """ + + def get_client_version(self) -> str: + """Returns the client libcarla version by consulting it in the "Version.h" file. Both client and server can use different libcarla versions but some issues may arise regarding unexpected incompatibilities. + """ + + def get_required_files(self, folder: str, download=True): + """Asks the server which files are required by the client to use the current map. Option to download files automatically if they are not already in the cache. + + Args: + `folder (str)`: Folder where files required by the client will be downloaded to.\n + `download (bool, optional)`: If `True`, downloads files that are not already in cache.. Defaults to True.\n + """ + + def get_server_version(self) -> str: + """Returns the server libcarla version by consulting it in the "Version.h" file. Both client and server should use the same libcarla version. + """ + + def get_trafficmanager(self, client_connection=8000) -> TrafficManager: + """Returns an instance of the traffic manager related to the specified port. If it does not exist, this will be created. + + Args: + `client_connection (int, optional)`: Port that will be used by the traffic manager.. Defaults to 8000.\n + """ + + def get_world(self) -> World: + """Returns the world object currently active in the simulation. This world will be later used for example to load maps. + """ + # endregion + + # region Setters + def set_files_base_folder(self, path: str): + """Specifies the base folder where the local cache for required files will be placed. + + Args: + `path (str)`: Specifies the base folder where the local cache for required files will be placed.\n + """ + + def set_replayer_ignore_hero(self, ignore_hero: bool): + """Enables or disables playback of the hero vehicle during a playback of a recorded simulation. + + Args: + `ignore_hero (bool)`: Enables or disables playback of the hero vehicle during a playback of a recorded simulation.\n + """ + + def set_replayer_ignore_spectator(self, ignore_spectator: bool): + """Determines whether the recorded spectator movements will be replicated by the replayer. + + Args: + `ignore_spectator (bool)`: Determines whether the recorded spectator movements will be replicated by the replayer.\n + """ + + def set_replayer_time_factor(self, time_factor=1.0): + """When used, the time speed of the reenacted simulation is modified at will. It can be used several times while a playback is in curse. + + Args: + `time_factor (float, optional)`: 1.0 means normal time speed. Greater than 1.0 means fast motion (2.0 would be double speed) and lesser means slow motion (0.5 would be half speed). Defaults to 1.0.\n + """ + + def set_timeout(self, second: float): + """Sets the maximum time a network call is allowed before blocking it and raising a timeout exceeded error. + + Args: + `second (float - seconds)`: New timeout value. Default is 5 seconds.\n + """ + + # endregion + + +class CollisionEvent(SensorData): + """Class that defines a collision data for sensor.other.collision. The sensor creates one of these for every collision detected. Each collision sensor produces one collision event per collision per frame. Multiple collision events may be produced in a single frame by collisions with multiple other actors. Learn more about this here. + + https://carla.readthedocs.io/en/latest/ref_sensors/#collision-detector + """ + # region Instance Variables + @property + def actor(self) -> Actor: + """The actor the sensor is attached to, the one that measured the collision.""" + @property + def other_actor(self) -> Actor: + """The second actor involved in the collision.""" + @property + def normal_impulse(self) -> Vector3D: + """Normal impulse resulting of the collision.(N*s)""" + # endregion + + +class Color(): + """Class that defines a 32-bit RGBA color.""" + + # region Instance Variables + @property + def r(self) -> int: + """Red color (0-255).""" + @property + def g(self) -> int: + """Green color (0-255).""" + @property + def b(self) -> int: + """Blue color (0-255).""" + @property + def a(self) -> int: + """Alpha channel (0-255).""" + # endregion + + # region Methods + def __init__(self, r=0, g=0, b=0, a=255): + """Initializes a color, black by default. + + Args: + `r (int, optional)`: Red color (0-255). Defaults to 0.\n + `g (int, optional)`: Green color (0-255). Defaults to 0.\n + `b (int, optional)`: Blue color (0-255). Defaults to 0.\n + `a (int, optional)`: Alpha channel (0-255). Defaults to 255.\n + """ + # endregion + + # region Dunder Methods + def __eq__(self, __value: Color) -> bool: ... + def __ne__(self, __value: Color) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class ColorConverter(int, __CarlaEnum): + """ + Class that defines conversion patterns that can be applied to a `carla.Image` in order to show + information provided by `carla.Sensor`. Depth conversions cause a loss of accuracy, as sensors + detect depth as float that is then converted to a grayscale value between 0 and 255. Take a look + at the snippet in `carla.Sensor.listen` to see an example of how to create and save image data + for `sensor.camera.semantic_segmentation`. + """ + + # region Instance Variables + Raw = 0 + """No changes applied to the image. Used by the `RGB camera`.""" + Depth = 1 + """Converts the image to a linear depth map. Used by the `depth camera`.""" + LogarithmicDepth = 2 + """Converts the image to a depth map using a logarithmic scale, leading to better precision for small distances at the expense of losing it when further away.""" + CityScapesPalette = 3 + """Converts the image to a segmented map using tags provided by the blueprint library. Used by the `semantic segmentation camera`.""" + # endregion + + +class DVSEvent(): + """Class that defines a DVS event. An event is a quadruple, so a tuple of 4 elements, with `x`, `y` pixel coordinate location, timestamp `t` and polarity `pol` of the event. Learn more about them here. + + https://carla.readthedocs.io/en/latest/ref_sensors/ + """ + + # region Instance Variables + @property + def x(self) -> int: + """X pixel coordinate.""" + @property + def y(self) -> int: + """Y pixel coordinate.""" + @property + def t(self) -> int: + """Timestamp of the moment the event happened.""" + @property + def pol(self) -> bool: + """Polarity of the event. True for positive and False for negative.""" + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class DVSEventArray(): + """ + Class that defines a stream of events in `carla.DVSEvent`. Such stream is an array of arbitrary + size depending on the number of events. This class also stores the field of view, the height and + width of the image and the timestamp from convenience. Learn more about them here. + + https://carla.readthedocs.io/en/latest/ref_sensors/ + """ + + # region Instance Variables + @property + def fov(self) -> float: + """Horizontal field of view of the image.""" + @property + def height(self) -> int: + """Image height in pixels.""" + @property + def width(self) -> int: + """Image width in pixels.""" + @property + def raw_data(self) -> bytes: ... + # endregion + + # region Methods + def to_array(self) -> Iterable: + """Converts the stream of events to an array of int values in the following order `[x, y, t, pol]`.""" + + def to_array_pol(self) -> Iterable: + """Returns an array with the polarity of all the events in the stream.""" + + def to_array_t(self) -> Iterable: + """Returns an array with the timestamp of all the events in the stream.""" + + def to_array_x(self) -> Iterable: + """Returns an array with X pixel coordinate of all the events in the stream.""" + + def to_array_y(self) -> Iterable: + """Returns an array with Y pixel coordinate of all the events in the stream.""" + + def to_image(self) -> Image: + """Converts the image following this pattern: blue indicates positive events, red indicates negative events.""" + # endregion + + # region Dunder Methods + def __getitem__(self, pos: int): ... + + def __iter__(self) -> Iterator[DVSEvent]: + """Iterate over the `carla.DVSEvent` retrieved as data.""" + + def __len__(self): ... + def __setitem(self, pos: int, color: Color): ... + def __str__(self) -> str: ... + # endregion + + +class DebugHelper(): + """ + Helper class part of `carla.World` that defines methods for creating debug shapes. By default, + shapes last one second. They can be permanent, but take into account the resources needed to do + so. Take a look at the snippets available for this class to learn how to debug easily in CARLA. + """ + + # region Methods + def draw_arrow(self, begin: Location, end: Location, thickness=0.1, arrow_size=0.1, color: Color =Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws an arrow from `begin` to `end` pointing in that direction. + + Args: + begin (Location): Point in the coordinate system where the arrow starts (meters). + end (Location): Point in the coordinate system where the arrow ends and points towards to (meters). + thickness (float, optional): Density of the line (meters). Defaults to 0.1. + arrow_size (float, optional): Size of the tip of the arrow (meters). Defaults to 0.1. + color (Color, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes (seconds). Defaults to -1.0. + """ + ... + + def draw_hud_arrow(self, begin: Location, end: Location, thickness=0.1, arrow_size=0.1, color: Color =Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws an arrow on the HUD from `begin` to `end` which can only be seen server-side. + + Args: + begin (Location): Point in the coordinate system where the arrow starts (meters). + end (Location): Point in the coordinate system where the arrow ends and points towards to (meters). + thickness (float, optional): Density of the line (meters). Defaults to 0.1. + arrow_size (float, optional): Size of the tip of the arrow (meters). Defaults to 0.1. + color (Color, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes (seconds). Defaults to -1.0. + """ + + def draw_box(self, box: BoundingBox, rotation: Rotation, thickness=0.1, color: Color =Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """Draws a box, usually to act for object colliders. + + Args: + box (BoundingBox): Object containing a location and the length of a box for every axis. + rotation (Rotation): Orientation of the box according to Unreal Engine's axis system (degrees (pitch,yaw,roll)). + thickness (float, optional): Density of the lines that define the box (meters). Defaults to 0.1. + color (Color, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes. Defaults to -1.0. + """ + ... + + def draw_hud_box(self, box: BoundingBox, rotation: Rotation, thickness=0.1, color: Color =Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws a box on the HUD, usually to act for object colliders. The box can only be seen server-side. + + Args: + box (BoundingBox): Object containing a location and the length of a box for every axis. + rotation (Rotation): Orientation of the box according to Unreal Engine's axis system (degrees (pitch,yaw,roll)). + thickness (float, optional): Density of the lines that define the box (meters). Defaults to 0.1. + color (Color, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes. Defaults to -1.0. + """ + ... + + + def draw_line(self, begin: Location, end: Location, thickness=0.1, color: Color =Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws a line in between `begin` and `end`. + + Args: + begin (Location): Point in the coordinate system where the line starts (meters). + end (Location): Spot in the coordinate system where the line ends (meters). + thickness (float, optional): Density of the line. Defaults to 0.1. + color (Color, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes. Defaults to -1.0. + """ + ... + + def draw_hud_line(self, begin: Location, end: Location, thickness=0.1, color: Color =Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws a line on the HUD in between `begin` and `end`. The line can only be seen server-side. + + Args: + begin (Location): Point in the coordinate system where the line starts (meters). + end (Location): Spot in the coordinate system where the line ends (meters). + thickness (float, optional): Density of the line. Defaults to 0.1. + color (Color, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes. Defaults to -1.0. + """ + ... + + def draw_point(self, location: Location, size=0.1, color: Color=Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws a point location. + + Args: + location (Location): Spot in the coordinate system to center the object (meters). + size (float, optional): Density of the point (meters). Defaults to 0.1. + color (tuple, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to 0 for permanent shapes (seconds). Defaults to -1.0. + """ + ... + + def draw_hud_point(self, location: Location, size=0.1, color: Color=Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """ + Draws a point on the HUD at `location`. The point can only be seen server-side. + + Args: + location (Location): Spot in the coordinate system to center the object (meters). + size (float, optional): Density of the point (meters). Defaults to 0.1. + color (tuple, optional): RGB code to color the object. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to 0 for permanent shapes (seconds). Defaults to -1.0. + """ + ... + + def draw_string(self, location: Location, text: str, draw_shadow=False, color: Color = Color(255, 0, 0), life_time=-1.0, persistent_lines=True) -> None: + """Draws a string in a given location of the simulation which can only be seen server-side. + + Args: + location (Location): Spot in the simulation where the text will be centered (meters). + text (str): Text intended to be shown in the world. + draw_shadow (bool, optional): Casts a shadow for the string that could help in visualization. It is disabled by default. Defaults to False. + color (Color, optional): RGB code to color the string. Defaults to (255,0,0). + life_time (float, optional): Shape's lifespan. By default it only lasts one frame. Set this to `0` for permanent shapes (seconds). Defaults to -1.0. + """ + ... + # endregion + + +class EnvironmentObject(): + """Class that represents a geometry in the level, this geometry could be part of an actor formed with other EnvironmentObjects (i.e.: buildings).""" + + # region Instance Variables + @property + def transform(self) -> Transform: + """Contains the location and orientation of the EnvironmentObject in world space.""" + ... + + @property + def bounding_box(self) -> BoundingBox: + """Object containing a location, rotation and the length of a box for every axis in world space.""" + ... + + @property + def id(self) -> int: + """Unique ID to identify the object in the level.""" + ... + + @property + def name(self) -> str: + """Name of the EnvironmentObject.""" + ... + + @property + def type(self) -> CityObjectLabel: + """Semantic tag.""" + ... + # endregion + + # region Dunder Methods + def __str__(self) -> str: + """Parses the EnvironmentObject to a string and shows them in command line.""" + ... + # endregion + + +class FloatColor(): + """Class that defines a float RGBA color.""" + + # region Instance Variables + @property + def r(self) -> float: + """Red color.""" + ... + + @property + def g(self) -> float: + """Green color.""" + ... + + @property + def b(self) -> float: + """Blue color.""" + ... + + @property + def a(self) -> float: + """Alpha channel.""" + ... + # endregion + + # region Methods + def __init__(self, r=.0, g=.0, b=.0, a=1.0): + """Initializes a color, black by default. + + Args: + r (float, optional): Red color. Defaults to .0. + g (float, optional): Green color. Defaults to .0. + b (float, optional): Blue color. Defaults to .0. + a (float, optional): Alpha channel. Defaults to 1.0. + """ + ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: FloatColor) -> bool: ... + def __ne__(self, __value: FloatColor) -> bool: ... + # endregion + + +class GBufferTextureID(int, __CarlaEnum): + """Defines the identifiers of each GBuffer texture (See the method `carla.Sensor.listen_to_gbuffer`).""" + + # region Instance Variables + SceneColor = 0 + """The texture "SceneColor" contains the final color of the image.""" + SceneDepth = 1 + """The texture "SceneDepth" contains the depth buffer - linear in world units.""" + SceneStencil = 2 + """The texture "SceneStencil" contains the stencil buffer.""" + GBufferA = 3 + """The texture "GBufferA" contains the world-space normal vectors in the RGB channels. The alpha channel contains "per-object data".""" + GBufferB = 4 + """The texture "GBufferB" contains the metallic, specular and roughness in the RGB channels, respectively. The alpha channel contains a mask where the lower 4 bits indicate the shading model and the upper 4 bits contain the selective output mask.""" + GBufferC = 5 + """The texture "GBufferC" contains the diffuse color in the RGB channels, with the indirect irradiance in the alpha channel. + + If static lightning is not allowed, the alpha channel will contain the ambient occlusion instead.""" + GBufferD = 6 + """ + The contents of the "GBufferD" varies depending on the rendered object's material shading model (GBufferB): + MSM_Subsurface (2), MSM_PreintegratedSkin (3), MSM_TwoSidedFoliage (6): + RGB: Subsurface color. + A: Opacity. + MSM_ClearCoat (4): + R: Clear coat. + G: Roughness. + MSM_SubsurfaceProfile (5): + RGB: Subsurface profile. + MSM_Hair (7): + RG: World normal. + B: Backlit value. + MSM_Cloth (8): + RGB: Subsurface color. + A: Cloth value. + MSM_Eye (9): + RG: Eye tangent. + B: Iris mask. + A: Iris distance. + """ + GBufferE = 7 + """The texture "GBufferE" contains the precomputed shadow factors in the RGBA channels. This texture is unavailable if the selective output mask (GBufferB) does not have its 4th bit set.""" + GBufferF = 8 + """The texture "GBufferF" contains the world-space tangent in the RGB channels and the anisotropy in the alpha channel. This texture is unavailable if the selective output mask (GBufferB) does not have its 5th bit set.""" + Velocity = 9 + """The texture "Velocity" contains the screen-space velocity of the scene objects.""" + SSAO = 10 + """The texture "SSAO" contains the screen-space ambient occlusion texture.""" + CustomDepth = 11 + """The texture "CustomDepth" contains the Unreal Engine custom depth data.""" + CustomStencil = 12 + """The texture "CustomStencil" contains the Unreal Engine custom stencil data.""" + # endregion + + +class GearPhysicsControl(): + """Class that provides access to vehicle transmission details by defining a gear and when to run on it. This will be later used by `carla.VehiclePhysicsControl` to help simulate physics. + """ + + # region Instance Variables + @property + def ratio(self) -> float: + """The transmission ratio of the gear.""" + ... + + @property + def down_ratio(self) -> float: + """Quotient between current RPM and MaxRPM where the autonomous gear box should shift down.""" + + @property + def up_ratio(self) -> float: + """Quotient between current RPM and MaxRPM where the autonomous gear box should shift up.""" + # endregion + + # region Methods + def __init__(self, ratio=1.0, down_ratio=0.5, up_ratio=0.65): + """Class that provides access to vehicle transmission details by defining a gear and when to run on it. This will be later used by `carla.VehiclePhysicsControl` to help simulate physics. + + Args: + `ratio (float, optional)`: The transmission ratio of the gear. Defaults to 1.0.\n + `down_ratio (float, optional)`: Quotient between current RPM and MaxRPM where the autonomous gear box should shift down. Defaults to 0.5.\n + `up_ratio (float, optional)`: Quotient between current RPM and MaxRPM where the autonomous gear box should shift up. Defaults to 0.65.\n + """ + ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: GearPhysicsControl) -> bool: ... + def __ne__(self, __value: GearPhysicsControl) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class GeoLocation(): + """Class that contains geographical coordinates simulated data. The `carla.Map` can convert simulation locations by using the tag in the OpenDRIVE file.""" + + # region Instance Variables + @property + def latitude(self) -> float: + """North/South value of a point on the map (degrees).""" + ... + + @property + def longitude(self) -> float: + """West/East value of a point on the map (degrees).""" + ... + + @property + def altitude(self) -> float: + """Height regarding ground level (meters).""" + ... + # endregion + + # region Methods + def __init__(self, latitude=0.0, longitude=0.0, altitude=0.0): + """Class that contains geographical coordinates simulated data. The `carla.Map` can convert simulation locations by using the tag in the OpenDRIVE file. + + Args: + `latitude (float, optional)`: North/South value of a point on the map (degrees). Defaults to 0.0.\n + `longitude (float, optional)`: West/East value of a point on the map (degrees). Defaults to 0.0.\n + `altitude (float, optional)`: Height regarding ground level (meters). Defaults to 0.0.\n + """ + ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: GeoLocation) -> bool: ... + def __ne__(self, __value: GeoLocation) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class GnssMeasurement(SensorData): + """Class that defines the Gnss data registered by a `sensor.other.gnss`. It essentially reports its position with the position of the sensor and an OpenDRIVE geo-reference.""" + + # region Instance Variables + @property + def altitude(self) -> float: + """Height regarding ground level (meters).""" + ... + + @property + def latitude(self) -> float: + """North/South value of a point on the map (degrees).""" + ... + + @property + def longitude(self) -> float: + """West/East value of a point on the map (degrees).""" + ... + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class IMUMeasurement(SensorData): + """Class that defines the data registered by a `sensor.other.imu`, regarding the sensor's transformation according to the current `carla.World`. It essentially acts as accelerometer, gyroscope and compass.""" + + # region Instance Variables + @property + def accelerometer(self) -> Vector3D: + """Linear acceleration (m/s2).""" + ... + + @property + def compass(self) -> float: + """Orientation with regard to the North ([0.0, -1.0, 0.0] in Unreal Engine) (radians).""" + ... + + @property + def gyroscope(self) -> Vector3D: + """Angular velocity. (rad/s)""" + ... + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class Image(SensorData): + """Class that defines an image of 32-bit BGRA colors that will be used as initial data retrieved by camera sensors. There are different camera sensors (currently three, RGB, depth and semantic segmentation) and each of these makes different use for the images. Learn more about them here. + + https://carla.readthedocs.io/en/latest/ref_sensors/""" + + # region Instance Variables + @property + def fov(self) -> float: + """Horizontal field of view of the image (degrees).""" + ... + + @property + def height(self) -> int: + """Image height in pixels.""" + ... + + @property + def width(self) -> int: + """Image width in pixels.""" + ... + + @property + def raw_data(self) -> bytes: + """Flattened array of pixel data, use reshape to create an image array.""" + ... + # endregion + + # region Methods + def convert(self, color_converter: ColorConverter): + """Converts the image following the `color_converter` pattern. + + Args: + `color_converter (ColorConverter)`\n + """ + + def save_to_disk(self, path: str, color_converter=ColorConverter.Raw): + """Saves the image to disk using a converter pattern stated as `color_converter`. The default conversion pattern is `Raw` that will make no changes to the image. + + Args: + `path (str)`:Path that will contain the image.\n + `color_converter (ColorConverter, optional)`: Default Raw will make no changes. Defaults to ColorConverter.Raw.\n + """ + # endregion + + # region Dunder Methods + def __getitem__(self, pos=int) -> Color: ... + + def __iter__(self) -> Iterator[Color]: + """Iterate over the `carla.Color` that form the image.""" + ... + + def __len__(self) -> int: ... + def __setitem__(self, pos: int, color: Color): ... + def __str__(self) -> str: ... + # endregion + + +class Junction(): + """Class that embodies the intersections on the road described in the OpenDRIVE file according to OpenDRIVE 1.4 standards.""" + + # region Instance Variables + @property + def id(self) -> int: + """Identifier found in the OpenDRIVE file.""" + ... + + @property + def bounding_box(self) -> BoundingBox: + """Bounding box encapsulating the junction lanes.""" + ... + # endregion + + # region Getters + def get_waypoints(self, lane_type: LaneType) -> list[tuple[Waypoint, Waypoint]]: + """Returns a list of pairs of waypoints. Every tuple on the list contains first an initial and then a final waypoint within the intersection boundaries that describe the beginning and the end of said lane along the junction. Lanes follow their OpenDRIVE definitions so there may be many different tuples with the same starting waypoint due to possible deviations, as this are considered different lanes. + + Args: + lane_type (LaneType): Type of lanes to get the waypoints. + + Returns: + list[tuple[Waypoint, Waypoint]] + """ + # endregion + + +class LabelledPoint(): + """Class that represent a position in space with a semantic label.""" + + # region Instance Variables + @property + def location(self) -> Location: + """Position in 3D space.""" + ... + + @property + def label(self) -> CityObjectLabel: + """Semantic tag of the point.""" + ... + # endregion + + +class Landmark(): + """Class that defines any type of traffic landmark or sign affecting a road. These class mediates between the OpenDRIVE 1.4 standard definition of the landmarks and their representation in the simulation. This class retrieves all the information defining a landmark in OpenDRIVE and facilitates information about which lanes does it affect and when. Landmarks will be accessed by `carla.Waypoint objects` trying to retrieve the regulation of their lane. Therefore some attributes depend on the waypoint that is consulting the landmark and so, creating the object.""" + + # region Instance Variables + @property + def road_id(self) -> int: + """The OpenDRIVE ID of the road where this landmark is defined. Due to OpenDRIVE road definitions, this road may be different from the road the landmark is currently affecting. It is mostly the case in junctions where the road diverges in different routes. + + Example: a traffic light is defined in one of the divergent roads in a junction, but it affects all the possible routes.""" + ... + + @property + def distance(self) -> float: + """Distance between the landmark and the waypoint creating the object (querying `get_landmarks` or `get_landmarks_of_type`) (meters).""" + ... + + @property + def s(self) -> float: + """Distance where the landmark is positioned along the geometry of the road `road_id` (meters).""" + ... + + @property + def t(self) -> float: + """Lateral distance where the landmark is positioned from the edge of the road `road_id` (meters).""" + ... + + @property + def id(self) -> str: + """Unique ID of the landmark in the OpenDRIVE file.""" + ... + + @property + def name(self) -> str: + """Name of the landmark in the in the OpenDRIVE file.""" + ... + + @property + def is_dynamic(self) -> bool: + """Indicates if the landmark has state changes over time such as traffic lights.""" + ... + + @property + def orientation(self) -> LandmarkOrientation: + """Indicates which lanes the landmark is facing towards to (degrees).""" + ... + + @property + def z_offset(self) -> float: + """Height where the landmark is placed (meters).""" + ... + + @property + def country(self) -> str: + """Country code where the landmark is defined (default to OpenDRIVE is Germany 2017).""" + ... + + @property + def type(self) -> str: + """Type identifier of the landmark according to the country code.""" + ... + + @property + def sub_type(self) -> str: + """Subtype identifier of the landmark according to the country code.""" + + @property + def value(self) -> float: + """Value printed in the signal (e.g. speed limit, maximum weight, etc).""" + + @property + def unit(self) -> str: + """Units of measurement for the attribute `value`.""" + ... + + @property + def height(self) -> float: + """Total height of the signal (meters).""" + + @property + def width(self) -> float: + """Total width of the signal (meters).""" + + @property + def text(self) -> str: + """Additional text in the signal.""" + + @property + def h_offset(self) -> float: + """Orientation offset of the signal relative to the the definition of `road_id` at `s` in OpenDRIVE (meters).""" + ... + + @property + def pitch(self) -> float: + """Pitch rotation of the signal (Y-axis in UE coordinates system) (meters).""" + + @property + def roll(self) -> float: + """Roll rotation of the signal (X-axis in UE coordinates system) (meters).""" + + @property + def waypoint(self) -> Waypoint: + """A waypoint placed in the lane of the one that made the query and at the `s` of the landmark. It is the first waypoint for which the landmark will be effective.""" + + @property + def transform(self) -> Transform: + """The location and orientation of the landmark in the simulation.""" + # endregion + + # region Getters + def get_lane_validities(self) -> list[tuple[int, int]]: + """Returns which lanes the landmark is affecting to. As there may be specific lanes where the landmark is not effective, the return is a list of pairs containing ranges of the `lane_id` affected: + + Example: In a road with 5 lanes, being 3 not affected: [(from_lane1,to_lane2),(from_lane4,to_lane5)].""" + # endregion + + +class LandmarkOrientation(int, __CarlaEnum): + """Helper class to define the orientation of a landmark in the road. The definition is not directly translated from OpenDRIVE but converted for the sake of understanding.""" + + # region Instance Variables + Positive = 0 + """The landmark faces towards vehicles going on the same direction as the road's geometry definition (lanes 0 and negative in OpenDRIVE).""" + Negative = 1 + """The landmark faces towards vehicles going on the opposite direction to the road's geometry definition (positive lanes in OpenDRIVE).""" + Both = 2 + """Affects vehicles going in both directions of the road.""" + # endregion + + +class LandmarkType(Enum): + """Helper class containing a set of commonly used landmark types as defined by the default country code in the OpenDRIVE standard (Germany 2017). `carla.Landmark` does not reference this class. The landmark type is a string that varies greatly depending on the country code being used. This class only makes it easier to manage some of the most commonly used in the default set by describing them as an enum.""" + + # NOTE: Has no attributes for `values` and `names` + + # region Instance Variables + Danger = "101", + LanesMerging = "121", + CautionPedestrian = "133", + CautionBicycle = "138" + LevelCrossing = "150", + StopSign = "206", + YieldSign = "205", + MandatoryTurnDirection = "209", + MandatoryLeftRightDirection = "211", + TwoChoiceTurnDirection = "214", + Roundabout = "215", + PassRightLeft = "222", + AccessForbidden = "250", + AccessForbiddenMotorvehicles = "251", + AccessForbiddenTrucks = "253", + AccessForbiddenBicycle = "254", + AccessForbiddenWeight = "263", + AccessForbiddenWidth = "264", + AccessForbiddenHeight = "265", + AccessForbiddenWrongDirection = "267", + ForbiddenUTurn = "272", + MaximumSpeed = "274", + ForbiddenOvertakingMotorvehicles = "276", + ForbiddenOvertakingTrucks = "277", + AbsoluteNoStop = "283", + RestrictedStop = "286", + HasWayNextIntersection = "301", + PriorityWay = "306", + PriorityWayEnd = "307", + CityBegin = "310", + CityEnd = "311", + Highway = "330", + DeadEnd = "357", + RecomendedSpeed = "380", # NOTE: Wrong Spelling, but is named like this internally! + RecomendedSpeedEnd = "381", # NOTE: Wrong Spelling, but is named like this internally! + # endregion + + +class LaneChange(IntFlag, __CarlaEnum): + """Class that defines the permission to turn either left, right, both or none (meaning only going straight is allowed). This information is stored for every `carla.Waypoint` according to the OpenDRIVE file. The snippet in `carla.Map.get_waypoint` shows how a waypoint can be used to learn which turns are permitted.""" + + # region Instance Variables + NONE = 0 + """Traffic rules do not allow turning right or left, only going straight.""" + Right = 1 + """Traffic rules allow turning right.""" + Left = 2 + """Traffic rules allow turning left.""" + Both = 3 + """Traffic rules allow turning either right or left.""" + # endregion + + +class LaneInvasionEvent(SensorData): + """Class that defines lanes invasion for `sensor.other.lane_invasion`. It works only client-side and is dependant on OpenDRIVE to provide reliable information. The sensor creates one of this every time there is a lane invasion, which may be more than once per simulation step. Learn more about this here. + + https://carla.readthedocs.io/en/latest/ref_sensors/#lane-invasion-detector + """ + + # region Instance Variables + @property + def actor(self) -> Actor: + """Gets the actor the sensor is attached to, the one that invaded another lane.""" + + @property + def crossed_lane_markings(self) -> list[LaneMarking]: + """List of lane markings that have been crossed and detected by the sensor.""" + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class LaneMarking(): + """Class that gathers all the information regarding a lane marking according to OpenDRIVE 1.4 standard standard.""" + + # region Instance Variables + @property + def color(self) -> LaneMarkingColor: + """Actual color of the marking.""" + + @property + def lane_change(self) -> LaneChange: + """Permissions for said lane marking to be crossed.""" + + @property + def type(self) -> LaneMarkingType: + """Lane marking type.""" + + @property + def width(self) -> float: + """Horizontal lane marking thickness.""" + # endregion + + +class LaneMarkingColor(int, __CarlaEnum): + """Class that defines the lane marking colors according to OpenDRIVE 1.4.""" + + # region Instance Variables + White = 0 + Standard = 0 + """White by default.""" + Blue = 1 + Green = 2 + Red = 3 + Yellow = 4 + Other = 5 + # endregion + + +class LaneMarkingType(int, __CarlaEnum): + """Class that defines the lane marking types accepted by OpenDRIVE 1.4. The snippet in `carla.Map.get_waypoint` shows how a waypoint can be used to retrieve the information about adjacent lane markings. + + + Note on double types: Lane markings are defined under the OpenDRIVE standard that determines whereas a line will be considered "BrokenSolid" or "SolidBroken". For each road there is a center lane marking, defined from left to right regarding the lane's directions. The rest of the lane markings are defined in order from the center lane to the closest outside of the road. + """ + + # region Instance Variables + Other = 0 + Broken = 1 + Solid = 2 + SolidSolid = 3 + SolidBroken = 4 + BrokenSolid = 5 + BrokenBroken = 6 + BottsDots = 7 + Grass = 8 + Curb = 9 + NONE = 0 + # endregion + + +class LaneType(IntFlag, __CarlaEnum): + """ + Class that defines the possible lane types accepted by OpenDRIVE 1.4. + This standards define the road information. The snippet in `carla.Map.get_waypoint` + makes use of a waypoint to get the current and adjacent lane types. + """ + + # region Instance Variables + Any = -2 + NONE = 1 + """Every type except for `NONE`.""" + Driving = 2 + Stop = 4 + Shoulder = 8 + Biking = 16 + Sidewalk = 32 + Border = 64 + Restricted = 128 + Parking = 256 + Bidirectional = 512 + Median = 1024 + Special1 = 2048 + Special2 = 4096 + Special3 = 8192 + RoadWorks = 16384 + Tram = 32768 + Rail = 65536 + Entry = 131072 + Exit = 262144 + OffRamp = 524288 + OnRamp = 1048576 + # endregion + + +class LidarDetection(): + """Data contained inside a `carla.LidarMeasurement`. Each of these represents one of the points in the cloud with its location and its associated intensity.""" + # region Instance Variables + @property + def point(self) -> Location: + """Point in xyz coordinates (meters).""" + @property + def intensity(self) -> float: + """Computed intensity for this point as a scalar value between [0.0 , 1.0].""" + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class LidarMeasurement(SensorData): + """Class that defines the LIDAR data retrieved by a `sensor.lidar.ray_cast`. This essentially simulates a rotating LIDAR using ray-casting. Learn more about this here. + + https://carla.readthedocs.io/en/latest/ref_sensors/#lidar-raycast-sensor + """ + # region Instance Variables + @property + def channels(self) -> int: + """Number of lasers shot.""" + + @property + def horizontal_angle(self) -> float: + """Horizontal angle the LIDAR is rotated at the time of the measurement (radians).""" + + @property + def raw_data(self) -> bytes: + """Received list of 4D points. Each point consists of [x,y,z] coordinates plus the intensity computed for that point.""" + # endregion + + # region Methods + def save_to_disk(self, path: str): + """Saves the point cloud to disk as a `.ply` file describing data from 3D scanners. The files generated are ready to be used within `MeshLab`, an open source system for processing said files. Just take into account that axis may differ from Unreal Engine and so, need to be reallocated. + + Args: + path (str) + """ + # endregion + + # region Getters + def get_point_count(self, channel: int): + """Retrieves the number of points sorted by channel that are generated by this measure. Sorting by channel allows to identify the original channel for every point. + + Args: + channel (int) + """ + # endregion + + # region Dunder Methods + def __getitem__(self, pos: int) -> LidarDetection: ... + + def __iter__(self) -> Iterator[LidarDetection]: + """Iterate over the carla.LidarDetection retrieved as data.""" + ... + + def __len__(self): ... + def __setitem__(self, pos: int, detection: LidarDetection): ... + def __str__(self) -> str: ... + # endregion + + +class Light(): + """This class exposes the lights that exist in the scene, except for vehicle lights. The properties of a light can be queried and changed at will. Lights are automatically turned on when the simulator enters night mode (sun altitude is below zero).""" + + # region Instance Variables + @property + def color(self) -> Color: + """Color of the light.""" + ... + + @property + def id(self) -> int: + """Identifier of the light.""" + ... + + @property + def intensity(self) -> float: + """Intensity of the light. (lumens)""" + + @property + def is_on(self) -> bool: + """Switch of the light. It is `True` when the light is on. When the night mode starts, this is set to `True`.""" + ... + + @property + def location(self) -> Location: + """Position of the light (meters).""" + ... + + @property + def light_group(self) -> LightGroup: + """Group the light belongs to.""" + + @property + def light_state(self) -> LightState: + """State of the light. Summarizes its attributes, group, and if it is on/off.""" + # endregion + + # region Methods + def turn_off(self): + """Switches off the light.""" + ... + + def turn_on(self): + """Switches on the light.""" + ... + # endregion + + # region Setters + def set_color(self, color: Color): + """Changes the color of the light to color. + + Args: + color (Color) + """ + ... + + def set_intensity(self, intensity: float): + """Changes the intensity of the light to `intensity`. + + Args: + intensity (float): (lumens) + """ + + def set_light_group(self, light_group: LightGroup): + """Changes the light to the group `light_group`. + + Args: + light_group (LightGroup) + """ + + def set_light_state(self, light_state: LightState): + """Changes the state of the light to `light_state`. This may change attributes, group and turn the light on/off all at once. + + + Args: + light_state (LightState) + """ + # endregion + + +class LightGroup(int, __CarlaEnum): + """This class categorizes the lights on scene into different groups. These groups available are provided as a enum values that can be used as flags. + + + Note. So far, though there is a `vehicle` group, vehicle lights are not available as `carla.Light` objects. These have to be managed using `carla.Vehicle` and `carla.VehicleLightState`.""" + + NONE = 0 + """All lights.""" + Vehicle = 1 + Street = 2 + Building = 3 + Other = 4 + + +class LightManager(): + """This class handles the lights in the scene. Its main use is to get and set the state of groups or lists of lights in one call. An instance of this class can be retrieved by the `carla.World.get_lightmanager()`. + + + Note. So far, though there is a `vehicle` group, vehicle lights are not available as `carla.Light` objects. These have to be managed using `carla.Vehicle` and `carla.VehicleLightState`. + """ + + # region Methods + def is_active(self, lights: list[Light]) -> list[bool]: + """Returns a list with booleans stating if the elements in `lights` are switched on/off. + + Args: + `lights (list[Light])`: List of lights to be queried.\n + + Returns: + `list[bool]`\n + """ + + def turn_off(self, lights: list[Light]): + """Switches off all the lights in `lights`. + + + Args: + `lights (list[Light])`: List of lights to be switched off.\n + """ + + def turn_on(self, lights: list[Light]): + """Switches on all the lights in `lights`. + + + Args: + `lights (list[Light])`: List of lights to be switched on.\n + """ + # endregion + + # region Getters + def get_all_lights(self, light_group: LightGroup = LightGroup.NONE) -> list[Light]: + """Returns a list containing the lights in a certain group. By default, the group is None. + + Args: + `light_group (LightGroup, optional)`: Group to filter the lights returned. Defaults to LightGroup.NONE.\n + """ + + def get_color(self, lights: list[Light]) -> list[Color]: + """Returns a list with the colors of every element in `lights`. + + + Setter: `carla.LightManager.set_color` + + Args: + `lights (list[Light])`: List of lights to be queried.\n + + Returns: + `list[Color]`: _description_\n + """ + + def get_intensity(self, lights: list[Light]) -> list[float]: + """Returns a list with the intensity of every element in `lights`. + + Args: + `lights (list[Light])`: List of lights to be queried.\n + + Returns: + `list[float]`: (lumens)\n + """ + + def get_light_group(self, lights: list[Light]) -> list[LightGroup]: + """Returns a list with the group of every element in `lights`. + + + Setter: `carla.LightManager.set_light_group` + + Args: + `lights (list[Light])`: List of lights to be queried.\n + """ + + def get_light_state(self, lights: list[Light]) -> list[LightState]: + """Returns a list with the state of all the attributes of every element in `lights`. + + + Setter: `carla.LightManager.set_light_state` + + Args: + `lights (list[Light])`: List of lights to be queried.\n + """ + + def get_turned_off_lights(self, light_group: LightGroup) -> list[Light]: + """Returns a list containing lights switched off in the scene, filtered by group. + + Args: + `light_group (LightGroup)`: List of lights to be queried.\n + """ + + def get_turned_on_lights(self, light_group: LightGroup) -> list[Light]: + """Returns a list containing lights switched on in the scene, filtered by group. + + Args: + `light_group (LightGroup)`: List of lights to be queried.\n + """ + # endregion + + # region Setters + def set_active(self, lights: list[Light], active: list[bool]): + """Switches on/off the elements in lights. + + Args: + `lights (list[Light])`: List of lights to be switched on/off.\n + `active (list[bool])`: List of booleans to be applied.\n + """ + + def set_color(self, lights: list[Light], color: Color): + """Changes the color of the elements in `lights` to `color`. + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `color (Color)`: Color to be applied.\n + """ + + def set_colors(self, lights: list[Light], colors: list[Color]): + """Changes the color of each element in lights to the corresponding in colors. + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `colors (list[Color])`: List of colors to be applied.\n + """ + + def set_day_night_cycle(self, active: bool): + """All scene lights have a day-night cycle, automatically turning on and off with the altitude of the sun. This interferes in cases where full control of the scene lights is required, so setting this to `False` deactivates it. It can reactivated by setting it to `True`. + + + Args: + `active (bool)`: (De)activation of the day-night cycle.\n + """ + + def set_intensities(self, lights: list[Light], intensities: list[float]): + """Changes the intensity of each element in lights to the corresponding in intensities. + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `intensities (list[float])`: Intensity to be applied (lumens).\n + """ + + def set_intensity(self, lights: list[Light], intensity: float): + """Changes the intensity of every element in `lights` to `intensity`. + + + Getter: `carla.LightManager.get_intensity` + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `intensity (float)`: Intensity to be applied.\n + """ + + def set_light_group(self, lights: list[Light], light_group: LightGroup): + """Changes the group of every element in `lights` to `light_group`. + + + Getter: carla.LightManager.get_light_group + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `light_group (LightGroup)`: Group to be applied.\n + """ + + def set_light_groups(self, lights: list[Light], light_groups: list[LightGroup]): + """Changes the group of each element in `lights` to the corresponding in `light_groups`. + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `light_groups (list[LightGroup])`: List of groups to be applied.\n + """ + + def set_light_state(self, lights: list[Light], light_state: LightState): + """Changes the state of the attributes of every element in lights to light_state. + + + Getter: `carla.LightManager.get_light_state` + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `light_state (LightState)`: State of the attributes to be applied.\n + """ + + def set_light_states(self, lights: list[Light], light_states: list[LightState]): + """Changes the state of the attributes of each element in lights to the corresponding in light_states. + + Args: + `lights (list[Light])`: List of lights to be changed.\n + `light_states (list[LightState])`: List of state of the attributes to be applied.\n + """ + # endregion + + +class LightState(): + """This class represents all the light variables except the identifier and the location, which are should to be static. Using this class allows to manage all the parametrization of the light in one call. + """ + + # region Instance Variables + @property + def intensity(self) -> float: + """Intensity of a light.""" + + @property + def color(self) -> Color: + """Color of a light.""" + + @property + def group(self) -> LightGroup: + """Group a light belongs to.""" + + @property + def active(self) -> bool: + """Switch of a light. It is `True` when the light is on.""" + # endregion + + # region Methods + def __init__(self, intensity=0.0, color=Color, group=LightGroup.NONE, active=False): + """This class represents all the light variables except the identifier and the location, which are should to be static. Using this class allows to manage all the parametrization of the light in one call. + + Args: + `intensity (float, optional)`: Intensity of a light (lumens). Defaults to 0.0.\n + `color (_type_, optional)`: Color of a light. Defaults to Color.\n + `group (_type_, optional)`: Group a light belongs to. Defaults to LightGroup.NONE.\n + `active (bool, optional)`: Switch of a light. It is True when the light is on. Defaults to False.\n + """ + # endregion + + +class Location(Vector3D): + """Represents a spot in the world.""" + # region Instance Variables + @property + def x(self) -> float: + """Distance from origin to spot on X axis (meter).""" + @property + def y(self) -> float: + """Distance from origin to spot on Y axis (meter).""" + @property + def z(self) -> float: + """Distance from origin to spot on Z axis. (meter)""" + # endregion + + # region Methods + @overload + def __init__(self, rhs: Vector3D): ... + + @overload + def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0): ... + + def __init__(self, x: float=0.0, y: float=0.0, z: float=0.0): + """Represents a spot in the world. + + Args: + `x (float, optional)`: Distance from origin to spot on X axis (meter). Defaults to 0.0.\n + `y (float, optional)`: Distance from origin to spot on Y axis (meter). Defaults to 0.0.\n + `z (float, optional)`: Distance from origin to spot on Z axis (meter). Defaults to 0.0.\n + """ + ... + + def distance(self, location: Location) -> float: + """Returns Euclidean distance from this location to another one. + + Args: + `location (Location)`: The other point to compute the distance with.\n + + Returns: + `float`: (meters)\n + """ + # endregion + + # region Dunder Methods + def __abs__(self) -> Location: + """Returns a Location with the absolute value of the components x, y and z.""" + + def __eq__(self, __value: Location) -> bool: + """Returns `True` if both locations are the same point in space.""" + ... + + def __ne__(self, __value: object) -> bool: + """Returns `True` if both locations are different points in space.""" + ... + + def __str__(self) -> str: + """Parses the axis' values to string.""" + ... + # endregion + pass + + +class Map(): + """Class containing the road information and waypoint managing. Data is retrieved from an OpenDRIVE file that describes the road. A query system is defined which works hand in hand with `carla.Waypoint` to translate geometrical information from the .xodr to natural world points. CARLA is currently working with OpenDRIVE 1.4 standard.""" + + # region Instance Variables + @property + def name(self) -> str: + """The name of the map. It corresponds to the .umap from Unreal Engine that is loaded from a CARLA server, which then references to the .xodr road description.""" + # endregion + + # region Methods + def __init__(self, name: str, xodr_content: str): + """Constructor for this class. Though a map is automatically generated when initializing the world, using this method in no-rendering mode facilitates working with an .xodr without any CARLA server running. + + Args: + `name (str)`: Name of the current map.\n + `xodr_content (str)`: xodr content in string format.\n + """ + ... + + def cook_in_memory_map(self, path: str): + """Generates a binary file from the CARLA map containing information used by the Traffic Manager. This method is only used during the import process for maps. + + Args: + `path (str)`: Path to the intended location of the stored binary map file.\n + """ + + def generate_waypoints(self, distance: float) -> list[Waypoint]: + """Returns a list of waypoints with a certain distance between them for every lane and centered inside of it. Waypoints are not listed in any particular order. Remember that waypoints closer than 2cm within the same road, section and lane will have the same identificator. + + Args: + `distance (float)`: Approximate distance between waypoints (meters).\n + + Returns: + `list[Waypoint]`\n + """ + + def save_to_disk(self, path: str): + """Saves the .xodr OpenDRIVE file of the current map to disk. + + Args: + `path (str)`: Path where the file will be saved.\n + """ + ... + + def to_opendrive(self) -> str: + """Returns the .xodr OpenDRIVe file of the current map as string. + + Returns: + `str`\n + """ + + def transform_to_geolocation(self, location: Location) -> GeoLocation: + """Converts a given `location`, a point in the simulation, to a `carla.GeoLocation`, which represents world coordinates. The geographical location of the map is defined inside OpenDRIVE within the tag . + + + Args: + `location (Location)`\n + + Returns: + `GeoLocation`\n + """ + ... + # endregion + + # region Getters + def get_all_landmarks(self) -> list[Landmark]: + """Returns all the landmarks in the map. Landmarks retrieved using this method have a `null` waypoint.""" + ... + + def get_all_landmarks_from_id(self, opendrive_id: str) -> list[Landmark]: + """Returns the landmarks with a certain OpenDRIVE ID. Landmarks retrieved using this method have a `null` waypoint. + + Args: + `opendrive_id (str)`: The OpenDRIVE ID of the landmarks.\n + """ + ... + + def get_all_landmarks_of_type(self, type: Union[str, LandmarkType]) -> list[Landmark]: + """Returns the landmarks of a specific type. Landmarks retrieved using this method have a null waypoint. + + Args: + `type (str)`: The type of the landmarks.\n + """ + ... + + def get_crosswalks(self) -> list[Location]: + """Returns a list of locations with all crosswalk zones in the form of closed polygons. The first point is repeated, symbolizing where the polygon begins and ends. + """ + ... + + def get_landmark_group(self, landmark: Landmark) -> list[Landmark]: + """Returns the landmarks in the same group as the specified landmark (including itself). Returns an empty list if the landmark does not belong to any group. + + Args: + `landmark (Landmark)`: A landmark that belongs to the group.\n + """ + ... + + def get_spawn_points(self) -> list[Transform]: + """Returns a list of recommendations made by the creators of the map to be used as spawning points for the vehicles. The list includes carla.Transform objects with certain location and orientation. Said locations are slightly on-air in order to avoid Z-collisions, so vehicles fall for a bit before starting their way. + """ + ... + + def get_topology(self) -> list[tuple[Waypoint, Waypoint]]: + """Returns a list of tuples describing a minimal graph of the topology of the OpenDRIVE file. The tuples contain pairs of waypoints located either at the point a road begins or ends. The first one is the origin and the second one represents another road end that can be reached. This graph can be loaded into NetworkX to work with. + + Output could look like this: `[(w0, w1), (w0, w2), (w1, w3), (w2, w3), (w0, w4)]`. + """ + ... + + @overload + def get_waypoint(self, location: Location, project_to_road: Literal[True]=True, lane_type: Literal[LaneType.Driving, LaneType.Any]=LaneType.Driving) -> Waypoint: + ... + + @overload + def get_waypoint(self, location: Location, project_to_road :bool | None=True, lane_type: LaneType=LaneType.Driving) -> Waypoint | None: + ... + + def get_waypoint(self, location: Location, project_to_road: bool | None=True, lane_type: LaneType=LaneType.Driving) -> Waypoint | None: + """Returns a waypoint that can be located in an exact location or translated to the center of the nearest lane. Said lane type can be defined using flags such as `LaneType.Driving & LaneType.Shoulder`. + + The method will return `None` if the waypoint is not found, which may happen only when trying to retrieve a waypoint for an exact location. That eases checking if a point is inside a certain road, as otherwise, it will return the corresponding waypoint. + + Args: + `location (Location)`: Location used as reference for the carla.Waypoint (meters).\n + `project_to_road (bool, optional)`: If `True`, the waypoint will be at the center of the closest lane. If `False`, the waypoint will be exactly in location. `None` means said location does not belong to a road. Defaults to True.\n + `lane_type (_type_, optional)`: Limits the search for nearest lane to one or various lane types that can be flagged. Defaults to LaneType.Driving.\n + """ + ... + + def get_waypoint_xodr(self, road_id: int, lane_id: int, s: float) -> Waypoint | None: + """Returns a waypoint if all the parameters passed are correct. Otherwise, returns `None`. + + Args: + `road_id (int)`: ID of the road to get the waypoint.\n + `lane_id (int)`: ID of the lane to get the waypoint.\n + `s (float)`: Specify the length from the road start (meters).\n + """ + ... + # endregion + + +class MapLayer(Flag, __CarlaEnum): + """Class that represents each manageable layer of the map. Can be used as flags. + + + WARNING: Only "Opt" maps are able to work with map layers.""" + NONE = 0 + Buildings = 1 + Decals = 2 + Foliage = 4 + Ground = 8 + ParkedVehicles = 16 + Particles = 32 + Props = 64 + StreetLights = 128 + Walls = 256 + All = 65535 + """All layers selected.""" + + +class MaterialParameter(int, __CarlaEnum): + """Class that represents material parameters. Not all objects in the scene contain all parameters.""" + + # region Instance Variables + Normal = 0 + """The Normal map of the object. Present in all objects.""" + AO_Roughness_Metallic_Emissive = 1 + """A texture where each color channel represent a property of the material (R: Ambient occlusion, G: Roughness, B: Metallic, A: Emissive/Height map in some objects).""" + Diffuse = 2 + """The Diffuse texture of the object. Present in all objects.""" + Emissive = 3 + """Emissive texture. Present in a few objects.""" + # endregion + + +class ObstacleDetectionEvent(SensorData): + """Class that defines the obstacle data for `sensor.other.obstacle`. Learn more about this here. + + https://carla.readthedocs.io/en/latest/ref_sensors/#obstacle-detector + """ + # region Instance Variables + @property + def actor(self) -> Actor: + """The actor the sensor is attached to.""" + ... + + @property + def other_actor(self) -> Actor: + """The actor or object considered to be an obstacle.""" + ... + + @property + def distance(self) -> float: + """Distance between actor and other (meters).""" + ... + # endregion + + # region Dunder methods + def __str__(self) -> str: ... + # endregion + + +class OpendriveGenerationParameters(): + """This class defines the parameters used when generating a world using an OpenDRIVE file.""" + # region Instance Variables + @property + def vertex_distance(self) -> float: + """Distance between vertices of the mesh generated. Default is 2.0.""" + ... + + @property + def max_road_length(self) -> float: + """Max road length for a single mesh portion. The mesh of the map is divided into portions, in order to avoid propagating issues. Default is 50.0.""" + ... + + @property + def wall_height(self) -> float: + """Height of walls created on the boundaries of the road. These prevent vehicles from falling off the road. Default is 1.0.""" + ... + + @property + def additional_width(self) -> float: + """Additional with applied junction lanes. Complex situations tend to occur at junctions, and a little increase can prevent vehicles from falling off the road. Default is 0.6.""" + ... + + @property + def smooth_junctions(self) -> bool: + """If `True`, the mesh at junctions will be smoothed to prevent issues where roads blocked other roads. Default is `True`.""" + ... + + @property + def enable_mesh_visibility(self) -> bool: + """If `True`, the road mesh will be rendered. Setting this to False should reduce the rendering overhead. Default is True.""" + ... + + @property + def enable_pedestrian_navigation(self) -> bool: + """If `True`, Pedestrian navigation will be enabled using Recast tool. For very large maps it is recommended to disable this option. Default is `True`.""" + ... + # endregion + + # region Methods + def __init__(self, vertex_distance: float =2.0, + max_road_length:float = 50.0, + wall_height:float = 1.0, + additional_width: float=0.6, + smooth_junctions: bool =True, + enable_mesh_visibility: bool=True, + enable_pedestrian_navigation: bool=True): + """Constructor method""" + ... + + +class OpticalFlowImage(SensorData): + """Class that defines an optical flow image of 2-Dimension float (32-bit) vectors representing the optical flow detected in the field of view. The components of the vector represents the displacement of an object in the image plane. Each component outputs values in the normalized range [-2,2] which scales to [-2 size, 2 size] with size being the total resolution in the corresponding component.""" + # region Instance Variables + @property + def fov(self) -> float: + """Horizontal field of view of the image. (degrees)""" + ... + + @property + def height(self) -> int: + """Image height in pixels.""" + ... + + @property + def width(self) -> int: + """Image width in pixels.""" + ... + + @property + def raw_data(self) -> bytes: + """Flattened array of pixel data, use reshape to create an image array.""" + # endregion + + # region Getters + def get_color_coded_flow(self) -> Image: + """Visualization helper. Converts the optical flow image to an RGB image.""" + ... + # endregion + + # region Dunder Methods + def __getitem__(self, pos: int) -> OpticalFlowPixel: ... + + def __iter__(self) -> Iterator[OpticalFlowPixel]: + """Iterate over the `carla.OpticalFlowPixel `that form the image.""" + + def __len__(self) -> int: ... + def __setitem__(self, pos: int, color: Color): ... + def __str__(self) -> str: ... + # endregion + + +class OpticalFlowPixel(): + """Class that defines a 2 dimensional vector representing an optical flow pixel.""" + + # region Instance Variables + @property + def x(self) -> float: + """Optical flow in the x component.""" + ... + + @property + def y(self) -> float: + """Optical flow in the y component.""" + # endregion + + # region Methods + def __init__(self, x=.0, y=.0): + """Initializes the Optical Flow Pixel. Zero by default. + + Args: + `x (float, optional)`: Optical flow in the x component. Defaults to .0.\n + `y (float, optional)`: Optical flow in the y component. Defaults to .0.\n + """ + ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: OpticalFlowPixel) -> bool: ... + def __ne__(self, __value: OpticalFlowPixel) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class Osm2Odr(): + """Class that converts an OpenStreetMap map to OpenDRIVE format, so that it can be loaded in CARLA. Find out more about this feature in the docs. + + https://carla.readthedocs.io/en/latest/tuto_G_openstreetmap/ + """ + # region Methods + @staticmethod + def convert(osm_file: str, settings: Osm2OdrSettings) -> str: + """Takes the content of an `.osm` file (OpenStreetMap format) and returns the content of the `.xodr` (OpenDRIVE format) describing said map. + + Args: + `osm_file (str)`: The content of the input OpenStreetMap file parsed as string.\n + `settings (Osm2OdrSettings)`: Parameterization for the conversion.\n + + Returns: + `str`\n + """ + # endregion + + +class Osm2OdrSettings(): + """Helper class that contains the parameterization that will be used by carla.Osm2Odr to convert an OpenStreetMap map to OpenDRIVE format. Find out more about this feature in the docs. + + https://carla.readthedocs.io/en/latest/tuto_G_openstreetmap/ + """ + + # region Instance Variables + @property + def use_offsets(self) -> bool: + """Enables the use of offset for the conversion. The offset will move the origin position of the map. Default value is False. + """ + ... + + @property + def offset_x(self) -> float: + """Offset in the X axis. Default value is 0.0 (meters).""" + ... + + @property + def offset_y(self) -> float: + """Offset in the Y axis. Default value is 0.0 (meters).""" + ... + + @property + def default_lane_width(self) -> float: + """Width of the lanes described in the resulting XODR map. Default value is 4.0 (meter).""" + ... + + @property + def elevation_layer_height(self) -> float: + """Defines the height separating two different OpenStreetMap layers. Default value is 0.0.""" + ... + + @property + def center_map(self) -> bool: + """When this option is enabled, the geometry of the map will be displaced so that the origin of coordinates matches the center of the bounding box of the entire road map.""" + ... + + @property + def proj_string(self) -> str: + """Defines the `proj4` string that will be used to compute the projection from geocoordinates to cartesian coordinates. This string will be written in the resulting OpenDRIVE unless the options `use_offsets` or `center_map` are enabled as these options override some of the definitions in the string.""" + ... + + @property + def generate_traffic_lights(self) -> bool: + """Indicates wether to generate traffic light data in the OpenDRIVE. Road types defined by `set_traffic_light_excluded_way_types(way_types)` will not generate traffic lights.""" + ... + + @property + def all_junctions_with_traffic_lights(self) -> bool: + """When disabled, the converter will generate traffic light data from the OpenStreetMaps data only. When enabled, all junctions will generate traffic lights.""" + # endregion + + # region Setters + def set_osm_way_types(self, way_types: list[str]): + """Defines the OpenStreetMaps road types that will be imported to OpenDRIVE. By default the road types imported are: + `motorway`, `motorway_link`, `trunk`, `trunk_link`, `primary`, `primary_link`, `secondary`, `secondary_link`, `tertiary`, `tertiary_link`, `unclassified`, `residential`. + For a full list of road types check here. + + https://wiki.openstreetmap.org/wiki/Main_Page + + Args: + `way_types (list[str])`: The list of road types.\n + """ + + def set_traffic_light_excluded_way_types(self, way_types: list[str]): + """Defines the OpenStreetMaps road types that will not generate traffic lights even if `generate_traffic_lights` is enabled. By default the road types excluded are + `motorway_link`, `primary_link`, `secondary_link`, `tertiary_link` + + Args: + `way_types (list[str])`: The list of road types.\n + """ + # endregion + + +class RadarDetection(): + """Data contained inside a `carla.RadarMeasurement`. Each of these represents one of the points in the cloud that a `sensor.other.radar` registers and contains the distance, angle and velocity in relation to the radar.""" + + # region Instance Variables + @property + def altitude(self) -> float: + """Altitude angle of the detection (radians).""" + ... + + @property + def azimuth(self) -> float: + """Azimuth angle of the detection (radians).""" + ... + + @property + def depth(self) -> float: + """Distance from the sensor to the detection position (meters).""" + ... + + @property + def velocity(self) -> float: + """The velocity of the detected object towards the sensor (m/s).""" + ... + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class RadarMeasurement(SensorData): + """Class that defines and gathers the measures registered by a `sensor.other.radar`, representing a wall of points in front of the sensor with a distance, angle and velocity in relation to it. The data consists of a `carla.RadarDetection` array. Learn more about this here. + + https://carla.readthedocs.io/en/latest/ref_sensors/#radar-sensor + """ + + # region Instance Variables + @property + def raw_data(self) -> bytes: + """The complete information of the `carla.RadarDetection` the radar has registered. + """ + # endregion + + # region Getters + def get_detection_count(self) -> int: + """Retrieves the number of entries generated, same as `__str__()`.""" + # endregion + + # region Dunder Methods + def __getitem__(self, pos: int) -> RadarDetection: ... + + def __iter__(self) -> Iterator[RadarDetection]: + """Iterate over the `carla.RadarDetection` retrieved as data.""" + + def __len__(self) -> int: ... + def __setitem__(self, pos: int, detection: RadarDetection): ... + def __str__(self) -> str: ... + # endregion + + +class Rotation(): + """Class that represents a 3D rotation and therefore, an orientation in space. CARLA uses the Unreal Engine coordinates system. This is a Z-up left-handed system. + + The constructor method follows a specific order of declaration: `(pitch, yaw, roll)`, which corresponds to `(Y-rotation,Z-rotation,X-rotation)`. + """ + + # region Instance Variables + @property + def pitch(self) -> float: + """Y-axis rotation angle (degrees).""" + ... + + @property + def yaw(self) -> float: + """Z-axis rotation angle (degrees).""" + ... + + @property + def roll(self) -> float: + """X-axis rotation angle (degrees).""" + ... + # endregion + + # region Methods + def __init__(self, pitch=.0, yaw=.0, roll=.0): + """+ Warning: The declaration order is different in CARLA (pitch,yaw,roll), and in the Unreal Engine Editor (roll,pitch,yaw). When working in a build from source, don't mix up the axes' rotations. + + Args: + `pitch (float, optional)`: Y-axis rotation angle (degrees). Defaults to .0.\n + `yaw (float, optional)`: Z-axis rotation angle (degrees). Defaults to .0.\n + `roll (float, optional)`: X-axis rotation angle (degrees). Defaults to .0.\n + """ + ... + # endregion + + # region Getters + def get_forward_vector(self) -> Vector3D: + """Computes the vector pointing forward according to the rotation of the object.""" + ... + + def get_right_vector(self) -> Vector3D: + """Computes the vector pointing to the right according to the rotation of the object.""" + ... + + def get_up_vector(self) -> Vector3D: + """Computes the vector pointing upwards according to the rotation of the object.""" + ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: Rotation) -> bool: + """Returns `True` if both rotations represent the same orientation for every axis.""" + ... + + def __ne__(self, __value: Rotation) -> bool: + ... + + def __str__(self) -> str: ... + # endregion + + +class SemanticLidarDetection(): + """Data contained inside a `carla.SemanticLidarMeasurement`. Each of these represents one of the points in the cloud with its location, the cosine of the incident angle, index of the object hit, and its semantic tag.""" + + # region Instance Variables + @property + def point(self) -> Location: + """[x,y,z] coordinates of the point (meters).""" + @property + def cos_inc_angle(self) -> float: + """Cosine of the incident angle between the ray, and the normal of the hit object.""" + @property + def object_idx(self) -> int: + """ID of the actor hit by the ray.""" + @property + def object_tag(self) -> int: + """`Semantic tag` of the component hit by the ray.""" + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class SemanticLidarMeasurement(SensorData): + """Class that defines the semantic LIDAR data retrieved by a `sensor.lidar.ray_cast_semantic`. This essentially simulates a rotating LIDAR using ray-casting. Learn more about this here. + + https://carla.readthedocs.io/en/latest/ref_sensors/#semanticlidar-raycast-sensor + """ + + # region Instance Variables + @property + def channels(self) -> int: + """Number of lasers shot.""" + @property + def horizontal_angle(self) -> float: + """Horizontal angle the LIDAR is rotated at the time of the measurement (radians).""" + @property + def raw_data(self) -> bytes: + """Received list of raw detection points. Each point consists of [x,y,z] coordinates plus the cosine of the incident angle, the index of the hit actor, and its semantic tag.""" + # endregion + + # region Methods + def save_to_disk(self, path: str): + """Saves the point cloud to disk as a `.ply` file describing data from 3D scanners. The files generated are ready to be used within `MeshLab`, an open-source system for processing said files. Just take into account that axis may differ from Unreal Engine and so, need to be reallocated. + + Args: + `path (str)`\n + """ + # endregion + + # region Getters + def get_point_count(self, channel: int): + """Retrieves the number of points sorted by channel that are generated by this measure. Sorting by channel allows to identify the original channel for every point. + + Args: + `channel (int)`\n + """ + # endregion + + # region Dunder Methods + def __getitem__(self, pos: int) -> SemanticLidarDetection: ... + + def __iter__(self) -> Iterator[SemanticLidarDetection]: + """Iterate over the `carla.SemanticLidarDetection` retrieved as data.""" + ... + + def __len__(self): ... + def __setitem__(self, pos: int, detection: SemanticLidarDetection): ... + def __str__(self) -> str: ... + # endregion + + +class Sensor(Actor): + """Sensors compound a specific family of actors quite diverse and unique. They are normally spawned as attachment/sons of a vehicle (take a look at `carla.World` to learn about actor spawning). Sensors are thoroughly designed to retrieve different types of data that they are listening to. The data they receive is shaped as different subclasses inherited from `carla.SensorData` (depending on the sensor). + + Most sensors can be divided in two groups: those receiving data on every tick (cameras, point clouds and some specific sensors) and those who only receive under certain circumstances (trigger detectors). CARLA provides a specific set of sensors and their blueprint can be found in `carla.BlueprintLibrary`. All the information on their preferences and settlement can be found here, but the list of those available in CARLA so far goes as follow. + + https://carla.readthedocs.io/en/latest/ref_sensors/ + + Receive data on every tick. + - Depth camera. + - Gnss sensor. + - IMU sensor. + - Lidar raycast. + - SemanticLidar raycast. + - Radar. + - RGB camera. + - RSS sensor. + - Semantic Segmentation camera. + + Only receive data when triggered. + - Collision detector. + - Lane invasion detector. + - Obstacle detector. + """ + + # region Instance Variables + #@property + #def is_listening() -> bool: + # """When `True` the sensor will be waiting for data.""" + # endregion + + # region Methods + + def is_listening(self) -> bool: + """Returns whether the sensor is in a listening state.""" + + def is_listening_gbuffer(self, gbuffer_id: GBufferTextureID) -> bool: + """Returns whether the sensor is in a listening state for a specific GBuffer texture. + + Args: + `gbuffer_id (GBufferTextureID)`: The ID of the target Unreal Engine GBuffer texture.\n + """ + + def listen(self, callback: Callable[[__SensorData], Any]) -> None: + """ + The function the sensor will be calling to every time a new measurement is received. + This function needs for an argument containing an object type `carla.SensorData` to work with. + + Args: + `callback (Callable[[SensorData], Any])`: The called function with one argument containing the sensor data.\n + """ + + def listen_to_gbuffer(self, gbuffer_id: GBufferTextureID, callback: Callable[[__SensorData], Any]) -> None: + """ + The function the sensor will be calling to every time the desired GBuffer texture is received. + This function needs for an argument containing an object type `carla.SensorData` to work with. + + Args: + `gbuffer_id (GBufferTextureID)`: The ID of the target Unreal Engine GBuffer texture.\n + `callback (Callable[[SensorData], Any])`: The called function with one argument containing the received GBuffer texture.\n + """ + + def stop(self): + """Commands the sensor to stop listening for data.""" + + def stop_gbuffer(self, gbuffer_id: GBufferTextureID): + """Commands the sensor to stop listening for the specified GBuffer texture. + + Args: + `gbuffer_id (GBufferTextureID)`: The ID of the Unreal Engine GBuffer texture.\n + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class SensorData(): + """ + Base class for all the objects containing data generated by a `carla.Sensor`. + This objects should be the argument of the function said sensor is listening to, + in order to work with them. Each of these sensors needs for a specific type of + sensor data. Hereunder is a list of the sensors and their corresponding data. + + - Cameras (RGB, depth and semantic segmentation): `carla.Image`. + - Collision detector: `carla.CollisionEvent`. + - GNSS sensor: `carla.GnssMeasurement`. + - IMU sensor: `carla.IMUMeasurement`. + - Lane invasion detector: `carla.LaneInvasionEvent`. + - LIDAR sensor: `carla.LidarMeasurement`. + - Obstacle detector: `carla.ObstacleDetectionEvent`. + - Radar sensor: `carla.RadarMeasurement`. + - RSS sensor: `carla.RssResponse`. + - Semantic LIDAR sensor: `carla.SemanticLidarMeasurement`. + """ + # region Instance Variables + @property + def frame(self) -> int: + """Frame count when the data was generated.""" + ... + + @property + def timestamp(self) -> float: + """Simulation-time(seconds) when the data was generated.""" + ... + + @property + def transform(self) -> Transform: + """Sensor's transform when the data was generated.""" + # endregion + + +class TextureColor(): + """ + Class representing a texture object to be uploaded to the server. + Pixel format is RGBA, uint8 per channel. + """ + # region Instance Variables + @property + def width(self) -> int: + """X-coordinate size of the texture.""" + @property + def height(self) -> int: + """Y-coordinate size of the texture.""" + # endregion + + # region Methods + def __init__(self, width: int, height: int): + """Initializes a the texture with a `(width, height)` size. + + Args: + `width (int)`: X-coordinate size of the texture.\n + `height (int)`: Y-coordinate size of the texture.\n + """ + ... + # endregion + + # region Getters + def get(self, x: int, y: int) -> Color: + """Get the `(x,y)` pixel data.""" + + # endregion + + # region Setters + def set(self, x: int, y: int, value: Color): + """Sets the `(x,y)` pixel data with `value`.""" + + def set_dimensions(self, width: int, height: int): + """Resizes the texture to te specified dimensions.""" + # endregion + + +class TextureFloatColor(): + """ + Class representing a texture object to be uploaded to the server. + Pixel format is RGBA, float per channel. + """ + + # region Instance Variables + @property + def width(self) -> int: + """X-coordinate size of the texture.""" + @property + def height(self) -> int: + """Y-coordinate size of the texture.""" + # endregion + + # region Getters + def get(self, x: int, y: int) -> FloatColor: + """Get the `(x,y)` pixel data.""" + + # endregion + + # region Setters + def set(self, x: int, y: int, value: FloatColor): + """Sets the `(x,y)` pixel data with `value`.""" + + def set_dimensions(self, width: int, height: int): + """Resizes the texture to te specified dimensions.""" + # endregion + + +class Timestamp(): + """ + Class that contains time information for simulated data. This information is automatically + retrieved as part of the `carla.WorldSnapshot` the client gets on every frame, but might also + be used in many other situations such as a `carla.Sensor` retrieving data. + """ + + # region Instance Variables + @property + def frame(self) -> int: + """The number of frames elapsed since the simulator was launched.""" + @property + def elapsed_seconds(self) -> float: + """Simulated seconds elapsed since the beginning of the current episode (seconds).""" + @property + def delta_seconds(self) -> float: + """Simulated seconds elapsed since the previous frame (seconds).""" + + @property + def platform_timestamp(self) -> float: + """Time register of the frame at which this measurement was taken given by the OS in seconds (seconds).""" + # endregion + + # region Methods + def __init__(self, frame: int, elapsed_seconds: float, delta_seconds: float, platform_timestamp: float): ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: Timestamp) -> bool: ... + def __ne__(self, __value: Timestamp) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class TrafficLight(TrafficSign): + """ traffic light actor, considered a specific type of traffic sign. As traffic lights will mostly appear at junctions, they belong to a group which contains the different traffic lights in it. Inside the group, traffic lights are differenciated by their pole index. + + Within a group the state of traffic lights is changed in a cyclic pattern: one index is chosen and it spends a few seconds in green, yellow and eventually red. The rest of the traffic lights remain frozen in red this whole time, meaning that there is a gap in the last seconds of the cycle where all the traffic lights are red. However, the state of a traffic light can be changed manually.""" + + # region Instance Variables + @property + def state(self) -> TrafficLightState: + """Current state of the traffic light.""" + # endregion + + # region Methods + def freeze(self, freeze: bool): + """Stops all the traffic lights in the scene at their current state.""" + + def is_frozen(self) -> bool: + """The client returns `True` if a traffic light is frozen according to last tick. The method does not call the simulator.""" + + def reset_group(self): + """Resets the state of the traffic lights of the group to the initial state at the start of the simulation. + + + Note: This method calls the simulator. + """ + # endregion + + # region Getters + def get_affected_lane_waypoints(self) -> list[Waypoint]: + """Returns a list of waypoints indicating the positions and lanes where the traffic light is having an effect.""" + + def get_elapsed_time(self) -> float: + """The client returns the time in seconds since current light state started according to last tick. The method does not call the simulator (seconds).""" + + def get_green_time(self) -> float: + """The client returns the time set for the traffic light to be green, according to last tick. The method does not call the simulator (seconds). + + Setter: `carla.TrafficLight.set_green_time` + """ + + def get_group_traffic_lights(self) -> list[TrafficLight]: + """Returns all traffic lights in the group this one belongs to. + + + Note: This method calls the simulator. + """ + + def get_light_boxes(self) -> list[BoundingBox]: + """Returns a list of the bounding boxes encapsulating each light box of the traffic light.""" + + def get_opendrive_id(self) -> str: + """Returns the OpenDRIVE id of this traffic light.""" + + def get_pole_index(self) -> int: + """Returns the index of the pole that identifies it as part of the traffic light group of a junction.""" + + def get_red_time(self) -> float: + """The client returns the time set for the traffic light to be red, according to last tick. The method does not call the simulator (seconds). + + Setter: `carla.TrafficLight.set_red_time` + """ + + def get_state(self) -> TrafficLightState: + """The client returns the state of the traffic light according to last tick. The method does not call the simulator. + + Setter: `carla.TrafficLight.set_state` + """ + + def get_stop_waypoints(self) -> list[Waypoint]: + """Returns a list of waypoints indicating the stop position for the traffic light. These waypoints are computed from the trigger boxes of the traffic light that indicate where a vehicle should stop.""" + + def get_yellow_time(self) -> float: + """The client returns the time set for the traffic light to be yellow, according to last tick. The method does not call the simulator (seconds). + + Setter: `carla.TrafficLight.set_yellow_time` + """ + # endregion + + # region Setters + def set_green_time(self, green_time: float): + """Sets a given time for the green light to be active. + + Getter: `carla.TrafficLight.get_green_time` + + Args: + green_time (float): (seconds) + """ + + def set_red_time(self, red_time: float): + """Sets a given time for the red state to be active. + + Getter: carla.TrafficLight.get_red_time + + Args: + red_time (float): (seconds) + """ + + def set_state(self, state: TrafficLightState): + """Sets a given state to a traffic light actor. + + Getter: `carla.TrafficLight.get_state` + + Args: + state (TrafficLightState) + """ + + def set_yellow_time(self, yellow_time: float): + """Sets a given time for the yellow light to be active. + + Getter: `carla.TrafficLight.get_yellow_time` + + Args: + yellow_time (float): (seconds) + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class TrafficLightState(int, __CarlaEnum): + """All possible states for traffic lights. These can either change at a specific time step or be changed manually. The snippet in `carla.TrafficLight.set_state` changes the state of a traffic light on the fly.""" + Red = 0 + Yellow = 1 + Green = 2 + Off = 3 + Unknown = 4 + + +class TrafficManager(): + """The traffic manager is a module built on top of the CARLA API in C++. It handles any group of vehicles set to autopilot mode to populate the simulation with realistic urban traffic conditions and give the chance to user to customize some behaviours. The architecture of the traffic manager is divided in five different goal-oriented stages and a PID controller where the information flows until eventually, a `carla.VehicleControl` is applied to every vehicle registered in a traffic manager. In order to learn more, visit the documentation regarding this module. + + https://carla.readthedocs.io/en/latest/adv_traffic_manager/ + """ + + # region Methods + def auto_lane_change(self, actor: Actor, enable: bool): + """Turns on or off lane changing behaviour for a vehicle. + + Args: + actor (Actor): The vehicle whose settings are changed. + enable (bool): `True` is default and enables lane changes. `False` will disable them. + """ + + def collision_detection(self, reference_actor: Actor, other_actor: Actor, detect_collision: bool): + """Turns on/off collisions between a vehicle and another specific actor. In order to ignore all other vehicles, traffic lights or walkers, use the specific `ignore` methods described in this same section. + + Args: + reference_actor (Actor): Vehicle that is going to ignore collisions. + other_actor (Actor): The actor that `reference_actor` is going to ignore collisions with. + detect_collision (bool): `True` is default and enables collisions. `False` will disable them. + """ + + def distance_to_leading_vehicle(self, actor: Actor, distance: float): + """Sets the minimum distance in meters that a vehicle has to keep with the others. The distance is in meters and will affect the minimum moving distance. It is computed from front to back of the vehicle objects. + + Args: + actor (Actor): Vehicle whose minimum distance is being changed. + distance (float): Meters between both vehicles (meters). + """ + + def force_lane_change(self, actor: Actor, direction: bool): + """Forces a vehicle to change either to the lane on its left or right, if existing, as indicated in `direction`. This method applies the lane change no matter what, disregarding possible collisions. + + Args: + actor (Actor): Vehicle being forced to change lanes. + direction (bool): Destination lane. `True` is the one on the right and `False` is the left one. + """ + + def global_lane_offset(self, offset: float): + """Sets a global lane offset displacement from the center line. Positive values imply a right offset while negative ones mean a left one. Default is 0. Numbers high enough to cause the vehicle to drive through other lanes might break the controller. + + Args: + offset (float): Lane offset displacement from the center line. + """ + + def global_percentage_speed_difference(self, percentage: float): + """Sets the difference the vehicle's intended speed and its current speed limit. Speed limits can be exceeded by setting the `perc` to a negative value. Default is 30. Exceeding a speed limit can be done using negative percentages. + + Args: + percentage (float): Percentage difference between intended speed and the current limit. + """ + + def ignore_lights_percentage(self, actor: Actor, perc: float): + """During the traffic light stage, which runs every frame, this method sets the percent chance that traffic lights will be ignored for a vehicle. + + Args: + actor (Actor): The actor that is going to ignore traffic lights. + perc (float): Between 0 and 100. Amount of times traffic lights will be ignored. + """ + + def ignore_signs_percentage(self, actor: Actor, perc: float): + """During the traffic light stage, which runs every frame, this method sets the percent chance that stop signs will be ignored for a vehicle. + + Args: + actor (Actor): The actor that is going to ignore stop signs. + perc (float): Between 0 and 100. Amount of times stop signs will be ignored. + """ + + def ignore_vehicles_percentage(self, actor: Actor, perc: float): + """During the collision detection stage, which runs every frame, this method sets a percent chance that collisions with another vehicle will be ignored for a vehicle. + + Args: + actor (Actor): The vehicle that is going to ignore other vehicles. + perc (float): Between 0 and 100. Amount of times collisions will be ignored. + """ + + def ignore_walkers_percentage(self, actor: Actor, perc: float): + """During the collision detection stage, which runs every frame, this method sets a percent chance that collisions with walkers will be ignored for a vehicle. + + Args: + actor (Actor): The vehicle that is going to ignore walkers on scene. + perc (float): Between 0 and 100. Amount of times collisions will be ignored. + """ + + def keep_right_rule_percentage(self, actor: Actor, perc: float): + """During the localization stage, this method sets a percent chance that vehicle will follow the keep right rule, and stay in the right lane. + + Args: + actor (Actor): Vehicle whose behaviour is being changed. + perc (float): Between 0 and 100. Amount of times the vehicle will follow the keep right rule. + """ + + def random_left_lanechange_percentage(self, actor: Actor, percentage: float): + """Adjust probability that in each timestep the actor will perform a left lane change, dependent on lane change availability. + + Args: + actor (Actor): The actor that you wish to query. + percentage (float): The probability of lane change in percentage units (between 0 and 100). + """ + + def random_right_lanechange_percentage(self, actor: Actor, percentage: float): + """Adjust probability that in each timestep the actor will perform a right lane change, dependent on lane change availability. + + Args: + actor (Actor): The actor that you wish to query. + percentage (float): The probability of lane change in percentage units (between 0 and 100). + """ + + def shut_down(self): + """Shuts down the traffic manager.""" + + def update_vehicle_lights(self, actor: Actor, do_update: bool): + """Sets if the Traffic Manager is responsible of updating the vehicle lights, or not. Default is False. The traffic manager will not change the vehicle light status of a vehicle, unless its auto_update_status is st to True. + + Args: + actor (Actor): Vehicle whose lights status is being changed. + do_update (bool): If `True` the traffic manager will manage the vehicle lights for the specified vehicle. + """ + + def vehicle_lane_offset(self, actor: Actor, offset: float): + """Sets a lane offset displacement from the center line. Positive values imply a right offset while negative ones mean a left one. Default is 0. Numbers high enough to cause the vehicle to drive through other lanes might break the controller. + + + Args: + actor (Actor): Vehicle whose lane offset behaviour is being changed. + offset (float): Lane offset displacement from the center line. + """ + + def vehicle_percentage_speed_difference(self, actor: Actor, percentage: float): + """Sets the difference the vehicle's intended speed and its current speed limit. Speed limits can be exceeded by setting the `perc` to a negative value. Default is 30. Exceeding a speed limit can be done using negative percentages. + + + Args: + actor (Actor): Vehicle whose speed behaviour is being changed. + percentage (float): Percentage difference between intended speed and the current limit. + """ + # endregion + + # region Getters + def get_all_actions(self, actor: Actor) -> list[Waypoint]: + """Returns all known actions (i.e. road options and waypoints) that an actor controlled by the Traffic Manager will perform in its next steps. + + Args: + actor (Actor): The actor that you wish to query. + + Returns: + list[Waypoint]: list of lists with each element as follows - [Road option (string e.g. 'Left', 'Right', 'Straight'), Next waypoint (carla.Waypoint)] + """ + + def get_next_action(self, actor: Actor) -> list[Waypoint]: + """Returns the next known road option and waypoint that an actor controlled by the Traffic Manager will follow. + + Args: + actor (Actor): The actor that you wish to query. + + Returns: + list[Waypoint]: list of two elements - [Road option (string e.g. 'Left', 'Right', 'Straight'), Next waypoint (carla.Waypoint)] + """ + + def get_port(self) -> int: + """Returns the port where the Traffic Manager is connected. If the object is a TM-Client, it will return the port of its TM-Server. Read the documentation to learn the difference. + + https://carla.readthedocs.io/en/latest/python_api/#adv_traffic_manager.md#multiclient-and-multitm-management + """ + # endregion + + # region Setters + def set_boundaries_respawn_dormant_vehicles(self, lower_bound: Annotated[float, ">=25.0"], upper_bound: Annotated[float, "<= WorldSettings.actor_active_distance"]) -> None: + """Sets the upper and lower boundaries for dormant actors to be respawned near the hero vehicle. + + + Warning: The `upper_bound` cannot be higher than the `actor_active_distance`. The `lower_bound` cannot be less than `25`. + + Args: + lower_bound (float, optional): The minimum distance in meters from the hero vehicle that a dormant actor will be respawned. + upper_bound (float, optional): The maximum distance in meters from the hero vehicle that a dormant actor will be respawned. + """ + + def set_desired_speed(self, actor: Actor, speed: float) -> None: + """Sets the speed of a vehicle to the specified value. + + Args: + actor (Actor): Vehicle whose speed is being changed. + speed (float): Desired speed at which the vehicle will move. + """ + + def set_global_distance_to_leading_vehicle(self, distance: float) -> None: + """Sets the minimum distance in meters that vehicles have to keep with the rest. The distance is in meters and will affect the minimum moving distance. It is computed from center to center of the vehicle objects. + + Args: + distance (float): Meters between vehicles (meters). + """ + + def set_hybrid_physics_mode(self, enabled=False): + """Enables or disables the hybrid physics mode. In this mode, vehicle's farther than a certain radius from the ego vehicle will have their physics disabled. Computation cost will be reduced by not calculating vehicle dynamics. Vehicles will be teleported. + + Args: + enabled (bool, optional): If `True`, enables the hybrid physics. Defaults to False. + """ + + def set_hybrid_physics_radius(self, r=50.0): + """With hybrid physics on, changes the radius of the area of influence where physics are enabled. + + Args: + r (float, optional): New radius where physics are enabled (meters). Defaults to 50.0. + """ + + def set_osm_mode(self, mode_switch=True): + """Enables or disables the OSM mode. This mode allows the user to run TM in a map created with the OSM feature. These maps allow having dead-end streets. Normally, if vehicles cannot find the next waypoint, TM crashes. If OSM mode is enabled, it will show a warning, and destroy vehicles when necessary. + + Args: + mode_switch (bool, optional): If True, the OSM mode is enabled. Defaults to True. + """ + + def set_path(self, actor: Actor, path: list[Location]): + """Sets a list of locations for a vehicle to follow while controlled by the Traffic Manager. + + Args: + actor (Actor): The actor that must follow the given path. + path (list[Location]): The list of carla.Locations for the actor to follow. + """ + + def set_random_device_seed(self, value: int): + """Sets a specific random seed for the Traffic Manager, thereby setting it to be deterministic. + + Args: + value (int): Seed value for the random number generation of the Traffic Manager. + """ + + def set_respawn_dormant_vehicles(self, mode_switch=False): + """If `True`, vehicles in large maps will respawn near the hero vehicle when they become dormant. Otherwise, they will stay dormant until they are within `actor_active_distance` of the hero vehicle again. + + + Args: + mode_switch (bool, optional) Defaults to False. + """ + + def set_route(self, actor: Actor, path: list[str]): + """Sets a list of route instructions for a vehicle to follow while controlled by the Traffic Manager. The possible route instructions are 'Left', 'Right', 'Straight'. + + + Warning: Ensure that the lane topology doesn't impede the given route. + + + Args: + actor (Actor): The actor that must follow the given route instructions. + path (list[str]): The list of route instructions (string) for the vehicle to follow. + """ + + def set_synchronous_mode(self, mode_switch=True): + """Sets the Traffic Manager to synchronous mode. In a multiclient situation, only the TM-Server can tick. Similarly, in a multiTM situation, only one TM-Server must tick. Use this method in the client that does the world tick, and right after setting the world to synchronous mode, to set which TM will be the master while in sync. + + + Warning: If the server is set to synchronous mode, the TM must be set to synchronous mode too in the same client that does the tick. + + Args: + mode_switch (bool, optional): If True, the TM synchronous mode is enabled.. Defaults to True. + """ + # endregion + + +class TrafficSign(Actor): + """Traffic signs appearing in the simulation except for traffic lights. These have their own class inherited from this in `carla.TrafficLight`. Right now, speed signs, stops and yields are mainly the ones implemented, but many others are borne in mind. + """ + + # region Instance Variables + @property + def trigger_volume(self) -> BoundingBox: + """A carla.BoundingBox situated near a traffic sign where the carla.Actor who is inside can know about it.""" + # endregion + + +class Transform(): + """Class that defines a transformation, a combination of location and rotation, without scaling. + """ + + # region Instance Variables + @property + def location(self) -> Location: + """Describes a point in the coordinate system.""" + @location.setter + def location(self, value: Location | Vector3D): + ... + + @property + def rotation(self) -> Rotation: + """Describes a rotation for an object according to Unreal Engine's axis system (degrees (pitch, yaw, roll)).""" + @rotation.setter + def rotation(self, value: Rotation | Vector3D): + ... + # endregion + + # region Methods + def __init__(self, location: Location = Location(0,0,0), rotation: Rotation = Rotation(0,0,0)): ... + + def transform(self, in_point: Vector3D) -> Vector3D: + """ + Translates a 3D point from local to global coordinates using the current + transformation as frame of reference. + + Args: + in_point (Location): Location in the space to which the transformation will be applied. + + Note: + This operation transforms `in_point` in place. + """ + + def inverse_transform(self, in_point: Vector3D) -> Vector3D: + """ + Applies the inverse of `transform` by translating a 3D point from global to local + coordinates using the current transformation as frame of reference. + + Args: + in_point (Vector3D): Vector to which the transformation will be applied. + + Note: + This operation transforms `in_point` in place. + """ + + def transform_vector(self, in_point: Vector3D) -> Vector3D: + """ + Rotates a vector using the current transformation as frame of reference, + without applying translation. Use this to transform, for example, a velocity. + + Args: + in_point (Vector3D): Vector to which the transformation will be applied. + + Note: + This operation transforms `in_point` in place. + """ + # endregion + + # region Getters + def get_forward_vector(self) -> Vector3D: + """Computes a forward vector using the rotation of the object.""" + + def get_inverse_matrix(self) -> list[list[float]]: + """Computes the 4-matrix representation of the inverse transformation.""" + + def get_matrix(self) -> list[list[float]]: + """Computes the 4-matrix representation of the transformation.""" + + def get_right_vector(self) -> Vector3D: + """Computes a right vector using the rotation of the object.""" + + def get_up_vector(self) -> Vector3D: + """Computes an up vector using the rotation of the object.""" + # endregion + + # region Dunder Methods + def __eq__(self, __value: Transform) -> bool: + """Returns `True` if both `location` and `rotation` are equal for this and `other`.""" + + def __ne__(self, __value: Transform) -> bool: + """Returns `True` if any `location` and `rotation` are not equal for this and `other`.""" + + def __str__(self) -> str: + """Parses both `location` and `rotation` to string.""" + # endregion + + +class Vector2D(): + """Helper class to perform 2D operations.""" + + # region Instance Variables + @property + def x(self) -> float: + """X-axis value.""" + @property + def y(self) -> float: + """Y-axis value.""" + # endregion + + # region Methods + def __init__(self, x=0.0, y=0.0): ... + + def length(self) -> float: + """Computes the length of the vector.""" + + def make_unit_vector(self) -> Vector3D: + """Returns a vector with the same direction and unitary length.""" + + def squared_length(self) -> float: + """Computes the squared length of the vector.""" + # endregion + + # region Dunder Methods + def __add__(self, other: Vector2D) -> Vector2D: ... + + def __eq__(self, other: Vector2D) -> bool: + """Returns `True` if values for every axis are equal.""" + + def __mul__(self, other: float) -> Vector2D: ... + + def __ne__(self, bool: Vector2D) -> bool: + """Returns `True` if the value for any axis is different.""" + + def __str__(self) -> str: + """Returns the axis values for the vector parsed as string.""" + ... + + def __sub__(self, other: Vector2D) -> Vector2D: ... + def __truediv__(self, other: float) -> Vector2D: ... + + # endregion + + +class Vector3D(): + """Helper class to perform 3D operations.""" + + # region Instance Variables + @property + def x(self) -> float: + """X-axis value.""" + @property + def y(self) -> float: + """Y-axis value.""" + @property + def z(self) -> float: + """Z-axis value.""" + # endregion + + # region Methods + def __init__(self, x=0.0, y=0.0, z=0.0): ... + + def cross(self, vector: Vector3D) -> Vector3D: + """Computes the cross product between two vectors.""" + + def distance(self, vector: Vector3D) -> float: + """Computes the distance between two vectors.""" + + def distance_2d(self, vector: Vector3D) -> Vector3D: + """Computes the 2-dimensional distance between two vectors.""" + + def distance_squared(self, vector: Vector3D) -> float: + """Computes the squared distance between two vectors.""" + + def distance_squared_2d(self, vector: Vector3D) -> float: + """Computes the 2-dimensional squared distance between two vectors.""" + + def dot(self, vector: Vector3D) -> float: + """Computes the dot product between two vectors.""" + + def dot_2d(self, vector: Vector3D) -> float: + """Computes the 2-dimensional dot product between two vectors.""" + + def length(self) -> float: + """Computes the length of the vector.""" + + def make_unit_vector(self) -> Vector3D: + """Returns a vector with the same direction and unitary length.""" + + def squared_length(self) -> float: + """Computes the squared length of the vector.""" + # endregion + + # region Getters + def get_vector_angle(self, vector: Vector3D) -> float: + """Computes the angle between a pair of 3D vectors in radians.""" + # endregion + + # region Dunder Methods + def __abs__(self) -> Vector3D: + """Returns a Vector3D with the absolute value of the components x, y and z.""" + + def __add__(self, other: Vector3D) -> Vector3D: ... + def __eq__(self, other: Vector3D) -> bool: ... + def __mul__(self, other: float) -> Vector3D: ... + def __ne__(self, other: Vector3D) -> bool: ... + def __str__(self) -> str: ... + def __sub__(self, other: Vector3D) -> Vector3D: ... + def __truediv__(self, other: float) -> Vector3D: ... + # endregion + + +class Vehicle(Actor): + """One of the most important groups of actors in CARLA. These include any type of vehicle from cars to trucks, motorbikes, vans, bycicles and also official vehicles such as police cars. A wide set of these actors is provided in `carla.BlueprintLibrary` to facilitate different requirements. Vehicles can be either manually controlled or set to an autopilot mode that will be conducted client-side by the `traffic manager`.""" + + # region Instance Variables + @property + def bounding_box(self) -> BoundingBox: + """Bounding box containing the geometry of the vehicle. Its location and rotation are relative to the vehicle it is attached to.""" + # endregion + + # region Methods + def apply_ackermann_control(self, control: VehicleAckermannControl): + """Applies an Ackermann control object on the next tick. + + Args: + `control (VehicleAckermannControl)`\n + """ + + def apply_ackermann_controller_settings(self, settings: VehicleAckermannControl): + """Applies a new Ackermann control settings to this vehicle in the next tick. + + + Warning: This method does call the simulator.""" + + def apply_control(self, control: VehicleControl) -> None: + """Applies a control object on the next tick, containing driving parameters such as throttle, steering or gear shifting.""" + + def apply_physics_control(self, physics_control: VehiclePhysicsControl): + """Applies a physics control object in the next tick containing the parameters that define the vehicle as a corporeal body. E.g.: moment of inertia, mass, drag coefficient and many more.""" + + def close_door(self, door_idx: VehicleDoor) -> None: + """Close the door `door_idx` if the vehicle has it. Use `carla.VehicleDoor.All` to close all available doors.""" + + def enable_carsim(self, simfile_path: str): + """Enables the CarSim physics solver for this particular vehicle. In order for this function to work, there needs to be a valid license manager running on the server side. The control inputs are redirected to CarSim which will provide the position and orientation of the vehicle for every frame. + + Args: + `simfile_path (str)`: Path to the `.simfile` file with the parameters of the simulation.\n + """ + + def enable_chrono_physics(self, max_substeps: int, max_substep_delta_time: int, vehicle_json: str, powertrain_json: str, tire_json: str, base_json_path: str): + """Enables Chrono physics on a spawned vehicle. + + + Note: Ensure that you have started the CARLA server with the ARGS="--chrono" flag. You will not be able to use Chrono physics without this flag set. + + Warning: Collisions are not supported. When a collision is detected, physics will revert to the default CARLA physics. + + Args: + `max_substeps (int)`: Max number of Chrono substeps.\n + `max_substep_delta_time (int)`: Max size of substep.\n + `vehicle_json (str)`: Path to vehicle json file relative to `base_json_path`.\n + `powertrain_json (str)`: Path to powertrain json file relative to `base_json_path`.\n + `tire_json (str)`: Path to tire json file relative to `base_json_path`.\n + `base_json_path (str)`: Path to `chrono/data/vehicle` folder. E.g., `/home/user/carla/Build/chrono-install/share/chrono/data/vehicle/` (the final / character is required).\n + """ + + def is_at_traffic_light(self) -> bool: + """Vehicles will be affected by a traffic light when the light is red and the vehicle is inside its bounding box. The client returns whether a traffic light is affecting this vehicle according to last tick (it does not call the simulator).""" + + def open_door(self, door_idx: VehicleDoor): + """Open the door `door_idx` if the vehicle has it. Use carla.VehicleDoor.All to open all available doors. + + Args: + `door_idx (VehicleDoor)`: door index.\n + """ + + def show_debug_telemetry(self, enabled=True): + """Enables or disables the telemetry on this vehicle. This shows information about the vehicles current state and forces applied to it in the spectator window. Only information for one vehicle can be shown so that, if you enable a second one, the previous will be automatically disabled. + """ + + def use_carsim_road(self, enabled: bool): + """Enables or disables the usage of CarSim vs terrain file specified in the `.simfile`. By default this option is disabled and CarSim uses unreal engine methods to process the geometry of the scene.""" + # endregion + + # region Getters + def get_ackermann_controller_settings(self) -> AckermannControllerSettings: + """Returns the last Ackermann control settings applied to this vehicle. + + + Warning: This method does call the simulator to retrieve the value. + """ + + def get_control(self) -> VehicleControl: + """The client returns the control applied in the last tick. The method does not call the simulator. + """ + + def get_failure_state(self) -> VehicleFailureState: + """Vehicle have failure states, to indicate that it is incapable of continuing its route. This function returns the vehicle's specific failure state, or in other words, the cause that resulted in it.""" + + def get_light_state(self) -> VehicleLightState: + """Returns a flag representing the vehicle light state, this represents which lights are active or not. + + + Setter: `carla.Vehicle.set_light_state` + """ + + def get_physics_control(self) -> VehiclePhysicsControl: + """The simulator returns the last physics control applied to this vehicle. + + + Warning: This method does call the simulator to retrieve the value. + """ + + def get_speed_limit(self) -> float: + """The client returns the speed limit affecting this vehicle according to last tick (it does not call the simulator). The speed limit is updated when passing by a speed limit signal, so a vehicle might have none right after spawning. + + Returns: + `float`: (km/h)\n + """ + + def get_traffic_light(self) -> TrafficLight: + """Retrieves the traffic light actor affecting this vehicle (if any) according to last tick. The method does not call the simulator. + """ + + def get_traffic_light_state(self) -> TrafficLightState: + """The client returns the state of the traffic light affecting this vehicle according to last tick. The method does not call the simulator. If no traffic light is currently affecting the vehicle, returns `green`. + """ + + def get_wheel_steer_angle(self, wheel_location: VehicleWheelLocation) -> float: + """ + Returns the physics angle in degrees of a vehicle's wheel. + + + Note: Returns the angle based on the physics of the wheel, not the visual angle. + """ + # endregion + + # region Setters + def set_autopilot(self, enabled=True, port=8000) -> None: + """Registers or deletes the vehicle from a Traffic Manager's list. When `True`, the Traffic Manager passed as parameter will move the vehicle around. The autopilot takes place client-side. + + Args: + `enabled (bool, optional)`: Defaults to True.\n + `port (int, optional)`: The port of the TM-Server where the vehicle is to be registered or unlisted. Defaults to 8000.\n + """ + + def set_light_state(self, light_state: VehicleLightState) -> None: + """Sets the light state of a vehicle using a flag that represents the lights that are on and off. + + + Getter: `carla.Vehicle.get_light_state` + """ + + def set_wheel_steer_direction(self, wheel_location: VehicleWheelLocation, angle_in_deg: float): + """Sets the angle of a vehicle's wheel visually. + + + Warning: Does not affect the physics of the vehicle. + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class VehicleAckermannControl(): + """Manages the basic movement of a vehicle using Ackermann driving controls.""" + + # region Instance Variables + @property + def steer(self) -> float: + """Desired steer (rad). Positive value is to the right. Default is 0.0.""" + @property + def steer_speed(self) -> float: + """Steering velocity (rad/s). Zero steering angle velocity means change the steering angle as quickly as possible. Default is 0.0.""" + + @property + def speed(self) -> float: + """Desired speed (m/s). Default is 0.0.""" + + @property + def acceleration(self) -> float: + """Desired acceleration (m/s2) Default is 0.0.""" + + @property + def jerk(self) -> float: + """Desired jerk (m/s3). Default is 0.0.""" + # endregion + + # region Methods + def __init__(self, steer=0.0, steer_speed=0.0, speed=0.0, acceleration=0.0, jerk=0.0): ... + # endregion + + # region Dunder Methods + def __eq__(self, other: VehicleAckermannControl) -> bool: ... + def __ne__(self, other: VehicleAckermannControl) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class VehicleControl(): + """Manages the basic movement of a vehicle using typical driving controls.""" + # region Instance Variables + + @property + def throttle(self) -> float: + """A scalar value to control the vehicle throttle [0.0, 1.0]. Default is 0.0.""" + @throttle.setter + def throttle(self, value: float):... + + @property + def steer(self) -> float: + """A scalar value to control the vehicle steering [-1.0, 1.0]. Default is 0.0.""" + @steer.setter + def steer(self, value: float): ... + + @property + def brake(self) -> float: + """A scalar value to control the vehicle brake [0.0, 1.0]. Default is 0.0.""" + @brake.setter + def brake(self, value: float): ... + + @property + def hand_brake(self) -> bool: + """Determines whether hand brake will be used. Default is `False`.""" + @hand_brake.setter + def hand_brake(self, value: bool): ... + + @property + def reverse(self) -> bool: + """Determines whether the vehicle will move backwards. Default is `False`.""" + @reverse.setter + def reverse(self, value: bool): ... + + @property + def manual_gear_shift(self) -> bool: + """Determines whether the vehicle will be controlled by changing gears manually. Default is `False`.""" + @manual_gear_shift.setter + def manual_gear_shift(self, value: bool): ... + + @property + def gear(self) -> int: + """States which gear is the vehicle running on.""" + @gear.setter + def gear(self, value: int): ... + # endregion + + # region Methods + def __init__(self, throttle=0.0, steer=0.0, brake=0.0, hand_brake=False, reverse=False, manual_gear_shift=False, gear=0): + """ + Args: + `throttle (float, optional)`: Scalar value between [0.0,1.0]. Defaults to 0.0.\n + `steer (float, optional)`: Scalar value between [0.0,1.0]. Defaults to 0.0.\n + `brake (float, optional)`: Scalar value between [0.0,1.0]. Defaults to 0.0.\n + `hand_brake (bool, optional)` Defaults to False.\n + `reverse (bool, optional)` Defaults to False.\n + `manual_gear_shift (bool, optional)` Defaults to False.\n + `gear (int, optional)` Defaults to 0.\n + """ + # endregion + + # region Dunder Methods + def __eq__(self, __value: VehicleControl) -> bool: ... + def __ne__(self, __value: VehicleControl) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class VehicleDoor(int, __CarlaEnum): + """Possible index representing the possible doors that can be open. Notice that not all possible doors are able to open in some vehicles.""" + FL = 0 + """Front left door.""" + FR = 1 + """Front right door.""" + RL = 2 + """Back left door.""" + RR = 3 + """Back right door.""" + All = 6 + """Represents all doors.""" + + +class VehicleFailureState(int, __CarlaEnum): + """Enum containing the different failure states of a vehicle, from which the it cannot recover. These are returned by get_failure_state() and only Rollover is currently implemented.""" + + NONE = 0 + Rollover = 1 + Engine = 2 + TirePuncture = 3 + + +class VehicleLightState(IntFlag, __CarlaEnum): + """Class that recaps the state of the lights of a vehicle, these can be used as a flags. + + E.g: `VehicleLightState.HighBeam & VehicleLightState.Brake` will return `True` when both are active. + + Lights are off by default in any situation and should be managed by the user via script. The blinkers blink automatically. + + + Warning: Right now, not all vehicles have been prepared to work with this functionality, this will be added to all of them in later updates.""" + NONE = 0 + """All lights off.""" + Position = 1 + LowBeam = 2 + HighBeam = 4 + Brake = 8 + RightBlinker = 16 + LeftBlinker = 32 + Reverse = 64 + Fog = 128 + Interior = 256 + Special1 = 512 + """This is reserved for certain vehicles that can have special lights, like a siren.""" + Special2 = 1024 + """This is reserved for certain vehicles that can have special lights, like a siren.""" + All = -1 + """All lights on.""" + + +class VehiclePhysicsControl(): + """Summarizes the parameters that will be used to simulate a carla.Vehicle as a physical object. The specific settings for the wheels though are stipulated using `carla.WheelPhysicsControl`.""" + + # region Instance Variables + @property + def torque_curve(self) -> list[Vector2D]: + """Curve that indicates the torque measured in Nm for a specific RPM of the vehicle's engine.""" + @property + def max_rpm(self) -> float: + """The maximum RPM of the vehicle's engine.""" + + @property + def moi(self) -> float: + """The moment of inertia of the vehicle's engine. (kg*m^2)""" + + @property + def damping_rate_full_throttle(self) -> float: + """Damping ratio when the throttle is maximum.""" + + @property + def damping_rate_zero_throttle_clutch_engaged(self) -> float: + """Damping ratio when the throttle is zero with clutch engaged.""" + + @property + def damping_rate_zero_throttle_clutch_disengaged(self) -> float: + """Damping ratio when the throttle is zero with clutch disengaged.""" + + @property + def use_gear_autobox(self) -> bool: + """If `True`, the vehicle will have an automatic transmission.""" + + @property + def gear_switch_time(self) -> float: + """Switching time between gears. (seconds)""" + + @property + def clutch_strength(self) -> float: + """Clutch strength of the vehicle (kg*m^2/s).""" + + @property + def final_ratio(self) -> float: + """Fixed ratio from transmission to wheels.""" + + @property + def forward_gears(self) -> list[GearPhysicsControl]: + """List of objects defining the vehicle's gears.""" + + @property + def mass(self) -> float: + """Mass of the vehicle (kilograms).""" + + @property + def drag_coefficient(self) -> float: + """Drag coefficient of the vehicle's chassis.""" + + @property + def center_of_mass(self) -> Vector3D: + """Center of mass of the vehicle (meters).""" + + @property + def steering_curve(self) -> list[Vector2D]: + """Curve that indicates the maximum steering for a specific forward speed.""" + + @property + def use_sweep_wheel_collision(self) -> bool: + """Enable the use of sweep for wheel collision. By default, it is disabled and it uses a simple raycast from the axis to the floor for each wheel. This option provides a better collision model in which the full volume of the wheel is checked against collisions.""" + + @property + def wheels(self) -> list[WheelPhysicsControl]: + """List of wheel physics objects. This list should have 4 elements, where index 0 corresponds to the front left wheel, index 1 corresponds to the front right wheel, index 2 corresponds to the back left wheel and index 3 corresponds to the back right wheel. For 2 wheeled vehicles, set the same values for both front and back wheels.""" + # endregion + + # region Methods + def __init__(self, + torque_curve=[[0.0, 500.0], [5000.0, 500.0]], + max_rpm=5000.0, + moi=1.0, + damping_rate_full_throttle=0.15, damping_rate_zero_throttle_clutch_engaged=2.0, damping_rate_zero_throttle_clutch_disengaged=0.35, use_gear_autobox=True, + gear_switch_time=0.5, + clutch_strength=10.0, + final_ratio=4.0, + forward_gears=list(), + drag_coefficient=0.3, + center_of_mass=[0.0, 0.0, 0.0], + steering_curve=[[0.0, 1.0], [10.0, 0.5]], + wheels=list(), + use_sweep_wheel_collision=False, + mass=1000.0): + """VehiclePhysicsControl constructor. + + Args: + `torque_curve (list, optional)`. Defaults to [[0.0, 500.0], [5000.0, 500.0]].\n + `max_rpm (float, optional)`. Defaults to 5000.0.\n + `moi (float, optional)`: (kg*m^2). Defaults to 1.0.\n + `damping_rate_full_throttle (float, optional)`. Defaults to 0.15.\n + `damping_rate_zero_throttle_clutch_engaged (float, optional)`: Defaults to 2.0.\n + `damping_rate_zero_throttle_clutch_disengaged (float, optional)`: Defaults to 0.35.\n + `use_gear_autobox (bool, optional)`: Defaults to True.\n + `gear_switch_time (float, optional)`: (seconds). Defaults to 0.5.\n + `clutch_strength (float, optional)`: (kg*m^2/s). Defaults to 10.0.\n + `final_ratio (float, optional)`: Defaults to 4.0.\n + `forward_gears (list[GearPhysicsControl] optional)`: Defaults to list().\n + `drag_coefficient (float, optional)`: Defaults to 0.3.\n + `center_of_mass (list, optional)`: Defaults to [0.0, 0.0, 0.0].\n + `steering_curve (list, optional)`: Defaults to [[0.0, 1.0], [10.0, 0.5]].\n + `wheels (_type_, optional)`: Defaults to list().\n + `use_sweep_wheel_collision (bool, optional)`: Defaults to False.\n + `mass (float, optional)`: (kilograms). Defaults to 1000.0.\n + """ + # endregion + + # region Dunder Methods + def __eq__(self, other: VehiclePhysicsControl) -> bool: ... + def __ne__(self, other: VehiclePhysicsControl) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class VehicleWheelLocation(int, __CarlaEnum): + """enum representing the position of each wheel on a vehicle. Used to identify the target wheel when setting an angle in `carla.Vehicle.set_wheel_steer_direction` or `carla.Vehicle.get_wheel_steer_angle`.""" + FL_Wheel = 0 + """Front left wheel of a 4 wheeled vehicle.""" + FR_Wheel = 1 + """Front right wheel of a 4 wheeled vehicle.""" + BL_Wheel = 2 + """Back left wheel of a 4 wheeled vehicle.""" + BR_Wheel = 3 + """Back right wheel of a 4 wheeled vehicle.""" + Front_Wheel = 0 + """Front wheel of a 2 wheeled vehicle.""" + Back_Wheel = 1 + """Back wheel of a 2 wheeled vehicle.""" + + +class Walker(Actor): + """This class inherits from the `carla.Actor` and defines pedestrians in the simulation. Walkers are a special type of actor that can be controlled either by an AI (`carla.WalkerAIController`) or manually via script, using a series of `carla.WalkerControl` to move these and their skeletons. + """ + + # region Methods + def apply_control(self, control: WalkerControl): + """On the next tick, the control will move the walker in a certain direction with a certain speed. Jumps can be commanded too.""" + + def blend_pose(self, blend_value: float): + """Set the blending value of the custom pose with the animation. The values can be: + + + 0: will show only the animation + + 1: will show only the custom pose (set by the user with set_bones()) + + any other: will interpolate all the bone positions between animation and the custom pose. + + Args: + `blend_value (float)`: value from 0 to 1 with the blend percentage\n + """ + + def hide_pose(self): + """Hide the custom pose and show the animation (same as calling `blend_pose(0)`). + """ + + def show_pose(self): + """Show the custom pose and hide the animation (same as calling `blend_pose(1)`). + """ + # endregion + + # region Getters + def get_bones(self) -> WalkerBoneControlOut: + """Return the structure with all the bone transformations from the actor. For each bone, we get the name and its transform in three different spaces: + + + name: bone name + + world: transform in world coordinates + + component: transform based on the pivot of the actor + + relative: transform based on the bone parent. + + + + Setter: `carla.Walker.set_bones` + + Returns: + `WalkerBoneControlOut`: _description_\n + """ + + def get_control(self) -> WalkerControl: + """The client returns the control applied to this walker during last tick. The method does not call the simulator. + """ + + def get_pose_from_animation(self): + """Make a copy of the current animation frame as the custom pose. Initially the custom pose is the neutral pedestrian pose.""" + + # endregion + + # region Setters + def set_bones(self, bones: list[WalkerBoneControlIn]): + """Set the bones of the actor. For each bone we want to set we use a relative transform. Only the bones in this list will be set. For each bone you need to setup this info: + + + name: bone name + + relative: transform based on the bone parent. + + + Getter: `carla.Walker.get_bones` + + Args: + `bones (WalkerBoneControlIn)`: list of pairs (bone_name, transform) for the bones that we want to set)\n + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class WalkerAIController(Actor): + """Class that conducts AI control for a walker. The controllers are defined as actors, but they are quite different from the rest. They need to be attached to a parent actor during their creation, which is the walker they will be controlling (take a look at `carla.World` if you are yet to learn on how to spawn actors). They also need for a special blueprint (already defined in `carla.BlueprintLibrary` as "controller.ai.walker"). This is an empty blueprint, as the AI controller will be invisible in the simulation but will follow its parent around to dictate every step of the way. + """ + + # region Methods + def go_to_location(self, destination: Location): + """Sets the destination that the pedestrian will reach. + + Args: + `destination (Location)`: (meters)\n + """ + + def start(self): + """Enables AI control for its parent walker.""" + + def stop(self): + """Disables AI control for its parent walker.""" + # endregion + + # region Setters + def set_max_speed(self, speed=1.4): + """Sets a speed for the walker in meters per second. + + Args: + `speed (float, optional)`: An easy walking speed is set by default (m/s). Defaults to 1.4.\n + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class WalkerBoneControlIn(): + """This class grants bone specific manipulation for walker. The skeletons of walkers have been unified for clarity and the transform applied to each bone are always relative to its parent. Take a look here to learn more on how to create a walker and define its movement. + + https://carla.readthedocs.io/en/latest/tuto_G_control_walker_skeletons/ + """ + + # region Instance Variables + @property + def bone_transforms(self) -> list[tuple[str, Transform]]: + """ + List with the data for each bone we want to set: + + name: bone name + + relative: transform based on the bone parent. + """ + # endregion + + # region Methods + def __init__(self, bone_transforms: list[tuple[str, Transform]]): + """Initializes an object containing moves to be applied on tick. These are listed with the name of the bone and the transform that will be applied to it. + + Args: + `bone_transforms (list[tuple[str,Transform]])`\n + """ + ... + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class WalkerBoneControlOut(): + """This class is used to return all bone positions of a pedestrian. For each bone we get its name and its transform in three different spaces (world, actor and relative).""" + + # region Instance Variables + @property + def bone_transforms(self) -> list[tuple[str, Transform, Transform, Transform]]: + """ + List of one entry per bone with this information: + + + name: bone name + + world: transform in world coordinates + + component: transform based on the pivot of the actor + + relative: transform based on the bone parent. + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class WalkerControl(): + """This class defines specific directions that can be commanded to a `carla.Walker` to control it via script. + + AI control can be settled for walkers, but the control used to do so is `carla.WalkerAIController`. + """ + + # region Instance Variables + @property + def direction(self) -> Vector3D: + """Vector using global coordinates that will correspond to the direction of the walker.""" + @property + def speed(self) -> float: + """A scalar value to control the walker's speed (m/s).""" + @property + def jump(self) -> bool: + """If `True`, the walker will perform a jump.""" + # endregion + + # region Methods + def __init__(self, direction=[1.0, 0.0, 0.0], speed=0.0, jump=False): + """This class defines specific directions that can be commanded to a `carla.Walker` to control it via script. + + Args: + `direction (list, optional)`: Vector using global coordinates that will correspond to the direction of the walker.. Defaults to [1.0, 0.0, 0.0].\n + `speed (float, optional)`: A scalar value to control the walker's speed (m/s). Defaults to 0.0.\n + `jump (bool, optional)`: If `True`, the walker will perform a jump. Defaults to False.\n + """ + # endregion + + # region Dunder Methods + def __eq__(self, __value: WalkerControl) -> bool: ... + def __ne__(self, __value: WalkerControl) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class Waypoint(): + """Waypoints in CARLA are described as 3D directed points. They have a `carla.Transform` which locates the waypoint in a road and orientates it according to the lane. They also store the road information belonging to said point regarding its lane and lane markings. + + All the information regarding waypoints and the waypoint API is retrieved as provided by the OpenDRIVE file. Once the client asks for the map object to the server, no longer communication will be needed. + """ + # region Instance Variables + @property + def id(self) -> int: + """The identifier is generated using a hash combination of the road, section, lane and s values that correspond to said point in the OpenDRIVE geometry. The s precision is set to 2 centimeters, so 2 waypoints closer than 2 centimeters in the same road, section and lane, will have the same identificator.""" + + @property + def transform(self) -> Transform: + """Position and orientation of the waypoint according to the current lane information. This data is computed the first time it is accessed. It is not created right away in order to ease computing costs when lots of waypoints are created but their specific transform is not needed.""" + + @property + def road_id(self) -> int: + """OpenDRIVE road's id.""" + + @property + def section_id(self) -> int: + """OpenDRIVE section's id, based on the order that they are originally defined.""" + + @property + def is_junction(self) -> bool: + """True if the current Waypoint is on a junction as defined by OpenDRIVE.""" + + @property + def junction_id(self) -> int: + """OpenDRIVE junction's id. For more information refer to OpenDRIVE documentation. + + http://www.opendrive.org/docs/OpenDRIVEFormatSpecRev1.4H.pdf#page=20 + """ + + @property + def lane_id(self) -> int: + """OpenDRIVE lane's id, this value can be positive or negative which represents the direction of the current lane with respect to the road. For more information refer to OpenDRIVE documentation.""" + + @property + def s(self) -> float: + """OpenDRIVE s value of the current position.""" + + @property + def lane_width(self) -> float: + """Horizontal size of the road at current `s`.""" + + @property + def lane_change(self) -> LaneChange: + """Lane change definition of the current Waypoint's location, based on the traffic rules defined in the OpenDRIVE file. It states if a lane change can be done and in which direction.""" + + @property + def lane_type(self) -> LaneType: + """The lane type of the current Waypoint, based on OpenDRIVE 1.4 standard.""" + + @property + def right_lane_marking(self) -> LaneMarking: + """The right lane marking information based on the direction of the Waypoint.""" + + @property + def left_lane_marking(self) -> LaneMarking: + """The left lane marking information based on the direction of the Waypoint.""" + # endregion + + # region Methods + def next(self, distance: float) -> list[Waypoint]: + """Returns a list of waypoints at a certain approximate `distance` from the current one. It takes into account the road and its possible deviations without performing any lane change and returns one waypoint per option. The list may be empty if the lane is not connected to any other at the specified distance. + + Args: + `distance (float)`: The approximate distance where to get the next waypoints (meters).\n + + Returns: + `list[Waypoint]`\n + """ + + def next_until_lane_end(self, distance: float) -> list[Waypoint]: + """Returns a list of waypoints from this to the end of the lane separated by a certain `distance`."" + + Args: + `distance (float)`: The approximate distance between waypoints.(meters). + + Returns: + `list[Waypoint]`\n + """ + + def previous(self, distance: float) -> list[Waypoint]: + """This method does not return the waypoint previously visited by an actor, but a list of waypoints at an approximate `distance` but in the opposite direction of the lane. Similarly to `next()`, it takes into account the road and its possible deviations without performing any lane change and returns one waypoint per option. The list may be empty if the lane is not connected to any other at the specified distance. + + Args: + `distance (float)`: The approximate distance where to get the previous waypoints (meters).\n + + Returns: + `list[Waypoint]`\n + """ + + def previous_until_lane_start(self, distance: float) -> list[Waypoint]: + """Returns a list of waypoints from this to the start of the lane separated by a certain distance. + + Args: + `distance (float)`: The approximate distance between waypoints (meters).\n + + Returns: + `list[Waypoint]`\n + """ + # endregion + # region Getters + + def get_junction(self) -> Junction: + """If the waypoint belongs to a junction this method returns the associated junction object. Otherwise returns `null`.""" + + def get_landmarks(self, distance: float, stop_at_junction=False) -> list[Landmark]: + """Returns a list of landmarks in the road from the current waypoint until the specified distance. + + Args: + `distance (float)`: The maximum distance to search for landmarks from the current waypoint (meters).\n + `stop_at_junction (bool, optional)`: Enables or disables the landmark search through junctions. Defaults to False.\n + """ + + def get_landmarks_of_type(self, distance: float, type: str, stop_at_junction=False) -> list[Landmark]: + """Returns a list of landmarks in the road of a specified type from the current waypoint until the specified distance. + + Args: + `distance (float)`: The maximum distance to search for landmarks from the current waypoint (meters).\n + `type (str)`: The type of landmarks to search.\n + `stop_at_junction (bool, optional)`: Enables or disables the landmark search through junctions. Defaults to False.\n + """ + + def get_left_lane(self) -> Waypoint | None: + """ + Generates a Waypoint at the center of the left lane based on the direction of the current + Waypoint, taking into account if the lane change is allowed in this location. + Will return `None` if the lane does not exist. + """ + + def get_right_lane(self) -> Waypoint | None: + """ + Generates a waypoint at the center of the right lane based on the direction of the current + waypoint, taking into account if the lane change is allowed in this location. + Will return `None` if the lane does not exist. + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: ... + # endregion + + +class WeatherParameters(): + """This class defines objects containing lighting and weather specifications that can later be applied in `carla.World`. So far, these conditions only intervene with `sensor.camera.rgb`. They neither affect the actor's physics nor other sensors. + + Each of these parameters acts independently from the rest. Increasing the rainfall will not automatically create puddles nor change the road's humidity. That makes for a better customization but means that realistic conditions need to be scripted. However an example of dynamic weather conditions working realistically can be found here. + + https://github.com/carla-simulator/carla/blob/master/PythonAPI/examples/dynamic_weather.py + """ + # region Instance Variables + @property + def cloudiness(self) -> float: + """Values range from 0 to 100, being 0 a clear sky and 100 one completely covered with clouds.""" + @property + def precipitation(self) -> float: + """Rain intensity values range from 0 to 100, being 0 none at all and 100 a heavy rain.""" + @property + def precipitation_deposits(self) -> float: + """Determines the creation of puddles. Values range from 0 to 100, being 0 none at all and 100 a road completely capped with water. Puddles are created with static noise, meaning that they will always appear at the same locations.""" + @property + def wind_intensity(self) -> float: + """Controls the strength of the wind with values from 0, no wind at all, to 100, a strong wind. The wind does affect rain direction and leaves from trees, so this value is restricted to avoid animation issues.""" + @property + def sun_azimuth_angle(self) -> float: + """The azimuth angle of the sun. Values range from 0 to 360. Zero is an origin point in a sphere determined by Unreal Engine (degrees).""" + @property + def sun_altitude_angle(self) -> float: + """Altitude angle of the sun. Values range from -90 to 90 corresponding to midnight and midday each (degrees).""" + @property + def fog_density(self) -> float: + """Fog concentration or thickness. It only affects the RGB camera sensor. Values range from 0 to 100.""" + @property + def fog_distance(self) -> float: + """Fog start distance. Values range from 0 to infinite (meters).""" + @property + def wetness(self) -> float: + """Wetness intensity. It only affects the RGB camera sensor. Values range from 0 to 100.""" + @property + def fog_falloff(self) -> float: + """Density of the fog (as in specific mass) from 0 to infinity. The bigger the value, the more dense and heavy it will be, and the fog will reach smaller heights. Corresponds to `Fog Height Falloff` in the UE docs. + + If the value is 0, the fog will be lighter than air, and will cover the whole scene. + A value of 1 is approximately as dense as the air, and reaches normal-sized buildings. + + For values greater than 5, the air will be so dense that it will be compressed on ground level. + """ + @property + def scattering_intensity(self) -> float: + """Controls how much the light will contribute to volumetric fog. When set to 0, there is no contribution.""" + @property + def mie_scattering_scale(self) -> float: + """Controls interaction of light with large particles like pollen or air pollution resulting in a hazy sky with halos around the light sources. When set to 0, there is no contribution.""" + @property + def rayleigh_scattering_scale(self) -> float: + """Controls interaction of light with small particles like air molecules. Dependent on light wavelength, resulting in a blue sky in the day or red sky in the evening.""" + @property + def dust_storm(self) -> float: + """Determines the strength of the dust storm weather. Values range from 0 to 100.""" + # endregion + + # region Methods + def __init__(self, + cloudiness=0.0, + precipitation=0.0, + precipitation_deposits=0.0, + wind_intensity=0.0, + sun_azimuth_angle=0.0, + sun_altitude_angle=0.0, + fog_density=0.0, + fog_distance=0.0, + wetness=0.0, + fog_falloff=0.0, + scattering_intensity=0.0, + mie_scattering_scale=0.0, + rayleigh_scattering_scale=0.0331): + """Method to initialize an object defining weather conditions. This class has some presets for different noon and sunset conditions listed in a note below. + + + Note: ClearNoon, CloudyNoon, WetNoon, WetCloudyNoon, SoftRainNoon, MidRainyNoon, HardRainNoon, ClearSunset, CloudySunset, WetSunset, WetCloudySunset, SoftRainSunset, MidRainSunset, HardRainSunset. + + Args: + `cloudiness (float, optional)`: 0 is a clear sky, 100 complete overcast. Defaults to 0.0.\n + `precipitation (float, optional)`: 0 is no rain at all, 100 a heavy rain. Defaults to 0.0.\n + `precipitation_deposits (float, optional)`: 0 means no puddles on the road, 100 means roads completely capped by rain. Defaults to 0.0.\n + `wind_intensity (float, optional)`: 0 is calm, 100 a strong wind. Defaults to 0.0.\n + `sun_azimuth_angle (float, optional)`: 0 is an arbitrary North, 180 its corresponding South. Defaults to 0.0.\n + `sun_altitude_angle (float, optional)`: 90 is midday, -90 is midnight. Defaults to 0.0.\n + `fog_density (float, optional)`: Concentration or thickness of the fog, from 0 to 100. Defaults to 0.0.\n + `fog_distance (float, optional)`: Distance where the fog starts in meters. Defaults to 0.0.\n + `wetness (float, optional)`: Humidity percentages of the road, from 0 to 100. Defaults to 0.0.\n + `fog_falloff (float, optional)`: Density (specific mass) of the fog, from 0 to infinity. Defaults to 0.0.\n + `scattering_intensity (float, optional)`: Controls how much the light will contribute to volumetric fog. When set to 0, there is no contribution. Defaults to 0.0.\n + `mie_scattering_scale (float, optional)`: Controls interaction of light with large particles like pollen or air pollution resulting in a hazy sky with halos around the light sources. When set to 0, there is no contribution. Defaults to 0.0.\n + `rayleigh_scattering_scale (float, optional)`: Controls interaction of light with small particles like air molecules. Dependent on light wavelength, resulting in a blue sky in the day or red sky in the evening. Defaults to 0.0331.\n + """ + # endregion + + # region Dunder Methods + def __eq__(self, __value: WeatherParameters) -> bool: ... + def __ne__(self, __value: WeatherParameters) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class WheelPhysicsControl(): + """Class that defines specific physical parameters for wheel objects that will be part of a `carla.VehiclePhysicsControl` to simulate vehicle it as a material object.""" + + # region Instance Variables + @property + def tire_friction(self) -> float: + """A scalar value that indicates the friction of the wheel.""" + @property + def damping_rate(self) -> float: + """Damping rate of the wheel.""" + @property + def max_steer_angle(self) -> float: + """Maximum angle that the wheel can steer (degrees).""" + @property + def radius(self) -> float: + """Radius of the wheel (centimeters).""" + @property + def max_brake_torque(self) -> float: + """Maximum brake torque (N*m).""" + @property + def max_handbrake_torque(self) -> float: + """Maximum handbrake torque.""" + @property + def position(self) -> Vector3D: + """World position of the wheel. This is a read-only parameter.""" + @property + def long_stiff_value(self) -> float: + """Tire longitudinal stiffness per unit gravitational acceleration. Each vehicle has a custom value (kg/rad).""" + @property + def lat_stiff_max_load(self) -> float: + """Maximum normalized tire load at which the tire can deliver no more lateral stiffness no matter how much extra load is applied to the tire. Each vehicle has a custom value.""" + @property + def lat_stiff_value(self) -> float: + """Maximum stiffness per unit of lateral slip. Each vehicle has a custom value.""" + # endregion + + # region Methods + def __init__(self, + tire_friction=2.0, + damping_rate=0.25, + max_steer_angle=70.0, + radius=30.0, + max_brake_torque=1500.0, + max_handbrake_torque=3000.0, + position: Vector3D = Vector3D(0.0, 0.0, 0.0)): ... + # endregion + + # region Dunder Methods + def __eq__(self, __value: WheelPhysicsControl) -> bool: ... + def __ne__(self, __value: WheelPhysicsControl) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class World(): + """World objects are created by the client to have a place for the simulation to happen. The world contains the map we can see, meaning the asset, not the navigation map. Navigation maps are part of the `carla.Map` class. It also manages the weather and actors present in it. There can only be one world per simulation, but it can be changed anytime.""" + + # region Instance Variables + @property + def id(self) -> int: + """The ID of the episode associated with this world. Episodes are different sessions of a simulation. These change everytime a world is disabled or reloaded. Keeping track is useful to avoid possible issues.""" + @property + def debug(self) -> DebugHelper: + """Responsible for creating different shapes for debugging. Take a look at its class to learn more about it.""" + # endregion + + # region Methods + def apply_color_texture_to_object(self, object_name: str, material_parameter: MaterialParameter, texture: TextureColor): + """Applies a `texture` object in the field corresponding to `material_parameter` (normal, diffuse, etc) to the object in the scene corresponding to `object_name`.""" + + def apply_color_texture_to_objects(self, objects_name_list: list[str], material_parameter: MaterialParameter, texture: TextureColor): + """Applies a `texture` object in the field corresponding to `material_parameter` (normal, diffuse, etc) to the object in the scene corresponding to all objects in `objects_name_list`.""" + + def apply_float_color_texture_to_object(self, object_name: str, material_parameter: MaterialParameter, texture: TextureFloatColor): + """Applies a `texture` object in the field corresponding to `material_parameter` (normal, diffuse, etc) to the object in the scene corresponding to all objects in `objects_name_list`.""" + + def apply_float_color_texture_to_objects(self, objects_name_list: list[str], material_parameter: MaterialParameter, texture: TextureFloatColor): + """Applies a `texture` object in the field corresponding to `material_parameter` (normal, diffuse, etc) to the object in the scene corresponding to all objects in `objects_name_list`.""" + + def apply_settings(self, world_settings: WorldSettings) -> int: + """This method applies settings contained in an object to the simulation running and returns the ID of the frame they were implemented. + + + Warning: If synchronous mode is enabled, and there is a Traffic Manager running, this must be set to sync mode too. Read this to learn how to do it. + https://carla.readthedocs.io/en/latest/adv_traffic_manager/#synchronous-mode + """ + + def apply_textures_to_object(self, object_name: str, diffuse_texture: TextureColor, emissive_texture: TextureFloatColor, normal_texture: TextureFloatColor, ao_roughness_metallic_emissive_texture: TextureFloatColor): + """Applies all texture fields in `carla.MaterialParameter` to the object `object_name`. Empty textures here will not be applied. + """ + + def apply_textures_to_objects(self, objects_name_list: list[str], diffuse_texture: TextureColor, emissive_texture: TextureFloatColor, normal_texture: TextureFloatColor, ao_roughness_metallic_emissive_texture: TextureFloatColor): + """Applies all texture fields in `carla.MaterialParameter` to all objects in `objects_name_list`. Empty textures here will not be applied.""" + + def cast_ray(self, initial_location: Location, final_location: Location) -> list[LabelledPoint]: + """Casts a ray from the specified initial_location to final_location. The function then detects all geometries intersecting the ray and returns a list of `carla.LabelledPoint` in order. + + Args: + initial_location (Location): The initial position of the ray. + final_location (Location): The final position of the ray. + """ + + def enable_environment_objects(self, env_objects_ids: set[int], enable: bool): + """Enable or disable a set of EnvironmentObject identified by their id. These objects will appear or disappear from the level. + + Args: + env_objects_ids (set[int]): Set of EnvironmentObject ids to change. + enable (bool): State to be applied to all the EnvironmentObject of the set. + """ + + def freeze_all_traffic_lights(self, frozen: bool): + """Freezes or unfreezes all traffic lights in the scene. Frozen traffic lights can be modified by the user but the time will not update them until unfrozen.""" + + def ground_projection(self, location: Location, search_distance: float) -> LabelledPoint: + """Projects the specified point downwards in the scene. The functions casts a ray from location in the direction (0,0,-1) (downwards) and returns a `carla.LabelledPoint` object with the first geometry this ray intersects (usually the ground). If no geometry is found in the search_distance range the function returns `None`. + + Args: + location (Location): The point to be projected. + search_distance (float): The maximum distance to perform the projection. + """ + + def load_map_layer(self, map_layers: MapLayer): + """Loads the selected layers to the level. If the layer is already loaded the call has no effect. + + + Warning: This only affects "Opt" maps. The minimum layout includes roads, sidewalks, traffic lights and traffic signs. + + Args: + map_layers (MapLayer): Mask of level layers to be loaded. + """ + + def on_tick(self, callback: Callable[[WorldSnapshot], Any]) -> int: + """This method is used in `asynchronous mode`. It starts callbacks from the client for the function defined as `callback`, and returns the ID of the callback. The function will be called everytime the server ticks. It requires a `carla.WorldSnapshot` as argument, which can be retrieved from `wait_for_tick()`. Use `remove_on_tick()` to stop the callbacks. + + Args: + callback (Callable[[WorldSnapshot], Any]): Function with a `snapshot` as compulsory parameter that will be called when the client receives a tick. + """ + + def project_point(self, location: Location, direction: Vector3D, search_distance: float) -> LabelledPoint: + """Projects the specified point to the desired direction in the scene. The functions casts a ray from location in a direction and returns a carla.Labelled object with the first geometry this ray intersects. If no geometry is found in the search_distance range the function returns `None`. + + Args: + `location (Location)`: The point to be projected.\n + `direction (Vector3D)`: The direction of projection.\n + `search_distance (float)`: The maximum distance to perform the projection.\n + + Returns: + `LabelledPoint`\n + """ + + def remove_on_tick(self, callback_id: int): + """Stops the callback for callback_id started with `on_tick()`. + + Args: + `callback_id (int)`: The callback to be removed. The ID is returned when creating the callback.\n + """ + + def reset_all_traffic_lights(self): + """Resets the cycle of all traffic lights in the map to the initial state. + """ + + def spawn_actor(self, blueprint: ActorBlueprint, transform: Transform, attach_to: Optional[Actor] = None, attachment_type=AttachmentType.Rigid) -> Actor: + """The method will create, return and spawn an actor into the world. The actor will need an available blueprint to be created and a transform (location and rotation). It can also be attached to a parent with a certain attachment type. + + Args: + `blueprint (ActorBlueprint)`: The reference from which the actor will be created.\n + `transform (Transform)`: Contains the location and orientation the actor will be spawned with.\n + `attach_to (Actor, optional)`: The parent object that the spawned actor will follow around. Defaults to None.\n + `attachment (AttachmentType, optional)`: Determines how fixed and rigorous should be the changes in position according to its parent object. Defaults to AttachmentType.Rigid.\n + + Returns: + `Actor`\n + """ + + def tick(self, seconds=10.0) -> int: + """This method is used in synchronous mode, when the server waits for a client tick before computing the next frame. This method will send the tick, and give way to the server. It returns the ID of the new frame computed by the server. + + + Note: If no tick is received in synchronous mode, the simulation will freeze. Also, if many ticks are received from different clients, there may be synchronization issues. Please read the docs about synchronous mode to learn more. + + Args: + `seconds (float, optional)`: Maximum time the server should wait for a tick. Defaults to 10.0.\n + + Returns: + `int`\n + """ + + def try_spawn_actor(self, blueprint: ActorBlueprint, transform: Transform, attach_to: Optional[Actor] = None, attachment_type=AttachmentType.Rigid) -> Actor: + """Same as `spawn_actor()` but returns `None` on failure instead of throwing an exception. + + Args: + `blueprint (ActorBlueprint)`: The reference from which the actor will be created.\n + `transform (Transform)`: Contains the location and orientation the actor will be spawned with.\n + `attach_to (Actor, optional)`: The parent object that the spawned actor will follow around. Defaults to None.\n + `attachment (AttachmentType, optional)`: Determines how fixed and rigorous should be the changes in position according to its parent object. Defaults to AttachmentType.Rigid.\n + + Returns: + `Actor`\n + """ + + def unload_map_layer(self, map_layers: MapLayer): + """Unloads the selected layers to the level. If the layer is already unloaded the call has no effect. + + + Warning: This only affects "Opt" maps. The minimum layout includes roads, sidewalks, traffic lights and traffic signs. + + Args: + `map_layers (MapLayer)`: Mask of level layers to be unloaded.\n + """ + + def wait_for_tick(self, seconds=10.0) -> WorldSnapshot: + """This method is used in asynchronous mode. It makes the client wait for a server tick. When the next frame is computed, the server will tick and return a snapshot describing the new state of the world. + + Args: + `seconds (float, optional)`: Maximum time the server should wait for a tick. Defaults to 10.0.\n + + Returns: + `WorldSnapshot`\n + """ + # endregion + + # region Getters + def get_actor(self, actor_id: int) -> Actor: + """Looks up for an actor by ID and returns `None` if not found.""" + + def get_actors(self, actor_ids: Optional[list[int]] = None) -> ActorList: + """ + Retrieves a list of `carla.Actor` elements, either using a list of IDs provided or just + listing everyone on stage. If an ID does not correspond with any actor, it will be excluded + from the list returned, meaning that both the list of IDs and the list of actors may have + different lengths. + + Args: + `actor_ids (list[int], optional)`: The IDs of the actors being searched. By default it is set to None and returns every actor on scene. + + Returns: + `ActorList` + """ + + def get_blueprint_library(self) -> BlueprintLibrary: + """Returns a list of actor blueprints available to ease the spawn of these into the world.""" + + def get_environment_objects(self, object_type: CityObjectLabel = CityObjectLabel.Any) -> list[EnvironmentObject]: + """Returns a list of EnvironmentObject with the requested semantic tag. The method returns all the EnvironmentObjects in the level by default, but the query can be filtered by semantic tags with the argument `object_type`. + + Args: + `object_type (CityObjectLabel, optional)`: Semantic tag of the EnvironmentObjects that are returned. Defaults to CityObjectLabel.Any.\n + """ + + def get_level_bbs(self, actor_type: CityObjectLabel = CityObjectLabel.Any) -> list[BoundingBox]: + """Returns an array of bounding boxes with location and rotation in world space. The method returns all the bounding boxes in the level by default, but the query can be filtered by semantic tags with the argument `actor_type`. + + Args: + `actor_type (CityObjectLabel, optional)`: Semantic tag of the elements contained in the bounding boxes that are returned. Defaults to CityObjectLabel.Any.\n + + Returns: + `list[BoundingBox]`\n + """ + + def get_lightmanager(self) -> LightManager: + """Returns an instance of carla.LightManager that can be used to handle the lights in the scene.""" + + def get_map(self) -> Map: + """Asks the server for the XODR containing the map file, and returns this parsed as a `carla.Map`. + + + Warning: This method does call the simulation. It is expensive, and should only be called once. + + """ + + def get_names_of_all_objects(self) -> list[str]: + """Returns a list of the names of all objects in the scene that can be painted with the apply texture functions.""" + + def get_random_location_from_navigation(self) -> Location: + """This can only be used with walkers. It retrieves a random location to be used as a destination using the `go_to_location()` method in `carla.WalkerAIController`. This location will be part of a sidewalk. Roads, crosswalks and grass zones are excluded. The method does not take into consideration locations of existing actors so if a collision happens when trying to spawn an actor, it will return an error. Take a look at `generate_traffic.py` for an example.""" + + def get_settings(self) -> WorldSettings: + """Returns an object containing some data about the simulation such as synchrony between client and server or rendering mode.""" + + def get_snapshot(self) -> WorldSnapshot: + """Returns a snapshot of the world at a certain moment comprising all the information about the actors.""" + + def get_spectator(self) -> Actor: + """Returns the spectator actor. The spectator is a special type of actor created by Unreal Engine, usually with ID=0, that acts as a camera and controls the view in the simulator window.""" + + def get_traffic_light(self, landmark: Landmark) -> TrafficLight: + """Provided a landmark, returns the traffic light object it describes. + + Args: + `landmark (Landmark)`: The landmark object describing a traffic light.\n + """ + + def get_traffic_light_from_opendrive_id(self, traffic_light_id: str) -> TrafficLight: + """Returns the traffic light actor corresponding to the indicated OpenDRIVE id. + + Args: + `traffic_light_id (str)`: The OpenDRIVE id.\n + """ + + def get_traffic_lights_from_waypoint(self, waypoint: Waypoint, distance: float) -> list[TrafficLight]: + """This function performs a search along the road in front of the specified waypoint and returns a list of traffic light actors found in the specified search distance. + + Args: + `waypoint (Waypoint)`: The input waypoint.\n + `distance (float)`: Search distance.\n + """ + + def get_traffic_lights_in_junction(self, junction_id: int) -> list[TrafficLight]: + """Returns the list of traffic light actors affecting the junction indicated in `junction_id`. + + Args: + `junction_id (int)`: The id of the junction.\n + """ + + def get_traffic_sign(self, landmark: Landmark) -> TrafficSign: + """Provided a landmark, returns the traffic sign object it describes. + + Args: + `landmark (Landmark)`: The landmark object describing a traffic sign.\n + """ + + def get_vehicles_light_states(self) -> dict[int, VehicleLightState]: + """Returns a dict where the keys are `carla.Actor` IDs and the values are `carla.VehicleLightState` of that vehicle. + """ + + def get_weather(self) -> WeatherParameters: + """Retrieves an object containing weather parameters currently active in the simulation, mainly cloudiness, precipitation, wind and sun position. + + + Setter: `carla.World.set_weather` + """ + # endregion + + # region Setters + def set_pedestrians_cross_factor(self, percentage: float): + """Sets the percentage of pedestrians that can walk on the road or cross at any point on the road. + + + Note: Should be set before pedestrians are spawned. + + Args: + `percentage (float)`: Value should be between 0.0 and 1.0. For example, a value of 0.1 would allow 10% of pedestrians to walk on the road.\n + """ + + def set_pedestrians_seed(self, seed: int): + """ Sets the seed to use for any random number generated in relation to pedestrians. + + + Note: Should be set before pedestrians are spawned. If you want to repeat the same exact bodies (blueprint) for each pedestrian, then use the same seed in the Python code (where the blueprint is chosen randomly) and here, otherwise the pedestrians will repeat the same paths but the bodies will be different. + """ + + def set_weather(self, weather: WeatherParameters): + """Changes the weather parameters ruling the simulation to another ones defined in an object. + + + Getter: `carla.World.get_weather` + + Args: + `weather (WeatherParameters)`: New conditions to be applied.\n + """ + # endregion + + # region Dunder Methods + def __str__(self) -> str: + """The content of the world is parsed and printed as a brief report of its current state.""" + # endregion + + +class WorldSettings(): + """The simulation has some advanced configuration options that are contained in this class and can be managed using carla.World and its methods. These allow the user to choose between client-server synchrony/asynchrony, activation of "no rendering mode" and either if the simulation should run with a fixed or variable time-step. Check this out if you want to learn about it. + + https://carla.readthedocs.io/en/latest/adv_synchrony_timestep/ + """ + + # region description + @property + def synchronous_mode(self) -> bool: + """States the synchrony between client and server. When set to true, the server will wait for a client tick in order to move forward. It is `False` by default.""" + @synchronous_mode.setter + def synchronous_mode(self, value: bool): + ... + + @property + def no_rendering_mode(self) -> bool: + """When enabled, the simulation will run no rendering at all. This is mainly used to avoid overhead during heavy traffic simulations. It is `False` by default.""" + @no_rendering_mode.setter + def no_rendering_mode(self, value: bool): + ... + + @property + def fixed_delta_seconds(self) -> float | None: + """Ensures that the time elapsed between two steps of the simulation is fixed. Set this to `0.0` to work with a variable time-step, as happens by default.""" + @fixed_delta_seconds.setter + def fixed_delta_seconds(self, value: float | None): + ... + + @property + def substepping(self) -> bool: + """Enable the physics substepping. This option allows computing some physics substeps between two render frames. If synchronous mode is set, the number of substeps and its time interval are fixed and computed are so they fulfilled the requirements of `carla.WorldSettings.max_substep` and `carla.WorldSettings.max_substep_delta_time`. These last two parameters need to be compatible with c`arla.WorldSettings.fixed_delta_seconds`. Enabled by default.""" + @substepping.setter + def substepping(self, value: bool): + ... + + @property + def max_substep_delta_time(self) -> float: + """Maximum delta time of the substeps. If the carla.`WorldSettingsmax_substep` is high enough, the substep delta time would be always below or equal to this value. By default, the value is set to 0.01.""" + @max_substep_delta_time.setter + def max_substep_delta_time(self, value: float): + ... + + @property + def max_substeps(self) -> int: + """The maximum number of physics substepping that are allowed. By default, the value is set to 10.""" + @max_substeps.setter + def max_substeps(self, value: int): + ... + + @property + def max_culling_distance(self) -> float: + """Configure the max draw distance for each mesh of the level.""" + @max_culling_distance.setter + def max_culling_distance(self, value: float): + ... + + @property + def deterministic_ragdolls(self) -> bool: + """Defines wether to use deterministic physics for pedestrian death animations or physical ragdoll simulation. When enabled, pedestrians have less realistic death animation but ensures determinism. When disabled, pedestrians are simulated as ragdolls with more realistic simulation and collision but no determinsm can be ensured.""" + @deterministic_ragdolls.setter + def deterministic_ragdolls(self, value: bool): + ... + + @property + def tile_stream_distance(self) -> bool: + """Used for large maps only. Configures the maximum distance from the hero vehicle to stream tiled maps. Regions of the map within this range will be visible (and capable of simulating physics). Regions outside this region will not be loaded.""" + @tile_stream_distance.setter + def tile_stream_distance(self, value: bool): + ... + + @property + def actor_active_distance(self) -> float: + """Used for large maps only. Configures the distance from the hero vehicle to convert actors to dormant. Actors within this range will be active, and actors outside will become dormant.""" + @actor_active_distance.setter + def actor_active_distance(self, value: float): + ... + + @property + def spectator_as_ego(self) -> float: + """Used for large maps only. Defines the influence of the spectator on tile loading in Large Maps. By default, the spectator will provoke loading of neighboring tiles in the absence of an ego actor. This might be inconvenient for applications that immediately spawn an ego actor.""" + @spectator_as_ego.setter + def spectator_as_ego(self, value: float): + ... + + # region Methods + def __init__(self, + synchronous_mode=False, + no_rendering_mode=False, + fixed_delta_seconds=0.0, + max_culling_distance=0.0, + deterministic_ragdolls=False, + tile_stream_distance=3000, + actor_active_distance=2000, + spectator_as_ego=True): + """Creates an object containing desired settings that could later be applied through `carla.World` and its method `apply_settings()`. + + Args: + `synchronous_mode (bool, optional)`: Set this to true to enable client-server synchrony. Defaults to False.\n + `no_rendering_mode (bool, optional)`: Set this to true to completely disable rendering in the simulation. Defaults to False.\n + `fixed_delta_seconds (float, optional)`: Set a fixed time-step in between frames. 0.0 means variable time-step (seconds). Defaults to 0.0.\n + `max_culling_distance (float, optional)`: Configure the max draw distance for each mesh of the level (meters). Defaults to 0.0.\n + `deterministic_ragdolls (bool, optional)`: Defines wether to use deterministic physics or ragdoll simulation for pedestrian deaths. Defaults to False.\n + `tile_stream_distance (int, optional)`: Used for large maps only. Configures the maximum distance from the hero vehicle to stream tiled maps (meters). Defaults to 3000.\n + `actor_active_distance (int, optional)`: Used for large maps only. Configures the distance from the hero vehicle to convert actors to dormant (meters). Defaults to 2000.\n + `spectator_as_ego (bool, optional)`: Used for large maps only. Defines the influence of the spectator on tile loading in Large Maps. Defaults to True.\n + + Returns: + `WorldSettings`: _description_\n + """ + # endregion + + # region Dunder Methods + def __eq__(self, __value: WorldSettings) -> bool: ... + def __ne__(self, __value: WorldSettings) -> bool: ... + def __str__(self) -> str: ... + # endregion + + +class WorldSnapshot(): + """ + This snapshot comprises all the information for every actor on scene at a certain moment of time. + It creates and gives access to a data structure containing a series of `carla.ActorSnapshot`. + The client receives a new snapshot on every tick that cannot be stored. + """ + + # region Instance Variables + @property + def id(self) -> int: + """A value unique for every snapshot to differentiate them.""" + @property + def frame(self) -> int: + """Simulation frame in which the snapshot was taken.""" + @property + def timestamp(self) -> Timestamp: + """Precise moment in time when snapshot was taken. This class works in seconds as given by the operative system (seconds).""" + # endregion + + # region Methods + def find(self, actor_id: int) -> ActorSnapshot: + """Given a certain actor ID, returns its corresponding snapshot or `None` if it is not found. + """ + + def has_actor(self, actor_id: int) -> bool: + """Given a certain actor ID, checks if there is a snapshot corresponding it and so, if the actor was present at that moment.""" + # endregion + + # region Dunder Methods + def __eq__(self, __value: WorldSnapshot) -> bool: + """Returns True if both `timestamp` are the same.""" + + def __iter__(self) -> Iterator[ActorSnapshot]: + """Iterate over the `carla.ActorSnapshot` stored in the snapshot.""" + + def __len__(self) -> int: + """Returns the amount of `carla.ActorSnapshot` present in this snapshot.""" + + def __ne__(self, __value: WorldSnapshot) -> bool: + """Returns True if both `timestamp` are different.""" + # endregion + + +class command(): + """ + Submodule with commands that can be used with `carla.Client.apply_batch` + and `carla.Client.apply_batch_sync`. + """ + + class ApplyAngularImpulse(): + """Command adaptation of `add_angular_impulse()` in `carla.Actor`. Applies an angular impulse to an actor. + """ + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def impulse(self) -> Vector3D: + """Angular impulse applied to the actor (degrees*s).""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], impulse: Vector3D): + """Applies an angular impulse to an actor. + + Args: + `actor (Union[Actor,int])`: Actor or its ID to whom the command will be applied to.\n + `impulse (Vector3D)`: (degrees*s)\n + """ + # endregion + + class ApplyForce(): + """Command adaptation of `add_force()` in `carla.Actor`. Applies a force to an actor.""" + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def force(self) -> Vector3D: + """Force applied to the actor over time (N).""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], force: Vector3D): + """Applies a force to an actor. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `force (Vector3D)`: (N)\n + """ + # endregion + + class ApplyImpulse(): + """Command adaptation of `add_impulse()` in `carla.Actor`. Applies an impulse to an actor.""" + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def impulse(self) -> Vector3D: + """Impulse applied to the actor (N*s).""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], impulse: Vector3D): + """Applies an impulse to an actor. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `impulse (Vector3D)`: (N*s)\n + """ + # endregion + + class ApplyTargetAngularVelocity(): + """Command adaptation of `set_target_angular_velocity()` in `carla.Actor`. Sets the actor's angular velocity vector. + """ + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def angular_velocity(self) -> Vector3D: + """The 3D angular velocity that will be applied to the actor (deg/s).""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], angular_velocity: Vector3D): + """Sets the actor's angular velocity vector. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `angular_velocity (Vector3D)`: Angular velocity vector applied to the actor.\n + """ + # endregion + + class ApplyTargetVelocity(): + """Command adaptation of `set_target_velocity()` in `carla.Actor`. Sets the actor's target velocity vector. + """ + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def velocity(self) -> Vector3D: + """The 3D velocity applied to the actor (m/s).""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], velocity: Vector3D): + """Sets the actor's target velocity vector. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `velocity (Vector3D)`: Velocity vector applied to the actor.\n + """ + # endregion + + class ApplyTorque(): + """ + Command adaptation of `add_torque()` in carla.Actor. Applies a torque to an actor. + """ + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + + @property + def transform(self) -> Vector3D: + """Torque applied to the actor over time (degrees).""" + + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], torque: Vector3D): + """Sets a new transform to an actor. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `torque (Vector3D)`: Torque vector in global coordinates (degrees). + """ + # endregion + + class ApplyTransform(): + """ + Command adaptation of `set_transform()` in `carla.Actor`. Sets a new transform to an actor. + """ + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def transform(self) -> Transform: + """Transformation to be applied.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], transform: Transform): + """Sets a new transform to an actor. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `transform (Transform)`\n + """ + # endregion + + class ApplyVehicleAckermannControl(): + """Command adaptation of `apply_ackermann_control()` in `carla.Vehicle`. Applies a certain akermann control to a vehicle. + """ + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def control(self) -> AckermannControllerSettings: + """Vehicle ackermann control to be applied.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], control: AckermannControllerSettings): + """Applies a certain akermann control to a vehicle. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `control (AckermannControllerSettings)`: Vehicle ackermann control to be applied.\n + """ + # endregion + + class ApplyVehicleControl(): + """Command adaptation of `apply_control()` in `carla.Vehicle`. Applies a certain control to a vehicle.""" + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def control(self) -> VehicleControl: + """Vehicle control to be applied.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], control: VehicleControl): + """Applies a certain control to a vehicle. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `control (VehicleControl)`: Vehicle control to be applied.\n + """ + # endregion + + class ApplyVehiclePhysicsControl(): + """Command adaptation of `apply_physics_control()` in `carla.Vehicle`. Applies a new physics control to a vehicle, modifying its physical parameters.""" + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + @property + def control(self) -> VehiclePhysicsControl: + """Physics control to be applied.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], control: VehicleControl): + """Applies a new physics control to a vehicle, modifying its physical parameters. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `control (VehicleControl)`: Physics control to be applied.\n + """ + # endregion + + class ApplyWalkerControl(): + """Command adaptation of `apply_control()` in `carla.Walker`. Applies a control to a walker.""" + + # region Instance Variables + @property + def actor_id(self) -> int: + """Walker actor affected by the command.""" + @property + def control(self) -> VehiclePhysicsControl: + """Walker control to be applied.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], control: VehicleControl): + """Applies a control to a walker. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `control (VehicleControl)`: Walker control to be applied.\n + """ + # endregion + + class ApplyWalkerState(): + """Apply a state to the walker actor. Specially useful to initialize an actor them with a specific location, orientation and speed.""" + + # region Instance Variables + @property + def actor_id(self) -> int: + """Walker actor affected by the command.""" + @property + def transform(self) -> Transform: + """Transform to be applied.""" + @property + def speed(self) -> float: + """Speed to be applied (m/s).""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], transform: Transform, speed: float): + """Apply a state to the walker actor. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `transform (Transform)`: Transform to be applied.\n + `speed (float)`: Speed to be applied (m/s).\n + """ + # endregion + + class DestroyActor(): + """Command adaptation of `destroy()` in `carla.Actor` that tells the simulator to destroy this actor. It has no effect if the actor was already destroyed. When executed with `apply_batch_sync()` in c`arla.Client` there will be a `command.Response` that will return a boolean stating whether the actor was successfully destroyed.""" + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor affected by the command.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int]): + """Command adaptation of `destroy()` in `carla.Actor` that tells the simulator to destroy this actor. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + """ + # endregion + + class FutureActor(): + """A utility object used to reference an actor that will be created in the command in the previous step, it has no parameters or methods.""" + + class Response(): + """States the result of executing a command as either the ID of the actor to whom the command was applied to (when succeeded) or an error string (when failed). actor ID, depending on whether or not the command succeeded. The method `apply_batch_sync()` in c`arla.Client` returns a list of these to summarize the execution of a batch. + """ + + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor to whom the command was applied to. States that the command was successful.""" + @property + def error(self) -> str: + """A string stating the command has failed.""" + # endregion + + # region Methods + def has_error(self) -> bool: + """Returns `True` if the command execution fails, and `False` if it was successful.""" + # endregion + + class SetAutopilot(): + """Command adaptation of `set_autopilot()` in `carla.Vehicle`. Turns on/off the vehicle's autopilot mode.""" + + # region Instance Methods + @property + def actor_id(self) -> int: + """Actor that is affected by the command.""" + @property + def enabled(self) -> bool: + """If autopilot should be activated or not.""" + @property + def port(self) -> int: + """Port of the Traffic Manager where the vehicle is to be registered or unlisted.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], enabled: bool, port=8000): + """Turns on/off the vehicle's autopilot mode. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `enabled (bool)`: _description_\n + `port (int, optional)`: The Traffic Manager port where the vehicle is to be registered or unlisted. If None is passed, it will consider a TM at default port 8000. Defaults to 8000.\n + """ + # endregion + + class SetEnableGravity(): + """Command adaptation of `set_enable_gravity()` in `carla.Actor`. Enables or disables gravity on an actor.""" + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor that is affected by the command.""" + @property + def enabled(self) -> bool: + """If gravity should be activated or not.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], enabled: bool): + """Enables or disables gravity on an actor. + + Args: + `actor (Union[Actor, int])`: Actor or Actor ID to which the command will be applied to.\n + `enabled (bool)`: If gravity should be activated or not.\n + """ + # endregion + + class SetSimulatePhysics(): + """Command adaptation of `set_simulate_physics()` in `carla.Actor`. Determines whether an actor will be affected by physics or not.""" + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor that is affected by the command.""" + @property + def enabled(self) -> bool: + """If physics should be activated or not.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], enabled: bool): + """Determines whether an actor will be affected by physics or not. + + Args: + `actor (Union[Actor, int])`: Actor or Actor ID to which the command will be applied to.\n + `enabled (bool)`: If physics should be activated or not.\n + """ + # endregion + + class SetVehicleLightState(): + """Command adaptation of `set_light_state()` in `carla.Vehicle`. Sets the light state of a vehicle.""" + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor that is affected by the command.""" + @property + def light_state(self) -> VehicleLightState: + """Recaps the state of the lights of a vehicle, these can be used as a flags.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], light_state: VehicleLightState): + """Sets the light state of a vehicle. + + Args: + `actor (Union[Actor, int])`: Actor or its ID to whom the command will be applied to.\n + `light_state (VehicleLightState)`: Recaps the state of the lights of a vehicle, these can be used as a flags.\n + """ + # endregion + + class ShowDebugTelemetry(): + """Command adaptation of `show_debug_telemetry()` in `carla.Actor`. Displays vehicle control telemetry data. + """ + # region Instance Variables + @property + def actor_id(self) -> int: + """Actor that is affected by the command.""" + @property + def enabled(self) -> bool: + """If debug should be activated or not.""" + # endregion + + # region Methods + def __init__(self, actor: Union[Actor, int], enabled: bool): + """Displays vehicle control telemetry data. + + Args: + `actor (Union[Actor, int])`: Actor or Actor ID to which the command will be applied to.\n + `enabled (bool)`: If debug should be activated or not.\n + """ + # endregion + + class SpawnActor(): + """Command adaptation of `spawn_actor()` in `carla.World`. Spawns an actor into the world based on the blueprint provided and the transform. If a parent is provided, the actor is attached to it.""" + + # region Instance Variables + @property + def transform(self) -> Transform: + """Transform to be applied.""" + @property + def parent_id(self) -> int: + """Identificator of the parent actor.""" + # endregion + + # region Methods + @overload + def __init__(self): ... + @overload + def __init__(self, blueprint: ActorBlueprint, transform: Transform): ... + @overload + def __init__(self, blueprint: ActorBlueprint, transform: Transform, parent: Union[Actor, int]): ... + + def then(self, command: command): + """Links another command to be executed right after. It allows to ease very common flows such as spawning a set of vehicles by command and then using this method to set them to autopilot automatically. + + Args: + `command (command)`: a Carla command.\n + """ + # endregion diff --git a/PythonAPI/carla/source/libcarla/Actor.cpp b/PythonAPI/carla/source/libcarla/Actor.cpp index 26d678460..62dbe05ea 100644 --- a/PythonAPI/carla/source/libcarla/Actor.cpp +++ b/PythonAPI/carla/source/libcarla/Actor.cpp @@ -195,6 +195,7 @@ void export_actor() { .def("apply_ackermann_controller_settings", &cc::Vehicle::ApplyAckermannControllerSettings, (arg("settings"))) .def("get_ackermann_controller_settings", CONST_CALL_WITHOUT_GIL(cc::Vehicle, GetAckermannControllerSettings)) .def("set_autopilot", CALL_WITHOUT_GIL_2(cc::Vehicle, SetAutopilot, bool, uint16_t), (arg("enabled") = true, arg("tm_port") = ctm::TM_DEFAULT_PORT)) + .def("get_telemetry_data", CONST_CALL_WITHOUT_GIL(cc::Vehicle, GetTelemetryData)) .def("show_debug_telemetry", &cc::Vehicle::ShowDebugTelemetry, (arg("enabled") = true)) .def("get_speed_limit", &cc::Vehicle::GetSpeedLimit) .def("get_traffic_light_state", &cc::Vehicle::GetTrafficLightState) diff --git a/PythonAPI/carla/source/libcarla/Blueprint.cpp b/PythonAPI/carla/source/libcarla/Blueprint.cpp index e711290e4..9f3c04664 100644 --- a/PythonAPI/carla/source/libcarla/Blueprint.cpp +++ b/PythonAPI/carla/source/libcarla/Blueprint.cpp @@ -37,7 +37,7 @@ namespace client { std::ostream &operator<<(std::ostream &out, const ActorAttribute &attr) { using Type = carla::rpc::ActorAttributeType; - static_assert(static_cast(Type::SIZE) == 5u, "Please update this function."); + static_assert(static_cast(Type::SIZE) == 6u, "Please update this function."); out << "ActorAttribute(id=" << attr.GetId(); switch (attr.GetType()) { case Type::Bool: diff --git a/PythonAPI/carla/source/libcarla/Control.cpp b/PythonAPI/carla/source/libcarla/Control.cpp index 98a0e9bfb..f0e8f5e5d 100644 --- a/PythonAPI/carla/source/libcarla/Control.cpp +++ b/PythonAPI/carla/source/libcarla/Control.cpp @@ -8,7 +8,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -116,6 +118,33 @@ namespace rpc { return out; } + std::ostream &operator<<(std::ostream &out, const WheelTelemetryData &telemetry) { + out << "WheelTelemetryData(tire_friction=" << std::to_string(telemetry.tire_friction) + << ", lat_slip=" << std::to_string(telemetry.lat_slip) + << ", long_slip=" << std::to_string(telemetry.long_slip) + << ", omega=" << std::to_string(telemetry.omega) + << ", tire_load=" << std::to_string(telemetry.tire_load) + << ", normalized_tire_load=" << std::to_string(telemetry.normalized_tire_load) + << ", torque=" << std::to_string(telemetry.torque) + << ", long_force=" << std::to_string(telemetry.long_force) + << ", lat_force=" << std::to_string(telemetry.lat_force) + << ", normalized_long_force=" << std::to_string(telemetry.normalized_long_force) + << ", normalized_lat_force=" << std::to_string(telemetry.normalized_lat_force) << ')'; + return out; + } + + std::ostream &operator<<(std::ostream &out, const VehicleTelemetryData &telemetry) { + out << "VehicleTelemetryData(speed=" << std::to_string(telemetry.speed) + << ", steer=" << std::to_string(telemetry.steer) + << ", throttle=" << std::to_string(telemetry.throttle) + << ", brake=" << std::to_string(telemetry.brake) + << ", engine_rpm=" << std::to_string(telemetry.engine_rpm) + << ", gear=" << std::to_string(telemetry.gear) + << ", drag=" << std::to_string(telemetry.drag) + << ", wheels=" << telemetry.wheels << ')'; + return out; + } + std::ostream &operator<<(std::ostream &out, const AckermannControllerSettings &settings) { out << "AckermannControllerSettings(speed_kp=" << std::to_string(settings.speed_kp) << ", speed_ki=" << std::to_string(settings.speed_ki) @@ -264,6 +293,54 @@ boost::python::object VehiclePhysicsControl_init(boost::python::tuple args, boos return res; } +static auto GetWheelsTelemetry(const carla::rpc::VehicleTelemetryData &self) { + const auto &wheels = self.GetWheels(); + boost::python::object get_iter = boost::python::iterator>(); + boost::python::object iter = get_iter(wheels); + return boost::python::list(iter); +} + +static void SetWheelsTelemetry(carla::rpc::VehicleTelemetryData &self, const boost::python::list &list) { + std::vector wheels; + auto length = boost::python::len(list); + for (auto i = 0u; i < length; ++i) { + wheels.push_back(boost::python::extract(list[i])); + } + self.SetWheels(wheels); +} + +boost::python::object VehicleTelemetryData_init(boost::python::tuple args, boost::python::dict kwargs) { + // Args names + const uint32_t NUM_ARGUMENTS = 7; + const char *args_names[NUM_ARGUMENTS] = { + "speed", + "steer", + "throttle", + "brake", + "engine_rpm", + "gear", + "wheels" + }; + + boost::python::object self = args[0]; + args = boost::python::tuple(args.slice(1, boost::python::_)); + + auto res = self.attr("__init__")(); + if (len(args) > 0) { + for (unsigned int i = 0; i < len(args); ++i) { + self.attr(args_names[i]) = args[i]; + } + } + + for (unsigned int i = 0; i < NUM_ARGUMENTS; ++i) { + if (kwargs.contains(args_names[i])) { + self.attr(args_names[i]) = kwargs[args_names[i]]; + } + } + + return res; +} + static auto GetBonesTransform(const carla::rpc::WalkerBoneControlIn &self) { const std::vector &bone_transform_data = self.bone_transforms; boost::python::object get_iter = @@ -507,4 +584,50 @@ void export_control() { .def("__ne__", &cr::VehiclePhysicsControl::operator!=) .def(self_ns::str(self_ns::self)) ; + + class_("WheelTelemetryData") + .def(init( + (arg("tire_friction")=0.0f, + arg("lat_slip")=0.0f, + arg("long_slip")=0.0f, + arg("omega")=0.0f, + arg("tire_load")=0.0f, + arg("normalized_tire_load")=0.0f, + arg("torque")=0.0f, + arg("long_force")=0.0f, + arg("lat_force")=0.0f, + arg("normalized_long_force")=0.0f, + arg("normalized_lat_force")=0.0f))) + .def_readwrite("tire_friction", &cr::WheelTelemetryData::tire_friction) + .def_readwrite("lat_slip", &cr::WheelTelemetryData::lat_slip) + .def_readwrite("long_slip", &cr::WheelTelemetryData::long_slip) + .def_readwrite("omega", &cr::WheelTelemetryData::omega) + .def_readwrite("tire_load", &cr::WheelTelemetryData::tire_load) + .def_readwrite("normalized_tire_load", &cr::WheelTelemetryData::normalized_tire_load) + .def_readwrite("torque", &cr::WheelTelemetryData::torque) + .def_readwrite("long_force", &cr::WheelTelemetryData::long_force) + .def_readwrite("lat_force", &cr::WheelTelemetryData::lat_force) + .def_readwrite("normalized_long_force", &cr::WheelTelemetryData::normalized_long_force) + .def_readwrite("normalized_lat_force", &cr::WheelTelemetryData::normalized_lat_force) + .def("__eq__", &cr::WheelTelemetryData::operator==) + .def("__ne__", &cr::WheelTelemetryData::operator!=) + .def(self_ns::str(self_ns::self)) + ; + + class_("VehicleTelemetryData", no_init) + .def("__init__", raw_function(VehicleTelemetryData_init)) + .def(init<>()) + .def_readwrite("speed", &cr::VehicleTelemetryData::speed) + .def_readwrite("steer", &cr::VehicleTelemetryData::steer) + .def_readwrite("throttle", &cr::VehicleTelemetryData::throttle) + .def_readwrite("brake", &cr::VehicleTelemetryData::brake) + .def_readwrite("engine_rpm", &cr::VehicleTelemetryData::engine_rpm) + .def_readwrite("gear", &cr::VehicleTelemetryData::gear) + .def_readwrite("drag", &cr::VehicleTelemetryData::drag) + .add_property("wheels", &GetWheelsTelemetry, &SetWheelsTelemetry) + .def("__eq__", &cr::VehicleTelemetryData::operator==) + .def("__ne__", &cr::VehicleTelemetryData::operator!=) + .def(self_ns::str(self_ns::self)) + ; + } diff --git a/PythonAPI/carla/source/libcarla/Geom.cpp b/PythonAPI/carla/source/libcarla/Geom.cpp index 4c0281270..57e3941cf 100644 --- a/PythonAPI/carla/source/libcarla/Geom.cpp +++ b/PythonAPI/carla/source/libcarla/Geom.cpp @@ -237,6 +237,10 @@ void export_geom() { self.TransformPoint(location); return location; }, arg("in_point")) + .def("inverse_transform", +[](const cg::Transform &self, cg::Vector3D &location) { + self.InverseTransformPoint(location); + return location; + }, arg("in_point")) .def("transform_vector", +[](const cg::Transform &self, cg::Vector3D &vector) { self.TransformVector(vector); return vector; diff --git a/PythonAPI/carla/source/libcarla/Sensor.cpp b/PythonAPI/carla/source/libcarla/Sensor.cpp index 9a8cf5f78..020b71592 100644 --- a/PythonAPI/carla/source/libcarla/Sensor.cpp +++ b/PythonAPI/carla/source/libcarla/Sensor.cpp @@ -26,7 +26,6 @@ void export_sensor() { namespace cc = carla::client; class_, boost::noncopyable, boost::shared_ptr>("Sensor", no_init) - .add_property("is_listening", &cc::Sensor::IsListening) .def("listen", &SubscribeToStream, (arg("callback"))) .def("is_listening", &cc::Sensor::IsListening) .def("stop", &cc::Sensor::Stop) @@ -41,6 +40,7 @@ void export_sensor() { .def("enable_for_ros", &cc::ServerSideSensor::EnableForROS) .def("disable_for_ros", &cc::ServerSideSensor::DisableForROS) .def("is_enabled_for_ros", &cc::ServerSideSensor::IsEnabledForROS) + .def("send", &cc::ServerSideSensor::Send, (arg("message"))) .def(self_ns::str(self_ns::self)) ; diff --git a/PythonAPI/carla/source/libcarla/SensorData.cpp b/PythonAPI/carla/source/libcarla/SensorData.cpp index d235dd6b7..61c39ab15 100644 --- a/PythonAPI/carla/source/libcarla/SensorData.cpp +++ b/PythonAPI/carla/source/libcarla/SensorData.cpp @@ -20,6 +20,9 @@ #include #include #include +#include +#include +#include #include @@ -166,6 +169,40 @@ namespace data { return out; } + std::ostream &operator<<(std::ostream &out, const CAMEvent &data) { + out << "CAMEvent(frame=" << std::to_string(data.GetFrame()) + << ", timestamp=" << std::to_string(data.GetTimestamp()) + << ", message_count=" << std::to_string(data.GetMessageCount()) + << ')'; + return out; + } + + std::ostream &operator<<(std::ostream &out, const CustomV2XEvent &data) { + out << "CustomV2XEvent(frame=" << std::to_string(data.GetFrame()) + << ", timestamp=" << std::to_string(data.GetTimestamp()) + << ", message_count=" << std::to_string(data.GetMessageCount()) + << ')'; + return out; + } + + std::ostream &operator<<(std::ostream &out, const CAMData &data) { + out << "CAMData(power=" << std::to_string(data.Power) + << ", stationId=" << std::to_string(data.Message.header.stationID) + << ", messageId=" << std::to_string(data.Message.header.messageID) + << ')'; + return out; + } + + std::ostream &operator<<(std::ostream &out, const CustomV2XData &data) { + out << "CustomV2XData(power=" << std::to_string(data.Power) + << ", stationId=" << std::to_string(data.Message.header.stationID) + << ", messageId=" << std::to_string(data.Message.header.messageID) + << ')'; + return out; + } + + + } // namespace s11n } // namespace sensor } // namespace carla @@ -356,6 +393,39 @@ static std::string SavePointCloudToDisk(T &self, std::string path) { return carla::pointcloud::PointCloudIO::SaveToDisk(std::move(path), self.begin(), self.end()); } +static boost::python::dict GetCAMData(const carla::sensor::data::CAMData message) +{ + boost::python::dict myDict; + try + { + myDict["Power"] = message.Power; + myDict["Message"] = GetCAMMessage(message); + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + + return myDict; +} + + +static boost::python::dict GetCustomV2XData(const carla::sensor::data::CustomV2XData message) +{ + boost::python::dict myDict; + try + { + myDict["Power"] = message.Power; + myDict["Message"] = GetCustomV2XMessage(message); + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + + return myDict; +} +/**********************************************************************************************/ void export_sensor_data() { using namespace boost::python; namespace cc = carla::client; @@ -573,4 +643,34 @@ void export_sensor_data() { .def("to_array_pol", CALL_RETURNING_LIST(csd::DVSEventArray, ToArrayPol)) .def(self_ns::str(self_ns::self)) ; + + class_("CAMMessage") + .def_readwrite("power", &csd::CAMData::Power) + .def("get", GetCAMData) + .def(self_ns::str(self_ns::self)) + ; + + class_("CustomV2XData") + .def_readwrite("power", &csd::CustomV2XData::Power) + .def("get", GetCustomV2XData) + .def(self_ns::str(self_ns::self)) + ; + + class_, boost::noncopyable, boost::shared_ptr>("CAMEvent", no_init) + .def("get_message_count", &csd::CAMEvent::GetMessageCount) + .def("__len__", &csd::CAMEvent::size) + .def("__iter__", iterator()) + .def("__getitem__", +[](const csd::CAMEvent &self, size_t pos) -> csd::CAMData { + return self.at(pos); + }) + ; + + class_, boost::noncopyable, boost::shared_ptr>("CustomV2XEvent", no_init) + .def("get_message_count", &csd::CustomV2XEvent::GetMessageCount) + .def("__len__", &csd::CustomV2XEvent::size) + .def("__iter__", iterator()) + .def("__getitem__", +[](const csd::CustomV2XEvent &self, size_t pos) -> csd::CustomV2XData { + return self.at(pos); + }) + ; } diff --git a/PythonAPI/carla/source/libcarla/V2XData.cpp b/PythonAPI/carla/source/libcarla/V2XData.cpp new file mode 100644 index 000000000..2be2198ce --- /dev/null +++ b/PythonAPI/carla/source/libcarla/V2XData.cpp @@ -0,0 +1,609 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include +#include +#include +#include +#include + +/**********************************************************************************************/ +// Functions to convert CAM message from V2X sensor to python dict +std::string GetStationTypeString(const ITSContainer::StationType_t stationType) +{ + switch (stationType) + { + case ITSContainer::StationType_unknown: + return "Uunknown"; + case ITSContainer::StationType_pedestrian: + return "Pedestrian"; + case ITSContainer::StationType_cyclist: + return "Cyclist"; + case ITSContainer::StationType_moped: + return "Moped"; + case ITSContainer::StationType_motorcycle: + return "Motorcycle"; + case ITSContainer::StationType_passengerCar: + return "Passenger Car"; + case ITSContainer::StationType_bus: + return "Bus"; + case ITSContainer::StationType_lightTruck: + return "Light Truck"; + case ITSContainer::StationType_heavyTruck: + return "HeavyTruck"; + case ITSContainer::StationType_trailer: + return "Trailer"; + case ITSContainer::StationType_specialVehicles: + return "Special Vehicle"; + case ITSContainer::StationType_tram: + return "Tram"; + case ITSContainer::StationType_roadSideUnit: + return "Road Side Unit"; + default: + return "Unknown"; + } +} +std::string GetSemiConfidenceString(const long confidence) +{ + switch(confidence) + { + case ITSContainer::SemiAxisLength_oneCentimeter: + return "Semi Axis Length One Centimeter"; + case ITSContainer::SemiAxisLength_outOfRange: + return "Semi Axis Length Out Of Range"; + default: + return "Semi Axis Length Unavailable"; + } +} + +std::string GetSemiOrientationString(const long orientation) +{ + switch(orientation) + { + case ITSContainer::HeadingValue_wgs84North: + return "Heading wgs84 North"; + case ITSContainer::HeadingValue_wgs84East: + return "Heading wgs84 East"; + case ITSContainer::HeadingValue_wgs84South: + return "Heading wgs84 South"; + case ITSContainer::HeadingValue_wgs84West: + return "Heading wgs84 West"; + default: + return "Heading Unavailable"; + } +} + +std::string GetAltitudeConfidenceString(ITSContainer::AltitudeConfidence_t altitudeConfidence) +{ + switch(altitudeConfidence) + { + case ITSContainer::AltitudeConfidence_alt_000_01: + return "AltitudeConfidence_alt_000_01"; + case ITSContainer::AltitudeConfidence_alt_000_02: + return "AltitudeConfidence_alt_000_02"; + case ITSContainer::AltitudeConfidence_alt_000_05: + return "AltitudeConfidence_alt_000_05"; + case ITSContainer::AltitudeConfidence_alt_000_10: + return "AltitudeConfidence_alt_000_10"; + case ITSContainer::AltitudeConfidence_alt_000_20: + return "AltitudeConfidence_alt_000_20"; + case ITSContainer::AltitudeConfidence_alt_000_50: + return "AltitudeConfidence_alt_000_50"; + case ITSContainer::AltitudeConfidence_alt_001_00: + return "AltitudeConfidence_alt_001_00"; + case ITSContainer::AltitudeConfidence_alt_002_00: + return "AltitudeConfidence_alt_002_00"; + case ITSContainer::AltitudeConfidence_alt_005_00: + return "AltitudeConfidence_alt_005_00"; + case ITSContainer::AltitudeConfidence_alt_010_00: + return "AltitudeConfidence_alt_010_00"; + case ITSContainer::AltitudeConfidence_alt_020_00: + return "AltitudeConfidence_alt_020_00"; + case ITSContainer::AltitudeConfidence_alt_050_00: + return "AltitudeConfidence_alt_050_00"; + case ITSContainer::AltitudeConfidence_alt_100_00: + return "AltitudeConfidence_alt_100_00"; + case ITSContainer::AltitudeConfidence_alt_200_00: + return "AltitudeConfidence_alt_200_00"; + case ITSContainer::AltitudeConfidence_outOfRange: + return "AltitudeConfidence_alt_outOfRange"; + default: + return "AltitudeConfidence_unavailable"; + } +} +static boost::python::dict GetReferenceContainer(const CAM_t message) +{ + boost::python::dict ReferencePosition; + ITSContainer::ReferencePosition_t ref = message.cam.camParameters.basicContainer.referencePosition; + ReferencePosition["Latitude"] = ref.latitude; + ReferencePosition["Longitude"] = ref.longitude; + boost::python::dict PosConfidence; + PosConfidence["Semi Major Confidence"] = GetSemiConfidenceString(ref.positionConfidenceEllipse.semiMajorConfidence); + PosConfidence["Semi Minor Confidence"] = GetSemiConfidenceString(ref.positionConfidenceEllipse.semiMinorConfidence); + PosConfidence["Semi Major Orientation"] = GetSemiOrientationString(ref.positionConfidenceEllipse.semiMajorOrientation); + ReferencePosition["Position Confidence Eliipse"] = PosConfidence; + boost::python::dict Altitude; + Altitude["Altitude Value"] = ref.altitude.altitudeValue; + Altitude["Altitude Confidence"] = GetAltitudeConfidenceString(ref.altitude.altitudeConfidence); + return ReferencePosition; +} +static boost::python::dict GetBasicContainer(const CAM_t message) +{ + boost::python::dict BasicContainer; + BasicContainer["Station Type"] = GetStationTypeString(message.cam.camParameters.basicContainer.stationType); + BasicContainer["Reference Position"] = GetReferenceContainer(message); + return BasicContainer; +} + +std::string GetHeadingConfidenceString(ITSContainer::HeadingConfidence_t confidence) +{ + switch (confidence) + { + case ITSContainer::HeadingConfidence_equalOrWithinZeroPointOneDegree: + return "Equal or With in Zero Point One Degree"; + case ITSContainer::HeadingConfidence_equalOrWithinOneDegree: + return "Equal or With in One Degree"; + case ITSContainer::HeadingConfidence_outOfRange: + return "Out of Range"; + default: + return "Unavailable"; + } +} + +std::string GetSpeedConfidenceString(ITSContainer::SpeedConfidence_t confidence) +{ + switch (confidence) + { + case ITSContainer::SpeedConfidence_equalOrWithInOneCentimerterPerSec: + return "Equal or With in One Centimeter per Sec"; + case ITSContainer::SpeedConfidence_equalOrWithinOneMeterPerSec: + return "Equal or With in One Meter per Sec"; + case ITSContainer::SpeedConfidence_outOfRange: + return "Out of Range"; + default: + return "Unavailable"; + } +} + +std::string GetVehicleLengthConfidenceString(ITSContainer::VehicleLengthConfidenceIndication_t confidence) +{ + switch (confidence) + { + case ITSContainer::VehicleLengthConfidenceIndication_noTrailerPresent: + return "No Trailer Present"; + case ITSContainer::VehicleLengthConfidenceIndication_trailerPresentWithKnownLength: + return "Trailer Present With Known Length"; + case ITSContainer::VehicleLengthConfidenceIndication_trailerPresentWithUnknownLength: + return "Trailer Present With Unknown Length"; + case ITSContainer::VehicleLengthConfidenceIndication_trailerPresenceIsUnknown: + return "Trailer Presence Is Unknown"; + default: + return "Unavailable"; + } +} + +std::string GetAccelerationConfidenceString(ITSContainer::AccelerationConfidence_t confidence) +{ + switch (confidence) + { + case ITSContainer::AccelerationConfindence_pointOneMeterPerSecSquared: + return "Point One Meter Per Sec Squared"; + case ITSContainer::AccelerationConfidence_outOfRange: + return "Out Of Range"; + default: + return "Unavailable"; + } +} + +std::string GetCurvatureConfidenceString(ITSContainer::CurvatureConfidence_t confidence) +{ + switch (confidence) + { + case ITSContainer::CurvatureConfidence_onePerMeter_0_00002: + return "One Per Meter 0_00002"; + case ITSContainer::CurvatureConfidence_onePerMeter_0_0001: + return "One Per Meter 0_0001"; + case ITSContainer::CurvatureConfidence_onePerMeter_0_0005: + return "One Per Meter 0_0005"; + case ITSContainer::CurvatureConfidence_onePerMeter_0_002: + return "One Per Meter 0_002"; + case ITSContainer::CurvatureConfidence_onePerMeter_0_01: + return "One Per Meter 0_01"; + case ITSContainer::CurvatureConfidence_onePerMeter_0_1: + return "One Per Meter 0_1"; + case ITSContainer::CurvatureConfidence_outOfRange: + return "Out Of Range"; + default: + return "Unavailable"; + } +} + +std::string GetYawRateConfidenceString(ITSContainer::YawRateConfidence_t confidence) +{ + switch (confidence) + { + case ITSContainer::YawRateConfidence_degSec_000_01: + return "degSec 000_01"; + case ITSContainer::YawRateConfidence_degSec_000_05: + return "degSec 000_05"; + case ITSContainer::YawRateConfidence_degSec_000_10: + return "degSec 000_10"; + case ITSContainer::YawRateConfidence_degSec_001_00: + return "degSec 001_00"; + case ITSContainer::YawRateConfidence_degSec_005_00: + return "degSec 005_00"; + case ITSContainer::YawRateConfidence_degSec_010_00: + return "degSec 010_00"; + case ITSContainer::YawRateConfidence_degSec_100_00: + return "degSec 100_00"; + case ITSContainer::YawRateConfidence_outOfRange: + return "Out Of Range"; + default: + return "Unavailable"; + } +} + +std::string GetSteeringWheelConfidenceString(ITSContainer::SteeringWheelAngleConfidence_t confidence) +{ + switch (confidence) + { + case ITSContainer::SteeringWheelAngleConfidence_equalOrWithinOnePointFiveDegree: + return "Equal or With in 1.5 degree"; + case ITSContainer::SteeringWheelAngleConfidence_outOfRange: + return "Out of Range"; + default: + return "Unavailable"; + } +} + +static boost::python::dict GetBVCHighFrequency(const CAM_t message) +{ + boost::python::dict BVCHighFrequency; + CAMContainer::BasicVehicleContainerHighFrequency_t bvchf = message.cam.camParameters.highFrequencyContainer.basicVehicleContainerHighFrequency; + boost::python::dict HeadingValueConfidence; + HeadingValueConfidence["Value"] = bvchf.heading.headingValue; + HeadingValueConfidence["Confidence"] = GetHeadingConfidenceString(bvchf.heading.headingConfidence); + BVCHighFrequency["Heading"] = HeadingValueConfidence; + boost::python::dict SpeedValueConfidence; + SpeedValueConfidence["Value"] = bvchf.speed.speedValue; + SpeedValueConfidence["Confidence"] = GetSpeedConfidenceString(bvchf.speed.speedConfidence); + BVCHighFrequency["Speed"] = SpeedValueConfidence; + + BVCHighFrequency["Drive Direction"] = bvchf.driveDirection; + + boost::python::dict VehicleLengthValueConfidence; + VehicleLengthValueConfidence["Value"] = bvchf.vehicleLength.vehicleLengthValue; + VehicleLengthValueConfidence["Confidence"] = GetVehicleLengthConfidenceString(bvchf.vehicleLength.vehicleLengthConfidenceIndication); + BVCHighFrequency["Vehicle Length"] = VehicleLengthValueConfidence; + + BVCHighFrequency["Vehicle Width"] = bvchf.vehicleWidth; + + boost::python::dict LongitudinalAccelerationValueConfidence; + LongitudinalAccelerationValueConfidence["Value"] = bvchf.longitudinalAcceleration.longitudinalAccelerationValue; + LongitudinalAccelerationValueConfidence["Confidence"] = GetAccelerationConfidenceString(bvchf.longitudinalAcceleration.longitudinalAccelerationConfidence); + BVCHighFrequency["Longitudinal Acceleration"] = LongitudinalAccelerationValueConfidence; + + boost::python::dict CurvatureValueConfidence; + CurvatureValueConfidence["Value"] = bvchf.curvature.curvatureValue; + CurvatureValueConfidence["Confidence"] = GetCurvatureConfidenceString(bvchf.curvature.curvatureConfidence); + BVCHighFrequency["Curvature"] = CurvatureValueConfidence; + BVCHighFrequency["Curvature Calculation Mode"] = bvchf.curvatureCalculationMode; + + boost::python::dict YawValueConfidence; + YawValueConfidence["Value"] = bvchf.yawRate.yawRateValue; + YawValueConfidence["Confidence"] = GetYawRateConfidenceString(bvchf.yawRate.yawRateConfidence); + BVCHighFrequency["Yaw Rate"] = YawValueConfidence; + + boost::python::dict ValueConfidence; + if (bvchf.accelerationControlAvailable) + { + BVCHighFrequency["Acceleration Control"] = bvchf.accelerationControl; + } + else + { + BVCHighFrequency["Acceleration Control"] = boost::python::object(); + } + + if (bvchf.lanePositionAvailable) + { + BVCHighFrequency["Lane Position"] = bvchf.lanePosition; + } + else + { + BVCHighFrequency["Lane Position"] = boost::python::object(); + } + + if (bvchf.steeringWheelAngleAvailable) + { + boost::python::dict ValueConfidence; + ValueConfidence["Value"] = bvchf.steeringWheelAngle.steeringWheelAngleValue; + ValueConfidence["Confidence"] = GetSteeringWheelConfidenceString(bvchf.steeringWheelAngle.steeringWheelAngleConfidence); + BVCHighFrequency["Steering Wheel Angle"] = ValueConfidence; + } + else + { + BVCHighFrequency["Steering Wheel Angle"] = boost::python::object(); + } + + if (bvchf.lateralAccelerationAvailable) + { + boost::python::dict ValueConfidence; + ValueConfidence["Value"] = bvchf.lateralAcceleration.lateralAccelerationValue; + ValueConfidence["Confidence"] = GetAccelerationConfidenceString(bvchf.lateralAcceleration.lateralAccelerationConfidence); + BVCHighFrequency["Lateral Acceleration"] = ValueConfidence; + } + else + { + BVCHighFrequency["Lateral Acceleration"] = boost::python::object(); + } + + if (bvchf.verticalAccelerationAvailable) + { + boost::python::dict ValueConfidence; + ValueConfidence["Value"] = bvchf.verticalAcceleration.verticalAccelerationValue; + ValueConfidence["Confidence"] = GetAccelerationConfidenceString(bvchf.verticalAcceleration.verticalAccelerationConfidence); + BVCHighFrequency["Vertical Acceleration"] = ValueConfidence; + } + else + { + BVCHighFrequency["Vertical Acceleration"] = boost::python::object(); + } + + if (bvchf.performanceClassAvailable) + { + BVCHighFrequency["Performance class"] = bvchf.performanceClass; + } + else + { + BVCHighFrequency["Performance class"] = boost::python::object(); + } + + if (bvchf.cenDsrcTollingZoneAvailable) + { + boost::python::dict ValueConfidence; + ValueConfidence["Protected Zone Latitude"] = bvchf.cenDsrcTollingZone.protectedZoneLatitude; + ValueConfidence["Protected Zone Longitude"] = bvchf.cenDsrcTollingZone.protectedZoneLongitude; + if (bvchf.cenDsrcTollingZone.cenDsrcTollingZoneIDAvailable) + { + ValueConfidence["Cen DSRC Tolling Zone ID"] = bvchf.cenDsrcTollingZone.cenDsrcTollingZoneID; + } + BVCHighFrequency["Cen DSRC Tolling Zone"] = ValueConfidence; + } + else + { + BVCHighFrequency["Cen DSRC Tolling Zone"] = boost::python::object(); + } + + return BVCHighFrequency; +} + +static boost::python::list GetProtectedCommunicationZone(const CAMContainer::RSUContainerHighFrequency_t rsuMessage) +{ + boost::python::list PCZlist; + + for (ITSContainer::ProtectedCommunicationZone_t data : rsuMessage.protectedCommunicationZonesRSU.list) + { + boost::python::dict PCZDict; + PCZDict["Protected Zone Type"] = data.protectedZoneType; + if (data.expiryTimeAvailable) + { + PCZDict["Expiry Time"] = data.expiryTime; + } + + PCZDict["Protected Zone Latitude"] = data.protectedZoneLatitude; + PCZDict["Protected Zone Longitude"] = data.protectedZoneLongitude; + + if (data.protectedZoneIDAvailable) + { + PCZDict["Protected Zone ID"] = data.protectedZoneID; + } + if (data.protectedZoneRadiusAvailable) + { + PCZDict["Protected Zone Radius"] = data.protectedZoneRadius; + } + + PCZlist.append(PCZDict); + } + return PCZlist; +} +static boost::python::dict GetRSUHighFrequency(const CAM_t message) +{ + boost::python::dict RSU; + CAMContainer::RSUContainerHighFrequency_t rsu = message.cam.camParameters.highFrequencyContainer.rsuContainerHighFrequency; + RSU["Protected Communication Zone"] = GetProtectedCommunicationZone(rsu); + return RSU; +} + +static boost::python::dict GetHighFrequencyContainer(const CAM_t message) +{ + boost::python::dict HFC; + CAMContainer::HighFrequencyContainer_t hfc = message.cam.camParameters.highFrequencyContainer; + switch (hfc.present) + { + case CAMContainer::HighFrequencyContainer_PR_basicVehicleContainerHighFrequency: + HFC["High Frequency Container Present"] = "Basic Vehicle Container High Frequency"; + HFC["Basic Vehicle Container High Frequency"] = GetBVCHighFrequency(message); + break; + case CAMContainer::HighFrequencyContainer_PR_rsuContainerHighFrequency: + HFC["High Frequency Container Present"] = "RSU Container High Frequency"; + HFC["RSU Container High Frequency"] = GetRSUHighFrequency(message); + break; + default: + HFC["High Frequency Container Present"] = "No container present"; + } + return HFC; +} +std::string GetVehicleRoleString(ITSContainer::VehicleRole_t vehicleRole) +{ + switch (vehicleRole) + { + case ITSContainer::VehicleRole_publicTransport: + return "Public Transport"; + case ITSContainer::VehicleRole_specialTransport: + return "Special Transport"; + case ITSContainer::VehicleRole_dangerousGoods: + return "Dangerous Goods"; + case ITSContainer::VehicleRole_roadWork: + return "Road Work"; + case ITSContainer::VehicleRole_rescue: + return "Rescue"; + case ITSContainer::VehicleRole_emergency: + return "Emergency"; + case ITSContainer::VehicleRole_safetyCar: + return "Safety Car"; + case ITSContainer::VehicleRole_agriculture: + return "Agriculture"; + case ITSContainer::VehicleRole_commercial: + return "Commercial"; + case ITSContainer::VehicleRole_military: + return "Military"; + case ITSContainer::VehicleRole_roadOperator: + return "Road Operator"; + case ITSContainer::VehicleRole_taxi: + return "Taxi"; + case ITSContainer::VehicleRole_reserved1: + return "Reserved 1"; + case ITSContainer::VehicleRole_reserved2: + return "Reserved 2"; + case ITSContainer::VehicleRole_reserved3: + return "Reserved 3"; + default: + return "Default"; + } +} + +boost::python::list GetPathHistory(const ITSContainer::PathHistory_t pathHistory) +{ + + boost::python::list PathHistoryList; + for (ITSContainer::PathPoint_t pathPoint : pathHistory.data) + { + boost::python::dict PathHistory; + PathHistory["Delta Latitude"] = pathPoint.pathPosition.deltaLatitude; + PathHistory["Delta Longitude"] = pathPoint.pathPosition.deltaLongitude; + PathHistory["Delta Altitude"] = pathPoint.pathPosition.deltaAltitude; + if (pathPoint.pathDeltaTime != nullptr) + { + PathHistory["Delta Time"] = *pathPoint.pathDeltaTime; + } + else + { + PathHistory["Delta Time"] = boost::python::object(); + } + PathHistoryList.append(PathHistory); + } + return PathHistoryList; +} +boost::python::dict GetBVCLowFrequency(const CAMContainer::BasicVehicleContainerLowFrequency_t bvc) +{ + boost::python::dict BVC; + BVC["Vehicle Role"] = GetVehicleRoleString(bvc.vehicleRole); + BVC["Exterior Light"] = bvc.exteriorLights; + if (bvc.pathHistory.NumberOfPathPoint != 0) + { + BVC["Path History"] = GetPathHistory(bvc.pathHistory); + } + else + { + BVC["Path History"] = boost::python::object(); + } + return BVC; +} + +boost::python::dict GetLowFrequencyContainer(const CAM_t message) +{ + boost::python::dict LFC = boost::python::dict(); + CAMContainer::LowFrequencyContainer_t lfc = message.cam.camParameters.lowFrequencyContainer; + switch (lfc.present) + { + case CAMContainer::LowFrequencyContainer_PR_basicVehicleContainerLowFrequency: + LFC["Low Frequency Container Present"] = "Basic Vehicle Container Low Frequency"; + LFC["Basic Vehicle Low Frequency"] = GetBVCLowFrequency(lfc.basicVehicleContainerLowFrequency); + break; + default: + LFC["Low Frequency Container Present"] = "No Container Present"; + break; + } + return LFC; +} +static boost::python::dict GetCAMParameters(const CAM_t message) +{ + boost::python::dict CAMParams; + try + { + + CAMParams["Basic Container"] = GetBasicContainer(message); + CAMParams["High Frequency Container"] = GetHighFrequencyContainer(message); + CAMParams["Low Frequency Container"] = GetLowFrequencyContainer(message); + } + catch (const std::exception &e) + { + std::cerr << e.what() << '\n'; + } + return CAMParams; +} + +static boost::python::dict GetCoopAwarness(const CAM_t message) +{ + + boost::python::dict Coop; + CAMContainer::CoopAwareness_t coop = message.cam; + Coop["Generation Delta Time"] = coop.generationDeltaTime; + Coop["CAM Parameters"] = GetCAMParameters(message); + return Coop; +} + +std::string GetMessageIDString(const long messageId) +{ + switch (messageId) + { + case ITSContainer::messageID_custom: + return "CUSTOM"; + case ITSContainer::messageID_denm: + return "DENM"; + case ITSContainer::messageID_cam: + return "CAM"; + case ITSContainer::messageID_poi: + return "POI"; + case ITSContainer::messageID_spat: + return "SPAT"; + case ITSContainer::messageID_map: + return "MAP"; + case ITSContainer::messageID_ivi: + return "IVI"; + case ITSContainer::messageID_ev_rsr: + return "EV_RSR"; + default: + return "Not Found"; + } +} + +static boost::python::dict GetMessageHeader(const ITSContainer::ItsPduHeader_t header) +{ + boost::python::dict Header; + Header["Protocol Version"] = header.protocolVersion; + Header["Message ID"] = GetMessageIDString(header.messageID); + Header["Station ID"] = header.stationID; + return Header; +} + +boost::python::dict GetCAMMessage(const carla::sensor::data::CAMData message) +{ + boost::python::dict CAM; + CAM_t CAMMessage = message.Message; + CAM["Header"] = GetMessageHeader(CAMMessage.header); + CAM["Message"] = GetCoopAwarness(CAMMessage); + return CAM; +} + +boost::python::dict GetCustomV2XMessage(const carla::sensor::data::CustomV2XData message) +{ + boost::python::dict CustomV2X; + CustomV2XM V2XMessage = message.Message; + CustomV2X["Header"] = GetMessageHeader(V2XMessage.header); + CustomV2X["Message"] = std::string(V2XMessage.message); + return CustomV2X; +} diff --git a/PythonAPI/carla/source/libcarla/libcarla.cpp b/PythonAPI/carla/source/libcarla/libcarla.cpp index 73998c2eb..9bd3fc83d 100644 --- a/PythonAPI/carla/source/libcarla/libcarla.cpp +++ b/PythonAPI/carla/source/libcarla/libcarla.cpp @@ -216,6 +216,7 @@ static auto MakeCallback(boost::python::object callback) { }; } +#include "V2XData.cpp" #include "Geom.cpp" #include "Actor.cpp" #include "Blueprint.cpp" diff --git a/PythonAPI/docs/client.yml b/PythonAPI/docs/client.yml index 3f4e40388..2977c9337 100644 --- a/PythonAPI/docs/client.yml +++ b/PythonAPI/docs/client.yml @@ -352,12 +352,12 @@ - param_name: folder type: str doc: > - Folder where files required by the client will be downloaded to. + Specifies a folder to look through on the server maps. Leaving this blank will search recursively through all map folders in the server, which is recommended if you're unfamiliar with the server map folder structure. - param_name: download type: bool default: True doc: > - If True, downloads files that are not already in cache. + If True, downloads files that are not already in cache. The cache can be found at "HOME\carlaCache" or "USERPROFILE\carlaCache", depending on OS. doc: > Asks the server which files are required by the client to use the current map. Option to download files automatically if they are not already in the cache. # -------------------------------------- diff --git a/PythonAPI/docs/sensor.yml b/PythonAPI/docs/sensor.yml index d1f118978..5885217cd 100644 --- a/PythonAPI/docs/sensor.yml +++ b/PythonAPI/docs/sensor.yml @@ -8,28 +8,28 @@ doc: > Sensors compound a specific family of actors quite diverse and unique. They are normally spawned as attachment/sons of a vehicle (take a look at carla.World to learn about actor spawning). Sensors are thoroughly designed to retrieve different types of data that they are listening to. The data they receive is shaped as different subclasses inherited from carla.SensorData (depending on the sensor). - Most sensors can be divided in two groups: those receiving data on every tick (cameras, point clouds and some specific sensors) and those who only receive under certain circumstances (trigger detectors). CARLA provides a specific set of sensors and their blueprint can be found in carla.BlueprintLibrary. All the information on their preferences and settlement can be found [here](ref_sensors.md), but the list of those available in CARLA so far goes as follow. -
Receive data on every tick. - - [Depth camera](ref_sensors.md#depth-camera). - - [Gnss sensor](ref_sensors.md#gnss-sensor). - - [IMU sensor](ref_sensors.md#imu-sensor). - - [Lidar raycast](ref_sensors.md#lidar-raycast-sensor). - - [SemanticLidar raycast](ref_sensors.md#semanticlidar-raycast-sensor). - - [Radar](ref_sensors.md#radar-sensor). - - [RGB camera](ref_sensors.md#rgb-camera). - - [RSS sensor](ref_sensors.md#rss-sensor). - - [Semantic Segmentation camera](ref_sensors.md#semantic-segmentation-camera). -
Only receive data when triggered. - - [Collision detector](ref_sensors.md#collision-detector). - - [Lane invasion detector](ref_sensors.md#lane-invasion-detector). - - [Obstacle detector](ref_sensors.md#obstacle-detector). - + Most sensors can be divided in two groups: those receiving data on every tick (cameras, point clouds and some specific sensors) and those who only receive under certain circumstances (trigger detectors). CARLA provides a specific set of sensors and their blueprint can be found in carla.BlueprintLibrary. All the information on their preferences and settlement can be found [here](ref_sensors.md), but the list of those available in CARLA so far goes as follows:
+
Receive data on every tick
+ - [Depth camera](ref_sensors.md#depth-camera)
+ - [Gnss sensor](ref_sensors.md#gnss-sensor)
+ - [IMU sensor](ref_sensors.md#imu-sensor)
+ - [Lidar raycast](ref_sensors.md#lidar-raycast-sensor)
+ - [SemanticLidar raycast](ref_sensors.md#semanticlidar-raycast-sensor)
+ - [Radar](ref_sensors.md#radar-sensor)
+ - [RGB camera](ref_sensors.md#rgb-camera)
+ - [RSS sensor](ref_sensors.md#rss-sensor)
+ - [Semantic Segmentation camera](ref_sensors.md#semantic-segmentation-camera)
+
Only receive data when triggered.
+ - [Collision detector](ref_sensors.md#collision-detector)
+ - [Lane invasion detector](ref_sensors.md#lane-invasion-detector)
+ - [Obstacle detector](ref_sensors.md#obstacle-detector)
+ - [V2X sensor](ref_sensors.md#v2x-sensor) # - PROPERTIES ------------------------- instance_variables: - var_name: is_listening type: boolean doc: > - When True the sensor will be waiting for data. + When **True** the sensor will be waiting for data. # - METHODS ---------------------------- methods: - def_name: listen @@ -44,6 +44,8 @@ - def_name: is_listening doc: > Returns whether the sensor is in a listening state. + return: + bool # -------------------------------------- - def_name: stop doc: > @@ -60,6 +62,8 @@ - def_name: is_enabled_for_ros doc: > Returns if the sensor is enabled or not to publish in ROS2 if there is no any listen to it. + return: + bool # -------------------------------------- - def_name: listen_to_gbuffer params: @@ -83,6 +87,8 @@ The ID of the target Unreal Engine GBuffer texture. doc: > Returns whether the sensor is in a listening state for a specific GBuffer texture. + return: + bool # -------------------------------------- - def_name: stop_gbuffer params: @@ -93,6 +99,15 @@ doc: > Commands the sensor to stop listening for the specified GBuffer texture. # -------------------------------------- + - def_name: send + params: + - param_name: message + type: string + doc: > + The data to send. Note: maximum string length is 100 chars. + doc: > + Instructs the sensor to send the string given by `message` to all other CustomV2XSensors on the next tick. + # -------------------------------------- - def_name: __str__ # -------------------------------------- diff --git a/PythonAPI/docs/sensor_data.yml b/PythonAPI/docs/sensor_data.yml index 1e0e477e1..cdd394a56 100644 --- a/PythonAPI/docs/sensor_data.yml +++ b/PythonAPI/docs/sensor_data.yml @@ -15,7 +15,9 @@ - Obstacle detector: carla.ObstacleDetectionEvent.
- Radar sensor: carla.RadarMeasurement.
- RSS sensor: carla.RssResponse.
- - Semantic LIDAR sensor: carla.SemanticLidarMeasurement. + - Semantic LIDAR sensor: carla.SemanticLidarMeasurement.
+ - Cooperative awareness messages V2X sensor: carla.CAMEvent.
+ - Custom V2X messages V2X sensor: carla.CustomV2XEvent. # - PROPERTIES ------------------------- instance_variables: - var_name: frame @@ -878,7 +880,7 @@ - class_name: GBufferTextureID # - DESCRIPTION ------------------------ doc: > - Defines the identifiers of each GBuffer texture (See the method `carla.Sensor.listen_to_gbuffer`). + Defines the of each GBuffer texture (See the method `carla.Sensor.listen_to_gbuffer`). # - PROPERTIES ------------------------- instance_variables: - var_name: SceneColor @@ -941,4 +943,110 @@ The texture "CustomStencil" contains the Unreal Engine custom stencil data. # -------------------------------------- + + - class_name: CAMData + parent: carla.SensorData + # - DESCRIPTION ------------------------ + doc: > + This is the data type for cooperative awareness message reception, contained in a [CAMEvent](#carlacamevent) + # - PROPERTIES ------------------------- + instance_variables: + - var_name: power + type: float - dBm + doc: > + Received power. + + # - METHODS ---------------------------- + # -------------------------------------- + methods: + - def_name: get + return: dict + doc: > + Get the CAM data. Returns a nested dictionary containing the message following the ETSI standard: - `Header`: dict - `Message`: dict + # -------------------------------------- + - def_name: __str__ + # -------------------------------------- + + - class_name: CAMEvent + parent: carla.SensorData + # - DESCRIPTION ------------------------ + doc: > + Class that defines the data provided by a **sensor.other.v2x**. This is a collection type to combine returning several [CAMData](#carlacamdata). + # - PROPERTIES ------------------------- + instance_variables: + + # - METHODS ---------------------------- + # -------------------------------------- + methods: + - def_name: get_message_count + return: int + doc: > + Get the number of received CAM's. + # -------------------------------------- + - def_name: __get_item__ + params: + - param_name: pos + type: int + # -------------------------------------- + - def_name: __iter__ + doc: > + Iterate over the [CAMData](#carlacamdata) retrieved as data. + # -------------------------------------- + - def_name: __len__ + # -------------------------------------- + + + - class_name: CustomV2XEvent + parent: carla.SensorData + # - DESCRIPTION ------------------------ + doc: > + Class that defines the data provided by a **sensor.other.v2x_custom**. This is a collection type to combine returning several [CustomV2XData](#carlacustomv2xdata). + # - PROPERTIES ------------------------- + instance_variables: + + # - METHODS ---------------------------- + # -------------------------------------- + methods: + - def_name: get_message_count + return: int + doc: > + Get the number of received CAM's. + # -------------------------------------- + - def_name: __get_item__ + params: + - param_name: pos + type: int + # -------------------------------------- + - def_name: __iter__ + doc: > + Iterate over the [CustomV2XData](#carlacustomv2xdata) retrieved as data. + # -------------------------------------- + - def_name: __len__ + # -------------------------------------- + + + - class_name: CustomV2XData + parent: carla.SensorData + # - DESCRIPTION ------------------------ + doc: > + This is the data type defining a custom V2X message. Received as part of a [CustomV2XEvent](#carlacustomv2xevent). + # - PROPERTIES ------------------------- + instance_variables: + - var_name: power + type: float - dBm + doc: > + Received power. + + # - METHODS ---------------------------- + # -------------------------------------- + methods: + - def_name: get + return: dict + doc: > + Get the custom message. Returns a nested dictionary containing the message. It has two primary keys: - `Header` : dict - `Message`: str + # -------------------------------------- + - def_name: __str__ + # -------------------------------------- + + ... diff --git a/PythonAPI/examples/V2XDemo.py b/PythonAPI/examples/V2XDemo.py new file mode 100644 index 000000000..eedfae968 --- /dev/null +++ b/PythonAPI/examples/V2XDemo.py @@ -0,0 +1,1419 @@ +#!/usr/bin/env python + +# Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma de +# Barcelona (UAB). +# +# This work is licensed under the terms of the MIT license. +# For a copy, see . + +# Allows controlling a vehicle with a keyboard. For a simpler and more +# documented example, please take a look at tutorial.py. + +""" +Welcome to CARLA manual control. + +Use ARROWS or WASD keys for control. + + W : throttle + S : brake + A/D : steer left/right + Q : toggle reverse + Space : hand-brake + P : toggle autopilot + M : toggle manual transmission + ,/. : gear up/down + CTRL + W : toggle constant velocity mode at 60 km/h + + L : toggle next light type + SHIFT + L : toggle high beam + Z/X : toggle right/left blinker + I : toggle interior light + + TAB : change sensor position + ` or N : next sensor + [1-9] : change to sensor [1-9] + G : toggle radar visualization + C : change weather (Shift+C reverse) + Backspace : change vehicle + + O : open/close all doors of vehicle + T : toggle vehicle's telemetry + + V : Select next map layer (Shift+V reverse) + B : Load current selected map layer (Shift+B to unload) + + R : toggle recording images to disk + + CTRL + R : toggle recording of simulation (replacing any previous) + CTRL + P : start replaying last recorded simulation + CTRL + + : increments the start time of the replay by 1 second (+SHIFT = 10 seconds) + CTRL + - : decrements the start time of the replay by 1 second (+SHIFT = 10 seconds) + + F1 : toggle HUD + H/? : toggle help + ESC : quit +""" + +from __future__ import print_function + + +# ============================================================================== +# -- find carla module --------------------------------------------------------- +# ============================================================================== + + +import glob +import os +import sys + +try: + sys.path.append(glob.glob('../carla/dist/carla-0.9.15-py*%d.%d-%s.egg' % ( + sys.version_info.major, + sys.version_info.minor, + 'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0]) +except IndexError: + pass + + +# ============================================================================== +# -- imports ------------------------------------------------------------------- +# ============================================================================== + + +import carla + +from carla import ColorConverter as cc + +import argparse +import collections +import datetime +import logging +import math +import random +import re +import weakref + +try: + import pygame + from pygame.locals import KMOD_CTRL + from pygame.locals import KMOD_SHIFT + from pygame.locals import K_0 + from pygame.locals import K_9 + from pygame.locals import K_BACKQUOTE + from pygame.locals import K_BACKSPACE + from pygame.locals import K_COMMA + from pygame.locals import K_DOWN + from pygame.locals import K_ESCAPE + from pygame.locals import K_F1 + from pygame.locals import K_LEFT + from pygame.locals import K_PERIOD + from pygame.locals import K_RIGHT + from pygame.locals import K_SLASH + from pygame.locals import K_SPACE + from pygame.locals import K_TAB + from pygame.locals import K_UP + from pygame.locals import K_a + from pygame.locals import K_b + from pygame.locals import K_c + from pygame.locals import K_d + from pygame.locals import K_f + from pygame.locals import K_g + from pygame.locals import K_h + from pygame.locals import K_i + from pygame.locals import K_l + from pygame.locals import K_m + from pygame.locals import K_n + from pygame.locals import K_o + from pygame.locals import K_p + from pygame.locals import K_q + from pygame.locals import K_r + from pygame.locals import K_s + from pygame.locals import K_t + from pygame.locals import K_v + from pygame.locals import K_w + from pygame.locals import K_x + from pygame.locals import K_z + from pygame.locals import K_MINUS + from pygame.locals import K_EQUALS +except ImportError: + raise RuntimeError('cannot import pygame, make sure pygame package is installed') + +try: + import numpy as np +except ImportError: + raise RuntimeError('cannot import numpy, make sure numpy package is installed') + + +# ============================================================================== +# -- Global functions ---------------------------------------------------------- +# ============================================================================== + + +def find_weather_presets(): + rgx = re.compile('.+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)') + name = lambda x: ' '.join(m.group(0) for m in rgx.finditer(x)) + presets = [x for x in dir(carla.WeatherParameters) if re.match('[A-Z].+', x)] + return [(getattr(carla.WeatherParameters, x), name(x)) for x in presets] + + +def get_actor_display_name(actor, truncate=250): + name = ' '.join(actor.type_id.replace('_', '.').title().split('.')[1:]) + return (name[:truncate - 1] + u'\u2026') if len(name) > truncate else name + +def get_actor_blueprints(world, filter, generation): + bps = world.get_blueprint_library().filter(filter) + + if generation.lower() == "all": + return bps + + # If the filter returns only one bp, we assume that this one needed + # and therefore, we ignore the generation + if len(bps) == 1: + return bps + + try: + int_generation = int(generation) + # Check if generation is in available generations + if int_generation in [1, 2]: + bps = [x for x in bps if int(x.get_attribute('generation')) == int_generation] + return bps + else: + print(" Warning! Actor Generation is not valid. No actor will be spawned.") + return [] + except: + print(" Warning! Actor Generation is not valid. No actor will be spawned.") + return [] + + +# ============================================================================== +# -- World --------------------------------------------------------------------- +# ============================================================================== + + +class World(object): + def __init__(self, carla_world, hud, args): + self.world = carla_world + self.sync = args.sync + self.actor_role_name = args.rolename + try: + self.map = self.world.get_map() + except RuntimeError as error: + print('RuntimeError: {}'.format(error)) + print(' The server could not send the OpenDRIVE (.xodr) file:') + print(' Make sure it exists, has the same name of your town, and is correct.') + sys.exit(1) + self.hud = hud + self.player = None + self.collision_sensor = None + # self.lane_invasion_sensor = None + self.gnss_sensor = None + self.imu_sensor = None + self.v2x_sensor = None + self.radar_sensor = None + self.camera_manager = None + self._weather_presets = find_weather_presets() + self._weather_index = 0 + self._actor_filter = args.filter + self._actor_generation = args.generation + self._gamma = args.gamma + self.restart() + self.world.on_tick(hud.on_world_tick) + self.recording_enabled = False + self.recording_start = 0 + self.constant_velocity_enabled = False + self.show_vehicle_telemetry = False + self.doors_are_open = False + self.current_map_layer = 0 + self.map_layer_names = [ + carla.MapLayer.NONE, + carla.MapLayer.Buildings, + carla.MapLayer.Decals, + carla.MapLayer.Foliage, + carla.MapLayer.Ground, + carla.MapLayer.ParkedVehicles, + carla.MapLayer.Particles, + carla.MapLayer.Props, + carla.MapLayer.StreetLights, + carla.MapLayer.Walls, + carla.MapLayer.All + ] + + def restart(self): + self.player_max_speed = 1.589 + self.player_max_speed_fast = 3.713 + # Keep same camera config if the camera manager exists. + cam_index = self.camera_manager.index if self.camera_manager is not None else 0 + cam_pos_index = self.camera_manager.transform_index if self.camera_manager is not None else 0 + # Get a random blueprint. + blueprint = random.choice(get_actor_blueprints(self.world, self._actor_filter, self._actor_generation)) + blueprint.set_attribute('role_name', self.actor_role_name) + if blueprint.has_attribute('terramechanics'): + blueprint.set_attribute('terramechanics', 'true') + if blueprint.has_attribute('color'): + color = random.choice(blueprint.get_attribute('color').recommended_values) + blueprint.set_attribute('color', color) + if blueprint.has_attribute('driver_id'): + driver_id = random.choice(blueprint.get_attribute('driver_id').recommended_values) + blueprint.set_attribute('driver_id', driver_id) + if blueprint.has_attribute('is_invincible'): + blueprint.set_attribute('is_invincible', 'true') + # set the max speed + if blueprint.has_attribute('speed'): + self.player_max_speed = float(blueprint.get_attribute('speed').recommended_values[1]) + self.player_max_speed_fast = float(blueprint.get_attribute('speed').recommended_values[2]) + + # Spawn the player. + if self.player is not None: + spawn_point = self.player.get_transform() + spawn_point.location.z += 2.0 + spawn_point.rotation.roll = 0.0 + spawn_point.rotation.pitch = 0.0 + self.destroy() + self.player = self.world.try_spawn_actor(blueprint, spawn_point) + self.show_vehicle_telemetry = False + self.modify_vehicle_physics(self.player) + while self.player is None: + if not self.map.get_spawn_points(): + print('There are no spawn points available in your map/town.') + print('Please add some Vehicle Spawn Point to your UE4 scene.') + sys.exit(1) + spawn_points = self.map.get_spawn_points() + spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform() + self.player = self.world.try_spawn_actor(blueprint, spawn_point) + self.show_vehicle_telemetry = False + self.modify_vehicle_physics(self.player) + # Set up the sensors. + self.collision_sensor = CollisionSensor(self.player, self.hud) + #self.lane_invasion_sensor = LaneInvasionSensor(self.player, self.hud) + self.gnss_sensor = GnssSensor(self.player) + self.imu_sensor = IMUSensor(self.player) + self.v2x_sensor = V2XSensor(self.player, self.hud) + self.camera_manager = CameraManager(self.player, self.hud, self._gamma) + self.camera_manager.transform_index = cam_pos_index + self.camera_manager.set_sensor(cam_index, notify=False) + actor_type = get_actor_display_name(self.player) + self.hud.notification(actor_type) + + if self.sync: + self.world.tick() + else: + self.world.wait_for_tick() + + def next_weather(self, reverse=False): + self._weather_index += -1 if reverse else 1 + self._weather_index %= len(self._weather_presets) + preset = self._weather_presets[self._weather_index] + self.hud.notification('Weather: %s' % preset[1]) + self.player.get_world().set_weather(preset[0]) + + def next_map_layer(self, reverse=False): + self.current_map_layer += -1 if reverse else 1 + self.current_map_layer %= len(self.map_layer_names) + selected = self.map_layer_names[self.current_map_layer] + self.hud.notification('LayerMap selected: %s' % selected) + + def load_map_layer(self, unload=False): + selected = self.map_layer_names[self.current_map_layer] + if unload: + self.hud.notification('Unloading map layer: %s' % selected) + self.world.unload_map_layer(selected) + else: + self.hud.notification('Loading map layer: %s' % selected) + self.world.load_map_layer(selected) + + def toggle_radar(self): + if self.radar_sensor is None: + self.radar_sensor = RadarSensor(self.player) + elif self.radar_sensor.sensor is not None: + self.radar_sensor.sensor.destroy() + self.radar_sensor = None + + def modify_vehicle_physics(self, actor): + #If actor is not a vehicle, we cannot use the physics control + try: + physics_control = actor.get_physics_control() + physics_control.use_sweep_wheel_collision = True + actor.apply_physics_control(physics_control) + except Exception: + pass + + def tick(self, clock): + self.hud.tick(self, clock) + + def render(self, display): + self.camera_manager.render(display) + self.hud.render(display) + + def destroy_sensors(self): + self.camera_manager.sensor.destroy() + self.camera_manager.sensor = None + self.camera_manager.index = None + + def destroy(self): + if self.radar_sensor is not None: + self.toggle_radar() + sensors = [ + self.camera_manager.sensor, + self.collision_sensor.sensor, + # self.lane_invasion_sensor.sensor, + self.gnss_sensor.sensor, + self.imu_sensor.sensor, + self.v2x_sensor.sensor] + for sensor in sensors: + if sensor is not None: + sensor.stop() + sensor.destroy() + if self.player is not None: + self.player.destroy() + + +# ============================================================================== +# -- KeyboardControl ----------------------------------------------------------- +# ============================================================================== + + +class KeyboardControl(object): + """Class that handles keyboard input.""" + def __init__(self, world, start_in_autopilot): + self._autopilot_enabled = start_in_autopilot + self._ackermann_enabled = False + self._ackermann_reverse = 1 + if isinstance(world.player, carla.Vehicle): + self._control = carla.VehicleControl() + self._ackermann_control = carla.VehicleAckermannControl() + self._lights = carla.VehicleLightState.NONE + world.player.set_autopilot(self._autopilot_enabled) + world.player.set_light_state(self._lights) + elif isinstance(world.player, carla.Walker): + self._control = carla.WalkerControl() + self._autopilot_enabled = False + self._rotation = world.player.get_transform().rotation + else: + raise NotImplementedError("Actor type not supported") + self._steer_cache = 0.0 + world.hud.notification("Press 'H' or '?' for help.", seconds=4.0) + + def parse_events(self, client, world, clock, sync_mode): + if isinstance(self._control, carla.VehicleControl): + current_lights = self._lights + for event in pygame.event.get(): + if event.type == pygame.QUIT: + return True + elif event.type == pygame.KEYUP: + if self._is_quit_shortcut(event.key): + return True + elif event.key == K_BACKSPACE: + if self._autopilot_enabled: + world.player.set_autopilot(False) + world.restart() + world.player.set_autopilot(True) + else: + world.restart() + elif event.key == K_F1: + world.hud.toggle_info() + elif event.key == K_v and pygame.key.get_mods() & KMOD_SHIFT: + world.next_map_layer(reverse=True) + elif event.key == K_v: + world.next_map_layer() + elif event.key == K_b and pygame.key.get_mods() & KMOD_SHIFT: + world.load_map_layer(unload=True) + elif event.key == K_b: + world.load_map_layer() + elif event.key == K_h or (event.key == K_SLASH and pygame.key.get_mods() & KMOD_SHIFT): + world.hud.help.toggle() + elif event.key == K_TAB: + world.camera_manager.toggle_camera() + elif event.key == K_c and pygame.key.get_mods() & KMOD_SHIFT: + world.next_weather(reverse=True) + elif event.key == K_c: + world.next_weather() + elif event.key == K_g: + world.toggle_radar() + elif event.key == K_BACKQUOTE: + world.camera_manager.next_sensor() + elif event.key == K_n: + world.camera_manager.next_sensor() + elif event.key == K_w and (pygame.key.get_mods() & KMOD_CTRL): + if world.constant_velocity_enabled: + world.player.disable_constant_velocity() + world.constant_velocity_enabled = False + world.hud.notification("Disabled Constant Velocity Mode") + else: + world.player.enable_constant_velocity(carla.Vector3D(17, 0, 0)) + world.constant_velocity_enabled = True + world.hud.notification("Enabled Constant Velocity Mode at 60 km/h") + elif event.key == K_o: + try: + if world.doors_are_open: + world.hud.notification("Closing Doors") + world.doors_are_open = False + world.player.close_door(carla.VehicleDoor.All) + else: + world.hud.notification("Opening doors") + world.doors_are_open = True + world.player.open_door(carla.VehicleDoor.All) + except Exception: + pass + elif event.key == K_t: + if world.show_vehicle_telemetry: + world.player.show_debug_telemetry(False) + world.show_vehicle_telemetry = False + world.hud.notification("Disabled Vehicle Telemetry") + else: + try: + world.player.show_debug_telemetry(True) + world.show_vehicle_telemetry = True + world.hud.notification("Enabled Vehicle Telemetry") + except Exception: + pass + elif event.key > K_0 and event.key <= K_9: + index_ctrl = 0 + if pygame.key.get_mods() & KMOD_CTRL: + index_ctrl = 9 + world.camera_manager.set_sensor(event.key - 1 - K_0 + index_ctrl) + elif event.key == K_r and not (pygame.key.get_mods() & KMOD_CTRL): + world.camera_manager.toggle_recording() + elif event.key == K_r and (pygame.key.get_mods() & KMOD_CTRL): + if (world.recording_enabled): + client.stop_recorder() + world.recording_enabled = False + world.hud.notification("Recorder is OFF") + else: + client.start_recorder("manual_recording.rec") + world.recording_enabled = True + world.hud.notification("Recorder is ON") + elif event.key == K_p and (pygame.key.get_mods() & KMOD_CTRL): + # stop recorder + client.stop_recorder() + world.recording_enabled = False + # work around to fix camera at start of replaying + current_index = world.camera_manager.index + world.destroy_sensors() + # disable autopilot + self._autopilot_enabled = False + world.player.set_autopilot(self._autopilot_enabled) + world.hud.notification("Replaying file 'manual_recording.rec'") + # replayer + client.replay_file("manual_recording.rec", world.recording_start, 0, 0) + world.camera_manager.set_sensor(current_index) + elif event.key == K_MINUS and (pygame.key.get_mods() & KMOD_CTRL): + if pygame.key.get_mods() & KMOD_SHIFT: + world.recording_start -= 10 + else: + world.recording_start -= 1 + world.hud.notification("Recording start time is %d" % (world.recording_start)) + elif event.key == K_EQUALS and (pygame.key.get_mods() & KMOD_CTRL): + if pygame.key.get_mods() & KMOD_SHIFT: + world.recording_start += 10 + else: + world.recording_start += 1 + world.hud.notification("Recording start time is %d" % (world.recording_start)) + if isinstance(self._control, carla.VehicleControl): + if event.key == K_f: + # Toggle ackermann controller + self._ackermann_enabled = not self._ackermann_enabled + world.hud.show_ackermann_info(self._ackermann_enabled) + world.hud.notification("Ackermann Controller %s" % + ("Enabled" if self._ackermann_enabled else "Disabled")) + if event.key == K_q: + if not self._ackermann_enabled: + self._control.gear = 1 if self._control.reverse else -1 + else: + self._ackermann_reverse *= -1 + # Reset ackermann control + self._ackermann_control = carla.VehicleAckermannControl() + elif event.key == K_m: + self._control.manual_gear_shift = not self._control.manual_gear_shift + self._control.gear = world.player.get_control().gear + world.hud.notification('%s Transmission' % + ('Manual' if self._control.manual_gear_shift else 'Automatic')) + elif self._control.manual_gear_shift and event.key == K_COMMA: + self._control.gear = max(-1, self._control.gear - 1) + elif self._control.manual_gear_shift and event.key == K_PERIOD: + self._control.gear = self._control.gear + 1 + elif event.key == K_p and not pygame.key.get_mods() & KMOD_CTRL: + if not self._autopilot_enabled and not sync_mode: + print("WARNING: You are currently in asynchronous mode and could " + "experience some issues with the traffic simulation") + self._autopilot_enabled = not self._autopilot_enabled + world.player.set_autopilot(self._autopilot_enabled) + world.hud.notification( + 'Autopilot %s' % ('On' if self._autopilot_enabled else 'Off')) + elif event.key == K_l and pygame.key.get_mods() & KMOD_CTRL: + current_lights ^= carla.VehicleLightState.Special1 + elif event.key == K_l and pygame.key.get_mods() & KMOD_SHIFT: + current_lights ^= carla.VehicleLightState.HighBeam + elif event.key == K_l: + # Use 'L' key to switch between lights: + # closed -> position -> low beam -> fog + if not self._lights & carla.VehicleLightState.Position: + world.hud.notification("Position lights") + current_lights |= carla.VehicleLightState.Position + else: + world.hud.notification("Low beam lights") + current_lights |= carla.VehicleLightState.LowBeam + if self._lights & carla.VehicleLightState.LowBeam: + world.hud.notification("Fog lights") + current_lights |= carla.VehicleLightState.Fog + if self._lights & carla.VehicleLightState.Fog: + world.hud.notification("Lights off") + current_lights ^= carla.VehicleLightState.Position + current_lights ^= carla.VehicleLightState.LowBeam + current_lights ^= carla.VehicleLightState.Fog + elif event.key == K_i: + current_lights ^= carla.VehicleLightState.Interior + elif event.key == K_z: + current_lights ^= carla.VehicleLightState.LeftBlinker + elif event.key == K_x: + current_lights ^= carla.VehicleLightState.RightBlinker + + if not self._autopilot_enabled: + if isinstance(self._control, carla.VehicleControl): + self._parse_vehicle_keys(pygame.key.get_pressed(), clock.get_time()) + self._control.reverse = self._control.gear < 0 + # Set automatic control-related vehicle lights + if self._control.brake: + current_lights |= carla.VehicleLightState.Brake + else: # Remove the Brake flag + current_lights &= ~carla.VehicleLightState.Brake + if self._control.reverse: + current_lights |= carla.VehicleLightState.Reverse + else: # Remove the Reverse flag + current_lights &= ~carla.VehicleLightState.Reverse + if current_lights != self._lights: # Change the light state only if necessary + self._lights = current_lights + world.player.set_light_state(carla.VehicleLightState(self._lights)) + # Apply control + if not self._ackermann_enabled: + world.player.apply_control(self._control) + else: + world.player.apply_ackermann_control(self._ackermann_control) + # Update control to the last one applied by the ackermann controller. + self._control = world.player.get_control() + # Update hud with the newest ackermann control + world.hud.update_ackermann_control(self._ackermann_control) + + elif isinstance(self._control, carla.WalkerControl): + self._parse_walker_keys(pygame.key.get_pressed(), clock.get_time(), world) + world.player.apply_control(self._control) + + def _parse_vehicle_keys(self, keys, milliseconds): + if keys[K_UP] or keys[K_w]: + if not self._ackermann_enabled: + self._control.throttle = min(self._control.throttle + 0.01, 1.00) + else: + self._ackermann_control.speed += round(milliseconds * 0.005, 2) * self._ackermann_reverse + else: + if not self._ackermann_enabled: + self._control.throttle = 0.0 + + if keys[K_DOWN] or keys[K_s]: + if not self._ackermann_enabled: + self._control.brake = min(self._control.brake + 0.2, 1) + else: + self._ackermann_control.speed -= min(abs(self._ackermann_control.speed), round(milliseconds * 0.005, 2)) * self._ackermann_reverse + self._ackermann_control.speed = max(0, abs(self._ackermann_control.speed)) * self._ackermann_reverse + else: + if not self._ackermann_enabled: + self._control.brake = 0 + + steer_increment = 5e-4 * milliseconds + if keys[K_LEFT] or keys[K_a]: + if self._steer_cache > 0: + self._steer_cache = 0 + else: + self._steer_cache -= steer_increment + elif keys[K_RIGHT] or keys[K_d]: + if self._steer_cache < 0: + self._steer_cache = 0 + else: + self._steer_cache += steer_increment + else: + self._steer_cache = 0.0 + self._steer_cache = min(0.7, max(-0.7, self._steer_cache)) + if not self._ackermann_enabled: + self._control.steer = round(self._steer_cache, 1) + self._control.hand_brake = keys[K_SPACE] + else: + self._ackermann_control.steer = round(self._steer_cache, 1) + + def _parse_walker_keys(self, keys, milliseconds, world): + self._control.speed = 0.0 + if keys[K_DOWN] or keys[K_s]: + self._control.speed = 0.0 + if keys[K_LEFT] or keys[K_a]: + self._control.speed = .01 + self._rotation.yaw -= 0.08 * milliseconds + if keys[K_RIGHT] or keys[K_d]: + self._control.speed = .01 + self._rotation.yaw += 0.08 * milliseconds + if keys[K_UP] or keys[K_w]: + self._control.speed = world.player_max_speed_fast if pygame.key.get_mods() & KMOD_SHIFT else world.player_max_speed + self._control.jump = keys[K_SPACE] + self._rotation.yaw = round(self._rotation.yaw, 1) + self._control.direction = self._rotation.get_forward_vector() + + @staticmethod + def _is_quit_shortcut(key): + return (key == K_ESCAPE) or (key == K_q and pygame.key.get_mods() & KMOD_CTRL) + + +# ============================================================================== +# -- HUD ----------------------------------------------------------------------- +# ============================================================================== + + +class HUD(object): + def __init__(self, width, height): + self.dim = (width, height) + font = pygame.font.Font(pygame.font.get_default_font(), 20) + font_name = 'courier' if os.name == 'nt' else 'mono' + fonts = [x for x in pygame.font.get_fonts() if font_name in x] + default_font = 'ubuntumono' + mono = default_font if default_font in fonts else fonts[0] + mono = pygame.font.match_font(mono) + self._font_mono = pygame.font.Font(mono, 12 if os.name == 'nt' else 14) + self._notifications = FadingText(font, (width, 40), (0, height - 40)) + self.help = HelpText(pygame.font.Font(mono, 16), width, height) + self.server_fps = 0 + self.frame = 0 + self.simulation_time = 0 + self._show_info = True + self._info_text = [] + self._server_clock = pygame.time.Clock() + + self._show_ackermann_info = False + self._ackermann_control = carla.VehicleAckermannControl() + + def on_world_tick(self, timestamp): + self._server_clock.tick() + self.server_fps = self._server_clock.get_fps() + self.frame = timestamp.frame + self.simulation_time = timestamp.elapsed_seconds + + def tick(self, world, clock): + self._notifications.tick(world, clock) + if not self._show_info: + return + t = world.player.get_transform() + v = world.player.get_velocity() + c = world.player.get_control() + compass = world.imu_sensor.compass + heading = 'N' if compass > 270.5 or compass < 89.5 else '' + heading += 'S' if 90.5 < compass < 269.5 else '' + heading += 'E' if 0.5 < compass < 179.5 else '' + heading += 'W' if 180.5 < compass < 359.5 else '' + colhist = world.collision_sensor.get_collision_history() + collision = [colhist[x + self.frame - 200] for x in range(0, 200)] + max_col = max(1.0, max(collision)) + collision = [x / max_col for x in collision] + vehicles = world.world.get_actors().filter('vehicle.*') + self._info_text = [ + 'Server: % 16.0f FPS' % self.server_fps, + 'Client: % 16.0f FPS' % clock.get_fps(), + '', + 'Vehicle: % 20s' % get_actor_display_name(world.player, truncate=20), + 'Map: % 20s' % world.map.name.split('/')[-1], + 'Simulation time: % 12s' % datetime.timedelta(seconds=int(self.simulation_time)), + '', + 'Speed: % 15.0f km/h' % (3.6 * math.sqrt(v.x**2 + v.y**2 + v.z**2)), + u'Compass:% 17.0f\N{DEGREE SIGN} % 2s' % (compass, heading), + 'Accelero: (%5.1f,%5.1f,%5.1f)' % (world.imu_sensor.accelerometer), + 'Gyroscop: (%5.1f,%5.1f,%5.1f)' % (world.imu_sensor.gyroscope), + 'Location:% 20s' % ('(% 5.1f, % 5.1f)' % (t.location.x, t.location.y)), + 'GNSS:% 24s' % ('(% 2.6f, % 3.6f)' % (world.gnss_sensor.lat, world.gnss_sensor.lon)), + 'Height: % 18.0f m' % t.location.z, + ''] + if isinstance(c, carla.VehicleControl): + self._info_text += [ + ('Throttle:', c.throttle, 0.0, 1.0), + ('Steer:', c.steer, -1.0, 1.0), + ('Brake:', c.brake, 0.0, 1.0), + ('Reverse:', c.reverse), + ('Hand brake:', c.hand_brake), + ('Manual:', c.manual_gear_shift), + 'Gear: %s' % {-1: 'R', 0: 'N'}.get(c.gear, c.gear)] + if self._show_ackermann_info: + self._info_text += [ + '', + 'Ackermann Controller:', + ' Target speed: % 8.0f km/h' % (3.6*self._ackermann_control.speed), + ] + elif isinstance(c, carla.WalkerControl): + self._info_text += [ + ('Speed:', c.speed, 0.0, 5.556), + ('Jump:', c.jump)] + self._info_text += [ + '', + 'Collision:', + collision, + '', + 'Number of vehicles: % 8d' % len(vehicles)] + if len(vehicles) > 1: + self._info_text += ['Nearby vehicles:'] + distance = lambda l: math.sqrt((l.x - t.location.x)**2 + (l.y - t.location.y)**2 + (l.z - t.location.z)**2) + vehicles = [(distance(x.get_location()), x) for x in vehicles if x.id != world.player.id] + for d, vehicle in sorted(vehicles, key=lambda vehicles: vehicles[0]): + if d > 200.0: + break + vehicle_type = get_actor_display_name(vehicle, truncate=22) + self._info_text.append('% 4dm %s' % (d, vehicle_type)) + + def show_ackermann_info(self, enabled): + self._show_ackermann_info = enabled + + def update_ackermann_control(self, ackermann_control): + self._ackermann_control = ackermann_control + + def toggle_info(self): + self._show_info = not self._show_info + + def notification(self, text, seconds=2.0): + self._notifications.set_text(text, seconds=seconds) + + def error(self, text): + self._notifications.set_text('Error: %s' % text, (255, 0, 0)) + + def render(self, display): + if self._show_info: + info_surface = pygame.Surface((220, self.dim[1])) + info_surface.set_alpha(100) + display.blit(info_surface, (0, 0)) + v_offset = 4 + bar_h_offset = 100 + bar_width = 106 + for item in self._info_text: + if v_offset + 18 > self.dim[1]: + break + if isinstance(item, list): + if len(item) > 1: + points = [(x + 8, v_offset + 8 + (1.0 - y) * 30) for x, y in enumerate(item)] + pygame.draw.lines(display, (255, 136, 0), False, points, 2) + item = None + v_offset += 18 + elif isinstance(item, tuple): + if isinstance(item[1], bool): + rect = pygame.Rect((bar_h_offset, v_offset + 8), (6, 6)) + pygame.draw.rect(display, (255, 255, 255), rect, 0 if item[1] else 1) + else: + rect_border = pygame.Rect((bar_h_offset, v_offset + 8), (bar_width, 6)) + pygame.draw.rect(display, (255, 255, 255), rect_border, 1) + f = (item[1] - item[2]) / (item[3] - item[2]) + if item[2] < 0.0: + rect = pygame.Rect((bar_h_offset + f * (bar_width - 6), v_offset + 8), (6, 6)) + else: + rect = pygame.Rect((bar_h_offset, v_offset + 8), (f * bar_width, 6)) + pygame.draw.rect(display, (255, 255, 255), rect) + item = item[0] + if item: # At this point has to be a str. + surface = self._font_mono.render(item, True, (255, 255, 255)) + display.blit(surface, (8, v_offset)) + v_offset += 18 + self._notifications.render(display) + self.help.render(display) + + +# ============================================================================== +# -- FadingText ---------------------------------------------------------------- +# ============================================================================== + + +class FadingText(object): + def __init__(self, font, dim, pos): + self.font = font + self.dim = dim + self.pos = pos + self.seconds_left = 0 + self.surface = pygame.Surface(self.dim) + + def set_text(self, text, color=(255, 255, 255), seconds=2.0): + text_texture = self.font.render(text, True, color) + self.surface = pygame.Surface(self.dim) + self.seconds_left = seconds + self.surface.fill((0, 0, 0, 0)) + self.surface.blit(text_texture, (10, 11)) + + def tick(self, _, clock): + delta_seconds = 1e-3 * clock.get_time() + self.seconds_left = max(0.0, self.seconds_left - delta_seconds) + self.surface.set_alpha(500.0 * self.seconds_left) + + def render(self, display): + display.blit(self.surface, self.pos) + + +# ============================================================================== +# -- HelpText ------------------------------------------------------------------ +# ============================================================================== + + +class HelpText(object): + """Helper class to handle text output using pygame""" + def __init__(self, font, width, height): + lines = __doc__.split('\n') + self.font = font + self.line_space = 18 + self.dim = (780, len(lines) * self.line_space + 12) + self.pos = (0.5 * width - 0.5 * self.dim[0], 0.5 * height - 0.5 * self.dim[1]) + self.seconds_left = 0 + self.surface = pygame.Surface(self.dim) + self.surface.fill((0, 0, 0, 0)) + for n, line in enumerate(lines): + text_texture = self.font.render(line, True, (255, 255, 255)) + self.surface.blit(text_texture, (22, n * self.line_space)) + self._render = False + self.surface.set_alpha(220) + + def toggle(self): + self._render = not self._render + + def render(self, display): + if self._render: + display.blit(self.surface, self.pos) + + +# ============================================================================== +# -- CollisionSensor ----------------------------------------------------------- +# ============================================================================== + + +class CollisionSensor(object): + def __init__(self, parent_actor, hud): + self.sensor = None + self.history = [] + self._parent = parent_actor + self.hud = hud + world = self._parent.get_world() + bp = world.get_blueprint_library().find('sensor.other.collision') + self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent) + # We need to pass the lambda a weak reference to self to avoid circular + # reference. + weak_self = weakref.ref(self) + self.sensor.listen(lambda event: CollisionSensor._on_collision(weak_self, event)) + + def get_collision_history(self): + history = collections.defaultdict(int) + for frame, intensity in self.history: + history[frame] += intensity + return history + + @staticmethod + def _on_collision(weak_self, event): + self = weak_self() + if not self: + return + actor_type = get_actor_display_name(event.other_actor) + self.hud.notification('Collision with %r' % actor_type) + impulse = event.normal_impulse + intensity = math.sqrt(impulse.x**2 + impulse.y**2 + impulse.z**2) + self.history.append((event.frame, intensity)) + if len(self.history) > 4000: + self.history.pop(0) + + +# ============================================================================== +# -- LaneInvasionSensor -------------------------------------------------------- +# ============================================================================== + + +class LaneInvasionSensor(object): + def __init__(self, parent_actor, hud): + self.sensor = None + + # If the spawn object is not a vehicle, we cannot use the Lane Invasion Sensor + if parent_actor.type_id.startswith("vehicle."): + self._parent = parent_actor + self.hud = hud + world = self._parent.get_world() + bp = world.get_blueprint_library().find('sensor.other.lane_invasion') + self.sensor = world.spawn_actor(bp, carla.Transform(), attach_to=self._parent) + # We need to pass the lambda a weak reference to self to avoid circular + # reference. + weak_self = weakref.ref(self) + self.sensor.listen(lambda event: LaneInvasionSensor._on_invasion(weak_self, event)) + + @staticmethod + def _on_invasion(weak_self, event): + self = weak_self() + if not self: + return + lane_types = set(x.type for x in event.crossed_lane_markings) + text = ['%r' % str(x).split()[-1] for x in lane_types] + self.hud.notification('Crossed line %s' % ' and '.join(text)) + + +# ============================================================================== +# -- GnssSensor ---------------------------------------------------------------- +# ============================================================================== + + +class GnssSensor(object): + def __init__(self, parent_actor): + self.sensor = None + self._parent = parent_actor + self.lat = 0.0 + self.lon = 0.0 + world = self._parent.get_world() + bp = world.get_blueprint_library().find('sensor.other.gnss') + self.sensor = world.spawn_actor(bp, carla.Transform(carla.Location(x=1.0, z=2.8)), attach_to=self._parent) + # We need to pass the lambda a weak reference to self to avoid circular + # reference. + weak_self = weakref.ref(self) + self.sensor.listen(lambda event: GnssSensor._on_gnss_event(weak_self, event)) + + @staticmethod + def _on_gnss_event(weak_self, event): + self = weak_self() + if not self: + return + self.lat = event.latitude + self.lon = event.longitude + + +# ============================================================================== +# -- IMUSensor ----------------------------------------------------------------- +# ============================================================================== + + +class IMUSensor(object): + def __init__(self, parent_actor): + self.sensor = None + self._parent = parent_actor + self.accelerometer = (0.0, 0.0, 0.0) + self.gyroscope = (0.0, 0.0, 0.0) + self.compass = 0.0 + world = self._parent.get_world() + bp = world.get_blueprint_library().find('sensor.other.imu') + self.sensor = world.spawn_actor( + bp, carla.Transform(), attach_to=self._parent) + # We need to pass the lambda a weak reference to self to avoid circular + # reference. + weak_self = weakref.ref(self) + self.sensor.listen( + lambda sensor_data: IMUSensor._IMU_callback(weak_self, sensor_data)) + + @staticmethod + def _IMU_callback(weak_self, sensor_data): + self = weak_self() + if not self: + return + limits = (-99.9, 99.9) + self.accelerometer = ( + max(limits[0], min(limits[1], sensor_data.accelerometer.x)), + max(limits[0], min(limits[1], sensor_data.accelerometer.y)), + max(limits[0], min(limits[1], sensor_data.accelerometer.z))) + self.gyroscope = ( + max(limits[0], min(limits[1], math.degrees(sensor_data.gyroscope.x))), + max(limits[0], min(limits[1], math.degrees(sensor_data.gyroscope.y))), + max(limits[0], min(limits[1], math.degrees(sensor_data.gyroscope.z)))) + self.compass = math.degrees(sensor_data.compass) + +# ============================================================================== +# -- V2XSensor ----------------------------------------------------------------- +# ============================================================================== + + +class V2XSensor(object): + def __init__(self, parent_actor, hud): + self.sensor = None + self._parent = parent_actor + world = self._parent.get_world() + #bp = world.get_blueprint_library().find('sensor.other.v2x_custom') + bp = world.get_blueprint_library().find('sensor.other.v2x') + bp.set_attribute("path_loss_model", "geometric") + self.hud = hud + self.sensor = world.spawn_actor( + bp, carla.Transform(), attach_to=self._parent) + # We need to pass the lambda a weak reference to self to avoid circular + # reference. + weak_self = weakref.ref(self) + self.sensor.listen( + lambda sensor_data: V2XSensor._V2X_callback(weak_self, sensor_data)) + + @staticmethod + def _V2X_callback(weak_self, sensor_data): + self = weak_self() + if not self: + return + print(sensor_data.get_message_count()) + for data in sensor_data: + msg = data.get() + # stationId = msg["Header"]["Station ID"] + power = data.power + print(msg) + # self.hud.notification('Cam message received from %s ' % stationId) + self.hud.notification('Cam message received with power %f ' % power) +# ============================================================================== +# -- RadarSensor --------------------------------------------------------------- +# ============================================================================== + + +class RadarSensor(object): + def __init__(self, parent_actor): + self.sensor = None + self._parent = parent_actor + bound_x = 0.5 + self._parent.bounding_box.extent.x + bound_y = 0.5 + self._parent.bounding_box.extent.y + bound_z = 0.5 + self._parent.bounding_box.extent.z + + self.velocity_range = 7.5 # m/s + world = self._parent.get_world() + self.debug = world.debug + bp = world.get_blueprint_library().find('sensor.other.radar') + bp.set_attribute('horizontal_fov', str(35)) + bp.set_attribute('vertical_fov', str(20)) + self.sensor = world.spawn_actor( + bp, + carla.Transform( + carla.Location(x=bound_x + 0.05, z=bound_z+0.05), + carla.Rotation(pitch=5)), + attach_to=self._parent) + # We need a weak reference to self to avoid circular reference. + weak_self = weakref.ref(self) + self.sensor.listen( + lambda radar_data: RadarSensor._Radar_callback(weak_self, radar_data)) + + @staticmethod + def _Radar_callback(weak_self, radar_data): + self = weak_self() + if not self: + return + # To get a numpy [[vel, altitude, azimuth, depth],...[,,,]]: + # points = np.frombuffer(radar_data.raw_data, dtype=np.dtype('f4')) + # points = np.reshape(points, (len(radar_data), 4)) + + current_rot = radar_data.transform.rotation + for detect in radar_data: + azi = math.degrees(detect.azimuth) + alt = math.degrees(detect.altitude) + # The 0.25 adjusts a bit the distance so the dots can + # be properly seen + fw_vec = carla.Vector3D(x=detect.depth - 0.25) + carla.Transform( + carla.Location(), + carla.Rotation( + pitch=current_rot.pitch + alt, + yaw=current_rot.yaw + azi, + roll=current_rot.roll)).transform(fw_vec) + + def clamp(min_v, max_v, value): + return max(min_v, min(value, max_v)) + + norm_velocity = detect.velocity / self.velocity_range # range [-1, 1] + r = int(clamp(0.0, 1.0, 1.0 - norm_velocity) * 255.0) + g = int(clamp(0.0, 1.0, 1.0 - abs(norm_velocity)) * 255.0) + b = int(abs(clamp(- 1.0, 0.0, - 1.0 - norm_velocity)) * 255.0) + self.debug.draw_point( + radar_data.transform.location + fw_vec, + size=0.075, + life_time=0.06, + persistent_lines=False, + color=carla.Color(r, g, b)) + +# ============================================================================== +# -- CameraManager ------------------------------------------------------------- +# ============================================================================== + + +class CameraManager(object): + def __init__(self, parent_actor, hud, gamma_correction): + self.sensor = None + self.surface = None + self._parent = parent_actor + self.hud = hud + self.recording = False + bound_x = 0.5 + self._parent.bounding_box.extent.x + bound_y = 0.5 + self._parent.bounding_box.extent.y + bound_z = 0.5 + self._parent.bounding_box.extent.z + Attachment = carla.AttachmentType + + if not self._parent.type_id.startswith("walker.pedestrian"): + self._camera_transforms = [ + (carla.Transform(carla.Location(x=-2.0*bound_x, y=+0.0*bound_y, z=2.0*bound_z), carla.Rotation(pitch=8.0)), Attachment.SpringArmGhost), + (carla.Transform(carla.Location(x=+0.8*bound_x, y=+0.0*bound_y, z=1.3*bound_z)), Attachment.Rigid), + (carla.Transform(carla.Location(x=+1.9*bound_x, y=+1.0*bound_y, z=1.2*bound_z)), Attachment.SpringArmGhost), + (carla.Transform(carla.Location(x=-2.8*bound_x, y=+0.0*bound_y, z=4.6*bound_z), carla.Rotation(pitch=6.0)), Attachment.SpringArmGhost), + (carla.Transform(carla.Location(x=-1.0, y=-1.0*bound_y, z=0.4*bound_z)), Attachment.Rigid)] + else: + self._camera_transforms = [ + (carla.Transform(carla.Location(x=-2.5, z=0.0), carla.Rotation(pitch=-8.0)), Attachment.SpringArmGhost), + (carla.Transform(carla.Location(x=1.6, z=1.7)), Attachment.Rigid), + (carla.Transform(carla.Location(x=2.5, y=0.5, z=0.0), carla.Rotation(pitch=-8.0)), Attachment.SpringArmGhost), + (carla.Transform(carla.Location(x=-4.0, z=2.0), carla.Rotation(pitch=6.0)), Attachment.SpringArmGhost), + (carla.Transform(carla.Location(x=0, y=-2.5, z=-0.0), carla.Rotation(yaw=90.0)), Attachment.Rigid)] + + self.transform_index = 1 + self.sensors = [ + ['sensor.camera.rgb', cc.Raw, 'Camera RGB', {}], + ['sensor.camera.depth', cc.Raw, 'Camera Depth (Raw)', {}], + ['sensor.camera.depth', cc.Depth, 'Camera Depth (Gray Scale)', {}], + ['sensor.camera.depth', cc.LogarithmicDepth, 'Camera Depth (Logarithmic Gray Scale)', {}], + ['sensor.camera.semantic_segmentation', cc.Raw, 'Camera Semantic Segmentation (Raw)', {}], + ['sensor.camera.semantic_segmentation', cc.CityScapesPalette, 'Camera Semantic Segmentation (CityScapes Palette)', {}], + ['sensor.camera.instance_segmentation', cc.CityScapesPalette, 'Camera Instance Segmentation (CityScapes Palette)', {}], + ['sensor.camera.instance_segmentation', cc.Raw, 'Camera Instance Segmentation (Raw)', {}], + # ['sensor.other.v2x', None, 'Lidar (Ray-Cast)', {'range': '50'}], + ['sensor.camera.dvs', cc.Raw, 'Dynamic Vision Sensor', {}], + ['sensor.camera.rgb', cc.Raw, 'Camera RGB Distorted', + {'lens_circle_multiplier': '3.0', + 'lens_circle_falloff': '3.0', + 'chromatic_aberration_intensity': '0.5', + 'chromatic_aberration_offset': '0'}], + ['sensor.camera.optical_flow', cc.Raw, 'Optical Flow', {}], + ['sensor.camera.normals', cc.Raw, 'Camera Normals', {}], + ] + world = self._parent.get_world() + bp_library = world.get_blueprint_library() + for item in self.sensors: + bp = bp_library.find(item[0]) + if item[0].startswith('sensor.camera'): + bp.set_attribute('image_size_x', str(hud.dim[0])) + bp.set_attribute('image_size_y', str(hud.dim[1])) + if bp.has_attribute('gamma'): + bp.set_attribute('gamma', str(gamma_correction)) + for attr_name, attr_value in item[3].items(): + bp.set_attribute(attr_name, attr_value) + elif item[0].startswith('sensor.lidar'): + self.lidar_range = 50 + + for attr_name, attr_value in item[3].items(): + bp.set_attribute(attr_name, attr_value) + if attr_name == 'range': + self.lidar_range = float(attr_value) + + item.append(bp) + self.index = None + + def toggle_camera(self): + self.transform_index = (self.transform_index + 1) % len(self._camera_transforms) + self.set_sensor(self.index, notify=False, force_respawn=True) + + def set_sensor(self, index, notify=True, force_respawn=False): + index = index % len(self.sensors) + needs_respawn = True if self.index is None else \ + (force_respawn or (self.sensors[index][2] != self.sensors[self.index][2])) + if needs_respawn: + if self.sensor is not None: + self.sensor.destroy() + self.surface = None + self.sensor = self._parent.get_world().spawn_actor( + self.sensors[index][-1], + self._camera_transforms[self.transform_index][0], + attach_to=self._parent, + attachment_type=self._camera_transforms[self.transform_index][1]) + # We need to pass the lambda a weak reference to self to avoid + # circular reference. + weak_self = weakref.ref(self) + self.sensor.listen(lambda image: CameraManager._parse_image(weak_self, image)) + if notify: + self.hud.notification(self.sensors[index][2]) + self.index = index + + def next_sensor(self): + self.set_sensor(self.index + 1) + + def toggle_recording(self): + self.recording = not self.recording + self.hud.notification('Recording %s' % ('On' if self.recording else 'Off')) + + def render(self, display): + if self.surface is not None: + display.blit(self.surface, (0, 0)) + + @staticmethod + def _parse_image(weak_self, image): + self = weak_self() + if not self: + return + if self.sensors[self.index][0].startswith('sensor.lidar'): + points = np.frombuffer(image.raw_data, dtype=np.dtype('f4')) + points = np.reshape(points, (int(points.shape[0] / 4), 4)) + lidar_data = np.array(points[:, :2]) + lidar_data *= min(self.hud.dim) / (2.0 * self.lidar_range) + lidar_data += (0.5 * self.hud.dim[0], 0.5 * self.hud.dim[1]) + lidar_data = np.fabs(lidar_data) # pylint: disable=E1111 + lidar_data = lidar_data.astype(np.int32) + lidar_data = np.reshape(lidar_data, (-1, 2)) + lidar_img_size = (self.hud.dim[0], self.hud.dim[1], 3) + lidar_img = np.zeros((lidar_img_size), dtype=np.uint8) + lidar_img[tuple(lidar_data.T)] = (255, 255, 255) + self.surface = pygame.surfarray.make_surface(lidar_img) + elif self.sensors[self.index][0].startswith('sensor.camera.dvs'): + # Example of converting the raw_data from a carla.DVSEventArray + # sensor into a NumPy array and using it as an image + dvs_events = np.frombuffer(image.raw_data, dtype=np.dtype([ + ('x', np.uint16), ('y', np.uint16), ('t', np.int64), ('pol', np.bool)])) + dvs_img = np.zeros((image.height, image.width, 3), dtype=np.uint8) + # Blue is positive, red is negative + dvs_img[dvs_events[:]['y'], dvs_events[:]['x'], dvs_events[:]['pol'] * 2] = 255 + self.surface = pygame.surfarray.make_surface(dvs_img.swapaxes(0, 1)) + elif self.sensors[self.index][0].startswith('sensor.camera.optical_flow'): + image = image.get_color_coded_flow() + array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8")) + array = np.reshape(array, (image.height, image.width, 4)) + array = array[:, :, :3] + array = array[:, :, ::-1] + self.surface = pygame.surfarray.make_surface(array.swapaxes(0, 1)) + else: + image.convert(self.sensors[self.index][1]) + array = np.frombuffer(image.raw_data, dtype=np.dtype("uint8")) + array = np.reshape(array, (image.height, image.width, 4)) + array = array[:, :, :3] + array = array[:, :, ::-1] + self.surface = pygame.surfarray.make_surface(array.swapaxes(0, 1)) + if self.recording: + image.save_to_disk('_out/%08d' % image.frame) + + +# ============================================================================== +# -- game_loop() --------------------------------------------------------------- +# ============================================================================== + + +def game_loop(args): + pygame.init() + pygame.font.init() + world = None + original_settings = None + + try: + client = carla.Client(args.host, args.port) + client.set_timeout(2000.0) + + sim_world = client.get_world() + if args.sync: + original_settings = sim_world.get_settings() + settings = sim_world.get_settings() + if not settings.synchronous_mode: + settings.synchronous_mode = True + settings.fixed_delta_seconds = 0.05 + sim_world.apply_settings(settings) + + traffic_manager = client.get_trafficmanager() + traffic_manager.set_synchronous_mode(True) + + if args.autopilot and not sim_world.get_settings().synchronous_mode: + print("WARNING: You are currently in asynchronous mode and could " + "experience some issues with the traffic simulation") + + display = pygame.display.set_mode( + (args.width, args.height), + pygame.HWSURFACE | pygame.DOUBLEBUF) + display.fill((0,0,0)) + pygame.display.flip() + # monitors = get_monitors() + # resolutions = [(monitor.name, monitor.width, monitor.height) for monitor in monitors] + # return resolutions + hud = HUD(args.width, args.height) + world = World(sim_world, hud, args) + controller = KeyboardControl(world, args.autopilot) + + if args.sync: + sim_world.tick() + else: + sim_world.wait_for_tick() + + clock = pygame.time.Clock() + while True: + if args.sync: + sim_world.tick() + clock.tick_busy_loop(60) + if controller.parse_events(client, world, clock, args.sync): + return + world.tick(clock) + world.render(display) + pygame.display.flip() + + finally: + + if original_settings: + sim_world.apply_settings(original_settings) + + if (world and world.recording_enabled): + client.stop_recorder() + + if world is not None: + world.destroy() + + pygame.quit() + + +# ============================================================================== +# -- main() -------------------------------------------------------------------- +# ============================================================================== + + +def main(): + argparser = argparse.ArgumentParser( + description='CARLA Manual Control Client') + argparser.add_argument( + '-v', '--verbose', + action='store_true', + dest='debug', + help='print debug information') + argparser.add_argument( + '--host', + metavar='H', + default='127.0.0.1', + help='IP of the host server (default: 127.0.0.1)') + argparser.add_argument( + '-p', '--port', + metavar='P', + default=2000, + type=int, + help='TCP port to listen to (default: 2000)') + argparser.add_argument( + '-a', '--autopilot', + action='store_true', + help='enable autopilot') + argparser.add_argument( + '--res', + metavar='WIDTHxHEIGHT', + default='1280x720', + help='window resolution (default: 1280x720)') + argparser.add_argument( + '--filter', + metavar='PATTERN', + default='vehicle.*', + help='actor filter (default: "vehicle.*")') + argparser.add_argument( + '--generation', + metavar='G', + default='2', + help='restrict to certain actor generation (values: "1","2","All" - default: "2")') + argparser.add_argument( + '--rolename', + metavar='NAME', + default='hero', + help='actor role name (default: "hero")') + argparser.add_argument( + '--gamma', + default=2.2, + type=float, + help='Gamma correction of the camera (default: 2.2)') + argparser.add_argument( + '--sync', + action='store_true', + help='Activate synchronous mode execution') + args = argparser.parse_args() + + args.width, args.height = [int(x) for x in args.res.split('x')] + + log_level = logging.DEBUG if args.debug else logging.INFO + logging.basicConfig(format='%(levelname)s: %(message)s', level=log_level) + + logging.info('listening to server %s:%s', args.host, args.port) + + print(__doc__) + + try: + + game_loop(args) + + except KeyboardInterrupt: + print('\nCancelled by user. Bye!') + + +if __name__ == '__main__': + + main() diff --git a/PythonAPI/examples/generate_traffic.py b/PythonAPI/examples/generate_traffic.py index b3b646abf..ef1ec66b3 100755 --- a/PythonAPI/examples/generate_traffic.py +++ b/PythonAPI/examples/generate_traffic.py @@ -279,8 +279,11 @@ def main(): for spawn_point in spawn_points: walker_bp = random.choice(blueprintsWalkers) # set as not invincible + probability = random.randint(0,100 + 1); if walker_bp.has_attribute('is_invincible'): walker_bp.set_attribute('is_invincible', 'false') + if walker_bp.has_attribute('can_use_wheelchair') and probability < 11: + walker_bp.set_attribute('use_wheelchair', 'true') # set the max speed if walker_bp.has_attribute('speed'): if (random.random() > percentagePedestriansRunning): diff --git a/PythonAPI/examples/test_addsecondvx.py b/PythonAPI/examples/test_addsecondvx.py new file mode 100644 index 000000000..367508b14 --- /dev/null +++ b/PythonAPI/examples/test_addsecondvx.py @@ -0,0 +1,95 @@ +import glob +import os +import sys + +try: + sys.path.append(glob.glob('../carla/dist/carla-0.9.15-py*%d.%d-%s.egg' % ( + sys.version_info.major, + sys.version_info.minor, + 'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0]) +except IndexError: + pass + +import carla +import random +import weakref + +def get_actor_blueprints(world, filter, generation): + bps = world.get_blueprint_library().filter(filter) + + if generation.lower() == "all": + return bps + + # If the filter returns only one bp, we assume that this one needed + # and therefore, we ignore the generation + if len(bps) == 1: + return bps + + try: + int_generation = int(generation) + # Check if generation is in available generations + if int_generation in [1, 2]: + bps = [x for x in bps if int(x.get_attribute('generation')) == int_generation] + return bps + else: + print(" Warning! Actor Generation is not valid. No actor will be spawned.") + return [] + except: + print(" Warning! Actor Generation is not valid. No actor will be spawned.") + return [] + +class V2XSensor(object): + def __init__(self, parent_actor): + self.sensor = None + self._parent = parent_actor + world = self._parent.get_world() + #bp = world.get_blueprint_library().find('sensor.other.v2x_custom') + bp = world.get_blueprint_library().find('sensor.other.v2x') + self.sensor = world.spawn_actor( + bp, carla.Transform(), attach_to=self._parent) + # We need to pass the lambda a weak reference to self to avoid circular + # reference. + weak_self = weakref.ref(self) + self.sensor.listen( + lambda sensor_data: V2XSensor._V2X_callback(weak_self, sensor_data)) + + def destroy(self): + self.sensor.stop() + self.sensor.destroy() + + @staticmethod + def _V2X_callback(weak_self, sensor_data): + self = weak_self() + if not self: + return + for data in sensor_data: + msg = data.get() + # stationId = msg["Header"]["Station ID"] + power = data.power + print(msg) + # print('Cam message received from %s ' % stationId) + print('Cam message received with power %f ' % power) + +client = carla.Client("localhost",2000) +client.set_timeout(2000.0) + +world = client.get_world() +smap = world.get_map() +# acl = world.get_actor(28) +# acl.send("test") + + +spawn_points = smap.get_spawn_points() +spawn_point = random.choice(spawn_points) if spawn_points else carla.Transform() +blueprint = random.choice(get_actor_blueprints(world, "vehicle.*", "2")) +blueprint.set_attribute('role_name', "test") +player = world.try_spawn_actor(blueprint, spawn_point) +v2x_sensor = V2XSensor(player) + +world.wait_for_tick() +try: + while True: + world.wait_for_tick() +finally: + v2x_sensor.destroy() + player.destroy() \ No newline at end of file diff --git a/PythonAPI/test/smoke/test_sensor_tick_time.py b/PythonAPI/test/smoke/test_sensor_tick_time.py index a7d144610..b98c04007 100644 --- a/PythonAPI/test/smoke/test_sensor_tick_time.py +++ b/PythonAPI/test/smoke/test_sensor_tick_time.py @@ -38,7 +38,9 @@ class TestSensorTickTime(SyncSmokeTest): "sensor.camera.semantic_segmentation", "sensor.camera.dvs", "sensor.other.obstacle", - "sensor.camera.instance_segmentation" + "sensor.camera.instance_segmentation", + "sensor.other.v2x", + "sensor.other.v2x_custom" } spawned_sensors = [] sensor_tick = 1.0 @@ -64,5 +66,3 @@ class TestSensorTickTime(SyncSmokeTest): self.assertEqual(sensor.num_ticks, num_sensor_ticks, "\n\n {} does not match tick count".format(sensor.bp_sensor.id)) sensor.destroy() - - diff --git a/README.md b/README.md index 8589994b0..72f85a537 100644 --- a/README.md +++ b/README.md @@ -19,12 +19,12 @@ environmental conditions. ### Download CARLA Linux: -* [**Get CARLA overnight build**](https://carla-releases.s3.us-east-005.backblazeb2.com/Linux/Dev/CARLA_Latest.tar.gz) -* [**Get AdditionalMaps overnight build**](https://carla-releases.s3.us-east-005.backblazeb2.com/Linux/Dev/AdditionalMaps_Latest.tar.gz) +* [**Get CARLA overnight build**](https://tiny.carla.org/carla-latest-linux) +* [**Get AdditionalMaps overnight build**](https://tiny.carla.org/additional-maps-latest-linux) Windows: -* [**Get CARLA overnight build**](https://carla-releases.s3.us-east-005.backblazeb2.com/Windows/Dev/CARLA_Latest.zip) -* [**Get AdditionalMaps overnight build**](https://carla-releases.s3.us-east-005.backblazeb2.com/Windows/Dev/AdditionalMaps_Latest.zip) +* [**Get CARLA overnight build**](https://tiny.carla.org/carla-latest-windows) +* [**Get AdditionalMaps overnight build**](https://tiny.carla.org/additional-maps-latest-windows) ### Recommended system diff --git a/Unreal/CarlaUE4/Config/DefaultEditorSettings.ini b/Unreal/CarlaUE4/Config/DefaultEditorSettings.ini new file mode 100644 index 000000000..6431ddc1d --- /dev/null +++ b/Unreal/CarlaUE4/Config/DefaultEditorSettings.ini @@ -0,0 +1,2 @@ +[/Script/UnrealEd.EditorPerformanceSettings] +bThrottleCPUWhenNotForeground=False diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp index ce637c739..dd657d6c2 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp @@ -10,6 +10,7 @@ #include "Carla/Sensor/LidarDescription.h" #include "Carla/Sensor/SceneCaptureSensor.h" #include "Carla/Sensor/ShaderBasedSensor.h" +#include "Carla/Sensor/V2X/PathLossModel.h" #include "Carla/Util/ScopedStack.h" #include @@ -1014,6 +1015,351 @@ void UActorBlueprintFunctionLibrary::MakeLidarDefinition( Success = CheckActorDefinition(Definition); } +FActorDefinition UActorBlueprintFunctionLibrary::MakeV2XDefinition() +{ + FActorDefinition Definition; + bool Success; + MakeV2XDefinition(Success, Definition); + check(Success); + return Definition; +} + +void UActorBlueprintFunctionLibrary::MakeV2XDefinition( + bool &Success, + FActorDefinition &Definition) +{ + FillIdAndTags(Definition, TEXT("sensor"), TEXT("other"), TEXT("v2x")); + AddVariationsForSensor(Definition); + + // - Noise seed -------------------------------- + FActorVariation NoiseSeed; + NoiseSeed.Id = TEXT("noise_seed"); + NoiseSeed.Type = EActorAttributeType::Int; + NoiseSeed.RecommendedValues = { TEXT("0") }; + NoiseSeed.bRestrictToRecommended = false; + + //Frequency + FActorVariation Frequency; + Frequency.Id = TEXT("frequency_ghz"); + Frequency.Type = EActorAttributeType::Float; + Frequency.RecommendedValues = { TEXT("5.9")}; + + //TransmitPower + FActorVariation TransmitPower; + TransmitPower.Id = TEXT("transmit_power"); + TransmitPower.Type = EActorAttributeType::Float; + TransmitPower.RecommendedValues = { TEXT("21.5")}; + + //ReceiveSensitivity + FActorVariation ReceiverSensitivity; + ReceiverSensitivity.Id = TEXT("receiver_sensitivity"); + ReceiverSensitivity.Type = EActorAttributeType::Float; + ReceiverSensitivity.RecommendedValues = { TEXT("-99.0")}; + + //Combined Antenna Gain in dBi + FActorVariation CombinedAntennaGain; + CombinedAntennaGain.Id = TEXT("combined_antenna_gain"); + CombinedAntennaGain.Type = EActorAttributeType::Float; + CombinedAntennaGain.RecommendedValues = { TEXT("10.0")}; + + //Scenario + FActorVariation Scenario; + Scenario.Id = TEXT("scenario"); + Scenario.Type = EActorAttributeType::String; + Scenario.RecommendedValues = { TEXT("highway"), TEXT("rural"), TEXT("urban")}; + Scenario.bRestrictToRecommended = true; + + //Path loss exponent + FActorVariation PLE; + PLE.Id = TEXT("path_loss_exponent"); + PLE.Type = EActorAttributeType::Float; + PLE.RecommendedValues = { TEXT("2.7")}; + + + //FSPL reference distance for LDPL calculation + FActorVariation FSPL_RefDistance; + FSPL_RefDistance.Id = TEXT("d_ref"); + FSPL_RefDistance.Type = EActorAttributeType::Float; + FSPL_RefDistance.RecommendedValues = { TEXT("1.0")}; + + //filter distance to speed up calculation + FActorVariation FilterDistance; + FilterDistance.Id = TEXT("filter_distance"); + FilterDistance.Type = EActorAttributeType::Float; + FilterDistance.RecommendedValues = { TEXT("500.0")}; + + //etsi fading + FActorVariation EtsiFading; + EtsiFading.Id = TEXT("use_etsi_fading"); + EtsiFading.Type = EActorAttributeType::Bool; + EtsiFading.RecommendedValues = { TEXT("true")}; + + //custom fading std deviation + FActorVariation CustomFadingStddev; + CustomFadingStddev.Id = TEXT("custom_fading_stddev"); + CustomFadingStddev.Type = EActorAttributeType::Float; + CustomFadingStddev.RecommendedValues = { TEXT("0.0")}; + + // Min Cam Generation + FActorVariation GenCamMin; + GenCamMin.Id = TEXT("gen_cam_min"); + GenCamMin.Type = EActorAttributeType::Float; + GenCamMin.RecommendedValues = { TEXT("0.1")}; + + // Max Cam Generation + FActorVariation GenCamMax; + GenCamMax.Id = TEXT("gen_cam_max"); + GenCamMax.Type = EActorAttributeType::Float; + GenCamMax.RecommendedValues = { TEXT("1.0")}; + + //Fixed Rate + FActorVariation FixedRate; + FixedRate.Id = TEXT("fixed_rate"); + FixedRate.Type = EActorAttributeType::Bool; + FixedRate.RecommendedValues = { TEXT("false")}; + + //path loss model + FActorVariation PLModel; + PLModel.Id = TEXT("path_loss_model"); + PLModel.Type = EActorAttributeType::String; + PLModel.RecommendedValues = { TEXT("winner"), TEXT("geometric")}; + PLModel.bRestrictToRecommended = true; + + //V2x Sensor sends GNSS position in CAM messages + // - Latitude ---------------------------------- + FActorVariation StdDevLat; + StdDevLat.Id = TEXT("noise_lat_stddev"); + StdDevLat.Type = EActorAttributeType::Float; + StdDevLat.RecommendedValues = { TEXT("0.0") }; + StdDevLat.bRestrictToRecommended = false; + FActorVariation BiasLat; + BiasLat.Id = TEXT("noise_lat_bias"); + BiasLat.Type = EActorAttributeType::Float; + BiasLat.RecommendedValues = { TEXT("0.0") }; + BiasLat.bRestrictToRecommended = false; + + // - Longitude --------------------------------- + FActorVariation StdDevLong; + StdDevLong.Id = TEXT("noise_lon_stddev"); + StdDevLong.Type = EActorAttributeType::Float; + StdDevLong.RecommendedValues = { TEXT("0.0") }; + StdDevLong.bRestrictToRecommended = false; + FActorVariation BiasLong; + BiasLong.Id = TEXT("noise_lon_bias"); + BiasLong.Type = EActorAttributeType::Float; + BiasLong.RecommendedValues = { TEXT("0.0") }; + BiasLong.bRestrictToRecommended = false; + + // - Altitude ---------------------------------- + FActorVariation StdDevAlt; + StdDevAlt.Id = TEXT("noise_alt_stddev"); + StdDevAlt.Type = EActorAttributeType::Float; + StdDevAlt.RecommendedValues = { TEXT("0.0") }; + StdDevAlt.bRestrictToRecommended = false; + FActorVariation BiasAlt; + BiasAlt.Id = TEXT("noise_alt_bias"); + BiasAlt.Type = EActorAttributeType::Float; + BiasAlt.RecommendedValues = { TEXT("0.0") }; + BiasAlt.bRestrictToRecommended = false; + + // - Heading ---------------------------------- + FActorVariation StdDevHeading; + StdDevHeading.Id = TEXT("noise_head_stddev"); + StdDevHeading.Type = EActorAttributeType::Float; + StdDevHeading.RecommendedValues = { TEXT("0.0") }; + StdDevHeading.bRestrictToRecommended = false; + FActorVariation BiasHeading; + BiasHeading.Id = TEXT("noise_head_bias"); + BiasHeading.Type = EActorAttributeType::Float; + BiasHeading.RecommendedValues = { TEXT("0.0") }; + BiasHeading.bRestrictToRecommended = false; + + //V2x Sensor sends acceleration in CAM messages + // - Accelerometer Standard Deviation ---------- + // X Component + FActorVariation StdDevAccelX; + StdDevAccelX.Id = TEXT("noise_accel_stddev_x"); + StdDevAccelX.Type = EActorAttributeType::Float; + StdDevAccelX.RecommendedValues = { TEXT("0.0") }; + StdDevAccelX.bRestrictToRecommended = false; + // Y Component + FActorVariation StdDevAccelY; + StdDevAccelY.Id = TEXT("noise_accel_stddev_y"); + StdDevAccelY.Type = EActorAttributeType::Float; + StdDevAccelY.RecommendedValues = { TEXT("0.0") }; + StdDevAccelY.bRestrictToRecommended = false; + // Z Component + FActorVariation StdDevAccelZ; + StdDevAccelZ.Id = TEXT("noise_accel_stddev_z"); + StdDevAccelZ.Type = EActorAttributeType::Float; + StdDevAccelZ.RecommendedValues = { TEXT("0.0") }; + StdDevAccelZ.bRestrictToRecommended = false; + + // Yaw rate + FActorVariation StdDevYawrate; + StdDevYawrate.Id = TEXT("noise_yawrate_stddev"); + StdDevYawrate.Type = EActorAttributeType::Float; + StdDevYawrate.RecommendedValues = { TEXT("0.0") }; + StdDevYawrate.bRestrictToRecommended = false; + FActorVariation BiasYawrate; + BiasYawrate.Id = TEXT("noise_yawrate_bias"); + BiasYawrate.Type = EActorAttributeType::Float; + BiasYawrate.RecommendedValues = { TEXT("0.0") }; + BiasYawrate.bRestrictToRecommended = false; + + //V2x Sensor sends speed in CAM messages + // X Component + FActorVariation StdDevVelX; + StdDevVelX.Id = TEXT("noise_vel_stddev_x"); + StdDevVelX.Type = EActorAttributeType::Float; + StdDevVelX.RecommendedValues = { TEXT("0.0") }; + StdDevVelX.bRestrictToRecommended = false; + + Definition.Variations.Append({ + NoiseSeed, + TransmitPower, + ReceiverSensitivity, + Frequency, + CombinedAntennaGain, + Scenario, + PLModel, + PLE, + FSPL_RefDistance, + FilterDistance, + EtsiFading, + CustomFadingStddev, + GenCamMin, + GenCamMax, + FixedRate, + StdDevLat, + BiasLat, + StdDevLong, + BiasLong, + StdDevAlt, + BiasAlt, + StdDevHeading, + BiasHeading, + StdDevAccelX, + StdDevAccelY, + StdDevAccelZ, + StdDevYawrate, + BiasYawrate, + StdDevVelX}); + Success = CheckActorDefinition(Definition); +} + +FActorDefinition UActorBlueprintFunctionLibrary::MakeCustomV2XDefinition() +{ + FActorDefinition Definition; + bool Success; + MakeCustomV2XDefinition(Success, Definition); + check(Success); + return Definition; +} + +void UActorBlueprintFunctionLibrary::MakeCustomV2XDefinition( + bool &Success, + FActorDefinition &Definition) +{ + FillIdAndTags(Definition, TEXT("sensor"), TEXT("other"), TEXT("v2x_custom")); + AddVariationsForSensor(Definition); + + // - Noise seed -------------------------------- + FActorVariation NoiseSeed; + NoiseSeed.Id = TEXT("noise_seed"); + NoiseSeed.Type = EActorAttributeType::Int; + NoiseSeed.RecommendedValues = { TEXT("0") }; + NoiseSeed.bRestrictToRecommended = false; + + //TransmitPower + FActorVariation TransmitPower; + TransmitPower.Id = TEXT("transmit_power"); + TransmitPower.Type = EActorAttributeType::Float; + TransmitPower.RecommendedValues = { TEXT("21.5")}; + + //ReceiveSensitivity + FActorVariation ReceiverSensitivity; + ReceiverSensitivity.Id = TEXT("receiver_sensitivity"); + ReceiverSensitivity.Type = EActorAttributeType::Float; + ReceiverSensitivity.RecommendedValues = { TEXT("-99.0")}; + + //Frequency + FActorVariation Frequency; + Frequency.Id = TEXT("frequency_ghz"); + Frequency.Type = EActorAttributeType::Float; + Frequency.RecommendedValues = { TEXT("5.9")}; + + //Combined Antenna Gain in dBi + FActorVariation CombinedAntennaGain; + CombinedAntennaGain.Id = TEXT("combined_antenna_gain"); + CombinedAntennaGain.Type = EActorAttributeType::Float; + CombinedAntennaGain.RecommendedValues = { TEXT("10.0")}; + + //Scenario + FActorVariation Scenario; + Scenario.Id = TEXT("scenario"); + Scenario.Type = EActorAttributeType::String; + Scenario.RecommendedValues = { TEXT("highway"), TEXT("rural"), TEXT("urban")}; + Scenario.bRestrictToRecommended = true; + + //Path loss exponent + FActorVariation PLE; + PLE.Id = TEXT("path_loss_exponent"); + PLE.Type = EActorAttributeType::Float; + PLE.RecommendedValues = { TEXT("2.7")}; + + + //FSPL reference distance for LDPL calculation + FActorVariation FSPL_RefDistance; + FSPL_RefDistance.Id = TEXT("d_ref"); + FSPL_RefDistance.Type = EActorAttributeType::Float; + FSPL_RefDistance.RecommendedValues = { TEXT("1.0")}; + + //filter distance to speed up calculation + FActorVariation FilterDistance; + FilterDistance.Id = TEXT("filter_distance"); + FilterDistance.Type = EActorAttributeType::Float; + FilterDistance.RecommendedValues = { TEXT("500.0")}; + + //etsi fading + FActorVariation EtsiFading; + EtsiFading.Id = TEXT("use_etsi_fading"); + EtsiFading.Type = EActorAttributeType::Bool; + EtsiFading.RecommendedValues = { TEXT("true")}; + + //custom fading std deviation + FActorVariation CustomFadingStddev; + CustomFadingStddev.Id = TEXT("custom_fading_stddev"); + CustomFadingStddev.Type = EActorAttributeType::Float; + CustomFadingStddev.RecommendedValues = { TEXT("0.0")}; + + //path loss model + FActorVariation PLModel; + PLModel.Id = TEXT("path_loss_model"); + PLModel.Type = EActorAttributeType::String; + PLModel.RecommendedValues = { TEXT("winner"), TEXT("geometric")}; + PLModel.bRestrictToRecommended = true; + + + Definition.Variations.Append({ + NoiseSeed, + TransmitPower, + ReceiverSensitivity, + Frequency, + CombinedAntennaGain, + Scenario, + PLModel, + PLE, + FSPL_RefDistance, + FilterDistance, + EtsiFading, + CustomFadingStddev +}); + + Success = CheckActorDefinition(Definition); +} + + FActorDefinition UActorBlueprintFunctionLibrary::MakeGnssDefinition() { FActorDefinition Definition; @@ -1247,6 +1593,12 @@ void UActorBlueprintFunctionLibrary::MakePedestrianDefinition( EActorAttributeType::String, GetAge(Parameters.Age)}); + + Definition.Attributes.Emplace(FActorAttribute{ + TEXT("can_use_wheelchair"), + EActorAttributeType::Bool, + Parameters.bCanUseWheelChair ? TEXT("true") : TEXT("false") }); + if (Parameters.Speed.Num() > 0) { FActorVariation Speed; @@ -1260,6 +1612,8 @@ void UActorBlueprintFunctionLibrary::MakePedestrianDefinition( Definition.Variations.Emplace(Speed); } + bool bCanUseWheelChair = Parameters.bCanUseWheelChair; + FActorVariation IsInvincible; IsInvincible.Id = TEXT("is_invincible"); IsInvincible.Type = EActorAttributeType::Bool; @@ -1267,6 +1621,20 @@ void UActorBlueprintFunctionLibrary::MakePedestrianDefinition( IsInvincible.bRestrictToRecommended = false; Definition.Variations.Emplace(IsInvincible); + FActorVariation WheelChairVariation; + WheelChairVariation.Id = TEXT("use_wheelchair"); + WheelChairVariation.Type = EActorAttributeType::Bool; + if(bCanUseWheelChair) + { + WheelChairVariation.RecommendedValues = { TEXT("false"), TEXT("true") }; + } + else + { + WheelChairVariation.RecommendedValues = { TEXT("false") }; + } + WheelChairVariation.bRestrictToRecommended = true; + Definition.Variations.Emplace(WheelChairVariation); + Success = CheckActorDefinition(Definition); } @@ -1763,4 +2131,136 @@ void UActorBlueprintFunctionLibrary::SetRadar( RetrieveActorAttributeToInt("points_per_second", Description.Variations, 1500)); } +void UActorBlueprintFunctionLibrary::SetV2X( + const FActorDescription &Description, + AV2XSensor* V2X) +{ + CARLA_ABFL_CHECK_ACTOR(V2X); + if (Description.Variations.Contains("noise_seed")) + { + V2X->SetSeed( + RetrieveActorAttributeToInt("noise_seed", Description.Variations, 0)); + } + else + { + V2X->SetSeed(V2X->GetRandomEngine()->GenerateRandomSeed()); + } + + V2X->SetPropagationParams( + RetrieveActorAttributeToFloat("transmit_power", Description.Variations, 21.5), + RetrieveActorAttributeToFloat("receiver_sensitivity", Description.Variations, -99.0), + RetrieveActorAttributeToFloat("frequency_ghz", Description.Variations, 5.9), + RetrieveActorAttributeToFloat("combined_antenna_gain", Description.Variations, 10.0), + RetrieveActorAttributeToFloat("path_loss_exponent", Description.Variations, 2.7), + RetrieveActorAttributeToFloat("d_ref", Description.Variations, 1.0), + RetrieveActorAttributeToFloat("filter_distance", Description.Variations, 500.0), + RetrieveActorAttributeToBool("use_etsi_fading", Description.Variations, true), + RetrieveActorAttributeToFloat("custom_fading_stddev", Description.Variations, 0.0f) + ); + + if (RetrieveActorAttributeToString("scenario", Description.Variations, "urban") == "urban") + { + V2X->SetScenario(EScenario::Urban); + } + else if (RetrieveActorAttributeToString("scenario", Description.Variations, "urban") == "rural") + { + V2X->SetScenario(EScenario::Rural); + } + else + { + V2X->SetScenario(EScenario::Highway); + } + + V2X->SetCaServiceParams( + RetrieveActorAttributeToFloat("gen_cam_min", Description.Variations, 0.1), + RetrieveActorAttributeToFloat("gen_cam_max", Description.Variations, 1.0), + RetrieveActorAttributeToBool("fixed_rate", Description.Variations, false)); + + V2X->SetAccelerationStandardDeviation({ + RetrieveActorAttributeToFloat("noise_accel_stddev_x", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_accel_stddev_y", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_accel_stddev_z", Description.Variations, 0.0f)}); + + V2X->SetGNSSDeviation( + RetrieveActorAttributeToFloat("noise_lat_stddev", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_lon_stddev", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_alt_stddev", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_head_stddev", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_lat_bias", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_lon_bias", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_alt_bias", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_head_bias", Description.Variations, 0.0f)); + + V2X->SetVelDeviation( + RetrieveActorAttributeToFloat("noise_vel_stddev_x", Description.Variations, 0.0f) + ); + V2X->SetYawrateDeviation( + RetrieveActorAttributeToFloat("noise_yawrate_stddev", Description.Variations, 0.0f), + RetrieveActorAttributeToFloat("noise_yawrate_bias", Description.Variations, 0.0f) + ); + + if (RetrieveActorAttributeToString("path_loss_model", Description.Variations, "geometric") == "winner") + { + V2X->SetPathLossModel(EPathLossModel::Winner); + } + else if(RetrieveActorAttributeToString("path_loss_model", Description.Variations, "geometric") == "geometric") + { + V2X->SetPathLossModel(EPathLossModel::Geometric); + } + + +} + +void UActorBlueprintFunctionLibrary::SetCustomV2X( + const FActorDescription &Description, + ACustomV2XSensor* V2X) +{ + CARLA_ABFL_CHECK_ACTOR(V2X); + if (Description.Variations.Contains("noise_seed")) + { + V2X->SetSeed( + RetrieveActorAttributeToInt("noise_seed", Description.Variations, 0)); + } + else + { + V2X->SetSeed(V2X->GetRandomEngine()->GenerateRandomSeed()); + } + + V2X->SetPropagationParams( + RetrieveActorAttributeToFloat("transmit_power", Description.Variations, 21.5), + RetrieveActorAttributeToFloat("receiver_sensitivity", Description.Variations, -99.0), + RetrieveActorAttributeToFloat("frequency_ghz", Description.Variations, 5.9), + RetrieveActorAttributeToFloat("combined_antenna_gain", Description.Variations, 10.0), + RetrieveActorAttributeToFloat("path_loss_exponent", Description.Variations, 2.7), + RetrieveActorAttributeToFloat("d_ref", Description.Variations, 1.0), + RetrieveActorAttributeToFloat("filter_distance", Description.Variations, 500.0), + RetrieveActorAttributeToBool("use_etsi_fading", Description.Variations, true), + RetrieveActorAttributeToFloat("custom_fading_stddev", Description.Variations, 0.0f) + ); + + if (RetrieveActorAttributeToString("scenario", Description.Variations, "urban") == "urban") + { + V2X->SetScenario(EScenario::Urban); + } + else if (RetrieveActorAttributeToString("scenario", Description.Variations, "urban") == "rural") + { + V2X->SetScenario(EScenario::Rural); + } + else + { + V2X->SetScenario(EScenario::Highway); + } + + + if (RetrieveActorAttributeToString("path_loss_model", Description.Variations, "geometric") == "winner") + { + V2X->SetPathLossModel(EPathLossModel::Winner); + } + else if(RetrieveActorAttributeToString("path_loss_model", Description.Variations, "geometric") == "geometric") + { + V2X->SetPathLossModel(EPathLossModel::Geometric); + } + + +} #undef CARLA_ABFL_CHECK_ACTOR diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h index 5ae41c795..e75a3fb25 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.h @@ -14,6 +14,10 @@ #include "Carla/Sensor/GnssSensor.h" #include "Carla/Sensor/Radar.h" #include "Carla/Sensor/InertialMeasurementUnit.h" +#include "Carla/Sensor/V2XSensor.h" +#include "Carla/Sensor/CustomV2XSensor.h" +#include "Carla/Sensor/V2XSensor.h" +#include "Carla/Sensor/CustomV2XSensor.h" #include "Kismet/BlueprintFunctionLibrary.h" @@ -108,6 +112,20 @@ public: bool &Success, FActorDefinition &Definition); + static FActorDefinition MakeV2XDefinition(); + + UFUNCTION(Category = "Carla Actor", BlueprintCallable) + static void MakeV2XDefinition( + bool &Success, + FActorDefinition &Definition); + + static FActorDefinition MakeCustomV2XDefinition(); + + UFUNCTION(Category = "Carla Actor", BlueprintCallable) + static void MakeCustomV2XDefinition( + bool &Success, + FActorDefinition &Definition); + UFUNCTION(Category = "Carla Actor", BlueprintCallable) static void MakeVehicleDefinition( const FVehicleParameters &Parameters, @@ -226,4 +244,7 @@ public: static void SetIMU(const FActorDescription &Description, AInertialMeasurementUnit *IMU); static void SetRadar(const FActorDescription &Description, ARadar *Radar); + + static void SetV2X(const FActorDescription &Description, AV2XSensor *V2X); + static void SetCustomV2X(const FActorDescription &Description, ACustomV2XSensor *V2X); }; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp index dfec0bc43..764f7849d 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.cpp @@ -969,6 +969,25 @@ ECarlaServerResponse FVehicleActor::SetActorAutopilot(bool bEnabled, bool bKeepS return ECarlaServerResponse::Success; } +ECarlaServerResponse FVehicleActor::GetVehicleTelemetryData(FVehicleTelemetryData& TelemetryData) +{ + if (IsDormant()) + { + FVehicleTelemetryData EmptyTelemetryData; + TelemetryData = EmptyTelemetryData; + } + else + { + auto Vehicle = Cast(GetActor()); + if (Vehicle == nullptr) + { + return ECarlaServerResponse::NotAVehicle; + } + TelemetryData = Vehicle->GetVehicleTelemetryData(); + } + return ECarlaServerResponse::Success; +} + ECarlaServerResponse FVehicleActor::ShowVehicleDebugTelemetry(bool bEnabled) { if (IsDormant()) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h index f7edb4b4f..dcef99905 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/CarlaActor.h @@ -9,6 +9,7 @@ #include "Carla/Actor/ActorInfo.h" #include "Carla/Actor/ActorData.h" #include "Carla/Vehicle/CarlaWheeledVehicle.h" +#include "Carla/Vehicle/VehicleTelemetryData.h" #include "Carla/Walker/WalkerController.h" #include "Carla/Traffic/TrafficLightState.h" @@ -322,6 +323,11 @@ public: return ECarlaServerResponse::ActorTypeMismatch; } + virtual ECarlaServerResponse GetVehicleTelemetryData(FVehicleTelemetryData&) + { + return ECarlaServerResponse::ActorTypeMismatch; + } + virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool) { return ECarlaServerResponse::ActorTypeMismatch; @@ -527,6 +533,8 @@ public: virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState = false) final; + virtual ECarlaServerResponse GetVehicleTelemetryData(FVehicleTelemetryData&) final; + virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final; virtual ECarlaServerResponse EnableCarSim(const FString& SimfilePath) final; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/PedestrianParameters.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/PedestrianParameters.h index 86310a6d9..7572e9b3a 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/PedestrianParameters.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/PedestrianParameters.h @@ -55,4 +55,7 @@ struct CARLA_API FPedestrianParameters UPROPERTY(EditAnywhere, BlueprintReadWrite) int32 Generation = 0; + + UPROPERTY(EditAnywhere, BlueprintReadWrite) + bool bCanUseWheelChair = false; }; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp index 503942ce5..da793561b 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Game/CarlaEngine.cpp @@ -136,7 +136,11 @@ void FCarlaEngine::NotifyInitGame(const UCarlaSettings &Settings) case carla::multigpu::MultiGPUCommand::LOAD_MAP: { FString FinalPath((char *) Data.data()); - UGameplayStatics::OpenLevel(CurrentEpisode->GetWorld(), *FinalPath, true); + if(GetCurrentEpisode()) + { + UGameplayStatics::OpenLevel(GetCurrentEpisode()->GetWorld(), *FinalPath, true); + } + break; } case carla::multigpu::MultiGPUCommand::GET_TOKEN: diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderAnimVehicleWheels.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderAnimVehicleWheels.cpp index a79162061..4cb890ca5 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderAnimVehicleWheels.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaRecorderAnimVehicleWheels.cpp @@ -37,12 +37,12 @@ void CarlaRecorderAnimWheels::Read(std::istream &InFile) ReadValue(InFile, DatabaseId); uint32_t NumWheels = 0; ReadValue(InFile, NumWheels); - WheelValues.reserve(NumWheels); + WheelValues.resize(NumWheels); for (size_t i = 0; i < NumWheels; ++i) { WheelInfo Wheel; Wheel.Read(InFile); - WheelValues.push_back(Wheel); + WheelValues[i] = Wheel; } } diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp index 64e208b55..0a2474e60 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayer.cpp @@ -808,7 +808,7 @@ void CarlaReplayer::InterpolatePosition( double DeltaTime) { // call the callback - Helper.ProcessReplayerPosition(Pos1, Pos2, Per, DeltaTime); + Helper.ProcessReplayerPosition(Pos1, Pos2, Per, DeltaTime, IgnoreSpectator); } // tick for the replayer diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp index 9bfa120f6..8b1ff4282 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.cpp @@ -202,7 +202,7 @@ std::pair CarlaReplayerHelper::ProcessReplayerEventAdd( } // check to ignore Hero or Spectator - if ((bIgnoreHero && IsHero) || + if ((bIgnoreHero && IsHero) || (bIgnoreSpectator && ActorDesc.Id.StartsWith("spectator"))) { return std::make_pair(3, 0); @@ -227,7 +227,11 @@ std::pair CarlaReplayerHelper::ProcessReplayerEventAdd( // disable physics SetActorSimulatePhysics(result.second, false); // disable collisions - result.second->GetActor()->SetActorEnableCollision(false); + result.second->GetActor()->SetActorEnableCollision(true); + auto RootComponent = Cast( + result.second->GetActor()->GetRootComponent()); + RootComponent->SetSimulatePhysics(false); + RootComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); // disable autopilot for vehicles if (result.second->GetActorType() == FCarlaActor::ActorType::Vehicle) SetActorAutopilot(result.second, false, false); @@ -296,7 +300,7 @@ bool CarlaReplayerHelper::ProcessReplayerEventParent(uint32_t ChildId, uint32_t } // reposition actors -bool CarlaReplayerHelper::ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime) +bool CarlaReplayerHelper::ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime, bool bIgnoreSpectator) { check(Episode != nullptr); FCarlaActor* CarlaActor = Episode->FindCarlaActor(Pos1.DatabaseId); @@ -304,6 +308,11 @@ bool CarlaReplayerHelper::ProcessReplayerPosition(CarlaRecorderPosition Pos1, Ca FRotator Rotation; if(CarlaActor) { + //Hot fix to avoid spectator we should investigate why this case is possible here + if(bIgnoreSpectator && CarlaActor->GetActor()->GetClass()->GetFName().ToString().Contains("Spectator")) + { + return false; + } // check to assign first position or interpolate between both if (Per == 0.0) { diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h index d4379dddd..42a27c85a 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Recorder/CarlaReplayerHelper.h @@ -52,7 +52,7 @@ public: bool ProcessReplayerEventParent(uint32_t ChildId, uint32_t ParentId); // reposition actors - bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime); + bool ProcessReplayerPosition(CarlaRecorderPosition Pos1, CarlaRecorderPosition Pos2, double Per, double DeltaTime, bool bIgnoreSpectator); // replay event for traffic light state bool ProcessReplayerStateTrafficLight(CarlaRecorderStateTrafficLight State); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/CustomV2XSensor.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/CustomV2XSensor.cpp new file mode 100644 index 000000000..60c5aabbb --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/CustomV2XSensor.cpp @@ -0,0 +1,225 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "Carla.h" +#include "Carla/Actor/ActorBlueprintFunctionLibrary.h" +#include "Carla/Game/CarlaEpisode.h" +#include "Carla/Vehicle/CarlaWheeledVehicle.h" +#include +#include +#include +#include "CustomV2XSensor.h" +#include "V2X/PathLossModel.h" + +std::list ACustomV2XSensor::mV2XActorContainer; +ACustomV2XSensor::ActorV2XDataMap ACustomV2XSensor::mActorV2XDataMap; + +ACustomV2XSensor::ACustomV2XSensor(const FObjectInitializer &ObjectInitializer) + : Super(ObjectInitializer) +{ + PrimaryActorTick.bCanEverTick = true; + RandomEngine = CreateDefaultSubobject(TEXT("RandomEngine")); + + // Init path loss model + PathLossModelObj = new PathLossModel(RandomEngine); +} + +void ACustomV2XSensor::SetOwner(AActor *Owner) +{ + UE_LOG(LogCarla, Warning, TEXT("CustomV2XSensor: called setowner with %p"), Owner); + if (GetOwner() != nullptr) + { + ACustomV2XSensor::mV2XActorContainer.remove(GetOwner()); + UE_LOG(LogCarla, Warning, TEXT("CustomV2XSensor: removed old owner %p"), GetOwner()); + } + + Super::SetOwner(Owner); + + // Store the actor into the static list if the actor details are not available + if(Owner != nullptr) + { + if (std::find(ACustomV2XSensor::mV2XActorContainer.begin(), ACustomV2XSensor::mV2XActorContainer.end(), Owner) == ACustomV2XSensor::mV2XActorContainer.end()) + { + ACustomV2XSensor::mV2XActorContainer.push_back(Owner); + UE_LOG(LogCarla, Warning, TEXT("CustomV2XSensor: added owner, length now %d"), ACustomV2XSensor::mV2XActorContainer.size()); + } + + } + + PathLossModelObj->SetOwner(Owner); + + UCarlaEpisode* CarlaEpisode = UCarlaStatics::GetCurrentEpisode(GetWorld()); + FCarlaActor* CarlaActor = CarlaEpisode->FindCarlaActor(Owner); + if (CarlaActor != nullptr) + { + mStationId = static_cast(CarlaActor->GetActorId()); + } +} + +FActorDefinition ACustomV2XSensor::GetSensorDefinition() +{ + return UActorBlueprintFunctionLibrary::MakeCustomV2XDefinition(); +} + +/* Function to add configurable parameters*/ +void ACustomV2XSensor::Set(const FActorDescription &ActorDescription) +{ + UE_LOG(LogCarla, Warning, TEXT("CustomV2XSensor: Set function called")); + Super::Set(ActorDescription); + UActorBlueprintFunctionLibrary::SetCustomV2X(ActorDescription, this); +} + +void ACustomV2XSensor::SetPropagationParams(const float TransmitPower, + const float ReceiverSensitivity, + const float Frequency, + const float combined_antenna_gain, + const float path_loss_exponent, + const float reference_distance_fspl, + const float filter_distance, + const bool use_etsi_fading, + const float custom_fading_stddev) +{ + // forward parameters to PathLossModel Obj + PathLossModelObj->SetParams(TransmitPower, ReceiverSensitivity, Frequency, combined_antenna_gain, path_loss_exponent, reference_distance_fspl, filter_distance, use_etsi_fading, custom_fading_stddev); +} + +void ACustomV2XSensor::SetPathLossModel(const EPathLossModel path_loss_model){ + PathLossModelObj->SetPathLossModel(path_loss_model); +} + +void ACustomV2XSensor::SetScenario(EScenario scenario) +{ + PathLossModelObj->SetScenario(scenario); +} + +/* + * Function stores the actor details in to the static list. + * Calls the CaService object to generate CAM message + * Stores the message in static map + */ +void ACustomV2XSensor::PrePhysTick(float DeltaSeconds) +{ + Super::PrePhysTick(DeltaSeconds); + // Clear the message created during the last sim cycle + if (GetOwner()) + { + ACustomV2XSensor::mActorV2XDataMap.erase(GetOwner()); + + // Step 0: Create message to send, if triggering conditions fulfilled + // this needs to be done in pre phys tick to enable synchronous reception in all other v2x sensors + // Check whether the message is generated + if (mMessageDataChanged) + { + // If message is generated store it + // make a pair of message and sending power + // if different v2x sensors send with different power, we need to store that + carla::sensor::data::CustomV2XData message_pw; + message_pw.Message = CreateCustomV2XMessage(); + + message_pw.Power = PathLossModelObj->GetTransmitPower(); + ACustomV2XSensor::mActorV2XDataMap.insert({GetOwner(), message_pw}); + } + } +} + +CustomV2XM_t ACustomV2XSensor::CreateCustomV2XMessage() +{ + CustomV2XM_t message = CustomV2XM_t(); + + CreateITSPduHeader(message); + std::strcpy(message.message,mMessageData.c_str()); + mMessageDataChanged = false; + return message; +} + +void ACustomV2XSensor::CreateITSPduHeader(CustomV2XM_t &message) +{ + ITSContainer::ItsPduHeader_t& header = message.header; + header.protocolVersion = mProtocolVersion; + header.messageID = mMessageId; + header.stationID = mStationId; +} + +/* + * Function takes care of sending messages to the current actor. + * First simulates the communication by calling LOSComm object. + * If there is a list present then messages from those list are sent to the current actor + */ +void ACustomV2XSensor::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) +{ + TRACE_CPUPROFILER_EVENT_SCOPE(ACustomV2XSensor::PostPhysTick); + + // Step 1: Create an actor list which has messages to send targeting this v2x sensor instance + std::vector ActorPowerList; + for (const auto &pair : ACustomV2XSensor::mActorV2XDataMap) + { + if (pair.first != GetOwner()) + { + ActorPowerPair actor_power_pair; + actor_power_pair.first = pair.first; + // actor sending with transmit power + actor_power_pair.second = pair.second.Power; + ActorPowerList.push_back(actor_power_pair); + } + } + + // Step 2: Simulate the communication for the actors in actor list to current actor. + if (!ActorPowerList.empty()) + { + UCarlaEpisode *carla_episode = UCarlaStatics::GetCurrentEpisode(GetWorld()); + PathLossModelObj->Simulate(ActorPowerList, carla_episode, GetWorld()); + // Step 3: Get the list of actors who can send message to current actor, and the receive power of their messages. + ActorPowerMap actor_receivepower_map = PathLossModelObj->GetReceiveActorPowerList(); + // Step 4: Retrieve the messages of the actors that are received + + // get registry to retrieve carla actor IDs + const FActorRegistry &Registry = carla_episode->GetActorRegistry(); + + ACustomV2XSensor::V2XDataList msg_received_power_list; + for (const auto &pair : actor_receivepower_map) + { + carla::sensor::data::CustomV2XData send_msg_and_pw = ACustomV2XSensor::mActorV2XDataMap.at(pair.first); + carla::sensor::data::CustomV2XData received_msg_and_pw; + // sent CAM + received_msg_and_pw.Message = send_msg_and_pw.Message; + // receive power + received_msg_and_pw.Power = pair.second; + + msg_received_power_list.push_back(received_msg_and_pw); + } + + WriteMessageToV2XData(msg_received_power_list); + } + // Step 5: Send message + + if (mV2XData.GetMessageCount() > 0) + { + auto DataStream = GetDataStream(*this); + DataStream.SerializeAndSend(*this, mV2XData, DataStream.PopBufferFromPool()); + } + mV2XData.Reset(); +} + +/* + * Function the store the message into the structure so it can be sent to python client + */ +void ACustomV2XSensor::WriteMessageToV2XData(const ACustomV2XSensor::V2XDataList &msg_received_power_list) +{ + for (const auto &elem : msg_received_power_list) + { + mV2XData.WriteMessage(elem); + } +} + + +void ACustomV2XSensor::Send(const FString message) +{ + //note: this is unsafe! + //should be fixed to limit length somewhere + mMessageData = TCHAR_TO_UTF8(*message); + mMessageDataChanged = true; +} + diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/CustomV2XSensor.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/CustomV2XSensor.h new file mode 100644 index 000000000..ced0cc287 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/CustomV2XSensor.h @@ -0,0 +1,73 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "Carla/Sensor/Sensor.h" +#include "Carla/Actor/ActorDefinition.h" +#include "Carla/Actor/ActorDescription.h" +#include +#include "V2X/PathLossModel.h" +#include +#include +#include "CustomV2XSensor.generated.h" + + +UCLASS() +class CARLA_API ACustomV2XSensor : public ASensor +{ + GENERATED_BODY() + + using FV2XData = carla::sensor::data::CustomV2XDataS; + using V2XDataList = std::vector; + using ActorV2XDataMap = std::map; + +public: + ACustomV2XSensor(const FObjectInitializer &ObjectInitializer); + + static FActorDefinition GetSensorDefinition(); + + void Set(const FActorDescription &ActorDescription) override; + void SetPropagationParams(const float TransmitPower, + const float ReceiverSensitivity, + const float Frequency, + const float combined_antenna_gain, + const float path_loss_exponent, + const float reference_distance_fspl, + const float filter_distance, + const bool use_etsi_fading, + const float custom_fading_stddev); + void SetScenario(EScenario scenario); + void SetPathLossModel(const EPathLossModel path_loss_model); + + virtual void PrePhysTick(float DeltaSeconds) override; + virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) override; + void SetOwner(AActor *Owner) override; + + void Send(const FString message); + +private: + static std::list mV2XActorContainer; + PathLossModel *PathLossModelObj; + + //store data + static ACustomV2XSensor::ActorV2XDataMap mActorV2XDataMap; + FV2XData mV2XData; + + //write + void WriteMessageToV2XData(const ACustomV2XSensor::V2XDataList &msg_received_power_list); + + //msg gen + void CreateITSPduHeader(CustomV2XM_t &message); + CustomV2XM_t CreateCustomV2XMessage(); + const long mProtocolVersion = 2; + const long mMessageId = ITSContainer::messageID_custom; + long mStationId; + std::string mMessageData; + bool mMessageDataChanged = false; + constexpr static uint16_t data_size = sizeof(CustomV2XM_t::message); + +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/CaService.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/CaService.cpp new file mode 100644 index 000000000..7e224c612 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/CaService.cpp @@ -0,0 +1,745 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "Carla.h" +#include "CaService.h" +#include +#include "carla/rpc/String.h" +#include "Carla/Util/BoundingBoxCalculator.h" +#include +static const float scLowFrequencyContainerInterval = 0.5; + +ITSContainer::SpeedValue_t CaService::BuildSpeedValue(const float vel) +{ + static const float lower = 0.0; // meter_per_second + static const float upper = 163.82; // meter_per_second + + ITSContainer::SpeedValue_t speed = ITSContainer::SpeedValue_unavailable; + if (vel >= upper) + { + speed = 16382; // see CDD A.74 (TS 102 894 v1.2.1) + } + else if (vel >= lower) + { + // to cm per second + speed = std::round(vel * 100.0) * ITSContainer::SpeedValue_oneCentimeterPerSec; + } + return speed; +} + +CaService::CaService(URandomEngine *random_engine) +{ + mRandomEngine = random_engine; + // The starting point now + std::chrono::system_clock::time_point start_Point = std::chrono::system_clock::now(); + // the reference point for ETSI (2004-01-01T00:00:00:000Z) + std::chrono::system_clock::time_point ref_point = std::chrono::system_clock::from_time_t(1072915200); // Unix time for 2004-01-01 + + mGenerationDelta0 = std::chrono::duration_cast(start_Point - ref_point); +} + +void CaService::SetOwner(UWorld *world, AActor *Owner) +{ + UE_LOG(LogCarla, Warning, TEXT("CaService:SetOwner function called")); + mWorld = world; + mCarlaEpisode = UCarlaStatics::GetCurrentEpisode(world); + + CurrentGeoReference = mCarlaEpisode->GetGeoReference(); + + mActorOwner = Owner; + mCarlaEpisode = UCarlaStatics::GetCurrentEpisode(mWorld); + mCarlaActor = mCarlaEpisode->FindCarlaActor(Owner); + + if (mCarlaActor != nullptr) + { + mVehicle = Cast(Owner); + + if (mCarlaActor->GetActorType() == FCarlaActor::ActorType::Vehicle) + { + UE_LOG(LogCarla, Warning, TEXT("CaService:Initialize Vehicle type")); + + mLastCamTimeStamp = mCarlaEpisode->GetElapsedGameTime() - mGenCamMax; + mLastLowCamTimeStamp = mCarlaEpisode->GetElapsedGameTime() - scLowFrequencyContainerInterval; + // Can add logic for this later + mDccRestriction = false; + + mElapsedTime = 0; + VehicleSpeed = 0; + VehiclePosition = {0, 0, 0}; + VehicleHeading = {0, 0, 0}; + mLastCamSpeed = 0; + mLastCamPosition = {0, 0, 0}; + mLastCamHeading = {0, 0, 0}; + } + else if ((mCarlaActor->GetActorType() == FCarlaActor::ActorType::TrafficLight) || + (mCarlaActor->GetActorType() == FCarlaActor::ActorType::TrafficSign)) + { + mGenerationInterval = 0.5; + mLastCamTimeStamp = -mGenerationInterval; + UE_LOG(LogCarla, Warning, TEXT("CaService:Initialize RSU type")); + } + + mStationId = static_cast(mCarlaActor->GetActorId()); + mStationType = GetStationType(); + } +} + +void CaService::SetParams(const float GenCamMin, const float GenCamMax, const bool FixedRate) +{ + UE_LOG(LogCarla, Warning, TEXT("CaService:SetParams function called")); + // Max and Min for generation rate + + mGenCamMin = GenCamMin; // in second + mGenCamMax = GenCamMax; // in second + mGenCam = mGenCamMax; + // If we want set a fix interval make this as true + mFixedRate = FixedRate; +} + +/* + * Function to check trigger condition for RSU + */ +bool CaService::Trigger(float DeltaSeconds) +{ + + mElapsedTime = mCarlaEpisode->GetElapsedGameTime(); + bool Trigger = false; + if (mStationType == ITSContainer::StationType_roadSideUnit) + { + if (mElapsedTime - mLastCamTimeStamp >= mGenerationInterval) + { + Trigger = true; + mCAMMessage = CreateCooperativeAwarenessMessage(DeltaSeconds); + mLastCamTimeStamp = mElapsedTime; + } + } + else + { + Trigger = CheckTriggeringConditions(DeltaSeconds); + } + return Trigger; +} + +/* + * Function to provide CAM message to other objects if necessary + */ +CAM_t CaService::GetCamMessage() +{ + return mCAMMessage; +} + +/* + * Check the trigger condition in case of vehicles and if trigger is true request + * to generate CAM message + */ +bool CaService::CheckTriggeringConditions(float DeltaSeconds) +{ + float &T_GenCam = mGenCam; + const float T_GenCamMin = mGenCamMin; + const float T_GenCamMax = mGenCamMax; + const float T_GenCamDcc = mDccRestriction ? 0 : T_GenCamMin; + const float T_elapsed = mElapsedTime - mLastCamTimeStamp; + if (T_elapsed >= T_GenCamDcc) + { + // If message need to be generated every sim tick then set this to true. + if (mFixedRate) + { + GenerateCamMessage(DeltaSeconds); + return true; + } + + else if (CheckHeadingDelta(DeltaSeconds) || CheckPositionDelta(DeltaSeconds) || CheckSpeedDelta(DeltaSeconds)) + { + GenerateCamMessage(DeltaSeconds); + T_GenCam = std::min(T_elapsed, T_GenCamMax); + mGenCamLowDynamicsCounter = 0; + return true; + } + else if (T_elapsed >= T_GenCam) + { + GenerateCamMessage(DeltaSeconds); + if (++mGenCamLowDynamicsCounter >= mGenCamLowDynamicsLimit) + { + T_GenCam = T_GenCamMax; + } + return true; + } + } + return false; +} + +bool CaService::CheckPositionDelta(float DeltaSeconds) +{ + // If position change is more the 4m + VehiclePosition = mVehicle->GetActorLocation(); + double Distance = FVector::Distance(VehiclePosition, mLastCamPosition) / 100.0f; // From cm to m + if (Distance > 4.0f) + { + return true; + } + return false; +} + +bool CaService::CheckSpeedDelta(float DeltaSeconds) +{ + VehicleSpeed = mVehicle->GetVehicleForwardSpeed() / 100.0f; // From cm/s to m/s + float DeltaSpeed = std::abs(VehicleSpeed - mLastCamSpeed); + + // Speed differance is greater than 0.5m/s + if (DeltaSpeed > 0.5) + { + return true; + } + + return false; +} + +double CaService::GetFVectorAngle(const FVector &a, const FVector &b) +{ + double Dot = a.X * b.X + a.Y * b.Y + a.Z * b.Z; + return std::acos(Dot / (a.Size() * b.Size())); +} + +void CaService::GenerateCamMessage(float DeltaTime) +{ + mCAMMessage = CreateCooperativeAwarenessMessage(DeltaTime); + mLastCamPosition = VehiclePosition; + mLastCamSpeed = VehicleSpeed; + mLastCamHeading = VehicleHeading; + mLastCamTimeStamp = mElapsedTime; +} + +// Function to get the station type +ITSContainer::StationType_t CaService::GetStationType() +{ + check(mActorOwner != nullptr); + mCarlaEpisode = UCarlaStatics::GetCurrentEpisode(mWorld); + mCarlaActor = mCarlaEpisode->FindCarlaActor(mActorOwner); + ITSContainer::StationType_t stationType = ITSContainer::StationType_unknown; + // return unknown if carla actor is gone + if (mCarlaActor == nullptr) + { + return static_cast(stationType); + } + auto Tag = ATagger::GetTagOfTaggedComponent(*mVehicle->GetMesh()); + + switch (Tag) + { + case crp::CityObjectLabel::None: + stationType = ITSContainer::StationType_unknown; + break; + case crp::CityObjectLabel::Pedestrians: + stationType = ITSContainer::StationType_pedestrian; + break; + case crp::CityObjectLabel::Bicycle: + stationType = ITSContainer::StationType_cyclist; + break; + case crp::CityObjectLabel::Motorcycle: + stationType = ITSContainer::StationType_motorcycle; + break; + case crp::CityObjectLabel::Car: + stationType = ITSContainer::StationType_passengerCar; + break; + case crp::CityObjectLabel::Bus: + stationType = ITSContainer::StationType_bus; + break; + // TODO Modify this in future is CARLA adds difference truck + case crp::CityObjectLabel::Truck: + stationType = ITSContainer::StationType_lightTruck; + break; + case crp::CityObjectLabel::Buildings: + case crp::CityObjectLabel::Walls: + case crp::CityObjectLabel::Fences: + case crp::CityObjectLabel::Poles: + case crp::CityObjectLabel::TrafficLight: + case crp::CityObjectLabel::TrafficSigns: + stationType = ITSContainer::StationType_roadSideUnit; + break; + case crp::CityObjectLabel::Train: + stationType = ITSContainer::StationType_tram; + break; + default: + stationType = ITSContainer::StationType_unknown; + } + + // Can improve this later for different special vehicles once carla implements it + FCarlaActor::ActorType Type = mCarlaActor->GetActorType(); + if (Type == FCarlaActor::ActorType::Vehicle) + { + if (mCarlaActor->GetActorInfo()->Description.Variations.Contains("special_type")) + { + std::string special_type = carla::rpc::FromFString(*mCarlaActor->GetActorInfo()->Description.Variations["special_type"].Value); + if (special_type.compare("emergency") == 0) + { + stationType = ITSContainer::StationType_specialVehicles; + } + } + } + return static_cast(stationType); +} + +FVector CaService::GetReferencePosition() +{ + FVector RefPos; + carla::geom::Location ActorLocation = mActorOwner->GetActorLocation(); + ALargeMapManager *LargeMap = UCarlaStatics::GetLargeMapManager(mWorld); + if (LargeMap) + { + ActorLocation = LargeMap->LocalToGlobalLocation(ActorLocation); + } + carla::geom::Location Location = ActorLocation; + carla::geom::GeoLocation CurrentLocation = CurrentGeoReference.Transform(Location); + + // Compute the noise for the sensor + const float LatError = mRandomEngine->GetNormalDistribution(0.0f, LatitudeDeviation); + const float LonError = mRandomEngine->GetNormalDistribution(0.0f, LongitudeDeviation); + const float AltError = mRandomEngine->GetNormalDistribution(0.0f, AltitudeDeviation); + + // Apply the noise to the sensor + double Latitude = CurrentLocation.latitude + LatitudeBias + LatError; + double Longitude = CurrentLocation.longitude + LongitudeBias + LonError; + double Altitude = CurrentLocation.altitude + AltitudeBias + AltError; + + RefPos.X = Latitude; + RefPos.Y = Longitude; + RefPos.Z = Altitude; + return RefPos; +} + +float CaService::GetHeading() +{ + // Magnetometer: orientation with respect to the North in rad + const FVector CarlaNorthVector = FVector(0.0f, -1.0f, 0.0f); + const FVector ForwVect = mActorOwner->GetActorForwardVector().GetSafeNormal2D(); + const float DotProd = FVector::DotProduct(CarlaNorthVector, ForwVect); + + // We check if the dot product is higher than 1.0 due to numerical error + if (DotProd >= 1.00f) + return 0.0f; + + float Heading = std::acos(DotProd); + // Keep the angle between [0, 2pi) + if (FVector::CrossProduct(CarlaNorthVector, ForwVect).Z < 0.0f) + Heading = carla::geom::Math::Pi2() - Heading; + + const double HeadingDegree = carla::geom::Math::ToDegrees(Heading); + + // Compute the noise for the sensor + const float HeadingError = mRandomEngine->GetNormalDistribution(0.0f, HeadingDeviation); + + // add errors + return HeadingDegree + HeadingBias + HeadingError; +} + +// Function to get the vehicle role +long CaService::GetVehicleRole() +{ + long VehicleRole = ITSContainer::VehicleRole_default; + long StationType = GetStationType(); + switch (StationType) + { + case ITSContainer::StationType_cyclist: + case ITSContainer::StationType_moped: + case ITSContainer::StationType_motorcycle: + VehicleRole = ITSContainer::VehicleRole_default; + break; + case ITSContainer::StationType_bus: + case ITSContainer::StationType_tram: + VehicleRole = ITSContainer::VehicleRole_publicTransport; + break; + case ITSContainer::StationType_specialVehicles: + VehicleRole = ITSContainer::VehicleRole_emergency; + break; + default: + VehicleRole = ITSContainer::VehicleRole_default; + break; + } + return VehicleRole; +} + +CAM_t CaService::CreateCooperativeAwarenessMessage(float DeltaTime) +{ + CAM_t message = CAM_t(); + + CreateITSPduHeader(message); + AddCooperativeAwarenessMessage(message.cam, DeltaTime); + + return message; +} + +void CaService::CreateITSPduHeader(CAM_t &message) +{ + ITSContainer::ItsPduHeader_t &header = message.header; + header.protocolVersion = mProtocolVersion; + header.messageID = mMessageId; + header.stationID = mStationId; +} + +void CaService::AddCooperativeAwarenessMessage(CAMContainer::CoopAwareness_t &CoopAwarenessMessage, float DeltaTime) +{ + + /* GenerationDeltaTime */ + auto genDeltaTime = mGenerationDelta0 + std::chrono::milliseconds(static_cast(mCarlaEpisode->GetElapsedGameTime() * 1000)); + CoopAwarenessMessage.generationDeltaTime = genDeltaTime.count() % 65536 * CAMContainer::GenerationDeltaTime_oneMilliSec; // TODOCheck this logic + AddBasicContainer(CoopAwarenessMessage.camParameters.basicContainer); + if (CoopAwarenessMessage.camParameters.basicContainer.stationType == ITSContainer::StationType_roadSideUnit) + { + // TODO Future Implementation + AddRSUContainerHighFrequency(CoopAwarenessMessage.camParameters.highFrequencyContainer); + } + else if (CoopAwarenessMessage.camParameters.basicContainer.stationType == ITSContainer::StationType_pedestrian) + { + // TODO no container available for Pedestrains + } + else + { + // BasicVehicleContainer + AddBasicVehicleContainerHighFrequency(CoopAwarenessMessage.camParameters.highFrequencyContainer, DeltaTime); + + if (mElapsedTime - mLastLowCamTimeStamp >= scLowFrequencyContainerInterval) + { + AddLowFrequencyContainer(CoopAwarenessMessage.camParameters.lowFrequencyContainer); + mLastLowCamTimeStamp = mElapsedTime; + } + else + { + // Store nothing if not used + CoopAwarenessMessage.camParameters.lowFrequencyContainer.present = CAMContainer::LowFrequencyContainer_PR_NOTHING; + } + /* + *TODO Add Special container if it a special vehicle + */ + } +} + +void CaService::AddBasicContainer(CAMContainer::BasicContainer_t &BasicContainer) +{ + BasicContainer.stationType = mStationType; + + /* CamParameters ReferencePosition */ + FVector RefPos = GetReferencePosition(); + BasicContainer.referencePosition.latitude = std::round(RefPos.X * 1e6) * ITSContainer::Latitude_oneMicroDegreeNorth; + BasicContainer.referencePosition.longitude = std::round(RefPos.Y * 1e6) * ITSContainer::Longitude_oneMicroDegreeEast; + BasicContainer.referencePosition.positionConfidenceEllipse.semiMajorConfidence = ITSContainer::SemiAxisLength_unavailable; + BasicContainer.referencePosition.positionConfidenceEllipse.semiMinorConfidence = ITSContainer::SemiAxisLength_unavailable; + BasicContainer.referencePosition.positionConfidenceEllipse.semiMajorOrientation = ITSContainer::HeadingValue_unavailable; + BasicContainer.referencePosition.altitude.altitudeValue = std::round(RefPos.Z * 100.0) * ITSContainer::AltitudeValue_oneCentimeter; + BasicContainer.referencePosition.altitude.altitudeConfidence = ITSContainer::AltitudeConfidence_unavailable; +} + +void CaService::SetAccelerationStandardDeviation(const FVector &Vec) +{ + StdDevAccel = Vec; +} + +void CaService::SetGNSSDeviation(const float noise_lat_stddev, + const float noise_lon_stddev, + const float noise_alt_stddev, + const float noise_head_stddev, + const float noise_lat_bias, + const float noise_lon_bias, + const float noise_alt_bias, + const float noise_head_bias) +{ + LatitudeDeviation = noise_lat_stddev; + LongitudeDeviation = noise_lon_stddev; + AltitudeDeviation = noise_alt_stddev; + HeadingDeviation = noise_head_stddev; + LatitudeBias = noise_lat_bias; + LongitudeBias = noise_lon_bias; + AltitudeBias = noise_alt_bias; + HeadingBias = noise_head_bias; +} + +void CaService::SetVelDeviation(const float noise_vel_stddev_x) +{ + VelocityDeviation = noise_vel_stddev_x; +} + +void CaService::SetYawrateDeviation(const float noise_yawrate_stddev, const float noise_yawrate_bias) +{ + YawrateDeviation = noise_yawrate_stddev; + YawrateBias = noise_yawrate_bias; +} + +void CaService::AddBasicVehicleContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc, float DeltaTime) +{ + hfc.present = CAMContainer::HighFrequencyContainer_PR_basicVehicleContainerHighFrequency; + CAMContainer::BasicVehicleContainerHighFrequency_t &bvc = hfc.basicVehicleContainerHighFrequency; + // heading + bvc.heading.headingValue = std::round(GetHeading() * 10.0); + bvc.heading.headingConfidence = ITSContainer::HeadingConfidence_equalOrWithinOneDegree; // TODO + // speed + // speed with noise + bvc.speed.speedValue = BuildSpeedValue(ComputeSpeed()); + bvc.speed.speedConfidence = ITSContainer::SpeedConfidence_equalOrWithInOneCentimerterPerSec * 3; // TODO + // direction + bvc.driveDirection = (mVehicle->GetVehicleForwardSpeed() / 100.0f) >= 0.0 ? ITSContainer::DriveDirection_forward : ITSContainer::DriveDirection_backward; + // length and width + auto bb = UBoundingBoxCalculator::GetActorBoundingBox(mActorOwner); // cm + float length = bb.Extent.X * 2.0; // half box + float width = bb.Extent.Y * 2.0; // half box + + bvc.vehicleLength.vehicleLengthValue = std::round(length * 10.0); // 0.1 meter + bvc.vehicleLength.vehicleLengthConfidenceIndication = ITSContainer::VehicleLengthConfidenceIndication_unavailable; + bvc.vehicleWidth = std::round(width * 10.0); // 0.1 meter + + // acceleration + carla::geom::Vector3D Accel = ComputeAccelerometer(DeltaTime); + + const double lonAccelValue = Accel.x * 10.0; // m/s to 0.1 m/s + // limit changes + if (lonAccelValue >= -160.0 && lonAccelValue <= 161.0) + { + bvc.longitudinalAcceleration.longitudinalAccelerationValue = std::round(lonAccelValue) * ITSContainer::LongitudinalAccelerationValue_pointOneMeterPerSecSquaredForward; + } + else + { + bvc.longitudinalAcceleration.longitudinalAccelerationValue = ITSContainer::LongitudinalAccelerationValue_unavailable; + } + bvc.longitudinalAcceleration.longitudinalAccelerationConfidence = ITSContainer::AccelerationConfidence_unavailable; // TODO + + // curvature TODO + bvc.curvature.curvatureValue = ITSContainer::CurvatureValue_unavailable; + bvc.curvature.curvatureConfidence = ITSContainer::CurvatureConfidence_unavailable; + bvc.curvatureCalculationMode = ITSContainer::CurvatureCalculationMode_yarRateUsed; + + // yaw rate is in rad/s --> to centidegree per second + bvc.yawRate.yawRateValue = std::round(carla::geom::Math::ToDegrees(ComputeYawRate()) * 100.0) * ITSContainer::YawRateValue_degSec_000_01ToLeft; + if (bvc.yawRate.yawRateValue < -32766 || bvc.yawRate.yawRateValue > 32766) + { + bvc.yawRate.yawRateValue = ITSContainer::YawRateValue_unavailable; + } + bvc.yawRate.yawRateConfidence = ITSContainer::YawRateConfidence_unavailable; // TODO + + // optional lat and vertical accelerations + bvc.lateralAccelerationAvailable = true; + const double latAccelValue = Accel.y * 10.0; // m/s to 0.1 m/s + if (latAccelValue >= -160.0 && latAccelValue <= 161.0) + { + bvc.lateralAcceleration.lateralAccelerationValue = std::round(latAccelValue) * ITSContainer::LateralAccelerationValue_pointOneMeterPerSecSquaredToLeft; + } + else + { + bvc.lateralAcceleration.lateralAccelerationValue = ITSContainer::LateralAccelerationValue_unavailable; + } + bvc.lateralAcceleration.lateralAccelerationConfidence = ITSContainer::AccelerationConfidence_unavailable; // TODO + + bvc.verticalAccelerationAvailable = true; + const double vertAccelValue = Accel.z * 10.0; // m/s to 0.1 m/s + if (vertAccelValue >= -160.0 && vertAccelValue <= 161.0) + { + bvc.verticalAcceleration.verticalAccelerationValue = std::round(vertAccelValue) * ITSContainer::VerticalAccelerationValue_pointOneMeterPerSecSquaredUp; + } + else + { + bvc.verticalAcceleration.verticalAccelerationValue = ITSContainer::VerticalAccelerationValue_unavailable; + } + bvc.verticalAcceleration.verticalAccelerationConfidence = ITSContainer::AccelerationConfidence_unavailable; // TODO + + // TODO + bvc.accelerationControlAvailable = false; + bvc.lanePositionAvailable = false; + bvc.steeringWheelAngleAvailable = false; + bvc.performanceClassAvailable = false; + bvc.cenDsrcTollingZoneAvailable = false; +} + +const carla::geom::Vector3D CaService::ComputeAccelerometerNoise( + const FVector &Accelerometer) +{ + // Normal (or Gaussian or Gauss) distribution will be used as noise function. + // A mean of 0.0 is used as a first parameter, the standard deviation is + // determined by the client + constexpr float Mean = 0.0f; + return carla::geom::Vector3D{ + Accelerometer.X + mRandomEngine->GetNormalDistribution(Mean, StdDevAccel.X), + Accelerometer.Y + mRandomEngine->GetNormalDistribution(Mean, StdDevAccel.Y), + Accelerometer.Z + mRandomEngine->GetNormalDistribution(Mean, StdDevAccel.Z)}; +} + +carla::geom::Vector3D CaService::ComputeAccelerometer( + const float DeltaTime) +{ + // Used to convert from UE4's cm to meters + constexpr float TO_METERS = 1e-2; + // Earth's gravitational acceleration is approximately 9.81 m/s^2 + constexpr float GRAVITY = 9.81f; + + // 2nd derivative of the polynomic (quadratic) interpolation + // using the point in current time and two previous steps: + // d2[i] = -2.0*(y1/(h1*h2)-y2/((h2+h1)*h2)-y0/(h1*(h2+h1))) + const FVector CurrentLocation = mVehicle->GetActorLocation(); + + const FVector Y2 = PrevLocation[0]; + const FVector Y1 = PrevLocation[1]; + const FVector Y0 = CurrentLocation; + const float H1 = DeltaTime; + const float H2 = PrevDeltaTime; + + const float H1AndH2 = H2 + H1; + const FVector A = Y1 / (H1 * H2); + const FVector B = Y2 / (H2 * (H1AndH2)); + const FVector C = Y0 / (H1 * (H1AndH2)); + FVector FVectorAccelerometer = TO_METERS * -2.0f * (A - B - C); + + // Update the previous locations + PrevLocation[0] = PrevLocation[1]; + PrevLocation[1] = CurrentLocation; + PrevDeltaTime = DeltaTime; + + // Add gravitational acceleration + FVectorAccelerometer.Z += GRAVITY; + + FQuat ImuRotation = mActorOwner->GetRootComponent()->GetComponentTransform().GetRotation(); + FVectorAccelerometer = ImuRotation.UnrotateVector(FVectorAccelerometer); + + // Cast from FVector to our Vector3D to correctly send the data in m/s^2 + // and apply the desired noise function, in this case a normal distribution + const carla::geom::Vector3D Accelerometer = + ComputeAccelerometerNoise(FVectorAccelerometer); + + return Accelerometer; +} + +float CaService::ComputeSpeed() +{ + + const float speed = mVehicle->GetVehicleForwardSpeed() / 100.0f; + + // Normal (or Gaussian or Gauss) distribution and a bias will be used as + // noise function. + // A mean of 0.0 is used as a first parameter.The standard deviation and the + // bias are determined by the client + constexpr float Mean = 0.0f; + return boost::algorithm::clamp(speed + mRandomEngine->GetNormalDistribution(Mean, VelocityDeviation), 0.0f, std::numeric_limits::max()); +} + +float CaService::ComputeYawRate() +{ + check(mActorOwner != nullptr); + const FVector AngularVelocity = + FIMU_GetActorAngularVelocityInRadians(*mActorOwner); + + const FQuat SensorLocalRotation = + mActorOwner->GetRootComponent()->GetRelativeTransform().GetRotation(); + + const FVector FVectorGyroscope = + SensorLocalRotation.RotateVector(AngularVelocity); + + // Cast from FVector to our Vector3D to correctly send the data in rad/s + // and apply the desired noise function, in this case a normal distribution + float yawrate = + ComputeYawNoise(FVectorGyroscope); + + return yawrate; // rad/s +} + +const float CaService::ComputeYawNoise( + const FVector &Gyroscope) +{ + // Normal (or Gaussian or Gauss) distribution and a bias will be used as + // noise function. + // A mean of 0.0 is used as a first parameter.The standard deviation and the + // bias are determined by the client + constexpr float Mean = 0.0f; + return Gyroscope.Z + YawrateBias + mRandomEngine->GetNormalDistribution(Mean, YawrateDeviation); +} + +long millisecondsSince2004() +{ + // Define the epoch time (2004-01-01T00:00:00.000Z) + std::tm epoch_time = {}; + epoch_time = {0, 0, 0, 1, 0, 104}; // January 1, 2004 + + // Convert epoch time to a std::chrono::time_point + std::chrono::system_clock::time_point epoch = std::chrono::system_clock::from_time_t(std::mktime(&epoch_time)); + + // Get the current time + std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + + // Calculate the duration since the epoch in milliseconds + std::chrono::milliseconds duration = std::chrono::duration_cast(now - epoch); + + // Return the number of milliseconds as a long + return duration.count(); +} + +void CaService::AddRSUContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc) +{ + hfc.present = CAMContainer::HighFrequencyContainer_PR_rsuContainerHighFrequency; + CAMContainer::RSUContainerHighFrequency_t &rsu = hfc.rsuContainerHighFrequency; + // TODO For future implementation ITSContainer::ProtectedCommunicationZonesRSU_t PCZR + + uint8_t ProtectedZoneDataLength = 16; // Maximum number of elements in path history + + for (uint8_t i = 0; i <= ProtectedZoneDataLength; ++i) + { + ITSContainer::ProtectedCommunicationZone_t PCZ; + PCZ.protectedZoneType = ITSContainer::ProtectedZoneType_cenDsrcTolling; + PCZ.expiryTimeAvailable = false; + PCZ.protectedZoneLatitude = 50; + PCZ.protectedZoneLongitude = 50; + PCZ.protectedZoneRadiusAvailable = false; + PCZ.protectedZoneIDAvailable = false; + rsu.protectedCommunicationZonesRSU.list.push_back(PCZ); + rsu.protectedCommunicationZonesRSU.ProtectedCommunicationZoneCount += 1; + } +} + +void CaService::AddLowFrequencyContainer(CAMContainer::LowFrequencyContainer_t &lfc) +{ + lfc.present = CAMContainer::LowFrequencyContainer_PR_basicVehicleContainerLowFrequency; + CAMContainer::BasicVehicleContainerLowFrequency_t &bvc = lfc.basicVehicleContainerLowFrequency; + + /*Vehicle Role*/ + bvc.vehicleRole = GetVehicleRole(); + + /*Exterior Lights*/ + uint8_t *buf = &bvc.exteriorLights; + FVehicleLightState LightStateData = mVehicle->GetVehicleLightState(); + if (LightStateData.LowBeam) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_lowBeamHeadlightsOn); + } + if (LightStateData.HighBeam) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_highBeamHeadlightsOn); + } + if (LightStateData.LeftBlinker) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_leftTurnSignalOn); + } + if (LightStateData.RightBlinker) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_rightTurnSignalOn); + } + if (LightStateData.Reverse) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_reverseLightOn); + } + if (LightStateData.Fog) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_fogLightOn); + } + if (LightStateData.Position) + { + buf[0] |= 1 << (7 - ITSContainer::ExteriorLights_parkingLightsOn); + } + bvc.pathHistory.NumberOfPathPoint = 0; +} + +bool CaService::CheckHeadingDelta(float DeltaSeconds) +{ + // if heading diff is more than 4degree + VehicleHeading = mVehicle->GetVehicleOrientation(); + double HeadingDelta = carla::geom::Math::ToDegrees(GetFVectorAngle(mLastCamHeading, VehicleHeading)); + if (HeadingDelta > 4.0) + { + return true; + } + return false; +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/CaService.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/CaService.h new file mode 100644 index 000000000..9f644a181 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/CaService.h @@ -0,0 +1,132 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "Carla/Sensor/Sensor.h" + +#include "Carla/Actor/ActorDefinition.h" +#include "Carla/Actor/ActorDescription.h" +#include "Carla/Vehicle/CarlaWheeledVehicle.h" +#include "carla/geom/Math.h" +#include "carla/geom/GeoLocation.h" +#include +#include "carla/sensor/data/LibITS.h" +#include + +class CaService +{ +public: + CaService(URandomEngine *random_engine); + void SetOwner(UWorld *world, AActor *Owner); + + void SetParams(const float GenCamMin, const float GenCamMax, const bool FixedRate); + void SetVelDeviation(const float noise_vel_stddev_x); + void SetYawrateDeviation(const float noise_yawrate_stddev, const float noise_yawrate_bias); + void SetAccelerationStandardDeviation(const FVector &Vec); + void SetGNSSDeviation(const float noise_lat_stddev, + const float noise_lon_stddev, + const float noise_alt_stddev, + const float noise_head_stddev, + const float noise_lat_bias, + const float noise_lon_bias, + const float noise_alt_bias, + const float noise_head_bias); + bool Trigger(float DeltaSeconds); + CAM_t GetCamMessage(); + +private: + AActor *mActorOwner; + FCarlaActor *mCarlaActor; + UCarlaEpisode *mCarlaEpisode; + UWorld *mWorld; + ACarlaWheeledVehicle *mVehicle; + float mLastCamTimeStamp; + float mLastLowCamTimeStamp; + float mGenCamMin; + float mGenCamMax; + float mGenCam; + double mElapsedTime; + float mGenDeltaTimeMod; + bool mDccRestriction; + bool mFixedRate; + unsigned int mGenCamLowDynamicsCounter; + unsigned int mGenCamLowDynamicsLimit; + float mGenerationInterval; + + float VehicleSpeed; + FVector VehiclePosition; + FVector VehicleHeading; + + FVector mLastCamPosition; + float mLastCamSpeed; + FVector mLastCamHeading; + std::chrono::milliseconds mGenerationDelta0; + + bool CheckTriggeringConditions(float DeltaSeconds); + bool CheckHeadingDelta(float DeltaSeconds); + bool CheckPositionDelta(float DeltaSeconds); + bool CheckSpeedDelta(float DeltaSeconds); + double GetFVectorAngle(const FVector &a, const FVector &b); + void GenerateCamMessage(float DeltaTime); + ITSContainer::StationType_t GetStationType(); + + float GetHeading(); + long GetVehicleRole(); + + /* Constant values for message*/ + const long mProtocolVersion = 2; + const long mMessageId = ITSContainer::messageID_cam; + long mStationId; + long mStationType; + + carla::geom::Vector3D ComputeAccelerometer(const float DeltaTime); + const carla::geom::Vector3D ComputeAccelerometerNoise(const FVector &Accelerometer); + /// Standard deviation for acceleration settings. + FVector StdDevAccel; + + /// Used to compute the acceleration + std::array PrevLocation; + + /// Used to compute the acceleration + float PrevDeltaTime; + + // GNSS reference position and heading + FVector GetReferencePosition(); + carla::geom::GeoLocation CurrentGeoReference; + float LatitudeDeviation; + float LongitudeDeviation; + float AltitudeDeviation; + float HeadingDeviation; + + float LatitudeBias; + float LongitudeBias; + float AltitudeBias; + float HeadingBias; + + // Velocity + float ComputeSpeed(); + float VelocityDeviation; + + // Yaw rate + const float ComputeYawNoise(const FVector &Gyroscope); + float ComputeYawRate(); + float YawrateDeviation; + float YawrateBias; + + CAM_t CreateCooperativeAwarenessMessage(float DeltaTime); + void CreateITSPduHeader(CAM_t &message); + void AddCooperativeAwarenessMessage(CAMContainer::CoopAwareness_t &CoopAwarenessMessage, float DeltaTime); + void AddBasicContainer(CAMContainer::BasicContainer_t &BasicContainer); + void AddBasicVehicleContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc, float DeltaTime); + void AddRSUContainerHighFrequency(CAMContainer::HighFrequencyContainer_t &hfc); + void AddLowFrequencyContainer(CAMContainer::LowFrequencyContainer_t &lfc); + CAM_t mCAMMessage; + + // random for noise + URandomEngine *mRandomEngine; + ITSContainer::SpeedValue_t BuildSpeedValue(const float vel); +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/PathLossModel.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/PathLossModel.cpp new file mode 100644 index 000000000..bd80f114e --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/PathLossModel.cpp @@ -0,0 +1,571 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "Carla.h" +#include "Carla/Game/CarlaEpisode.h" +#include "Math/UnrealMathUtility.h" + +#include "PathLossModel.h" +#include +#include + +double PathLossModel::Frequency_GHz = 5.9f; +double PathLossModel::Frequency = 5.9f * std::pow(10, 9); +double PathLossModel::lambda = PathLossModel::c_speedoflight / (5.9f * std::pow(10, 9)); + +PathLossModel::PathLossModel(URandomEngine *random_engine) +{ + mRandomEngine = random_engine; +} + +void PathLossModel::SetOwner(AActor *Owner) +{ + mActorOwner = Owner; +} + +void PathLossModel::SetParams(const float TransmitPower, + const float ReceiverSensitivity, + const float Frequency, + const float combined_antenna_gain, + const float path_loss_exponent, + const float reference_distance_fspl, + const float filter_distance, + const bool use_etsi_fading, + const float custom_fading_stddev) +{ + this->TransmitPower = TransmitPower; + this->ReceiverSensitivity = ReceiverSensitivity; + this->path_loss_exponent = path_loss_exponent; + this->reference_distance_fspl = reference_distance_fspl; + this->filter_distance = filter_distance; + this->use_etsi_fading = use_etsi_fading; + this->custom_fading_stddev = custom_fading_stddev; + this->combined_antenna_gain = combined_antenna_gain; + PathLossModel::Frequency_GHz = Frequency; + PathLossModel::Frequency = PathLossModel::Frequency_GHz * std::pow(10, 9); + PathLossModel::lambda = PathLossModel::c_speedoflight / PathLossModel::Frequency; + // when reference distance is set, we prepare the FSPL for the reference distance to be used in LDPL + CalculateFSPL_d0(); +} + +void PathLossModel::SetScenario(EScenario scenario) +{ + this->scenario = scenario; +} + +std::map PathLossModel::GetReceiveActorPowerList() +{ + return mReceiveActorPowerList; +} + +void PathLossModel::Simulate(const std::vector ActorList, UCarlaEpisode *CarlaEpisode, UWorld *World) +{ + // Set current world and episode + mWorld = World; + mCarlaEpisode = CarlaEpisode; + + CurrentActorLocation = mActorOwner->GetTransform().GetLocation(); + FVector OtherActorLocation; + mReceiveActorPowerList.clear(); + float ReceivedPower = 0; + // Logic to get height of the vehicle + // TODO: make that thing use the actual attachment and transform of the sensor + + double tx_height_local = (mActorOwner->GetSimpleCollisionHalfHeight() * 2.0f) + 2.0; + + const FActorRegistry &Registry = mCarlaEpisode->GetActorRegistry(); + + for (auto &actor_power_pair : ActorList) + { + const FCarlaActor *view = Registry.FindCarlaActor(actor_power_pair.first); + // ensure other actor is still alive + if (!view) + { + continue; + } + OtherActorLocation = actor_power_pair.first->GetTransform().GetLocation(); + double rx_height_local = (actor_power_pair.first->GetSimpleCollisionHalfHeight() * 2.0) + 2.0; + + // calculate relative ht and hr respecting slope and elevation + // cm + // if objects are on a slope, minimum Z height of both is the reference to calculate transmitter height + double ref0 = std::min(CurrentActorLocation.Z, OtherActorLocation.Z); + // cm + double ht = CurrentActorLocation.Z + tx_height_local - ref0; + double hr = OtherActorLocation.Z + rx_height_local - ref0; + // localize to common ref0 as ground + FVector source_rel = CurrentActorLocation; + source_rel.Z += tx_height_local; + FVector dest_rel = OtherActorLocation; + dest_rel.Z += rx_height_local; + + double Distance3d = FVector::Distance(source_rel, dest_rel) / 100.0f; // From cm to m + // to meters + ht = ht / 100.0f; + hr = hr / 100.0f; + + if (Distance3d < filter_distance) // maybe change this for highway + { + float OtherTransmitPower = actor_power_pair.second; + ReceivedPower = CalculateReceivedPower(actor_power_pair.first, + OtherTransmitPower, + CurrentActorLocation, + OtherActorLocation, + Distance3d, + ht, + tx_height_local, + hr, + rx_height_local, + ref0); + if (ReceivedPower > -1.0 * std::numeric_limits::max()) + { + mReceiveActorPowerList.insert(std::make_pair(actor_power_pair.first, ReceivedPower)); + } + } + } +} + +float PathLossModel::CalculateReceivedPower(AActor *OtherActor, + const float OtherTransmitPower, + const FVector Source, + const FVector Destination, + const double Distance3d, + const double ht, + const double ht_local, + const double hr, + const double hr_local, + const double reference_z) +{ + // hr in m + // ht in m + // reference_z in cm + // distance3d in m + bool ret = false; + FCollisionObjectQueryParams ObjectParams; + // Channels to check for collision with different object types + ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldStatic); + ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_PhysicsBody); + ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_Vehicle); + ObjectParams.AddObjectTypesToQuery(ECollisionChannel::ECC_WorldDynamic); + HitResult.Reset(); + + FVector tx = Source; + tx.Z += ht_local; + FVector rx = Destination; + rx.Z += hr_local; + mWorld->LineTraceMultiByObjectType(HitResult, tx, rx, ObjectParams); + + // all losses + float loss = ComputeLoss(OtherActor, Source, Destination, Distance3d, ht, hr, reference_z); + + // we incorporate the tx power of the sender (the other actor), not our own + // NOTE: combined antenna gain is parametrized for each sensor. Better solution would be to parametrize individual antenna gain + // and combine at the receiver. This would allow to better account for antenna characteristics. + float ReceivedPower = OtherTransmitPower + combined_antenna_gain - loss; + + if (ReceivedPower >= ReceiverSensitivity) + { + ret = true; + } + float deltaPercentage = loss / (OtherTransmitPower - ReceiverSensitivity); + + // Works only when run in debug mode + DrawDebugLine( + mWorld, + tx, + rx, + FColor::Cyan, + false, 0.05f, 0, + 30); + if (deltaPercentage < 0.65) + { + DrawDebugLine( + mWorld, + tx, + rx, + FColor::Green, + false, 0.1f, 0, + 30); + } + else if (deltaPercentage < 0.8) + { + DrawDebugLine( + mWorld, + tx, + rx, + FColor::Orange, + false, 0.1f, 0, + 30); + } + else if (ReceivedPower >= ReceiverSensitivity) + { + DrawDebugLine( + mWorld, + tx, + rx, + FColor::Red, + false, 0.1f, 0, + 30); + } + + if (ret) + { + return ReceivedPower; + } + else + { + return -1.0 * std::numeric_limits::max(); + } +} + +void PathLossModel::EstimatePathStateAndVehicleObstacles(AActor *OtherActor, + FVector CurrentActorLocation, + double TxHeight, + double RxHeight, + double reference_z, + EPathState &state, + std::vector &vehicle_obstacles) +{ + // CurrentActorLocation in cm original + // TxHeight in m + // RxHeight in m + // reference_z in cm + + // init with LOS + state = EPathState::LOS; + if (HitResult.Num() == 0) + { + // no hits --> LOS + return; + } + + // check all hits + for (const FHitResult &HitInfo : HitResult) + { + + FVector location; + if (HitIsSelfOrOther(HitInfo, OtherActor)) + { + // the current hit is either Tx or Rx, so we can skip it, no obstacle + continue; + } + + // cal by ref + if (GetLocationIfVehicle(CurrentActorLocation, HitInfo, reference_z, location)) + { + // we found a vehicle + // Note: we may set this several times if we have several vehicles in between + state = EPathState::NLOSv; + // z (height) is gonna be in m in relation to reference height + // x,y also in meters + // call by reference + vehicle_obstacles.emplace_back(location); + + // alternative (cf Etsi): statistical model + // vehicle_blockage_loss += MakeVehicleBlockageLoss(TxHeight, RxHeight, obj_height, obj_dist); + } + // but if we hit a building, we stop and switch to NLOSb + else + { + state = EPathState::NLOSb; + break; + } + } +} + +double PathLossModel::CalcVehicleLoss(const double d1, const double d2, const double h) +{ + double V = h * sqrt(2.0 * (d1 + d2) / (lambda * d1 * d2)); + if (V >= -0.78) { + double T = std::pow(V - 0.1, 2); + return 6.9 + 20.0 * log10(sqrt(T + 1.0) + V - 0.1); + } + return 0.0; +} + +double PathLossModel::CalculateNLOSvLoss(const FVector Source, + const FVector Destination, + const double TxHeight, + const double RxHeight, + const double RxDistance3d, + std::vector &vehicle_obstacles) +{ + + // convert all positions to meters + FVector pos_tx = Source; + pos_tx.X /= 100.0f; + pos_tx.Y /= 100.0f; + pos_tx.Z = TxHeight; + + FVector pos_rx = Destination; + pos_rx.X /= 100.0f; + pos_rx.Y /= 100.0f; + pos_rx.Z = RxHeight; + + double max_loss = 0.0; + for(auto veh_it = vehicle_obstacles.begin(); veh_it != vehicle_obstacles.end(); veh_it++) + { + double dist_tx_veh = sqrt(std::pow(veh_it->X - pos_tx.X, 2) + std::pow(veh_it->Y - pos_tx.Y, 2)); + double dist_veh_rx = sqrt(std::pow(pos_rx.X - veh_it->X, 2) + std::pow(pos_rx.Y - veh_it->Y, 2)); + double cur_loss = CalcVehicleLoss(dist_tx_veh,dist_veh_rx,veh_it->Z); + if(cur_loss >= max_loss) + { + max_loss = cur_loss; + } + } + + return max_loss; +} + +void PathLossModel::SetPathLossModel(const EPathLossModel path_loss_model) +{ + model = path_loss_model; +} + +float PathLossModel::ComputeLoss(AActor *OtherActor, FVector Source, FVector Destination, double Distance3d, double TxHeight, double RxHeight, double reference_z) +{ + // TxHeight in m + // RxHeight in m + // reference_z in cm + // distance3d in m + EPathState state; + + float PathLoss = 0.0; + double VehicleBlockageLoss = 0.0; + float ShadowFadingLoss = 0.0; + + // state and vehicle obstacles are call-by-reference + std::vector vehicle_obstacles; + EstimatePathStateAndVehicleObstacles(OtherActor, Source, TxHeight, RxHeight, reference_z, state, vehicle_obstacles); + + if (model == EPathLossModel::Winner) + { + // calculate pure path loss depending on state and scenario + PathLoss = CalculatePathLoss_WINNER(state, Distance3d); + // in nlosv case, add multi knife edge + if (state == EPathState::NLOSv) + { + PathLoss = PathLoss + CalculateNLOSvLoss(Source, Destination, TxHeight, RxHeight, Distance3d, vehicle_obstacles); + } + } + else + { + if (state == EPathState::LOS) + { + // full two ray path loss + PathLoss = CalculateTwoRayPathLoss(Distance3d, TxHeight, RxHeight); + } + else if (state == EPathState::NLOSb) + { + // log distance path loss + PathLoss = (m_fspl_d0 + 10.0 * path_loss_exponent * log10(Distance3d / reference_distance_fspl)); + } + else + { + // fspl + knife edge + // fspl + double free_space_loss = 20.0 * log10(Distance3d) + 20.0 * log10(4.0 * PI / lambda); + // add the knife edge vehicle blockage loss + PathLoss = free_space_loss + CalculateNLOSvLoss(Source, Destination, TxHeight, RxHeight, Distance3d, vehicle_obstacles); + } + } + + // add random shadows + ShadowFadingLoss = CalculateShadowFading(state); + return PathLoss + ShadowFadingLoss; +} + +bool PathLossModel::IsVehicle(const FHitResult &HitInfo) +{ + bool Vehicle = false; + const FActorRegistry &Registry = mCarlaEpisode->GetActorRegistry(); + + const AActor *actor = HitInfo.Actor.Get(); + + if (actor != nullptr) + { + + const FCarlaActor *view = Registry.FindCarlaActor(actor); + if (view) + { + if (view->GetActorType() == FCarlaActor::ActorType::Vehicle) + { + Vehicle = true; + } + } + } + return Vehicle; +} + +bool PathLossModel::HitIsSelfOrOther(const FHitResult &HitInfo, AActor *OtherActor) +{ + const AActor *actor = HitInfo.Actor.Get(); + if (actor != nullptr) + { + if (actor == mActorOwner) + { + return true; + } + else if (actor == OtherActor) + { + return true; + } + } + return false; +} + +bool PathLossModel::GetLocationIfVehicle(const FVector CurrentActorLocation, const FHitResult &HitInfo, const double reference_z, FVector &location) +{ + // reference_z in cm + bool Vehicle = false; + const FActorRegistry &Registry = mCarlaEpisode->GetActorRegistry(); + + const AActor *actor = HitInfo.Actor.Get(); + + if (actor != nullptr) + { + + const FCarlaActor *view = Registry.FindCarlaActor(actor); + if (view) + { + if (view->GetActorType() == FCarlaActor::ActorType::Vehicle) + { + Vehicle = true; + location = actor->GetTransform().GetLocation(); + location.Z = location.Z - reference_z + (actor->GetSimpleCollisionHalfHeight() * 2.0) + 2.0; + location.Z = location.Z / 100.0f; + // cm to m + location.X /= 100.0f; + location.Y /= 100.0f; + } + } + } + return Vehicle; +} + +void PathLossModel::CalculateFSPL_d0() +{ + m_fspl_d0 = 20.0 * log10(reference_distance_fspl) + 20.0 * log10(Frequency) + 20.0 * log10(4.0 * PI / c_speedoflight); +} + +// Following ETSI TR 103 257-1 V1.1.1 (2019-05: from WINNER Project Board: "D5.3 - WINNER+ Final Channel Models", 30 06 2010. +float PathLossModel::CalculatePathLoss_WINNER(EPathState state, double Distance) +{ + + if (state == EPathState::NLOSb) + { + // Distance should be euclidean here. + return 36.85f + 30.0f * log10(Distance) + 18.9f * log10(Frequency_GHz); + } + else // LOS, NLOSv + { + if (scenario == EScenario::Highway) + { + return 32.4f + 20.0f * log10(Distance) + 20.0f * log10(Frequency_GHz); + } + else // Rural or Urban + { + return 38.77f + 16.7f * log10(Distance) + 18.2f * log10(Frequency_GHz); + } + } +} + +// Following ETSI TR 103 257-1 V1.1.1 Table 6: Shadow-fading parameter σ for V2V +float PathLossModel::CalculateShadowFading(EPathState state) +{ + const float Mean = 0.0f; + float std_dev_dB; // = 5.2; + if (use_etsi_fading) + { + switch (state) + { + case EPathState::LOS: + switch (scenario) + { + case EScenario::Highway: + std_dev_dB = 3.3f; + break; + case EScenario::Urban: + std_dev_dB = 5.2f; + break; + case EScenario::Rural: + // no known values in ETSI Standard, take middle of Highway and Urban + std_dev_dB = 4.25f; + break; + } + break; + case EPathState::NLOSb: + switch (scenario) + { + // Note: according to ETSI, NLOSb is not applicable in Highway scenario, only Urban + // we use the same std_dev for all three scenarios if in NLOSb + case EScenario::Highway: + std_dev_dB = 6.8f; + break; + case EScenario::Urban: + std_dev_dB = 6.8f; + break; + case EScenario::Rural: + std_dev_dB = 6.8f; + break; + } + break; + case EPathState::NLOSv: + switch (scenario) + { + case EScenario::Highway: + std_dev_dB = 3.8f; + break; + case EScenario::Urban: + std_dev_dB = 5.3f; + break; + case EScenario::Rural: + // no known values in ETSI Standard, take middle of Highway and Urban + std_dev_dB = 4.55f; + break; + } + break; + } + } + else + { + // custom fading param + std_dev_dB = custom_fading_stddev; + } + + // in dB + return mRandomEngine->GetNormalDistribution(Mean, std_dev_dB); +} + +float PathLossModel::CalculateTwoRayPathLossSimple(double Distance3d, double TxHeight, double RxHeight) +{ + // simplified Two Ray Path Loss (https://en.wikipedia.org/wiki/Two-ray_ground-reflection_model) + // is only a valid assumption, if distance >> 4 pi TxHeight * RxHeight / lambda + // with f=5.9 Ghz -> lambda = c/ f = 0.05m + // and with average antenna height 2m: distance >> 1000m + return 40 * log10(Distance3d) - 10 * log10(TxHeight * TxHeight * RxHeight * RxHeight); +} + +double PathLossModel::CalculateTwoRayPathLoss(double Distance3d, double TxHeight, double RxHeight) +{ + // tx and rx height in m + // distance 3d is LOS in m + double d_ground = sqrt(std::pow(Distance3d, 2) - std::pow(TxHeight - RxHeight, 2)); + + // reflected path + // d_reflection = sqrt(d_ground^2+(ht+hr)^2) -> with d_ground = sqrt(d_los^2 - (ht-hr)^2): + double d_refl = sqrt(std::pow(Distance3d, 2) + 4.0 * TxHeight * RxHeight); + + // Sine and cosine of incident angle + double sin_theta = (TxHeight + RxHeight) / d_refl; + double cos_theta = d_ground / d_refl; + + double gamma = (sin_theta - sqrt(epsilon_r - std::pow(cos_theta, 2))) / (sin_theta + sqrt(epsilon_r - std::pow(cos_theta, 2))); + + double phi = (2.0 * PI / lambda * (Distance3d - d_refl)); + + return 20 * log10(4.0 * PI * d_ground / lambda * 1.0 / sqrt(std::pow(1 + gamma * cos(phi), 2) + std::pow(gamma, 2) * std::pow(sin(phi), 2))); +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/PathLossModel.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/PathLossModel.h new file mode 100644 index 000000000..2e9fd6071 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2X/PathLossModel.h @@ -0,0 +1,124 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include + + +using ActorPowerMap = std::map; +using ActorPowerPair = std::pair; + +enum EPathState +{ + LOS, + NLOSb, + NLOSv +}; + +enum EPathLossModel +{ + Winner, + Geometric, +}; + +enum EScenario +{ + Highway, + Rural, + Urban +}; + +class PathLossModel +{ +public: + PathLossModel(URandomEngine *random_engine); + void SetOwner(AActor *Owner); + void SetScenario(EScenario scenario); + void Simulate(const std::vector ActorList, UCarlaEpisode *CarlaEpisode, UWorld *World); + ActorPowerMap GetReceiveActorPowerList(); + void SetParams(const float TransmitPower, + const float ReceiverSensitivity, + const float Frequency, + const float combined_antenna_gain, + const float path_loss_exponent, + const float reference_distance_fspl, + const float filter_distance, + const bool use_etsi_fading, + const float custom_fading_stddev); + float GetTransmitPower() { return TransmitPower; } + void SetPathLossModel(const EPathLossModel path_loss_model); + +private: + // diffraction for NLOSv + double CalcVehicleLoss(const double d1, const double d2, const double h); + // powers + float CalculateReceivedPower(AActor *OtherActor, + const float OtherTransmitPower, + const FVector Source, + const FVector Destination, + const double Distance3d, + const double ht, + const double ht_local, + const double hr, + const double hr_local, + const double reference_z); + void EstimatePathStateAndVehicleObstacles(AActor *OtherActor, FVector Source, double TxHeight, double RxHeight, double reference_z, EPathState &state, std::vector &vehicle_obstacles); + double MakeVehicleBlockageLoss(double TxHeight, double RxHeight, double obj_height, double obj_distance); + // variables + AActor *mActorOwner; + UCarlaEpisode *mCarlaEpisode; + UWorld *mWorld; + URandomEngine *mRandomEngine; + + ActorPowerMap mReceiveActorPowerList; + FVector CurrentActorLocation; + + // constants + constexpr static float c_speedoflight = 299792458.0; // m/s + + // full two ray path loss + const double epsilon_r = 1.02; + + // params + static double Frequency_GHz; // 5.9f;//5.9 GHz + static double Frequency; // Frequency_GHz * std::pow(10,9); + static double lambda; // c_speedoflight/Frequency; + float reference_distance_fspl; // m + float TransmitPower; // dBm + float ReceiverSensitivity; // dBm + EScenario scenario; + float path_loss_exponent; // no unit, default 2.7; + float filter_distance; // in meters default 500.0 + EPathLossModel model; + bool use_etsi_fading; + float custom_fading_stddev; + float combined_antenna_gain; // 10.0 dBi + + // dependent params that are precalculated on setting of params + float m_fspl_d0; + +protected: + /// Method that allow to preprocess if the rays will be traced. + + float ComputeLoss(AActor *OtherActor, FVector Source, FVector Destination, double Distance3d, double TxHeight, double RxHeight, double reference_z); + bool IsVehicle(const FHitResult &HitInfo); + bool GetLocationIfVehicle(const FVector CurrentActorLocation, const FHitResult &HitInfo, const double reference_z, FVector &location); + bool HitIsSelfOrOther(const FHitResult &HitInfo, AActor *OtherActor); + float CalculatePathLoss_WINNER(EPathState state, double Distance); + double CalculateNLOSvLoss(const FVector Source, const FVector Destination, const double TxHeight, const double RxHeight, const double RxDistance3d, std::vector &vehicle_obstacles); + + float CalculateShadowFading(EPathState state); + + // full two ray model + double CalculateTwoRayPathLoss(double Distance3d, double TxHeight, double RxHeight); + // simplified two ray model + float CalculateTwoRayPathLossSimple(double Distance3d, double TxHeight, double RxHeight); + + // functions for precalculation + void CalculateFSPL_d0(); + TArray HitResult; +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2XSensor.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2XSensor.cpp new file mode 100644 index 000000000..2e5c88692 --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2XSensor.cpp @@ -0,0 +1,234 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "Carla.h" +#include "Carla/Sensor/V2XSensor.h" +#include "Carla/Actor/ActorBlueprintFunctionLibrary.h" +#include "Carla/Game/CarlaEpisode.h" +#include "Carla/Vehicle/CarlaWheeledVehicle.h" +#include +#include +#include "V2X/CaService.h" +#include "V2XSensor.h" +#include "V2X/PathLossModel.h" +std::list AV2XSensor::mV2XActorContainer; +AV2XSensor::ActorV2XDataMap AV2XSensor::mActorV2XDataMap; + +AV2XSensor::AV2XSensor(const FObjectInitializer &ObjectInitializer) + : Super(ObjectInitializer) +{ + PrimaryActorTick.bCanEverTick = true; + RandomEngine = CreateDefaultSubobject(TEXT("RandomEngine")); + + // Init path loss model + PathLossModelObj = new PathLossModel(RandomEngine); + CaServiceObj = new CaService(RandomEngine); +} + +void AV2XSensor::SetOwner(AActor *Owner) +{ + UE_LOG(LogCarla, Warning, TEXT("V2XSensor: called setowner with %p"), Owner); + if (GetOwner() != nullptr) + { + AV2XSensor::mV2XActorContainer.remove(GetOwner()); + UE_LOG(LogCarla, Warning, TEXT("V2XSensor: removed old owner %p"), GetOwner()); + } + + Super::SetOwner(Owner); + + // Store the actor into the static list if the actor details are not available + if (Owner != nullptr) + { + if (std::find(AV2XSensor::mV2XActorContainer.begin(), AV2XSensor::mV2XActorContainer.end(), Owner) == AV2XSensor::mV2XActorContainer.end()) + { + AV2XSensor::mV2XActorContainer.push_back(Owner); + UE_LOG(LogCarla, Warning, TEXT("V2XSensor: added owner, length now %d"), AV2XSensor::mV2XActorContainer.size()); + } + UWorld *world = GetWorld(); + CaServiceObj->SetOwner(world, Owner); + PathLossModelObj->SetOwner(Owner); + } +} + +FActorDefinition AV2XSensor::GetSensorDefinition() +{ + return UActorBlueprintFunctionLibrary::MakeV2XDefinition(); +} + +/* Function to add configurable parameters*/ +void AV2XSensor::Set(const FActorDescription &ActorDescription) +{ + UE_LOG(LogCarla, Warning, TEXT("V2XSensor: Set function called")); + Super::Set(ActorDescription); + UActorBlueprintFunctionLibrary::SetV2X(ActorDescription, this); +} + +void AV2XSensor::SetCaServiceParams(const float GenCamMin, const float GenCamMax, const bool FixedRate) +{ + // forward parameters to CaService Obj + CaServiceObj->SetParams(GenCamMin, GenCamMax, FixedRate); +} + +void AV2XSensor::SetPropagationParams(const float TransmitPower, + const float ReceiverSensitivity, + const float Frequency, + const float combined_antenna_gain, + const float path_loss_exponent, + const float reference_distance_fspl, + const float filter_distance, + const bool use_etsi_fading, + const float custom_fading_stddev) +{ + // forward parameters to PathLossModel Obj + PathLossModelObj->SetParams(TransmitPower, ReceiverSensitivity, Frequency, combined_antenna_gain, path_loss_exponent, reference_distance_fspl, filter_distance, use_etsi_fading, custom_fading_stddev); +} + +void AV2XSensor::SetPathLossModel(const EPathLossModel path_loss_model) +{ + PathLossModelObj->SetPathLossModel(path_loss_model); +} + +void AV2XSensor::SetScenario(EScenario scenario) +{ + PathLossModelObj->SetScenario(scenario); +} + +/* + * Function stores the actor details in to the static list. + * Calls the CaService object to generate CAM message + * Stores the message in static map + */ +void AV2XSensor::PrePhysTick(float DeltaSeconds) +{ + Super::PrePhysTick(DeltaSeconds); + // Clear the message created during the last sim cycle + if (GetOwner()) + { + AV2XSensor::mActorV2XDataMap.erase(GetOwner()); + + // Step 0: Create message to send, if triggering conditions fulfilled + // this needs to be done in pre phys tick to enable synchronous reception in all other v2x sensors + // Check whether the message is generated + if (CaServiceObj->Trigger(DeltaSeconds)) + { + // If message is generated store it + // make a pair of message and sending power + // if different v2x sensors send with different power, we need to store that + carla::sensor::data::CAMData cam_pw; + cam_pw.Message = CaServiceObj->GetCamMessage(); + cam_pw.Power = PathLossModelObj->GetTransmitPower(); + AV2XSensor::mActorV2XDataMap.insert({GetOwner(), cam_pw}); + } + } +} + +void AV2XSensor::SetAccelerationStandardDeviation(const FVector &Vec) +{ + CaServiceObj->SetAccelerationStandardDeviation(Vec); +} + +void AV2XSensor::SetGNSSDeviation(const float noise_lat_stddev, + const float noise_lon_stddev, + const float noise_alt_stddev, + const float noise_head_stddev, + const float noise_lat_bias, + const float noise_lon_bias, + const float noise_alt_bias, + const float noise_head_bias) +{ + CaServiceObj->SetGNSSDeviation(noise_lat_stddev, + noise_lon_stddev, + noise_alt_stddev, + noise_head_stddev, + noise_lat_bias, + noise_lon_bias, + noise_alt_bias, + noise_head_bias); +} + +void AV2XSensor::SetVelDeviation(const float noise_vel_stddev) +{ + CaServiceObj->SetVelDeviation(noise_vel_stddev); +} + +void AV2XSensor::SetYawrateDeviation(const float noise_yawrate_stddev, const float noise_yawrate_bias) +{ + CaServiceObj->SetYawrateDeviation(noise_yawrate_stddev, noise_yawrate_bias); +} + +/* + * Function takes care of sending messages to the current actor. + * First simulates the communication by calling LOSComm object. + * If there is a list present then messages from those list are sent to the current actor + */ +void AV2XSensor::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) +{ + TRACE_CPUPROFILER_EVENT_SCOPE(AV2XSensor::PostPhysTick); + if (GetOwner()) + { + // Step 1: Create an actor list which has messages to send targeting this v2x sensor instance + std::vector ActorPowerList; + for (const auto &pair : AV2XSensor::mActorV2XDataMap) + { + if (pair.first != GetOwner()) + { + ActorPowerPair actor_power_pair; + actor_power_pair.first = pair.first; + // actor sending with transmit power + actor_power_pair.second = pair.second.Power; + ActorPowerList.push_back(actor_power_pair); + } + } + + // Step 2: Simulate the communication for the actors in actor list to current actor. + if (!ActorPowerList.empty()) + { + UCarlaEpisode *carla_episode = UCarlaStatics::GetCurrentEpisode(GetWorld()); + PathLossModelObj->Simulate(ActorPowerList, carla_episode, GetWorld()); + // Step 3: Get the list of actors who can send message to current actor, and the receive power of their messages. + ActorPowerMap actor_receivepower_map = PathLossModelObj->GetReceiveActorPowerList(); + // Step 4: Retrieve the messages of the actors that are received + + // get registry to retrieve carla actor IDs + const FActorRegistry &Registry = carla_episode->GetActorRegistry(); + + AV2XSensor::V2XDataList msg_received_power_list; + for (const auto &pair : actor_receivepower_map) + { + // Note: AActor* sender_actor = pair.first; + carla::sensor::data::CAMData send_msg_and_pw = AV2XSensor::mActorV2XDataMap.at(pair.first); + carla::sensor::data::CAMData received_msg_and_pw; + // sent CAM + received_msg_and_pw.Message = send_msg_and_pw.Message; + // receive power + received_msg_and_pw.Power = pair.second; + + msg_received_power_list.push_back(received_msg_and_pw); + } + + WriteMessageToV2XData(msg_received_power_list); + } + // Step 5: Send message + + if (mV2XData.GetMessageCount() > 0) + { + auto DataStream = GetDataStream(*this); + DataStream.SerializeAndSend(*this, mV2XData, DataStream.PopBufferFromPool()); + } + mV2XData.Reset(); + } +} + +/* + * Function the store the message into the structure so it can be sent to python client + */ +void AV2XSensor::WriteMessageToV2XData(const AV2XSensor::V2XDataList &msg_received_power_list) +{ + for (const auto &elem : msg_received_power_list) + { + mV2XData.WriteMessage(elem); + } +} diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2XSensor.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2XSensor.h new file mode 100644 index 000000000..9ce46dd2a --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Sensor/V2XSensor.h @@ -0,0 +1,77 @@ +// Copyright (c) 2024 Institut fuer Technik der Informationsverarbeitung (ITIV) at the +// Karlsruhe Institute of Technology +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "Carla/Sensor/Sensor.h" + +#include "Carla/Actor/ActorDefinition.h" +#include "Carla/Actor/ActorDescription.h" +#include +#include "V2X/CaService.h" +#include "V2X/PathLossModel.h" +#include +#include +#include "V2XSensor.generated.h" + +UCLASS() +class CARLA_API AV2XSensor : public ASensor +{ + GENERATED_BODY() + + using FV2XData = carla::sensor::data::CAMDataS; + using ActorV2XDataMap = std::map; + using V2XDataList = std::vector; + +public: + AV2XSensor(const FObjectInitializer &ObjectInitializer); + + static FActorDefinition GetSensorDefinition(); + + void Set(const FActorDescription &ActorDescription) override; + + void SetCaServiceParams(const float GenCamMin, const float GenCamMax, const bool FixedRate); + void SetPropagationParams(const float TransmitPower, + const float ReceiverSensitivity, + const float Frequency, + const float combined_antenna_gain, + const float path_loss_exponent, + const float reference_distance_fspl, + const float filter_distance, + const bool use_etsi_fading, + const float custom_fading_stddev); + void SetScenario(EScenario scenario); + + // CAM params + void SetAccelerationStandardDeviation(const FVector &Vec); + void SetGNSSDeviation(const float noise_lat_stddev, + const float noise_lon_stddev, + const float noise_alt_stddev, + const float noise_head_stddev, + const float noise_lat_bias, + const float noise_lon_bias, + const float noise_alt_bias, + const float noise_head_bias); + void SetVelDeviation(const float noise_vel_stddev); + void SetYawrateDeviation(const float noise_yawrate_stddev, const float noise_yawrate_bias); + void SetPathLossModel(const EPathLossModel path_loss_model); + + virtual void PrePhysTick(float DeltaSeconds) override; + virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) override; + void SetOwner(AActor *Owner) override; + +private: + static std::list mV2XActorContainer; + CaService *CaServiceObj; + PathLossModel *PathLossModelObj; + + // store data + static ActorV2XDataMap mActorV2XDataMap; + FV2XData mV2XData; + + // write + void WriteMessageToV2XData(const V2XDataList &msg_received_power_list); +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp index 7824ddfde..215780a27 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Server/CarlaServer.cpp @@ -20,6 +20,7 @@ #include "Carla/Util/NavigationMesh.h" #include "Carla/Util/RayTracer.h" #include "Carla/Vehicle/CarlaWheeledVehicle.h" +#include "Carla/Sensor/CustomV2XSensor.h" #include "Carla/Walker/WalkerController.h" #include "Carla/Walker/WalkerBase.h" #include "GameFramework/CharacterMovementComponent.h" @@ -64,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -964,6 +966,41 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ } }; + + BIND_SYNC(send) << [this]( + cr::ActorId ActorId, + std::string message) -> R + { + REQUIRE_CARLA_EPISODE(); + FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId); + if (!CarlaActor) + { + return RespondError( + "send", + ECarlaServerResponse::ActorNotFound, + " Actor Id: " + FString::FromInt(ActorId)); + } + + if (CarlaActor->IsDormant()) + { + return RespondError( + "send", + ECarlaServerResponse::FunctionNotAvailiableWhenDormant, + " Actor Id: " + FString::FromInt(ActorId)); + } + ACustomV2XSensor* Sensor = Cast(CarlaActor->GetActor()); + if (!Sensor) + { + return RespondError( + "send", + ECarlaServerResponse::ActorTypeMismatch, + " Actor Id: " + FString::FromInt(ActorId)); + } + + Sensor->Send(cr::ToFString(message)); + return R::Success(); + }; + // ~~ Actor physics ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ BIND_SYNC(set_actor_location) << [this]( @@ -2209,6 +2246,31 @@ BIND_SYNC(is_sensor_enabled_for_ros) << [this](carla::streaming::detail::stream_ return R::Success(); }; + BIND_SYNC(get_telemetry_data) << [this]( + cr::ActorId ActorId) -> R + { + REQUIRE_CARLA_EPISODE(); + FCarlaActor* CarlaActor = Episode->FindCarlaActor(ActorId); + if (!CarlaActor) + { + return RespondError( + "get_telemetry_data", + ECarlaServerResponse::ActorNotFound, + " Actor Id: " + FString::FromInt(ActorId)); + } + FVehicleTelemetryData TelemetryData; + ECarlaServerResponse Response = + CarlaActor->GetVehicleTelemetryData(TelemetryData); + if (Response != ECarlaServerResponse::Success) + { + return RespondError( + "get_telemetry_data", + Response, + " Actor Id: " + FString::FromInt(ActorId)); + } + return cr::VehicleTelemetryData(TelemetryData); + }; + BIND_SYNC(show_vehicle_debug_telemetry) << [this]( cr::ActorId ActorId, bool bEnabled) -> R diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp index 22a025444..dbcc64449 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.cpp @@ -814,6 +814,56 @@ void ACarlaWheeledVehicle::DeactivateVelocityControl() VelocityControl->Deactivate(); } +FVehicleTelemetryData ACarlaWheeledVehicle::GetVehicleTelemetryData() const +{ + FVehicleTelemetryData TelemetryData; + + auto *MovementComponent = GetVehicleMovement(); + + // Vehicle telemetry data + TelemetryData.Speed = GetVehicleForwardSpeed() / 100.0f; // From cm/s to m/s + TelemetryData.Steer = LastAppliedControl.Steer; + TelemetryData.Throttle = LastAppliedControl.Throttle; + TelemetryData.Brake = LastAppliedControl.Brake; + TelemetryData.EngineRPM = MovementComponent->GetEngineRotationSpeed(); + TelemetryData.Gear = GetVehicleCurrentGear(); + TelemetryData.Drag = MovementComponent->DebugDragMagnitude / 100.0f; // kg*cm/s2 to Kg*m/s2 + + // Wheels telemetry data + FPhysXVehicleManager* MyVehicleManager = FPhysXVehicleManager::GetVehicleManagerFromScene(GetWorld()->GetPhysicsScene()); + + SCOPED_SCENE_READ_LOCK(MyVehicleManager->GetScene()); + PxWheelQueryResult* WheelsStates = MyVehicleManager->GetWheelsStates_AssumesLocked(MovementComponent); + check(WheelsStates); + + TArray Wheels; + for (uint32 w = 0; w < MovementComponent->PVehicle->mWheelsSimData.getNbWheels(); ++w) + { + FWheelTelemetryData WheelTelemetryData; + + WheelTelemetryData.TireFriction = WheelsStates[w].tireFriction; + WheelTelemetryData.LatSlip = FMath::RadiansToDegrees(WheelsStates[w].lateralSlip); + WheelTelemetryData.LongSlip = WheelsStates[w].longitudinalSlip; + WheelTelemetryData.Omega = MovementComponent->PVehicle->mWheelsDynData.getWheelRotationSpeed(w); + + UVehicleWheel* Wheel = MovementComponent->Wheels[w]; + WheelTelemetryData.TireLoad = Wheel->DebugTireLoad / 100.0f; + WheelTelemetryData.NormalizedTireLoad = Wheel->DebugNormalizedTireLoad; + WheelTelemetryData.Torque = Wheel->DebugWheelTorque / (100.0f * 100.0f); // From cm2 to m2 + WheelTelemetryData.LongForce = Wheel->DebugLongForce / 100.f; + WheelTelemetryData.LatForce = Wheel->DebugLatForce / 100.f; + WheelTelemetryData.NormalizedLongForce = (FMath::Abs(WheelTelemetryData.LongForce)*WheelTelemetryData.NormalizedTireLoad) / (WheelTelemetryData.TireLoad); + WheelTelemetryData.NormalizedLatForce = (FMath::Abs(WheelTelemetryData.LatForce)*WheelTelemetryData.NormalizedTireLoad) / (WheelTelemetryData.TireLoad); + + Wheels.Add(WheelTelemetryData); + } + + TelemetryData.Wheels = Wheels; + + return TelemetryData; + +} + void ACarlaWheeledVehicle::ShowDebugTelemetry(bool Enabled) { if (GetWorld()->GetFirstPlayerController()) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h index 0f5b4fea8..ae10be15f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CarlaWheeledVehicle.h @@ -16,6 +16,7 @@ #include "Vehicle/VehicleLightState.h" #include "Vehicle/VehicleInputPriority.h" #include "Vehicle/VehiclePhysicsControl.h" +#include "Vehicle/VehicleTelemetryData.h" #include "VehicleVelocityControl.h" #include "WheeledVehicleMovementComponent4W.h" #include "WheeledVehicleMovementComponentNW.h" @@ -240,6 +241,9 @@ public: UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) void DeactivateVelocityControl(); + UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) + FVehicleTelemetryData GetVehicleTelemetryData() const; + UFUNCTION(Category = "CARLA Wheeled Vehicle", BlueprintCallable) void ShowDebugTelemetry(bool Enabled); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp index 62a994b51..e199f46bf 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp @@ -1310,13 +1310,13 @@ void UCustomTerrainPhysicsComponent::BeginPlay() SparseMap.SavePath = SavePath; // Creating the FileManager IPlatformFile& FileManager = FPlatformFileManager::Get().GetPlatformFile(); - if( FileManager.CreateDirectory(*SavePath)){ + /*if( FileManager.CreateDirectory(*SavePath)){ UE_LOG(LogCarla, Warning, TEXT("Folder was created at %s"), *SavePath); }else{ UE_LOG(LogCarla, Error, TEXT("Folder was not created at %s"), *SavePath); - } + }*/ if(bUseDeformationPlane){ DeformationPlaneActor = GetWorld()->SpawnActor(); diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehicleTelemetryData.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehicleTelemetryData.h new file mode 100644 index 000000000..b5c5aeb0e --- /dev/null +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/VehicleTelemetryData.h @@ -0,0 +1,78 @@ +// Copyright (c) 2022 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "VehicleTelemetryData.generated.h" + +USTRUCT(BlueprintType) +struct FWheelTelemetryData +{ + GENERATED_USTRUCT_BODY() + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float TireFriction = 0.0f; + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float LatSlip = 0.0f; // degrees + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float LongSlip = 0.0f; + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Omega = 0.0f; + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float TireLoad = 0.0f; + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float NormalizedTireLoad = 0.0f; + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Torque = 0.0f; // [Nm] + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float LongForce = 0.0f; // [N] + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float LatForce = 0.0f; // [N] + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float NormalizedLongForce = 0.0f; + + UPROPERTY(Category = "Wheel Telemetry Data", EditAnywhere, BlueprintReadWrite) + float NormalizedLatForce = 0.0f; +}; + +USTRUCT(BlueprintType) +struct CARLA_API FVehicleTelemetryData +{ + GENERATED_BODY() + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Speed = 0.0f; // [m/s] + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Steer = 0.0f; + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Throttle = 0.0f; + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Brake = 0.0f; + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + float EngineRPM = 0.0f; + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + int32 Gear = 0.0f; + + UPROPERTY(Category = "Vehicle Telemetry Data", EditAnywhere, BlueprintReadWrite) + float Drag = 0.0f; // [N] + + UPROPERTY(Category = "Vehicle Engine Physics Control", EditAnywhere, BlueprintReadWrite) + TArray Wheels; +}; diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.cpp index 598bfd4bc..9bae6381b 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.cpp @@ -5,3 +5,9 @@ // For a copy, see . #include "WalkerBase.h" + + +AWalkerBase::AWalkerBase(const FObjectInitializer &ObjectInitializer) + : Super(ObjectInitializer) +{ +} \ No newline at end of file diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h index 676569ed4..1ac0014f4 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h @@ -16,6 +16,7 @@ class CARLA_API AWalkerBase : public ACharacter GENERATED_BODY() + AWalkerBase(const FObjectInitializer &ObjectInitializer); public: UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere) @@ -24,6 +25,9 @@ public: UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere) float AfterLifeSpan = 10.0f; + UPROPERTY(Category="Walker Base", BlueprintReadWrite, EditAnywhere) + bool bUsesWheelChair = false; + UFUNCTION(BlueprintCallable) void StartDeathLifeSpan() { diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/BP_OpenDriveToMap.uasset b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/BP_OpenDriveToMap.uasset index 94bee4e50..255471a5f 100644 Binary files a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/BP_OpenDriveToMap.uasset and b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/BP_OpenDriveToMap.uasset differ diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/Blueprints/BP_BuildingGenerator.uasset b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/Blueprints/BP_BuildingGenerator.uasset index 0e6e56b65..548e86b22 100644 Binary files a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/Blueprints/BP_BuildingGenerator.uasset and b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/OnroadMapGenerator/Blueprints/BP_BuildingGenerator.uasset differ diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/Python/generate_tile.py b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/Python/generate_tile.py index e68a03b11..d0ae1126b 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Content/Python/generate_tile.py +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Content/Python/generate_tile.py @@ -30,9 +30,10 @@ if os.name == "nt": editor_path = "%s/Engine/Binaries/%s/UE4Editor" % (ue4_path, sys_name) command = [editor_path, uproject_path, run] command.extend(arguments) + full_command = editor_path + " " + uproject_path + " " + run + " " + arguments print("Commandlet:", command) print("Arguments:", arguments) - subprocess.check_call(command, shell=True) + subprocess.check_call(full_command, shell=True) elif os.name == "posix": sys_name = "Linux" editor_path = "%s/Engine/Binaries/%s/UE4Editor" % (ue4_path, sys_name) diff --git a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/OpenDriveToMap.cpp b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/OpenDriveToMap.cpp index a3049125b..d1bee7cb7 100644 --- a/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/OpenDriveToMap.cpp +++ b/Unreal/CarlaUE4/Plugins/CarlaTools/Source/CarlaTools/Private/OpenDriveToMap.cpp @@ -293,11 +293,13 @@ AActor* UOpenDriveToMap::SpawnActorWithCheckNoCollisions(UClass* ActorClassToSpa void UOpenDriveToMap::GenerateTileStandalone(){ UE_LOG(LogCarlaToolsMapGenerator, Log, TEXT("UOpenDriveToMap::GenerateTileStandalone Function called")); +#if PLATFORM_WINDOWS + GenerateTile(); +#else ExecuteTileCommandlet(); - +#endif UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true); UEditorLevelLibrary::SaveCurrentLevel(); - } void UOpenDriveToMap::GenerateTile(){ @@ -361,7 +363,10 @@ void UOpenDriveToMap::GenerateTile(){ UEditorLoadingAndSavingUtils::SaveDirtyPackages(true, true); UEditorLevelLibrary::SaveCurrentLevel(); +#if PLATFORM_LINUX RemoveFromRoot(); +#endif + } } diff --git a/Util/BuildTools/BuildCarlaUE4.bat b/Util/BuildTools/BuildCarlaUE4.bat index cce890090..cf475cf27 100644 --- a/Util/BuildTools/BuildCarlaUE4.bat +++ b/Util/BuildTools/BuildCarlaUE4.bat @@ -110,6 +110,7 @@ if %REMOVE_INTERMEDIATE% == true ( "%UE4_PROJECT_FOLDER%Intermediate", "%UE4_PROJECT_FOLDER%Plugins\Carla\Binaries", "%UE4_PROJECT_FOLDER%Plugins\Carla\Intermediate", + "%UE4_PROJECT_FOLDER%Plugins\HoudiniEngine\", "%UE4_PROJECT_FOLDER%.vs" ) do ( if exist %%G ( diff --git a/Util/BuildTools/BuildCarlaUE4.sh b/Util/BuildTools/BuildCarlaUE4.sh index 19f204447..4db570edb 100755 --- a/Util/BuildTools/BuildCarlaUE4.sh +++ b/Util/BuildTools/BuildCarlaUE4.sh @@ -128,6 +128,10 @@ if ${REMOVE_INTERMEDIATE} ; then rm -Rf ${UE4_INTERMEDIATE_FOLDERS} + cd Plugins + rm -Rf HoudiniEngine + cd .. + popd >/dev/null fi diff --git a/Util/BuildTools/BuildOSM2ODR.bat b/Util/BuildTools/BuildOSM2ODR.bat index 7d2a7df60..77a4eff2b 100644 --- a/Util/BuildTools/BuildOSM2ODR.bat +++ b/Util/BuildTools/BuildOSM2ODR.bat @@ -71,7 +71,7 @@ rem ============================================================================ rem Set the visual studio solution directory rem set OSM2ODR_VSPROJECT_PATH=%INSTALLATION_DIR:/=\%osm2odr-visualstudio\ -set OSM2ODR_SOURCE_PATH=%INSTALLATION_DIR:/=\%om2odr-source\ +set OSM2ODR_SOURCE_PATH=%INSTALLATION_DIR:/=\%osm2odr-source\ set OSM2ODR_INSTALL_PATH=%ROOT_PATH:/=\%PythonAPI\carla\dependencies\ set OSM2ODR__SERVER_INSTALL_PATH=%ROOT_PATH:/=\%Unreal\CarlaUE4\Plugins\Carla\CarlaDependencies set CARLA_DEPENDENCIES_FOLDER=%ROOT_PATH:/=\%Unreal\CarlaUE4\Plugins\Carla\CarlaDependencies\ @@ -92,24 +92,19 @@ if %REMOVE_INTERMEDIATE% == true ( rem Build OSM2ODR if %BUILD_OSM2ODR% == true ( - - if %GIT_PULL% == true ( - if not exist "%OSM2ODR_SOURCE_PATH%" git clone -b %OSM2ODR_BRANCH% %OSM2ODR_REPO% %OSM2ODR_SOURCE_PATH% - cd "%OSM2ODR_SOURCE_PATH%" - git fetch - git checkout %CURRENT_OSM2ODR_COMMIT% + cd "%INSTALLATION_DIR%" + if not exist "%OSM2ODR_SOURCE_PATH%" ( + curl --retry 5 --retry-max-time 120 -L -o OSM2ODR.zip https://github.com/carla-simulator/sumo/archive/%CURRENT_OSM2ODR_COMMIT%.zip + tar -xf OSM2ODR.zip + del OSM2ODR.zip + ren sumo-%CURRENT_OSM2ODR_COMMIT% osm2odr-source ) - + + cd .. if not exist "%OSM2ODR_VSPROJECT_PATH%" mkdir "%OSM2ODR_VSPROJECT_PATH%" cd "%OSM2ODR_VSPROJECT_PATH%" - echo.%GENERATOR% | findstr /C:"Visual Studio" >nul && ( - set PLATFORM=-A x64 - ) || ( - set PLATFORM= - ) - - cmake -G %GENERATOR% %PLATFORM%^ + cmake -G %GENERATOR% -A x64^ -DCMAKE_CXX_FLAGS_RELEASE="/MD /MP"^ -DCMAKE_INSTALL_PREFIX="%OSM2ODR_INSTALL_PATH:\=/%"^ -DPROJ_INCLUDE_DIR=%INSTALLATION_DIR:/=\%\proj-install\include^ diff --git a/Util/BuildTools/BuildOSM2ODR.sh b/Util/BuildTools/BuildOSM2ODR.sh index 61e7d449f..6264c9a2f 100755 --- a/Util/BuildTools/BuildOSM2ODR.sh +++ b/Util/BuildTools/BuildOSM2ODR.sh @@ -76,19 +76,18 @@ fi if ${BUILD_OSM2ODR} ; then log "Building OSM2ODR." - # [ ! -d ${OSM2ODR_BUILD_FOLDER} ] && mkdir ${OSM2ODR_BUILD_FOLDER} - if ${GIT_PULL} ; then - if [ ! -d ${OSM2ODR_SOURCE_FOLDER} ] ; then - git clone -b ${OSM2ODR_BRANCH} ${OSM2ODR_REPO} ${OSM2ODR_SOURCE_FOLDER} - fi - cd ${OSM2ODR_SOURCE_FOLDER} - git fetch - git checkout ${CURRENT_OSM2ODR_COMMIT} + if [ ! -d ${OSM2ODR_SOURCE_FOLDER} ] ; then + cd ${CARLA_BUILD_FOLDER} + curl --retry 5 --retry-max-time 120 -L -o OSM2ODR.zip https://github.com/carla-simulator/sumo/archive/${CURRENT_OSM2ODR_COMMIT}.zip + unzip -qq OSM2ODR.zip + rm -f OSM2ODR.zip + mv sumo-${CURRENT_OSM2ODR_COMMIT} ${OSM2ODR_SOURCE_FOLDER} fi mkdir -p ${OSM2ODR_BUILD_FOLDER} cd ${OSM2ODR_BUILD_FOLDER} + export CC="$UE4_ROOT/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang" export CXX="$UE4_ROOT/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang++" export PATH="$UE4_ROOT/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v17_clang-10.0.1-centos7/x86_64-unknown-linux-gnu/bin:$PATH" diff --git a/Util/BuildTools/BuildPythonAPI.sh b/Util/BuildTools/BuildPythonAPI.sh index 8a46145de..f5bbb5c61 100755 --- a/Util/BuildTools/BuildPythonAPI.sh +++ b/Util/BuildTools/BuildPythonAPI.sh @@ -105,7 +105,7 @@ if ${BUILD_PYTHONAPI} ; then cp dist/.tmp/$(ls dist/.tmp | grep .whl) dist else /usr/bin/env python${PY_VERSION} setup.py bdist_egg bdist_wheel --dist-dir dist/.tmp --plat ${TARGET_WHEEL_PLATFORM} - /usr/bin/env python3 -m auditwheel repair --plat ${TARGET_WHEEL_PLATFORM} --wheel-dir dist dist/.tmp/$(ls dist/.tmp | grep .whl) + /usr/bin/env python${PY_VERSION} -m auditwheel repair --plat ${TARGET_WHEEL_PLATFORM} --wheel-dir dist dist/.tmp/$(ls dist/.tmp | grep .whl) fi rm -rf dist/.tmp diff --git a/Util/BuildTools/Setup.sh b/Util/BuildTools/Setup.sh index e91d149d7..64774d017 100755 --- a/Util/BuildTools/Setup.sh +++ b/Util/BuildTools/Setup.sh @@ -94,16 +94,16 @@ for PY_VERSION in ${PY_VERSION_LIST[@]} ; do log "Retrieving boost." start=$(date +%s) - wget "https://archives.boost.io/release/${BOOST_VERSION}/source/${BOOST_PACKAGE_BASENAME}.tar.gz" || true + wget "https://archives.boost.io/release/${BOOST_VERSION}/source/${BOOST_PACKAGE_BASENAME}.tar.gz" -O ${BOOST_PACKAGE_BASENAME}.tar.gz || true end=$(date +%s) echo "Elapsed Time downloading from boost webpage: $(($end-$start)) seconds" # try to use the backup boost we have in Jenkins - if [ ! -f "${BOOST_PACKAGE_BASENAME}.tar.gz" ] || [[ $(sha256sum "${BOOST_PACKAGE_BASENAME}.tar.gz") != "${BOOST_SHA256SUM}" ]] ; then + if [ ! -f "${BOOST_PACKAGE_BASENAME}.tar.gz" ] || [[ $(sha256sum "${BOOST_PACKAGE_BASENAME}.tar.gz" | cut -d " " -f 1 ) != "${BOOST_SHA256SUM}" ]] ; then log "Using boost backup" start=$(date +%s) - wget "https://carla-releases.s3.us-east-005.backblazeb2.com/Backup/${BOOST_PACKAGE_BASENAME}.tar.gz" || true + wget "https://carla-releases.s3.us-east-005.backblazeb2.com/Backup/${BOOST_PACKAGE_BASENAME}.tar.gz" -O ${BOOST_PACKAGE_BASENAME}.tar.gz || true end=$(date +%s) echo "Elapsed Time downloading from boost carla backup in backblaze: $(($end-$start)) seconds"