From 4952c747297561e0b348dd8faa21d256b41f6406 Mon Sep 17 00:00:00 2001 From: MattRoweEAIF <125647690+MattRoweEAIF@users.noreply.github.com> Date: Thu, 11 Jul 2024 14:40:52 +0200 Subject: [PATCH 1/6] added cpp client build docs (#7942) --- Docs/adv_cpp_client.md | 142 +++++++++++++++++++++++++++++++ Docs/build_linux_ue5.md | 6 +- Docs/cpp_client_cmake_windows.md | 68 +++++++++++++++ Docs/ref_cpp.md | 11 +++ 4 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 Docs/adv_cpp_client.md create mode 100644 Docs/cpp_client_cmake_windows.md 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/build_linux_ue5.md b/Docs/build_linux_ue5.md index 62a270441..54de572a3 100644 --- a/Docs/build_linux_ue5.md +++ b/Docs/build_linux_ue5.md @@ -88,4 +88,8 @@ If you want to install the Python API corresponding to the package you have buil ```sh pip3 install PythonAPI/carla/dist/carla-*.whl -``` \ No newline at end of file +``` + +## 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/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/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)
From 5c2d2978a8fe7a0602f35ad82605a6b40b2cf96b Mon Sep 17 00:00:00 2001 From: MattRoweEAIF <125647690+MattRoweEAIF@users.noreply.github.com> Date: Wed, 17 Jul 2024 12:33:47 +0200 Subject: [PATCH 2/6] fixed IMU units (#7960) --- Docs/ref_sensors.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Docs/ref_sensors.md b/Docs/ref_sensors.md index 5e1fd5e48..142798920 100644 --- a/Docs/ref_sensors.md +++ b/Docs/ref_sensors.md @@ -186,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 From 29fbcce198534f4ea471376d615e5eb0b451e26c Mon Sep 17 00:00:00 2001 From: MattRoweEAIF <125647690+MattRoweEAIF@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:02:13 +0200 Subject: [PATCH 3/6] Update README.md with new TinyURL links (#7988) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 From eeb507e5854bdf95a4712c6f6210c5dcb779f7f5 Mon Sep 17 00:00:00 2001 From: glopezdiest <58212725+glopezdiest@users.noreply.github.com> Date: Wed, 31 Jul 2024 10:37:32 +0200 Subject: [PATCH 4/6] Added inverse transform (#7999) Co-authored-by: glopezdiest --- PythonAPI/carla/source/libcarla/Geom.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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; From f2695a17d17432fee31bccfaa28bce33b0169b94 Mon Sep 17 00:00:00 2001 From: Blyron <53337103+Blyron@users.noreply.github.com> Date: Wed, 31 Jul 2024 13:10:11 +0200 Subject: [PATCH 5/6] Aaron/fixwheelchair (#8001) * Fix OSM2ODR build * Updated fix wheelchair default value --- PythonAPI/examples/generate_traffic.py | 3 +++ .../Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp | 4 ++-- .../Plugins/Carla/Source/Carla/Walker/WalkerBase.cpp | 6 ++++++ .../CarlaUE4/Plugins/Carla/Source/Carla/Walker/WalkerBase.h | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) 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/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp index 823859d4d..dd657d6c2 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Actor/ActorBlueprintFunctionLibrary.cpp @@ -1595,7 +1595,7 @@ void UActorBlueprintFunctionLibrary::MakePedestrianDefinition( Definition.Attributes.Emplace(FActorAttribute{ - TEXT("can_use_wheel_chair"), + TEXT("can_use_wheelchair"), EActorAttributeType::Bool, Parameters.bCanUseWheelChair ? TEXT("true") : TEXT("false") }); @@ -1626,7 +1626,7 @@ void UActorBlueprintFunctionLibrary::MakePedestrianDefinition( WheelChairVariation.Type = EActorAttributeType::Bool; if(bCanUseWheelChair) { - WheelChairVariation.RecommendedValues = { TEXT("true"), TEXT("false") }; + WheelChairVariation.RecommendedValues = { TEXT("false"), TEXT("true") }; } else { 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 5990bceeb..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) From 1ef3f55c9555de401681cb26ce87f81718943624 Mon Sep 17 00:00:00 2001 From: MattRoweEAIF <125647690+MattRoweEAIF@users.noreply.github.com> Date: Wed, 31 Jul 2024 15:23:11 +0200 Subject: [PATCH 6/6] Docs/unit updates (#8007) * fixed IMU units * updated autitwheel version --- Docs/build_linux.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ``` ---