Skip to content

Commit 3de7c09

Browse files
committed
Extend ROS2 support Step 3: Rework ROS2 handling
This commit is extending the built-in ROS2 support of CARLA: - the internal interface is simplified and object oriented to allow easier ROS2 extensions in future and reduce code duplication - the sensor/actor stream existing for the TCP counterparts are used in a shared manner, which results in lower processing overhead and requires little individual code changes for ROS2 within UE-sensors - enable Boost and Asio exceptions for FastDDS to ensure properly - additional service interfaces are provided to control CARLA directly from ROS2 (Map, Blueprint and Episode handling, Spawn/DestroyObject) - convenient interfaces previously available via carla_ros_bridge are provided (e.g. pseudo sensors, object messages, traffic light/sign, actor/sensor lists) - new interfaces like e.g. CarlaVehicleTelemetryData, V2X, SynchronizationWindow,... - get detailed vehicle meshes as exact ground truth for e.g. LiDAR perception - Vehicle publisher implements a variety of individual publishers to mimick also old ROS-bridge convenient publisher: + CarlaVehicleInfo + CarlaVehicleControlStatus + Speed + Odometry + Object + ObjectWithCovariance + VehicleTelemetryData - Vehicle subscribers: + VehicleControlSubscriber + AckermannControlSubscriber, + SetTransformSubscriber - use of c++17 to support std::sample() usage - Dynamic switching on ROS visibility is possible for all actors now - Default startup behavior is selectable by ROS2TopicVisibility parameter in DefaultGame.ini: If true, then all and every topic that is currently offered by the implementation is visible from the beginning. If false, then only the sensors/actors created via the Client- or ROS-Interface are visible by defaults. Others can be activated via EnableForRos() calls (this allows for disabling interfaces e.g. for leaderboard) - ensure multiple service calls at once are working: + qos history kind eprosima::fastdds::dds::KEEP_ALL_HISTORY_QOS + qos reliablility kind eprosima::fastdds::dds::RELIABLE_RELIABILITY_QOS + qos durability kind eprosima::fastdds::dds::TRANSIENT_LOCAL_DURABILITY_QOS for reader, writer, topic - add set_transform() call to RGB Cameras - add odometry publisher to walkers - filter out invalid bounding boxes observed on a few traffic signs using bounding box transmission within object data
1 parent 8606f3c commit 3de7c09

File tree

920 files changed

+136919
-9453
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

920 files changed

+136919
-9453
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
* Improved V2X sensor capabilities: send complex custom user-defined data, support V2I sensors not attached to a vehicle
1111
* Introduced fine grained ServerSynchronization mechanism: each client decides for its own if it requires synchronization or not and provides its own synchronization window.
1212
Be aware: some existing code using master/slave sync mechanism might need rework. See also generate_traffic.py.
13-
13+
* ROS2Native: Extended functionality and performance of ROS2 support
14+
1415
## CARLA 0.9.16
1516

1617
* Added NVIDIA Cosmos Transfer1 integration
Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,97 @@
11
cmake_minimum_required(VERSION 3.5.1)
22
project(libcarla_fastdds)
33

4-
# Install headers.
5-
6-
file(GLOB libcarla_carla_fastdds_headers
7-
"${libcarla_source_path}/carla/ros2/*.h"
8-
"${libcarla_source_path}/carla/ros2/publishers/*.h"
9-
"${libcarla_source_path}/carla/ros2/subscribers/*.h"
10-
"${libcarla_source_path}/carla/ros2/listeners/*.h"
11-
"${libcarla_source_path}/carla/ros2/types/*.h"
4+
# Install the required public interface headers
5+
foreach(dir "" "types/" )
6+
file(GLOB libcarla_carla_ros2_public_headers
7+
"${libcarla_source_path}/carla/ros2/${dir}*.h"
128
)
13-
install(FILES ${libcarla_carla_fastdds_headers} DESTINATION include/carla/ros2)
14-
9+
install(FILES ${libcarla_carla_ros2_public_headers} DESTINATION include/carla/ros2/${dir})
10+
endforeach()
11+
12+
file(GLOB subdirs RELATIVE "${libcarla_source_path}/carla/ros2/fastdds" "${libcarla_source_path}/carla/ros2/fastdds/*")
13+
foreach(typedir "msg" "srv")
14+
foreach(dir ${subdirs})
15+
if(IS_DIRECTORY "${libcarla_source_path}/carla/ros2/fastdds/${dir}/${typedir}")
16+
file(GLOB libcarla_carla_ros2_types_${dir}_headers
17+
"${libcarla_source_path}/carla/ros2/fastdds/${dir}/${typedir}/*.h"
18+
"${libcarla_source_path}/carla/ros2/fastdds/${dir}/${typedir}/*.hpp"
19+
"${libcarla_source_path}/carla/ros2/fastdds/${dir}/${typedir}/*.ipp"
20+
)
21+
install(FILES ${libcarla_carla_ros2_types_${dir}_headers} DESTINATION include/carla/ros2/ros_types/${dir}/${typedir}/)
22+
endif()
23+
endforeach()
24+
endforeach()
25+
26+
# Install dependencies for UE4 build
1527
file(GLOB fast_dds_dependencies "${FASTDDS_LIB_PATH}/*.a")
1628
install(FILES ${fast_dds_dependencies} DESTINATION lib)
17-
18-
19-
file(GLOB libcarla_fastdds_sources
20-
"${libcarla_source_path}/carla/ros2/*.cpp"
21-
"${libcarla_source_path}/carla/ros2/publishers/*.cpp"
22-
"${libcarla_source_path}/carla/ros2/subscribers/*.cpp"
23-
"${libcarla_source_path}/carla/ros2/listeners/*.cpp"
24-
"${libcarla_source_path}/carla/ros2/types/*.cpp")
29+
file(GLOB fast_dds_include_dirs "${FASTDDS_INCLUDE_PATH}/*")
30+
foreach(fast_dds_include_dir ${fast_dds_include_dirs})
31+
install(DIRECTORY "${fast_dds_include_dir}" DESTINATION include)
32+
endforeach()
33+
34+
# Collect the sources
35+
foreach(ros2_dir
36+
"/"
37+
"fastdds/carla/ros2/impl/"
38+
"publishers/"
39+
"services/"
40+
"subscribers/"
41+
"types/")
42+
43+
file(GLOB sources "${libcarla_source_path}/carla/ros2/${ros2_dir}*.cpp")
44+
list(APPEND libcarla_fastdds_sources ${sources})
45+
endforeach()
46+
47+
file(GLOB msg_sources "${libcarla_source_path}/carla/ros2/fastdds/*/msg/*.cxx")
48+
list(APPEND libcarla_fastdds_sources ${msg_sources})
49+
50+
file(GLOB srv_sources "${libcarla_source_path}/carla/ros2/fastdds/*/srv/*.cxx")
51+
list(APPEND libcarla_fastdds_sources ${srv_sources})
2552

2653
# ==============================================================================
2754
# Create targets for debug and release in the same build type.
2855
# ==============================================================================
56+
set(libcarla_fastdds_include_directories
57+
# first the fastdds local folder allowing potential overrides of header files
58+
"${libcarla_source_path}/carla/ros2/fastdds"
59+
"${BOOST_INCLUDE_PATH}"
60+
"${RPCLIB_INCLUDE_PATH}"
61+
"${FASTDDS_INCLUDE_PATH}"
62+
"${libcarla_source_path}/carla/ros2"
63+
)
2964

3065
if (LIBCARLA_BUILD_RELEASE)
31-
add_library(carla_fastdds STATIC ${libcarla_fastdds_sources})
32-
33-
target_compile_options(carla_fastdds PRIVATE -fexceptions)
34-
66+
add_library(carla_fastdds STATIC
67+
${libcarla_fastdds_sources}
68+
)
3569
target_include_directories(carla_fastdds SYSTEM PRIVATE
36-
"${BOOST_INCLUDE_PATH}"
37-
"${RPCLIB_INCLUDE_PATH}")
38-
39-
target_include_directories(carla_fastdds PRIVATE "${FASTDDS_INCLUDE_PATH}")
40-
target_include_directories(carla_fastdds PRIVATE "${libcarla_source_path}/carla/ros2")
41-
target_link_libraries(carla_fastdds fastrtps fastcdr "${FAST_DDS_LIBRARIES}")
70+
${libcarla_fastdds_include_directories}
71+
)
72+
target_link_directories(carla_fastdds PRIVATE
73+
${FASTDDS_LIB_PATH}
74+
)
4275
install(TARGETS carla_fastdds DESTINATION lib)
43-
set_target_properties(carla_fastdds PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_RELEASE}")
44-
76+
if(NOT WIN32)
77+
set(CMAKE_CXX_FLAGS_RELEASE "-O3 ${CMAKE_CXX_FLAGS_RELEASE}" CACHE STRING "" FORCE)
78+
endif()
79+
set_target_properties(carla_fastdds PROPERTIES COMPILE_FLAGS
80+
"-fexceptions ${CMAKE_CXX_FLAGS_RELEASE}")
81+
target_compile_definitions(carla_fastdds PUBLIC
82+
WITH_ROS2 CARLA_SERVER_BUILD)
4583
endif()
4684

4785
if (LIBCARLA_BUILD_DEBUG)
48-
49-
add_library(carla_fastdds_debug STATIC ${libcarla_fastdds_sources})
50-
51-
target_compile_options(carla_fastdds_debug PRIVATE -fexceptions)
52-
86+
add_library(carla_fastdds_debug STATIC
87+
${libcarla_fastdds_sources}
88+
)
5389
target_include_directories(carla_fastdds_debug SYSTEM PRIVATE
54-
"${BOOST_INCLUDE_PATH}"
55-
"${RPCLIB_INCLUDE_PATH}")
90+
"${libcarla_fastdds_include_directories}"
91+
)
5692
install(TARGETS carla_fastdds_debug DESTINATION lib)
57-
set_target_properties(carla_fastdds_debug PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}")
58-
target_compile_definitions(carla_fastdds_debug PUBLIC -DBOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
59-
93+
set_target_properties(carla_fastdds_debug PROPERTIES COMPILE_FLAGS
94+
"-fexceptions ${CMAKE_CXX_FLAGS_DEBUG}")
95+
target_compile_definitions(carla_fastdds_debug PUBLIC
96+
WITH_ROS2 CARLA_SERVER_BUILD BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)
6097
endif()

LibCarla/cmake/server/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ foreach(dir ""
2323
"rpc/"
2424
"sensor/" "sensor/data/" "sensor/s11n/"
2525
"streaming/" "streaming/detail/" "streaming/detail/tcp/" "streaming/low_level/"
26-
"multigpu/"
27-
"ros2/")
26+
"multigpu/")
2827

2928
file(GLOB headers "${libcarla_source_path}/carla/${dir}*.h")
3029
install(FILES ${headers} DESTINATION include/carla/${dir})

LibCarla/source/carla/Buffer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace carla {
77
void Buffer::ReuseThisBuffer() {
88
auto pool = _parent_pool.lock();
99
if (pool != nullptr) {
10+
log_debug("Buffer[", static_cast<void*>(_data.get()), ":", _size, "]::ReuseThisBuffer() returning buffer to pool:", pool.get());
1011
pool->Push(std::move(*this));
1112
}
1213
}

LibCarla/source/carla/Buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ namespace carla {
251251
/// allocated.
252252
void reset(size_type size) {
253253
if (_capacity < size) {
254-
log_debug("allocating buffer of", size, "bytes");
255254
_data = std::make_unique<value_type[]>(size);
256255
_capacity = size;
256+
log_debug("Buffer[", static_cast<void*>(_data.get()), ":", size, "]::reset() Allocated buffer data (old size: ", _size, ")");
257257
}
258258
_size = size;
259259
}

0 commit comments

Comments
 (0)