Skip to content

Commit 3b938d7

Browse files
Extend ROS2 support Step 1: Prepare for mulistream (#9431)
Prepare server for multistream support and ROS2 client calls - Moved Blueprint handling sources to carla/actor from carla/client to allow using of that functionalilty within ROS2 server calls - Moved streaming/detail/tcp/Message.h -> streaming/detail/Message.h to be deployed for non-tcp communication streams like ROS2 - Moved general (tcp-independent parts) from tcp/ServerSession to streaming/detail/Session.h to be used for ROS2 streams. Had to rename a Write() function to WriteMessage because of virtual function overloaded with template function not possible. - Make Dispatcher a shared_pointer to be able to access from ROS2 - CarlaServer uses rpc::RpcServerInterface to communicate with TCP-Clients and upcoming DDS-Client - 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)
1 parent 590d54f commit 3b938d7

Some content is hidden

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

60 files changed

+1249
-795
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix OpenDrive Builder lane width
77
* Introduced geom::AngularVelocity, geom::Velocity, geom::Acceleration, geom::Quaternion types
88
* Fixed geom::Rotation::RotateVector() rotation directions of pitch and roll
9+
* Prepare server for multistream support and ROS2 client calls
910

1011
## CARLA 0.9.16
1112

Docs/python_api.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ Tells the simulator to destroy this actor and returns <b>True</b> if it was succ
9494
_</font>
9595
- <a name="carla.Actor.disable_constant_velocity"></a>**<font color="#7fb800">disable_constant_velocity</font>**(<font color="#00a6ed">**self**</font>)
9696
Disables any constant velocity previously set for a [carla.Vehicle](#carla.Vehicle) actor.
97+
- <a name="carla.Actor.disable_for_ros"></a>**<font color="#7fb800">disable_for_ros</font>**(<font color="#00a6ed">**self**</font>)
98+
Commands the actor to stop publishing via ROS2.
9799
- <a name="carla.Actor.enable_constant_velocity"></a>**<font color="#7fb800">enable_constant_velocity</font>**(<font color="#00a6ed">**self**</font>, <font color="#00a6ed">**velocity**</font>)
98100
Sets a vehicle's velocity vector to a constant value over time. The resulting velocity will be approximately the `velocity` being set, as with __<font color="#7fb800">set_target_velocity()</font>__.
99101
- **Parameters:**
@@ -102,6 +104,11 @@ Sets a vehicle's velocity vector to a constant value over time. The resulting ve
102104
_</font>
103105
- **Warning:** <font color="#ED2F2F">_Enabling a constant velocity for a vehicle managed by the [Traffic Manager](adv_traffic_manager.md) may cause conflicts. This method overrides any changes in velocity by the TM.
104106
_</font>
107+
- <a name="carla.Actor.enable_for_ros"></a>**<font color="#7fb800">enable_for_ros</font>**(<font color="#00a6ed">**self**</font>)
108+
Commands the actor to publish their content via ROS2.
109+
- <a name="carla.Actor.is_enabled_for_ros"></a>**<font color="#7fb800">is_enabled_for_ros</font>**(<font color="#00a6ed">**self**</font>)
110+
Returns if the actor is enabled or not to publish via ROS2.
111+
- **Return:** _bool_
105112

106113
##### Getters
107114
- <a name="carla.Actor.get_acceleration"></a>**<font color="#7fb800">get_acceleration</font>**(<font color="#00a6ed">**self**</font>)
@@ -2468,13 +2475,6 @@ Sensors compound a specific family of actors quite diverse and unique. They are
24682475
When **True** the sensor will be waiting for data.
24692476

24702477
### Methods
2471-
- <a name="carla.Sensor.disable_for_ros"></a>**<font color="#7fb800">disable_for_ros</font>**(<font color="#00a6ed">**self**</font>)
2472-
Commands the sensor to not be processed for publishing in ROS2 if there is no any listen to it.
2473-
- <a name="carla.Sensor.enable_for_ros"></a>**<font color="#7fb800">enable_for_ros</font>**(<font color="#00a6ed">**self**</font>)
2474-
Commands the sensor to be processed to be able to publish in ROS2 without any listen to it.
2475-
- <a name="carla.Sensor.is_enabled_for_ros"></a>**<font color="#7fb800">is_enabled_for_ros</font>**(<font color="#00a6ed">**self**</font>)
2476-
Returns if the sensor is enabled or not to publish in ROS2 if there is no any listen to it.
2477-
- **Return:** _bool_
24782478
- <a name="carla.Sensor.is_listening"></a>**<font color="#7fb800">is_listening</font>**(<font color="#00a6ed">**self**</font>)
24792479
Returns whether the sensor is in a listening state.
24802480
- **Return:** _bool_

Examples/CppClient/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ BINDIR=$(CURDIR)/bin
44
INSTALLDIR=$(CURDIR)/libcarla-install
55
TOOLCHAIN=$(CURDIR)/ToolChain.cmake
66

7-
CC=/usr/bin/gcc-9
8-
CXX=/usr/bin/g++-9
9-
CXXFLAGS=-std=c++14 -pthread -fPIC -O3 -DNDEBUG -Werror -Wall -Wextra
7+
CC=/usr/bin/gcc
8+
CXX=/usr/bin/g++
9+
CXXFLAGS=-std=c++17 -pthread -fPIC -O3 -DNDEBUG -Werror -Wall -Wextra
1010

1111
define log
1212
@echo "\033[1;35m$(1)\033[0m"

Examples/CppClient/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#include <thread>
77
#include <tuple>
88

9-
#include <carla/client/ActorBlueprint.h>
10-
#include <carla/client/BlueprintLibrary.h>
9+
#include <carla/actors/ActorBlueprint.h>
10+
#include <carla/actors/BlueprintLibrary.h>
1111
#include <carla/client/Client.h>
1212
#include <carla/client/Map.h>
1313
#include <carla/client/Sensor.h>

LibCarla/cmake/client/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ file(GLOB libcarla_carla_sources
9898
set(libcarla_sources "${libcarla_sources};${libcarla_carla_sources}")
9999
install(FILES ${libcarla_carla_sources} DESTINATION include/carla)
100100

101+
file(GLOB libcarla_carla_actors_sources
102+
"${libcarla_source_path}/carla/actors/*.cpp"
103+
"${libcarla_source_path}/carla/actors/*.h")
104+
set(libcarla_sources "${libcarla_sources};${libcarla_carla_actors_sources}")
105+
install(FILES ${libcarla_carla_actors_sources} DESTINATION include/carla/actors)
106+
101107
file(GLOB libcarla_carla_client_sources
102108
"${libcarla_source_path}/carla/client/*.cpp"
103109
"${libcarla_source_path}/carla/client/*.h")

LibCarla/cmake/server/CMakeLists.txt

Lines changed: 52 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -14,66 +14,24 @@ install(FILES ${libcarla_carla_rpclib} DESTINATION lib)
1414

1515
install(DIRECTORY "${libcarla_source_path}/compiler" DESTINATION include)
1616

17-
file(GLOB libcarla_carla_headers "${libcarla_source_path}/carla/*.h")
18-
install(FILES ${libcarla_carla_headers} DESTINATION include/carla)
19-
20-
file(GLOB libcarla_carla_geom_headers "${libcarla_source_path}/carla/geom/*.h")
21-
install(FILES ${libcarla_carla_geom_headers} DESTINATION include/carla/geom)
22-
23-
file(GLOB libcarla_carla_opendrive "${libcarla_source_path}/carla/opendrive/*.h")
24-
install(FILES ${libcarla_carla_opendrive} DESTINATION include/carla/opendrive)
25-
26-
file(GLOB libcarla_carla_opendrive_parser "${libcarla_source_path}/carla/opendrive/parser/*.h")
27-
install(FILES ${libcarla_carla_opendrive_parser} DESTINATION include/carla/opendrive/parser)
28-
29-
file(GLOB libcarla_carla_profiler_headers "${libcarla_source_path}/carla/profiler/*.h")
30-
install(FILES ${libcarla_carla_profiler_headers} DESTINATION include/carla/profiler)
31-
32-
file(GLOB libcarla_carla_road_headers "${libcarla_source_path}/carla/road/*.h")
33-
install(FILES ${libcarla_carla_road_headers} DESTINATION include/carla/road)
34-
35-
file(GLOB libcarla_carla_road_element_headers "${libcarla_source_path}/carla/road/element/*.h")
36-
install(FILES ${libcarla_carla_road_element_headers} DESTINATION include/carla/road/element)
37-
38-
file(GLOB libcarla_carla_road_general_headers "${libcarla_source_path}/carla/road/general/*.h")
39-
install(FILES ${libcarla_carla_road_general_headers} DESTINATION include/carla/road/general)
40-
41-
file(GLOB libcarla_carla_road_object_headers "${libcarla_source_path}/carla/road/object/*.h")
42-
install(FILES ${libcarla_carla_road_object_headers} DESTINATION include/carla/road/object)
43-
44-
file(GLOB libcarla_carla_road_signal_headers "${libcarla_source_path}/carla/road/signal/*.h")
45-
install(FILES ${libcarla_carla_road_signal_headers} DESTINATION include/carla/road/signal)
46-
47-
file(GLOB libcarla_carla_rpc_headers "${libcarla_source_path}/carla/rpc/*.h")
48-
install(FILES ${libcarla_carla_rpc_headers} DESTINATION include/carla/rpc)
49-
50-
file(GLOB libcarla_carla_sensor_headers "${libcarla_source_path}/carla/sensor/*.h")
51-
install(FILES ${libcarla_carla_sensor_headers} DESTINATION include/carla/sensor)
52-
53-
file(GLOB libcarla_carla_sensor_data_headers "${libcarla_source_path}/carla/sensor/data/*.h")
54-
install(FILES ${libcarla_carla_sensor_data_headers} DESTINATION include/carla/sensor/data)
55-
56-
file(GLOB libcarla_carla_sensor_s11n_headers "${libcarla_source_path}/carla/sensor/s11n/*.h")
57-
install(FILES ${libcarla_carla_sensor_s11n_headers} DESTINATION include/carla/sensor/s11n)
58-
59-
file(GLOB libcarla_carla_streaming_headers "${libcarla_source_path}/carla/streaming/*.h")
60-
install(FILES ${libcarla_carla_streaming_headers} DESTINATION include/carla/streaming)
61-
62-
file(GLOB libcarla_carla_streaming_detail_headers "${libcarla_source_path}/carla/streaming/detail/*.h")
63-
install(FILES ${libcarla_carla_streaming_detail_headers} DESTINATION include/carla/streaming/detail)
64-
65-
file(GLOB libcarla_carla_streaming_detail_tcp_headers "${libcarla_source_path}/carla/streaming/detail/tcp/*.h")
66-
install(FILES ${libcarla_carla_streaming_detail_tcp_headers} DESTINATION include/carla/streaming/detail/tcp)
67-
68-
file(GLOB libcarla_carla_streaming_low_level_headers "${libcarla_source_path}/carla/streaming/low_level/*.h")
69-
install(FILES ${libcarla_carla_streaming_low_level_headers} DESTINATION include/carla/streaming/low_level)
70-
71-
file(GLOB libcarla_carla_multigpu_headers "${libcarla_source_path}/carla/multigpu/*.h")
72-
install(FILES ${libcarla_carla_multigpu_headers} DESTINATION include/carla/multigpu)
73-
74-
file(GLOB libcarla_carla_ros2_headers "${libcarla_source_path}/carla/ros2/*.h")
75-
install(FILES ${libcarla_carla_ros2_headers} DESTINATION include/carla/ros2)
76-
17+
foreach(dir ""
18+
"actors/"
19+
"geom/"
20+
"opendrive/" "opendrive/parser/"
21+
"profiler/"
22+
"road/" "road/element/" "road/general/" "road/object/" "road/signal/"
23+
"rpc/"
24+
"sensor/" "sensor/data/" "sensor/s11n/"
25+
"streaming/" "streaming/detail/" "streaming/detail/tcp/" "streaming/low_level/"
26+
"multigpu/"
27+
"ros2/")
28+
29+
file(GLOB headers "${libcarla_source_path}/carla/${dir}*.h")
30+
install(FILES ${headers} DESTINATION include/carla/${dir})
31+
32+
endforeach()
33+
34+
# Install boost headers and libraries.
7735
install(DIRECTORY "${BOOST_INCLUDE_PATH}/boost" DESTINATION include)
7836

7937
if(WIN32)
@@ -85,45 +43,40 @@ if(WIN32)
8543
endif()
8644

8745
# carla_server library.
88-
89-
file(GLOB libcarla_server_sources
90-
"${libcarla_source_path}/carla/*.h"
91-
"${libcarla_source_path}/carla/Buffer.cpp"
92-
"${libcarla_source_path}/carla/Exception.cpp"
93-
"${libcarla_source_path}/carla/geom/*.cpp"
94-
"${libcarla_source_path}/carla/geom/*.h"
95-
"${libcarla_source_path}/carla/opendrive/*.cpp"
96-
"${libcarla_source_path}/carla/opendrive/*.h"
97-
"${libcarla_source_path}/carla/opendrive/parser/*.cpp"
98-
"${libcarla_source_path}/carla/opendrive/parser/*.h"
99-
"${libcarla_source_path}/carla/road/*.cpp"
100-
"${libcarla_source_path}/carla/road/*.h"
101-
"${libcarla_source_path}/carla/road/element/*.cpp"
102-
"${libcarla_source_path}/carla/road/element/*.h"
103-
"${libcarla_source_path}/carla/road/general/*.cpp"
104-
"${libcarla_source_path}/carla/road/general/*.h"
105-
"${libcarla_source_path}/carla/road/object/*.cpp"
106-
"${libcarla_source_path}/carla/road/object/*.h"
107-
"${libcarla_source_path}/carla/road/signal/*.cpp"
108-
"${libcarla_source_path}/carla/road/signal/*.h"
109-
"${libcarla_source_path}/carla/rpc/*.cpp"
110-
"${libcarla_source_path}/carla/rpc/*.h"
111-
"${libcarla_source_path}/carla/sensor/*.h"
112-
"${libcarla_source_path}/carla/sensor/s11n/*.h"
113-
"${libcarla_source_path}/carla/sensor/s11n/SensorHeaderSerializer.cpp"
114-
"${libcarla_source_path}/carla/streaming/*.h"
115-
"${libcarla_source_path}/carla/streaming/detail/*.cpp"
116-
"${libcarla_source_path}/carla/streaming/detail/*.h"
117-
"${libcarla_source_path}/carla/streaming/detail/tcp/*.cpp"
118-
"${libcarla_source_path}/carla/streaming/low_level/*.h"
119-
"${libcarla_source_path}/carla/multigpu/*.h"
120-
"${libcarla_source_path}/carla/multigpu/*.cpp"
121-
"${libcarla_source_thirdparty_path}/odrSpiral/*.cpp"
122-
"${libcarla_source_thirdparty_path}/odrSpiral/*.h"
123-
"${libcarla_source_thirdparty_path}/moodycamel/*.cpp"
124-
"${libcarla_source_thirdparty_path}/moodycamel/*.h"
125-
"${libcarla_source_thirdparty_path}/pugixml/*.cpp"
126-
"${libcarla_source_thirdparty_path}/pugixml/*.hpp")
46+
# first the sources which are picked from some directories
47+
set(libcarla_server_sources
48+
"${libcarla_source_path}/carla/Buffer.cpp"
49+
"${libcarla_source_path}/carla/Exception.cpp"
50+
"${libcarla_source_path}/carla/StringUtil.cpp"
51+
# other cpp files only define Deserialize used in client
52+
"${libcarla_source_path}/carla/sensor/s11n/SensorHeaderSerializer.cpp"
53+
)
54+
# then the globs on the folders to add as a whole
55+
foreach(dir
56+
"actors"
57+
"geom"
58+
"opendrive" "opendrive/parser"
59+
"profiler"
60+
"road" "road/element" "road/general" "road/object" "road/signal"
61+
"rpc"
62+
"sensor" "sensor/data"
63+
"streaming" "streaming/detail" "streaming/detail/tcp" "streaming/low_level"
64+
"multigpu")
65+
66+
file(GLOB sources "${libcarla_source_path}/carla/${dir}/*.cpp")
67+
list(APPEND libcarla_server_sources ${sources})
68+
69+
endforeach()
70+
71+
foreach(thirdparty_dir
72+
"odrSpiral"
73+
"moodycamel"
74+
"pugixml")
75+
76+
file(GLOB sources "${libcarla_source_thirdparty_path}/${thirdparty_dir}/*.cpp")
77+
list(APPEND libcarla_server_sources ${sources})
78+
79+
endforeach()
12780

12881
# ==============================================================================
12982
# Create targets for debug and release in the same build type.

LibCarla/source/carla/client/ActorAttribute.cpp renamed to LibCarla/source/carla/actors/ActorAttribute.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
// This work is licensed under the terms of the MIT license.
55
// For a copy, see <https://opensource.org/licenses/MIT>.
66

7-
#include "carla/client/ActorAttribute.h"
7+
#include "carla/actors/ActorAttribute.h"
88

99
#include "carla/Exception.h"
1010
#include "carla/Logging.h"
1111
#include "carla/StringUtil.h"
1212

1313
namespace carla {
14-
namespace client {
14+
namespace actors {
1515

1616
#define LIBCARLA_THROW_INVALID_VALUE(message) throw_exception(InvalidAttributeValue(GetId() + ": " + message));
1717
#define LIBCARLA_THROW_BAD_VALUE_CAST(type) \
@@ -103,5 +103,5 @@ namespace client {
103103
#undef LIBCARLA_THROW_BAD_VALUE_CAST
104104
#undef LIBCARLA_THROW_INVALID_VALUE
105105

106-
} // namespace client
106+
} // namespace actors
107107
} // namespace carla

LibCarla/source/carla/client/ActorAttribute.h renamed to LibCarla/source/carla/actors/ActorAttribute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <type_traits>
1515

1616
namespace carla {
17-
namespace client {
17+
namespace actors {
1818

1919
// ===========================================================================
2020
// -- InvalidAttributeValue --------------------------------------------------
@@ -237,5 +237,5 @@ namespace client {
237237
return rhs.operator==(*this);
238238
}
239239

240-
} // namespace client
240+
} // namespace actors
241241
} // namespace carla

LibCarla/source/carla/client/ActorBlueprint.cpp renamed to LibCarla/source/carla/actors/ActorBlueprint.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
// This work is licensed under the terms of the MIT license.
55
// For a copy, see <https://opensource.org/licenses/MIT>.
66

7-
#include "carla/client/ActorBlueprint.h"
7+
#include "carla/actors/ActorBlueprint.h"
88

99
#include "carla/Exception.h"
1010
#include "carla/StringUtil.h"
1111

1212
#include <algorithm>
1313

1414
namespace carla {
15-
namespace client {
15+
namespace actors {
1616

1717
template <typename Map, typename Container>
1818
static void FillMap(Map &destination, Container &source) {
@@ -62,5 +62,5 @@ namespace client {
6262
return description;
6363
}
6464

65-
} // namespace client
65+
} // namespace actors
6666
} // namespace carla

LibCarla/source/carla/client/ActorBlueprint.h renamed to LibCarla/source/carla/actors/ActorBlueprint.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
#include "carla/Debug.h"
1010
#include "carla/Iterator.h"
11-
#include "carla/client/ActorAttribute.h"
11+
#include "carla/actors/ActorAttribute.h"
1212
#include "carla/rpc/ActorDefinition.h"
1313
#include "carla/rpc/ActorDescription.h"
1414

@@ -17,7 +17,7 @@
1717
#include <unordered_set>
1818

1919
namespace carla {
20-
namespace client {
20+
namespace actors {
2121

2222
/// Contains all the necessary information for spawning an Actor.
2323
class ActorBlueprint {
@@ -120,5 +120,5 @@ namespace client {
120120
std::unordered_map<std::string, ActorAttribute> _attributes;
121121
};
122122

123-
} // namespace client
123+
} // namespace actors
124124
} // namespace carla

0 commit comments

Comments
 (0)