-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added cpp client build docs (#7942) * fixed IMU units (#7960) * Update README.md with new TinyURL links (#7988) * Added inverse transform (#7999) Co-authored-by: glopezdiest <glopez@cvc.uab.cat> * Aaron/fixwheelchair (#8001) * Fix OSM2ODR build * Updated fix wheelchair default value * Docs/unit updates (#8007) * fixed IMU units * updated autitwheel version * Add a `*.pyi` file for auto-completion & hints. To enable auto-completion and hints in code editors such as VScode, create a `*.pyi` file. This feature is compatible with `python 3.9` and later versions. * Fixes and missing Iterators * Fixed Actor.parent Can be None or an Actor * Fixed missing return types * Updated changelog needs merge with dev version * Added DSVEventArray iterator * Added missing type for Labelled Point * Fixed spelling misstakes * Removed wrong unit indication * Added missing -> World to load_world * Added missing return value to reload_world * FIX: __init__ methods do not return * FIX: added ApplyTransform, fixed ApplyTorque * Filled in missing information and types. * ActorList.filter actually returns ActorList * Fixed CityObjectLabels * Disambiguated get_waypoint signature Syntax fix (squased) * Added undocumented variables FutureActor laod_world_if_different * Corrected Sensor.is_listening Was changed to a function in 0.9.15. More info see: #7439 * Added type hints for `values` attribute on enums * Fix intendation shadowing methods * Fix missing @Property * Formatted some docstring to be shorter * Added stubs for HUD drawing Functions from #7168 * Corrected and more precise type-hints - fixed carla.Waypoint.next_until_lane_end * Improved get_waypoint disambiguation correctly added two overload function * Fix spelling mistakes * Better usage of Enum if typing.Self is availiable Using Self will not report an override / incompatible error. * Fix: Enum values were tuples. Added Flag or Int to Enums * Fixes for wrong stubs - OpendriveGenerationParameter had no init - missing @Property - wrong signatures * Added self parameter to property signatures * Various fixes - wrong signatures - wrong names * Added setters for VehicleControl * Improved get_waypoints and Literal type hints * Corrected [try_]spawn_actor keyword name * Added Transform.inverse_transform and corrected signature parameter is called in_point not in_vector * Improved Callable and callbacks signature * Corrections and additions more setters missing, wrong types corrected spelling * Fixed Vector arithmetic * added digital twins video (#8090) * navigation information is now loaded when changing maps * Porting the changes done to UE5 to fix the recording leak to UE4 The slowdown is considerably more noticeable here since the engine runs much smoother. This makes evident that this is a stopgap measure, and should be looked into further down the line. * Fixed typo in CityScapes palette (#8137) * Correcting makefile typo to avoid override warning for target "downloadplugins" (#8167) The downloadplugins target is already defined below (line 162). --------- Co-authored-by: MattRoweEAIF <125647690+MattRoweEAIF@users.noreply.github.com> Co-authored-by: glopezdiest <58212725+glopezdiest@users.noreply.github.com> Co-authored-by: glopezdiest <glopez@cvc.uab.cat> Co-authored-by: Minokori <73998474+Minokori@users.noreply.github.com> Co-authored-by: Daniel <github.blurry@9ox.net> Co-authored-by: AreopagX <49414432+AreopagX@users.noreply.github.com> Co-authored-by: Jorge Virgos <jorgevirgos.dev@gmail.com> Co-authored-by: Sergio Paniego Blanco <sergiopaniegoblanco@gmail.com> Co-authored-by: Ylmdrin <150919430+Ylmdrin@users.noreply.github.com>
- Loading branch information
1 parent
b013f17
commit 43441c7
Showing
19 changed files
with
6,015 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <iostream> | ||
#include <random> | ||
#include <sstream> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <thread> | ||
#include <tuple> | ||
|
||
#include <carla/client/ActorBlueprint.h> | ||
#include <carla/client/BlueprintLibrary.h> | ||
#include <carla/client/Client.h> | ||
#include <carla/client/Map.h> | ||
#include <carla/client/Sensor.h> | ||
#include <carla/client/TimeoutException.h> | ||
#include <carla/client/World.h> | ||
#include <carla/geom/Transform.h> | ||
#include <carla/image/ImageIO.h> | ||
#include <carla/image/ImageView.h> | ||
#include <carla/sensor/data/Image.h> | ||
|
||
``` | ||
|
||
### Connecting the C++ client to the server | ||
|
||
Include `carla/client/Client.h` and then connect the client: | ||
|
||
```cpp | ||
... | ||
#include <carla/client/Client.h> | ||
... | ||
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<cc::Vehicle>(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 | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.