Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,63 @@ _STUDIO := carla-studio-$(_PLATFORM)-$(_ARCH)$(_APP_EXT)
_CLI := carla-studio-test-suite-$(_PLATFORM)-$(_ARCH)$(_EXT)

ifdef CARLA_DIR
_CARLA := -DCARLA_DIR="$(CARLA_DIR)"
_CARLA_ABS := $(abspath "$(CARLA_DIR)")
_CARLA := -DCARLA_DIR="$(_CARLA_ABS)"
_CARLA_BUILD := $(_CARLA_ABS)/Build
_CARLA_LIB := $(_CARLA_ABS)/Build/LibCarla/libcarla-client.a

ifdef UNREAL_DIR
# Full build: delegates to CarlaSetup.sh (same as `carla-studio build --engine`).
# Builds libcarla + UE5 simulator + shipping package in one shot.
_UNREAL_ABS := $(abspath $(UNREAL_DIR))
_CARLA_SIM_STAMP := $(_CARLA_BUILD)/.carla-studio-setup-done

$(_CARLA_SIM_STAMP):
@rm -rf "$(_CARLA_BUILD)"
CARLA_UNREAL_ENGINE_PATH="$(_UNREAL_ABS)" \
cmake -S "$(CARLA_DIR)" -B "$(_CARLA_BUILD)" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$(_CARLA_ABS)/CMake/Toolchain.cmake" \
-DBUILD_CARLA_CLIENT=ON \
-DBUILD_CARLA_SERVER=ON \
-DBUILD_CARLA_UNREAL=ON \
-DBUILD_PYTHON_API=ON \
-DBUILD_OSM2ODR=OFF \
-DENABLE_ROS2=OFF
cmake --build "$(_CARLA_BUILD)" --target carla-client -j$(JOBS)
cmake --build "$(_CARLA_BUILD)" --target carla-unreal -j$(JOBS)
cmake --build "$(_CARLA_BUILD)" --target carla-unreal-editor -j$(JOBS)
@touch "$(_CARLA_SIM_STAMP)"

$(_CARLA_LIB): $(_CARLA_SIM_STAMP)

$(BUILD)/CMakeCache.txt: $(_CARLA_SIM_STAMP)
cmake -S src -B "$(BUILD)" -DCMAKE_BUILD_TYPE=Release $(_CARLA)

else
_CARLA :=
# Client-only build: libcarla-client.a only, no UE5.
$(_CARLA_LIB):
cmake -S "$(CARLA_DIR)" -B "$(_CARLA_BUILD)" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_CARLA_CLIENT=ON \
-DBUILD_CARLA_SERVER=OFF \
-DBUILD_PYTHON_API=ON \
-DBUILD_OSM2ODR=OFF \
-DENABLE_ROS2=OFF
cmake --build "$(_CARLA_BUILD)" --target carla-client -j$(JOBS)

$(BUILD)/CMakeCache.txt: $(_CARLA_LIB)
cmake -S src -B "$(BUILD)" -DCMAKE_BUILD_TYPE=Release $(_CARLA)

endif

else
_CARLA :=

$(BUILD)/CMakeCache.txt:
cmake -S src -B "$(BUILD)" -DCMAKE_BUILD_TYPE=Release $(_CARLA)
cmake -S src -B "$(BUILD)" -DCMAKE_BUILD_TYPE=Release

endif

_build: $(BUILD)/CMakeCache.txt
cmake --build "$(BUILD)" --target carla-studio -j$(JOBS)
Expand Down Expand Up @@ -101,10 +151,21 @@ all: $(BUILD)/CMakeCache.txt
app: $(BUILD)/CMakeCache.txt
cmake --build "$(BUILD)" --target carla-studio -j$(JOBS)

ifdef UNREAL_DIR
_CARLA_SIM_ROOT := $(shell find "$(_CARLA_BUILD)/Package" -maxdepth 2 \
\( -name "CarlaUnreal-Linux-Shipping" -o -name "CarlaUnreal.sh" \
-o -name "CarlaUE5.sh" -o -name "CarlaUE4.sh" \) \
-printf '%h\n' 2>/dev/null | head -1)
endif

test: $(BUILD)/CMakeCache.txt
cmake --build "$(BUILD)" --target carla-studio -j$(JOBS)
cmake --build "$(BUILD)" --target test-suite -j$(JOBS)
ifdef _CARLA_SIM_ROOT
CARLA_SIM_ROOT="$(_CARLA_SIM_ROOT)" "$(BUILD)/carla-studio-test-suite$(_EXT)" --update-documentation
else
"$(BUILD)/carla-studio-test-suite$(_EXT)" --update-documentation
endif

clean:
rm -rf "$(BUILD)"
Expand All @@ -116,7 +177,7 @@ ifeq ($(_PLATFORM), linux)
endif

help:
@echo "Usage: make [target] [CARLA_DIR=/path/to/carla/source]"
@echo "Usage: make [target] [CARLA_DIR=<path>] [UNREAL_DIR=<path>] [JOBS=N]"
@echo ""
@echo "Targets:"
@echo " make build + keep only carla-studio binary (default)"
Expand All @@ -129,5 +190,9 @@ help:
@echo " make test build + run full test suite"
@echo " make clean remove app/ and uninstall .desktop entry (Linux)"
@echo ""
@echo " CARLA_DIR=<path> link against CARLA source tree"
@echo " JOBS=N parallel build jobs (default: all cores via nproc)"
@echo " CARLA_DIR=<path> link against CARLA source tree (builds libcarla-client.a)"
@echo " UNREAL_DIR=<path> also build full UE5 simulator + shipping package"
@echo " requires CARLA_DIR; builds carla-unreal-package-shipping"
@echo " simulator lands at CARLA_DIR/Build/Package/Carla-*-Linux-Shipping/"
@echo " test target sets CARLA_SIM_ROOT automatically"
@echo " JOBS=N parallel build jobs (default: all cores via nproc)"
50 changes: 50 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,56 @@ option (CARLA_STUDIO_FETCH_ASSIMP
"Fetch + build Assimp at configure time for multi-format mesh ingest in CarlaStudio."
OFF)

if (DEFINED CARLA_DIR AND NOT DEFINED CARLA_BUILD_DIR)
set (CARLA_BUILD_DIR "${CARLA_DIR}/Build")
endif ()

if (DEFINED CARLA_BUILD_DIR AND NOT TARGET carla-client)
set (_cbd "${CARLA_BUILD_DIR}")
set (_libcarla_a "${_cbd}/LibCarla/libcarla-client.a")
if (NOT EXISTS "${_libcarla_a}")
carla_warning ("CARLA_BUILD_DIR=${_cbd}: libcarla-client.a not found; LibCarla disabled.")
else ()
get_filename_component (_carla_root "${_cbd}/.." ABSOLUTE)
set (_boost_src "${_cbd}/_deps/boost-src")
set (_boost_bld "${_cbd}/_deps/boost-build/libs")
set (_rpclib_src "${_cbd}/_deps/rpclib-src")
set (_rpclib_a "${_cbd}/_deps/rpclib-build/librpc.a")
set (_png_a "${_cbd}/_deps/libpng-build/libpng16.a")
set (_zlib_a "${_cbd}/_deps/zlib-build/libz.a")

file (GLOB _boost_lib_incs "${_boost_src}/libs/*/include")
file (GLOB _boost_numeric_incs "${_boost_src}/libs/numeric/*/include")
file (GLOB _boost_compiled_libs "${_boost_bld}/*/libboost_*.a")

add_library (carla-client STATIC IMPORTED GLOBAL)
set_target_properties (carla-client PROPERTIES
IMPORTED_LOCATION "${_libcarla_a}"
INTERFACE_INCLUDE_DIRECTORIES
"${_carla_root}/LibCarla/source;${_boost_lib_incs};${_boost_numeric_incs};${_rpclib_src}/include;${_rpclib_src}/dependencies/include"
INTERFACE_COMPILE_DEFINITIONS
"BOOST_ATOMIC_NO_LIB;BOOST_ATOMIC_STATIC_LINK;\
BOOST_CHRONO_NO_LIB;BOOST_CHRONO_STATIC_LINK;\
BOOST_CONTAINER_NO_LIB;BOOST_CONTAINER_STATIC_LINK;\
BOOST_COROUTINE_NO_LIB;BOOST_COROUTINE_STATIC_LINK;\
BOOST_DATE_TIME_NO_LIB;BOOST_DATE_TIME_STATIC_LINK;\
BOOST_FILESYSTEM_NO_LIB;BOOST_FILESYSTEM_STATIC_LINK=1;\
BOOST_RANDOM_NO_LIB;BOOST_RANDOM_STATIC_LINK;\
BOOST_SERIALIZATION_NO_LIB;BOOST_SERIALIZATION_STATIC_LINK;\
BOOST_THREAD_NO_LIB;BOOST_THREAD_STATIC_LINK;BOOST_THREAD_USE_LIB;\
LIBCARLA_IMAGE_SUPPORT_PNG=1;\
RPCLIB_LINUX;RPCLIB_MSGPACK=clmdep_msgpack"
INTERFACE_LINK_LIBRARIES
"${_rpclib_a};${_boost_compiled_libs};\
${_cbd}/_deps/recastnavigation-build/DetourCrowd/libDetourCrowd.a;\
${_cbd}/_deps/recastnavigation-build/Detour/libDetour.a;\
${_cbd}/_deps/recastnavigation-build/Recast/libRecast.a;\
${_png_a};${_zlib_a}"
)
carla_message ("LibCarla integration enabled (CARLA_BUILD_DIR=${_cbd})")
endif ()
endif ()

if (CARLA_STUDIO_FETCH_ASSIMP)
include (FetchContent)
set (ASSIMP_BUILD_TESTS OFF CACHE BOOL "" FORCE)
Expand Down
42 changes: 21 additions & 21 deletions src/carla_studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3332,8 +3332,8 @@ int main(int argc, char *argv[]) {

const float cameraDistance = 6.0f;
cg::Location cameraLocation = vehicleTransform.location;
cameraLocation.x -= static_cast<float>(std::cos(yawRad) * cameraDistance);
cameraLocation.y -= static_cast<float>(std::sin(yawRad) * cameraDistance);
cameraLocation.x -= static_cast<float>(std::cos(yawRad) * static_cast<double>(cameraDistance));
cameraLocation.y -= static_cast<float>(std::sin(yawRad) * static_cast<double>(cameraDistance));
cameraLocation.z += 2.6f;
cg::Rotation cameraRotation(-12.0f, vehicleTransform.rotation.yaw, 0.0f);

Expand Down Expand Up @@ -3877,8 +3877,8 @@ int main(int argc, char *argv[]) {
for (int xi = 0; xi < 4; ++xi) {
for (int yi = 0; yi < 11; ++yi) {
if ((xi + yi) % 2 != 0) continue;
const float x0 = 88.0f + xi * 1.0f;
const float y0 = -5.5f + yi * 1.0f;
const float x0 = 88.0f + static_cast<float>(xi);
const float y0 = -5.5f + static_cast<float>(yi);
for (float dy = 0.0f; dy <= 1.0f; dy += 0.12f) {
dbg.DrawLine(cg::Location(x0, y0 + dy, 0.12f),
cg::Location(x0 + 1.0f, y0 + dy, 0.12f),
Expand Down Expand Up @@ -10029,7 +10029,7 @@ int main(int argc, char *argv[]) {
double maxMag = 1e-6;
for (size_t i = 0; i < flow->size(); ++i) {
const auto &p = (*flow)[i];
const double m = std::sqrt(double(p.x) * p.x + double(p.y) * p.y);
const double m = std::sqrt(double(p.x) * double(p.x) + double(p.y) * double(p.y));
if (m > maxMag) maxMag = m;
}

Expand All @@ -10038,12 +10038,12 @@ int main(int argc, char *argv[]) {
uchar *L = frame.scanLine(y);
for (int x = 0; x < w; ++x) {
const auto &p = (*flow)[size_t(y * w + x)];
const double mag = std::sqrt(double(p.x) * p.x + double(p.y) * p.y);
const double mag = std::sqrt(double(p.x) * double(p.x) + double(p.y) * double(p.y));
const double ang = std::atan2(double(p.y), double(p.x));
const double hue = (ang + M_PI) / (2.0 * M_PI);
const double sat = std::min(1.0, mag / maxMag);
const QColor c = QColor::fromHsvF(hue, sat, 1.0);
L[x*3+0] = c.red(); L[x*3+1] = c.green(); L[x*3+2] = c.blue();
const QColor c = QColor::fromHsvF(static_cast<float>(hue), static_cast<float>(sat), 1.0f);
L[x*3+0] = static_cast<uchar>(c.red()); L[x*3+1] = static_cast<uchar>(c.green()); L[x*3+2] = static_cast<uchar>(c.blue());
}
}
postImageToSink(tab, frame);
Expand Down Expand Up @@ -10107,7 +10107,7 @@ int main(int argc, char *argv[]) {
QString("accel=(%1,%2,%3) gyro=(%4,%5,%6) compass=%7°")
.arg(a.x, 0, 'f', 2).arg(a.y, 0, 'f', 2).arg(a.z, 0, 'f', 2)
.arg(g.x, 0, 'f', 2).arg(g.y, 0, 'f', 2).arg(g.z, 0, 'f', 2)
.arg(m->GetCompass() * 180.0 / M_PI, 0, 'f', 1),
.arg(static_cast<double>(m->GetCompass()) * 180.0 / M_PI, 0, 'f', 1),
true);
break;
}
Expand All @@ -10123,7 +10123,7 @@ int main(int argc, char *argv[]) {
QString("[%1] ↯ %2 impulse=%3")
.arg(QTime::currentTime().toString("HH:mm:ss"))
.arg(otherName)
.arg(std::sqrt(double(imp.x)*imp.x + double(imp.y)*imp.y + double(imp.z)*imp.z), 0, 'f', 1),
.arg(std::sqrt(double(imp.x)*double(imp.x) + double(imp.y)*double(imp.y) + double(imp.z)*double(imp.z)), 0, 'f', 1),
false);
break;
}
Expand Down Expand Up @@ -10376,8 +10376,8 @@ int main(int argc, char *argv[]) {
if (!bp) continue;

const SensorMountConfig mount = getOrCreateSensorMount(name);
cg::Location loc(mount.tx, mount.ty, mount.tz);
cg::Rotation rot(mount.ry, mount.rz, mount.rx);
cg::Location loc(static_cast<float>(mount.tx), static_cast<float>(mount.ty), static_cast<float>(mount.tz));
cg::Rotation rot(static_cast<float>(mount.ry), static_cast<float>(mount.rz), static_cast<float>(mount.rx));
cg::Transform tr(loc, rot);

for (int k = 0; k < counts[i]; ++k) {
Expand Down Expand Up @@ -11356,7 +11356,7 @@ int main(int argc, char *argv[]) {
if (bp.ContainsAttribute("role_name")) {
bp.SetAttribute("role_name", "scenario_traffic");
}
auto actor = world.TrySpawnActor(bp, spawns[idx[i]]);
auto actor = world.TrySpawnActor(bp, spawns[idx[static_cast<size_t>(i)]]);
if (!actor) continue;
try {
auto v = std::static_pointer_cast<cc::Vehicle>(actor);
Expand Down Expand Up @@ -11449,10 +11449,10 @@ int main(int argc, char *argv[]) {
};
for (const auto &pair : topology) {
if (!pair.first || !pair.second) continue;
const auto l1 = pair.first->GetTransform().location;
const auto l2 = pair.second->GetTransform().location;
grow(l1.x, l1.y);
grow(l2.x, l2.y);
const auto loc1 = pair.first->GetTransform().location;
const auto loc2 = pair.second->GetTransform().location;
grow(loc1.x, loc1.y);
grow(loc2.x, loc2.y);
}
for (const auto &tr : spawns) {
grow(tr.location.x, tr.location.y);
Expand All @@ -11466,17 +11466,17 @@ int main(int argc, char *argv[]) {
topoPen.setWidthF(0);
for (const auto &pair : topology) {
if (!pair.first || !pair.second) continue;
const auto l1 = pair.first->GetTransform().location;
const auto l2 = pair.second->GetTransform().location;
previewScene->addLine(l1.x, -l1.y, l2.x, -l2.y, topoPen);
const auto loc1 = pair.first->GetTransform().location;
const auto loc2 = pair.second->GetTransform().location;
previewScene->addLine(loc1.x, -loc1.y, loc2.x, -loc2.y, topoPen);
}

const double r = std::max(1.5, (std::max(maxX - minX, maxY - minY)) / 300.0);
QPen spawnPen(QColor(47, 166, 107));
spawnPen.setWidthF(0);
QBrush spawnBrush(QColor(47, 166, 107, 200));
for (const auto &tr : spawns) {
previewScene->addEllipse(tr.location.x - r, -tr.location.y - r,
previewScene->addEllipse(static_cast<double>(tr.location.x) - r, -static_cast<double>(tr.location.y) - r,
2 * r, 2 * r, spawnPen, spawnBrush);
}

Expand Down
Loading