Skip to content

Commit 43441c7

Browse files
BlyronMattRoweEAIFglopezdiestglopezdiestMinokori
authored
Dev (#8185)
* 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 <[email protected]> * 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 <[email protected]> Co-authored-by: glopezdiest <[email protected]> Co-authored-by: glopezdiest <[email protected]> Co-authored-by: Minokori <[email protected]> Co-authored-by: Daniel <[email protected]> Co-authored-by: AreopagX <[email protected]> Co-authored-by: Jorge Virgos <[email protected]> Co-authored-by: Sergio Paniego Blanco <[email protected]> Co-authored-by: Ylmdrin <[email protected]>
1 parent b013f17 commit 43441c7

File tree

19 files changed

+6015
-27
lines changed

19 files changed

+6015
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Latest Changes
2+
* Fixed a bug that caused navigation information not to be loaded when switching maps
23
* Prevent from segfault on failing SignalReference identification when loading OpenDrive files
34
* Added vehicle doors to the recorder
45
* Added functions to get actor' components transform
@@ -18,6 +19,7 @@
1819
* PythonAPI `Sensor.is_listening` was defined twice (property and method), cleaned and clarified it as a method.
1920
* Added V2X sensors for cooperative awareness message and custom user-defined messages to support vehicle-to-vehicle communication
2021
* Added named tuples for BasicAgent.py's detection result to allow for type-hints and better semantics.
22+
* Added type-hint support for the PythonAPI
2123

2224

2325
## CARLA 0.9.15

Docs/adv_cpp_client.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# C++ client example
2+
3+
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.
4+
5+
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`.
6+
7+
This C++ example will connect to the server, spawn a vehicle and apply a command to the vehicle before destroying it and terminating.
8+
9+
### Include the relevant header files
10+
11+
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:
12+
13+
```cpp
14+
#include <iostream>
15+
#include <random>
16+
#include <sstream>
17+
#include <stdexcept>
18+
#include <string>
19+
#include <thread>
20+
#include <tuple>
21+
22+
#include <carla/client/ActorBlueprint.h>
23+
#include <carla/client/BlueprintLibrary.h>
24+
#include <carla/client/Client.h>
25+
#include <carla/client/Map.h>
26+
#include <carla/client/Sensor.h>
27+
#include <carla/client/TimeoutException.h>
28+
#include <carla/client/World.h>
29+
#include <carla/geom/Transform.h>
30+
#include <carla/image/ImageIO.h>
31+
#include <carla/image/ImageView.h>
32+
#include <carla/sensor/data/Image.h>
33+
34+
```
35+
36+
### Connecting the C++ client to the server
37+
38+
Include `carla/client/Client.h` and then connect the client:
39+
40+
```cpp
41+
...
42+
#include <carla/client/Client.h>
43+
...
44+
int main(int argc, const char *argv[]) {
45+
46+
std::string host;
47+
uint16_t port;
48+
std::tie(host, port) = ParseArguments(argc, argv);
49+
...
50+
// Connect the client to the server
51+
auto client = cc::Client(host, port);
52+
client.SetTimeout(40s);
53+
```
54+
55+
### Load a map
56+
57+
Now let's load a randomly chosen map:
58+
59+
```cpp
60+
// Initialize random number generator
61+
std::mt19937_64 rng((std::random_device())());
62+
...
63+
auto town_name = RandomChoice(client.GetAvailableMaps(), rng);
64+
std::cout << "Loading world: " << town_name << std::endl;
65+
auto world = client.LoadWorld(town_name);
66+
```
67+
68+
### Spawn a randomly chosen vehicle
69+
70+
Next we will fetch the blueprint library, filter for vehicles and choose a random vehicle blueprint:
71+
72+
```cpp
73+
auto blueprint_library = world.GetBlueprintLibrary();
74+
auto vehicles = blueprint_library->Filter("vehicle");
75+
auto blueprint = RandomChoice(*vehicles, rng);
76+
```
77+
78+
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):
79+
80+
```cpp
81+
auto map = world.GetMap();
82+
auto transform = RandomChoice(map->GetRecommendedSpawnPoints(), rng);
83+
```
84+
85+
Now we have the blueprint and spawn location, we can now spawn the vehicle using the `world.SpawnActor(...)` method:
86+
87+
```cpp
88+
auto actor = world.SpawnActor(blueprint, transform);
89+
std::cout << "Spawned " << actor->GetDisplayId() << '\n';
90+
// Retrieve a pointer to the vehicle object
91+
auto vehicle = boost::static_pointer_cast<cc::Vehicle>(actor);
92+
```
93+
94+
### Apply a control
95+
96+
Let's now apply some control to the vehicle to move it using the `ApplyControl(...)` method:
97+
98+
```cpp
99+
cc::Vehicle::Control control;
100+
control.throttle = 1.0f;
101+
vehicle->ApplyControl(control);
102+
```
103+
104+
Now we will relocate the spectator so that we can see our newly spawned vehicle in the map:
105+
106+
```cpp
107+
auto spectator = world.GetSpectator();
108+
// Adjust the transform to look
109+
transform.location += 32.0f * transform.GetForwardVector();
110+
transform.location.z += 2.0f;
111+
transform.rotation.yaw += 180.0f;
112+
transform.rotation.pitch = -15.0f;
113+
// Now set the spectator transform
114+
spectator->SetTransform(transform);
115+
```
116+
117+
We'll also sleep the process for 10 seconds to observe the simulation shortly, before the client closes:
118+
119+
120+
```cpp
121+
std::this_thread::sleep_for(10s);
122+
123+
```
124+
125+
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.
126+
127+
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:
128+
129+
```make
130+
CARLADIR=$(CURDIR)/../..
131+
BUILDDIR=$(CURDIR)/build
132+
BINDIR=$(CURDIR)/bin
133+
INSTALLDIR=$(CURDIR)/libcarla-install
134+
TOOLCHAIN=$(CURDIR)/ToolChain.cmake
135+
```
136+
137+
138+
139+
140+
141+
142+

Docs/adv_digital_twin.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
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.
1717

18+
<iframe width="100%" height="400px" src="https://www.youtube.com/embed/gTutXdS2UkQ?si=hssM3YRCAjSIzdXM" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
19+
1820
## Building the OSM renderer
1921

2022
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:

Docs/build_linux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pip3 install --user -Iv setuptools==47.3.1 &&
129129
pip install --user distro &&
130130
pip3 install --user distro &&
131131
pip install --user wheel &&
132-
pip3 install --user wheel auditwheel
132+
pip3 install --user wheel auditwheel==4.0.0
133133
```
134134

135135
---

Docs/build_linux_ue5.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,8 @@ If you want to install the Python API corresponding to the package you have buil
8888

8989
```sh
9090
pip3 install PythonAPI/carla/dist/carla-*.whl
91-
```
91+
```
92+
93+
## Additional build targets
94+
95+
The procedure outlined above will download all necessary components to build CARLA, you may not want to

Docs/cpp_client_cmake_windows.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
```make
2+
cmake_minimum_required(VERSION 3.5.1)
3+
project(example)
4+
5+
link_directories(
6+
${RPCLIB_LIB_PATH})
7+
8+
file(GLOB example_sources "*.cpp" "*.h")
9+
10+
file(GLOB example_client_sources "")
11+
12+
set(carla_config client)
13+
list(APPEND build_targets example_${carla_config}_debug)
14+
15+
# Create targets for debug and release in the same build type.
16+
foreach(target ${build_targets})
17+
18+
add_executable(${target} ${example_sources})
19+
20+
target_compile_definitions(${target} PUBLIC
21+
-DLIBCARLA_ENABLE_PROFILER)
22+
23+
target_include_directories(${target} SYSTEM PRIVATE
24+
"../../LibCarla/source"
25+
"../../Build/boost-1.80.0-install/include"
26+
"../../Build/rpclib-install/include/"
27+
"../../Build/recast-22dfcb-install/include/"
28+
"../../Build/zlib-install/include/"
29+
"../../Build/libpng-1.2.37-install/include/"
30+
"../../LibCarla/source/third-party/")
31+
32+
target_link_directories(${target} SYSTEM PRIVATE
33+
"../../Build/boost-1.80.0-install/lib"
34+
"../../Build/rpclib-install/lib/"
35+
"../../Build/recast-22dfcb-install/lib/"
36+
"../../Build/zlib-install/lib/"
37+
"../../Build/libcarla-visualstudio/LibCarla/cmake/client/Release/"
38+
"../../Build/libpng-1.2.37-install/lib/")
39+
40+
target_include_directories(${target} PRIVATE
41+
"${libcarla_source_path}/test")
42+
43+
if (WIN32)
44+
target_link_libraries(${target} "rpc.lib")
45+
target_link_libraries(${target} "carla_client.lib")
46+
target_link_libraries(${target} "DebugUtils.lib")
47+
target_link_libraries(${target} "Detour.lib")
48+
target_link_libraries(${target} "DetourCrowd.lib")
49+
target_link_libraries(${target} "DetourTileCache.lib")
50+
target_link_libraries(${target} "Recast.lib")
51+
target_link_libraries(${target} "Shlwapi.lib")
52+
else()
53+
target_link_libraries(${target} "-lrpc")
54+
endif()
55+
56+
install(TARGETS ${target} DESTINATION test OPTIONAL)
57+
endforeach(target)
58+
59+
if (LIBCARLA_BUILD_DEBUG)
60+
# Specific options for debug.
61+
set_target_properties(example_${carla_config}_debug PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
62+
target_link_libraries(example_${carla_config}_debug "carla_${carla_config}${carla_target_postfix}_debug")
63+
target_compile_definitions(example_${carla_config}_debug PUBLIC -DBOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
64+
if (CMAKE_BUILD_TYPE STREQUAL "Client")
65+
target_link_libraries(example_${carla_config}_debug "${BOOST_LIB_PATH}/libboost_filesystem.a")
66+
endif()
67+
endif()
68+
```

Docs/ref_cpp.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
# C++ Reference
2+
3+
## C++ client
4+
5+
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.
6+
7+
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.
8+
9+
Please see the [C++ client example](adv_cpp_client.md) for more details on this example script.
10+
11+
## C++ documentation
12+
213
We use Doxygen to generate the documentation of our C++ code:
314

415
[Libcarla/Source](http://carla.org/Doxygen/html/dir_b9166249188ce33115fd7d5eed1849f2.html)<br>

Docs/ref_sensors.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ Provides measures that accelerometer, gyroscope and compass would retrieve for t
186186
| `timestamp` | double | Simulation time of the measurement in seconds since the beginning of the episode. |
187187
| `transform` | [carla.Transform](<../python_api#carlatransform>) | Location and rotation in world coordinates of the sensor at the time of the measurement. |
188188
| `accelerometer` | [carla.Vector3D](<../python_api#carlavector3d>) | Measures linear acceleration in `m/s^2`. |
189-
| `gyroscope` | [carla.Vector3D](<../python_api#carlavector3d>) | Measures angular velocity in `rad/sec`. |
190-
| `compass` | float | Orientation in radians. North is `(0.0, -1.0, 0.0)` in UE. |
191-
189+
| `gyroscope` | [carla.Vector3D](<../python_api#carlavector3d>) | Measures angular velocity in `rad/s`. |
190+
| `compass` | float | Orientation in radians. North is 0 radians. |
192191

192+
!!! note
193+
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.
193194

194195
---
195196
## Lane invasion detector
@@ -735,7 +736,7 @@ The following tags are currently available (Note, tags changed from version 0.9.
735736
| `14` | Car | `(0, 0, 142)` | Cars, vans |
736737
| `15` | Truck | `(0, 0, 70)` | Trucks |
737738
| `16` | Bus | `(0, 60, 100)` | Busses |
738-
| `17` | Train | `(0, 60, 100)` | Trains |
739+
| `17` | Train | `(0, 80, 100)` | Trains |
739740
| `18` | Motorcycle | `(0, 0, 230)` | Motorcycle, Motorbike |
740741
| `19` | Bicycle | `(119, 11, 32)` | Bicylces |
741742
| `20` | Static | `(110, 190, 160)` | Elements in the scene and props that are immovable. <br> E.g. fire hydrants, fixed benches, fountains, bus stops, etc. |

LibCarla/source/carla/client/detail/Simulator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ namespace detail {
8888
const auto id = GetCurrentEpisode().GetId();
8989
_client.LoadEpisode(std::move(map_name), reset_settings, map_layers);
9090

91+
// delete the pointer to _episode so that the Navigation information
92+
// will be loaded for the correct map
93+
assert(_episode.use_count() == 1);
94+
_episode.reset();
95+
GetReadyCurrentEpisode();
96+
9197
// We are waiting 50ms for the server to reload the episode.
9298
// If in this time we have not detected a change of episode, we try again
9399
// 'number_of_attempts' times.

LibCarla/source/carla/streaming/detail/tcp/Client.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <boost/asio/connect.hpp>
1616
#include <boost/asio/read.hpp>
1717
#include <boost/asio/write.hpp>
18-
#include <boost/asio/post.hpp>
1918
#include <boost/asio/bind_executor.hpp>
2019

2120
#include <exception>
@@ -86,7 +85,6 @@ namespace tcp {
8685

8786
void Client::Connect() {
8887
auto self = shared_from_this();
89-
boost::asio::post(_strand, [this, self]() {
9088
if (_done) {
9189
return;
9290
}
@@ -139,18 +137,15 @@ namespace tcp {
139137

140138
log_debug("streaming client: connecting to", ep);
141139
_socket.async_connect(ep, boost::asio::bind_executor(_strand, handle_connect));
142-
});
143140
}
144141

145142
void Client::Stop() {
146143
_connection_timer.cancel();
147144
auto self = shared_from_this();
148-
boost::asio::post(_strand, [this, self]() {
149145
_done = true;
150146
if (_socket.is_open()) {
151147
_socket.close();
152148
}
153-
});
154149
}
155150

156151
void Client::Reconnect() {
@@ -165,7 +160,6 @@ namespace tcp {
165160

166161
void Client::ReadData() {
167162
auto self = shared_from_this();
168-
boost::asio::post(_strand, [this, self]() {
169163
if (_done) {
170164
return;
171165
}
@@ -182,7 +176,7 @@ namespace tcp {
182176
// Move the buffer to the callback function and start reading the next
183177
// piece of data.
184178
// log_debug("streaming client: success reading data, calling the callback");
185-
boost::asio::post(_strand, [self, message]() { self->_callback(message->pop()); });
179+
self->_callback(message->pop());
186180
ReadData();
187181
} else {
188182
// As usual, if anything fails start over from the very top.
@@ -219,7 +213,6 @@ namespace tcp {
219213
_socket,
220214
message->size_as_buffer(),
221215
boost::asio::bind_executor(_strand, handle_read_header));
222-
});
223216
}
224217

225218
} // namespace tcp

0 commit comments

Comments
 (0)