11#include "EngineUtils.h"
12#include "Components/SkeletalMeshComponent.h"
13#include "Components/SkinnedMeshComponent.h"
14#include "Components/SceneComponent.h"
15#include "Engine/SkeletalMesh.h"
16#include "Engine/SkeletalMeshSocket.h"
26#include "GameFramework/CharacterMovementComponent.h"
35#include "Misc/FileHelper.h"
40#include <carla/Version.h>
92template <
typename T,
typename Other>
95 return {Array.GetData(), Array.GetData() + Array.Num()};
106 FPimpl(uint16_t RPCPort, uint16_t StreamingPort, uint16_t SecondaryPort)
114 SecondaryServer = std::make_shared<carla::multigpu::Router>(SecondaryPort);
148# define CARLA_ENSURE_GAME_THREAD() check(IsInGameThread());
150# define CARLA_ENSURE_GAME_THREAD()
153#define RESPOND_ERROR(str) { \
154 UE_LOG(LogCarlaServer, Log, TEXT("Responding error: %s"), TEXT(str)); \
155 return carla::rpc::ResponseError(str); }
158#define RESPOND_ERROR_FSTRING(fstr) { \
159 UE_LOG(LogCarlaServer, Log, TEXT("Responding error: %s"), *fstr); \
160 return carla::rpc::ResponseError(carla::rpc::FromFString(fstr)); }
162#define REQUIRE_CARLA_EPISODE() \
163 CARLA_ENSURE_GAME_THREAD(); \
164 if (Episode == nullptr) { RESPOND_ERROR("episode not ready"); }
167 const FString& FuncName,
168 const FString& ErrorMessage,
169 const FString& ExtraInfo =
"")
171 FString TotalMessage =
"Responding error from function " + FuncName +
": " +
172 ErrorMessage +
". " + ExtraInfo;
173 UE_LOG(LogCarlaServer, Log, TEXT(
"%s"), *TotalMessage);
178 const FString& FuncName,
180 const FString& ExtraInfo =
"")
196 template <
typename FuncT>
219#define BIND_SYNC(name) auto name = ServerBinder(# name, Server, true)
220#define BIND_ASYNC(name) auto name = ServerBinder(# name, Server, false)
239 BIND_SYNC(get_traffic_manager_running) << [
this] (uint16_t port) ->
R<std::pair<std::string, uint16_t>>
243 return std::pair<std::string, uint16_t>(it->second, it->first);
245 return std::pair<std::string, uint16_t>(
"",0);
249 BIND_SYNC(add_traffic_manager_running) << [
this] (std::pair<std::string, uint16_t> trafficManagerInfo) ->
R<bool>
251 uint16_t port = trafficManagerInfo.second;
255 std::pair<uint16_t, std::string>(port, trafficManagerInfo.first));
275 return carla::version();
290 BIND_ASYNC(get_available_maps) << [
this]() ->
R<std::vector<std::string>>
294 std::vector<std::string> result;
297 result.reserve(MapNames.Num());
299 for (
const auto &MapName : MapNames)
301 if (MapName.Contains(
"/Sublevels/"))
303 if (MapName.Contains(
"/BaseMap/"))
305 if (MapName.Contains(
"/BaseLargeMap/"))
307 if (MapName.Contains(
"_Tile_"))
311 result.emplace_back(cr::FromFString(MapName));
317 BIND_SYNC(load_new_episode) << [
this](
const std::string &map_name,
const bool reset_settings, cr::MapLayer MapLayers) ->
R<void>
326 GameInstance->
SetMapLayer(
static_cast<int32
>(MapLayers));
328 if(!
Episode->LoadNewEpisode(cr::ToFString(map_name), reset_settings))
330 FString Str(TEXT(
"Map '"));
331 Str += cr::ToFString(map_name);
332 Str += TEXT(
"' not found");
371 BIND_SYNC(copy_opendrive_to_file) << [
this](
const std::string &opendrive, cr::OpendriveGenerationParameters Params) ->
R<void>
377 if (!
Episode->LoadNewOpendriveEpisode(cr::ToLongFString(opendrive), Params))
384 BIND_SYNC(apply_color_texture_to_objects) << [
this](
385 const std::vector<std::string> &actors_name,
386 const cr::MaterialParameter& parameter,
387 const cr::TextureColor& Texture) ->
R<void>
398 TArray<AActor*> ActorsToPaint;
399 for(
const std::string& actor_name : actors_name)
404 ActorsToPaint.Add(ActorToPaint);
408 if(!ActorsToPaint.Num())
415 for(
AActor* ActorToPaint : ActorsToPaint)
425 BIND_SYNC(apply_float_color_texture_to_objects) << [
this](
426 const std::vector<std::string> &actors_name,
427 const cr::MaterialParameter& parameter,
428 const cr::TextureFloatColor& Texture) ->
R<void>
436 TArray<AActor*> ActorsToPaint;
437 for(
const std::string& actor_name : actors_name)
442 ActorsToPaint.Add(ActorToPaint);
446 if(!ActorsToPaint.Num())
453 for(
AActor* ActorToPaint : ActorsToPaint)
463 BIND_SYNC(get_names_of_all_objects) << [
this]() ->
R<std::vector<std::string>>
472 std::vector<std::string> NamesStd;
473 for (
const FString &Name : NamesFString)
475 NamesStd.emplace_back(cr::FromFString(Name));
492 const auto &SpawnPoints =
Episode->GetRecommendedSpawnPoints();
494 FString MapDir = FullMapPath.RightChop(FullMapPath.Find(
"Content/", ESearchCase::CaseSensitive) + 8);
495 MapDir +=
"/" +
Episode->GetMapName();
497 cr::FromFString(MapDir),
498 MakeVectorFromTArray<cg::Transform>(SpawnPoints)};
507 BIND_SYNC(get_navigation_mesh) << [
this]() ->
R<std::vector<uint8_t>>
512 std::vector<uint8_t> Result(FileContents.Num());
513 memcpy(&Result[0], FileContents.GetData(), FileContents.Num());
517 BIND_SYNC(get_required_files) << [
this](std::string folder =
"") ->
R<std::vector<std::string>>
522 if (folder[folder.size() - 1] !=
'/' && folder[folder.size() - 1] !=
'\\') {
529 const auto folderDir = mapDir +
"/" + folder.c_str();
530 const auto fileName = mapDir.EndsWith(
Episode->GetMapName()) ?
"*" :
Episode->GetMapName();
533 TArray<FString> Files;
534 IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName +
".xodr"),
true,
false,
false);
535 IFileManager::Get().FindFilesRecursive(Files, *folderDir, *(fileName +
".bin"),
true,
false,
false);
538 std::vector<std::string> result;
539 for (
auto File : Files) {
540 File.RemoveFromStart(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
541 result.emplace_back(TCHAR_TO_UTF8(*File));
546 BIND_SYNC(request_file) << [
this](std::string name) ->
R<std::vector<uint8_t>>
551 FString path(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
552 path.Append(name.c_str());
555 TArray<uint8_t> Content;
556 FFileHelper::LoadFileToArray(Content, *path, 0);
557 std::vector<uint8_t> Result(Content.Num());
558 memcpy(&Result[0], Content.GetData(), Content.Num());
566 return cr::EpisodeSettings{
Episode->GetSettings()};
569 BIND_SYNC(set_episode_settings) << [
this](
570 const cr::EpisodeSettings &settings) ->
R<uint64_t>
573 Episode->ApplySettings(settings);
590 BIND_SYNC(get_actor_definitions) << [
this]() ->
R<std::vector<cr::ActorDefinition>>
593 return MakeVectorFromTArray<cr::ActorDefinition>(
Episode->GetActorDefinitions());
604 return Episode->SerializeActor(CarlaActor);
607 BIND_SYNC(get_all_level_BBs) << [
this](uint8 QueriedTag) ->
R<std::vector<cg::BoundingBox>>
610 TArray<FBoundingBox> Result;
620 for(
auto& Box : Result)
625 return MakeVectorFromTArray<cg::BoundingBox>(Result);
628 BIND_SYNC(get_environment_objects) << [
this](uint8 QueriedTag) ->
R<std::vector<cr::EnvironmentObject>>
640 for(
auto& Object : Result)
645 return MakeVectorFromTArray<cr::EnvironmentObject>(Result);
648 BIND_SYNC(enable_environment_objects) << [
this](std::vector<uint64_t> EnvObjectIds,
bool Enable) ->
R<void>
657 TSet<uint64> EnvObjectIdsSet;
658 for(uint64 Id : EnvObjectIds)
660 EnvObjectIdsSet.Emplace(Id);
672 auto *Weather =
Episode->GetWeather();
673 if (Weather ==
nullptr)
677 return Weather->GetCurrentWeather();
680 BIND_SYNC(set_weather_parameters) << [
this](
681 const cr::WeatherParameters &weather) ->
R<void>
684 auto *Weather =
Episode->GetWeather();
685 if (Weather ==
nullptr)
689 Weather->ApplyWeather(weather);
699 if (GameMode ==
nullptr)
701 RESPOND_ERROR(
"get_imui_gravity error: unable to get carla gamemode");
710 if (GameMode ==
nullptr)
712 RESPOND_ERROR(
"get_imui_gravity error: unable to get carla gamemode");
721 const std::vector<FCarlaActor::IdType> &ids) ->
R<std::vector<cr::Actor>>
725 std::vector<cr::Actor> Result;
726 Result.reserve(ids.size());
728 for (
auto &&Id : ids)
733 Result.emplace_back(
Episode->SerializeActor(View));
740 cr::ActorDescription Description,
746 auto Result =
Episode->SpawnActorWithInfo(Transform, std::move(Description));
748 if (Result.Key != EActorSpawnResultStatus::Success)
750 UE_LOG(LogCarla, Error, TEXT(
"Actor not Spawned"));
760 return Episode->SerializeActor(Result.Value);
763 BIND_SYNC(spawn_actor_with_parent) << [
this](
764 cr::ActorDescription Description,
765 const cr::Transform &Transform,
766 cr::ActorId ParentId,
767 cr::AttachmentType InAttachmentType,
774 auto Result =
Episode->SpawnActorWithInfo(Transform, std::move(Description));
776 if (Result.Key != EActorSpawnResultStatus::Success)
789 if (!ParentCarlaActor)
791 RESPOND_ERROR(
"unable to attach actor: parent actor not found");
798 #if defined(WITH_ROS2)
800 if (ROS2->IsEnabled())
807 if (Attr.Key ==
"ros_name")
809 const std::string value = std::string(TCHAR_TO_UTF8(*Attr.Value.Value));
810 ROS2->AddActorParentRosName(
static_cast<void*
>(CarlaActor->
GetActor()),
static_cast<void*
>(CurrentActor->
GetActor()));
825 FString(socket_name.c_str()));
832 return Episode->SerializeActor(CarlaActor);
843 UE_LOG(LogCarla, Log, TEXT(
"CarlaServer destroy_actor %d"), ActorId);
846 if (!
Episode->DestroyActor(ActorId))
856 APlayerController* PController= UGameplayStatics::GetPlayerController(
Episode->GetWorld(), 0);
859 auto result = PController->ConsoleCommand(UTF8_TO_TCHAR(cmd.c_str()),
true);
861 result.Contains(FString(TEXT(
"Command not recognized"))) ||
862 result.Contains(FString(TEXT(
"Error")))
865 return GEngine->Exec(
Episode->GetWorld(), UTF8_TO_TCHAR(cmd.c_str()));
872 bool ForceInPrimary =
false;
877 ForceInPrimary =
true;
881 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
882 if (Desc ==
"" || Desc ==
"sensor.other.collision")
884 ForceInPrimary =
true;
890 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in secondary server"), sensor_id, *Desc);
896 UE_LOG(LogCarla, Log, TEXT(
"Sensor %d '%s' created in primary server"), sensor_id, *Desc);
905 bool ForceInPrimary =
false;
910 ForceInPrimary =
true;
914 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
915 if (Desc ==
"" || Desc ==
"sensor.other.collision")
917 ForceInPrimary =
true;
937 bool ForceInPrimary =
false;
942 ForceInPrimary =
true;
946 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
947 if (Desc ==
"" || Desc ==
"sensor.other.collision")
949 ForceInPrimary =
true;
969 bool ForceInPrimary =
false;
974 ForceInPrimary =
true;
978 FString Desc =
Episode->GetActorDescriptionFromStream(sensor_id);
979 if (Desc ==
"" || Desc ==
"sensor.other.collision")
981 ForceInPrimary =
true;
999 std::string message) ->
R<void>
1007 ECarlaServerResponse::ActorNotFound,
1008 " Actor Id: " + FString::FromInt(ActorId));
1015 ECarlaServerResponse::FunctionNotAvailiableWhenDormant,
1016 " Actor Id: " + FString::FromInt(ActorId));
1023 ECarlaServerResponse::ActorTypeMismatch,
1024 " Actor Id: " + FString::FromInt(ActorId));
1027 Sensor->
Send(cr::ToFString(message));
1033 BIND_SYNC(set_actor_location) << [
this](
1034 cr::ActorId ActorId,
1035 cr::Location Location) ->
R<void>
1042 "set_actor_location",
1043 ECarlaServerResponse::ActorNotFound,
1044 " Actor Id: " + FString::FromInt(ActorId));
1048 Location, ETeleportType::TeleportPhysics);
1052 BIND_SYNC(set_actor_transform) << [
this](
1053 cr::ActorId ActorId,
1054 cr::Transform Transform) ->
R<void>
1061 "set_actor_transform",
1062 ECarlaServerResponse::ActorNotFound,
1063 " Actor Id: " + FString::FromInt(ActorId));
1067 Transform, ETeleportType::TeleportPhysics);
1072 cr::ActorId ActorId,
1073 cr::Transform Transform,
1082 ECarlaServerResponse::ActorNotFound,
1083 " Actor Id: " + FString::FromInt(ActorId));
1092 if (Response != ECarlaServerResponse::Success)
1097 " Actor Id: " + FString::FromInt(ActorId));
1104 BIND_SYNC(set_actor_target_velocity) << [
this](
1105 cr::ActorId ActorId,
1106 cr::Vector3D vector) ->
R<void>
1113 "set_actor_target_velocity",
1114 ECarlaServerResponse::ActorNotFound,
1115 " Actor Id: " + FString::FromInt(ActorId));
1119 if (Response != ECarlaServerResponse::Success)
1122 "set_actor_target_velocity",
1124 " Actor Id: " + FString::FromInt(ActorId));
1129 BIND_SYNC(set_actor_target_angular_velocity) << [
this](
1130 cr::ActorId ActorId,
1131 cr::Vector3D vector) ->
R<void>
1138 "set_actor_target_angular_velocity",
1139 ECarlaServerResponse::ActorNotFound,
1140 " Actor Id: " + FString::FromInt(ActorId));
1144 if (Response != ECarlaServerResponse::Success)
1147 "set_actor_target_angular_velocity",
1149 " Actor Id: " + FString::FromInt(ActorId));
1154 BIND_SYNC(enable_actor_constant_velocity) << [
this](
1155 cr::ActorId ActorId,
1156 cr::Vector3D vector) ->
R<void>
1163 "enable_actor_constant_velocity",
1164 ECarlaServerResponse::ActorNotFound,
1165 " Actor Id: " + FString::FromInt(ActorId));
1170 if (Response != ECarlaServerResponse::Success)
1173 "enable_actor_constant_velocity",
1175 " Actor Id: " + FString::FromInt(ActorId));
1181 BIND_SYNC(disable_actor_constant_velocity) << [
this](
1182 cr::ActorId ActorId) ->
R<void>
1189 "disable_actor_constant_velocity",
1190 ECarlaServerResponse::ActorNotFound,
1191 " Actor Id: " + FString::FromInt(ActorId));
1196 if (Response != ECarlaServerResponse::Success)
1199 "disable_actor_constant_velocity",
1201 " Actor Id: " + FString::FromInt(ActorId));
1208 cr::ActorId ActorId,
1209 cr::Vector3D vector) ->
R<void>
1216 "add_actor_impulse",
1217 ECarlaServerResponse::ActorNotFound,
1218 " Actor Id: " + FString::FromInt(ActorId));
1223 if (Response != ECarlaServerResponse::Success)
1226 "add_actor_impulse",
1228 " Actor Id: " + FString::FromInt(ActorId));
1233 BIND_SYNC(add_actor_impulse_at_location) << [
this](
1234 cr::ActorId ActorId,
1235 cr::Vector3D impulse,
1236 cr::Vector3D location) ->
R<void>
1243 "add_actor_impulse_at_location",
1244 ECarlaServerResponse::ActorNotFound,
1245 " Actor Id: " + FString::FromInt(ActorId));
1247 FVector UELocation = location.ToCentimeters().ToFVector();
1256 if (Response != ECarlaServerResponse::Success)
1259 "add_actor_impulse_at_location",
1261 " Actor Id: " + FString::FromInt(ActorId));
1268 cr::ActorId ActorId,
1269 cr::Vector3D vector) ->
R<void>
1277 ECarlaServerResponse::ActorNotFound,
1278 " Actor Id: " + FString::FromInt(ActorId));
1281 CarlaActor->
AddActorForce(vector.ToCentimeters().ToFVector());
1282 if (Response != ECarlaServerResponse::Success)
1287 " Actor Id: " + FString::FromInt(ActorId));
1292 BIND_SYNC(add_actor_force_at_location) << [
this](
1293 cr::ActorId ActorId,
1295 cr::Vector3D location) ->
R<void>
1302 "add_actor_force_at_location",
1303 ECarlaServerResponse::ActorNotFound,
1304 " Actor Id: " + FString::FromInt(ActorId));
1306 FVector UELocation = location.ToCentimeters().ToFVector();
1315 if (Response != ECarlaServerResponse::Success)
1318 "add_actor_force_at_location",
1320 " Actor Id: " + FString::FromInt(ActorId));
1325 BIND_SYNC(add_actor_angular_impulse) << [
this](
1326 cr::ActorId ActorId,
1327 cr::Vector3D vector) ->
R<void>
1334 "add_actor_angular_impulse",
1335 ECarlaServerResponse::ActorNotFound,
1336 " Actor Id: " + FString::FromInt(ActorId));
1340 if (Response != ECarlaServerResponse::Success)
1343 "add_actor_angular_impulse",
1345 " Actor Id: " + FString::FromInt(ActorId));
1351 cr::ActorId ActorId,
1352 cr::Vector3D vector) ->
R<void>
1360 ECarlaServerResponse::ActorNotFound,
1361 " Actor Id: " + FString::FromInt(ActorId));
1365 if (Response != ECarlaServerResponse::Success)
1370 " Actor Id: " + FString::FromInt(ActorId));
1375 BIND_SYNC(get_actor_component_world_transform) << [
this](
1376 cr::ActorId ActorId,
1384 "get_actor_component_world_transform",
1385 ECarlaServerResponse::ActorNotFound,
1386 " Actor Id: " + FString::FromInt(ActorId));
1390 TArray<UActorComponent*> Components;
1391 CarlaActor->
GetActor()->GetComponents(Components);
1393 USceneComponent* Component =
nullptr;
1394 for(
auto Cmp : Components)
1396 if(USceneComponent* SCMP = Cast<USceneComponent>(Cmp))
1398 if(SCMP->GetName() == componentName.c_str())
1409 "get_actor_component_world_transform",
1410 ECarlaServerResponse::ComponentNotFound,
1411 " Component Name: " + FString(componentName.c_str()));
1414 FTransform ComponentWorldTransform = Component->GetComponentTransform();
1415 return cr::Transform(ComponentWorldTransform);
1419 BIND_SYNC(get_actor_component_relative_transform) << [
this](
1420 cr::ActorId ActorId,
1428 "get_actor_component_relative_transform",
1429 ECarlaServerResponse::ActorNotFound,
1430 " Actor Id: " + FString::FromInt(ActorId));
1434 TArray<UActorComponent*> Components;
1435 CarlaActor->
GetActor()->GetComponents(Components);
1437 USceneComponent* Component =
nullptr;
1438 for(
auto Cmp : Components)
1440 if(USceneComponent* SCMP = Cast<USceneComponent>(Cmp))
1442 if(SCMP->GetName() == componentName.c_str())
1453 "get_actor_component_world_transform",
1454 ECarlaServerResponse::ComponentNotFound,
1455 " Component Name: " + FString(componentName.c_str()));
1458 FTransform ComponentRelativeTransform = Component->GetRelativeTransform();
1459 return cr::Transform(ComponentRelativeTransform);
1463 BIND_SYNC(get_actor_bone_world_transforms) << [
this](
1464 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1471 "get_actor_bone_world_transforms",
1472 ECarlaServerResponse::ActorNotFound,
1473 " Actor Id: " + FString::FromInt(ActorId));
1477 TArray<FTransform> BoneWorldTransforms;
1478 TArray<USkinnedMeshComponent*> SkinnedMeshComponents;
1479 CarlaActor->
GetActor()->GetComponents<USkinnedMeshComponent>(SkinnedMeshComponents);
1480 if(!SkinnedMeshComponents[0])
1483 "get_actor_bone_world_transforms",
1484 ECarlaServerResponse::ComponentNotFound,
1485 " Component Name: SkinnedMeshComponent ");
1489 for(USkinnedMeshComponent* SkinnedMeshComponent : SkinnedMeshComponents)
1491 const int32 NumBones = SkinnedMeshComponent->GetNumBones();
1492 for (int32 BoneIndex = 0; BoneIndex < NumBones; ++BoneIndex)
1494 FTransform WorldTransform = SkinnedMeshComponent->GetComponentTransform();
1495 FTransform BoneTransform = SkinnedMeshComponent->GetBoneTransform(BoneIndex, WorldTransform);
1496 BoneWorldTransforms.Add(BoneTransform);
1499 return MakeVectorFromTArray<cr::Transform>(BoneWorldTransforms);
1504 BIND_SYNC(get_actor_bone_relative_transforms) << [
this](
1505 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1512 "get_actor_bone_relative_transforms",
1513 ECarlaServerResponse::ActorNotFound,
1514 " Actor Id: " + FString::FromInt(ActorId));
1518 TArray<FTransform> BoneRelativeTransforms;
1519 TArray<USkinnedMeshComponent*> SkinnedMeshComponents;
1520 CarlaActor->
GetActor()->GetComponents<USkinnedMeshComponent>(SkinnedMeshComponents);
1521 if(!SkinnedMeshComponents[0])
1524 "get_actor_bone_relative_transforms",
1525 ECarlaServerResponse::ComponentNotFound,
1526 " Component Name: SkinnedMeshComponent ");
1530 for(USkinnedMeshComponent* SkinnedMeshComponent : SkinnedMeshComponents)
1532 const int32 NumBones = SkinnedMeshComponent->GetNumBones();
1533 for (int32 BoneIndex = 0; BoneIndex < NumBones; ++BoneIndex)
1535 FTransform BoneTransform = SkinnedMeshComponent->GetBoneTransform(BoneIndex, FTransform::Identity);
1536 BoneRelativeTransforms.Add(BoneTransform);
1539 return MakeVectorFromTArray<cr::Transform>(BoneRelativeTransforms);
1544 BIND_SYNC(get_actor_component_names) << [
this](
1545 cr::ActorId ActorId) ->
R<std::vector<std::string>>
1552 "get_actor_component_names",
1553 ECarlaServerResponse::ActorNotFound,
1554 " Actor Id: " + FString::FromInt(ActorId));
1558 TArray<UActorComponent*> Components;
1559 CarlaActor->
GetActor()->GetComponents(Components);
1560 std::vector<std::string> ComponentNames;
1561 for(
auto Cmp : Components)
1563 FString ComponentName = Cmp->GetName();
1564 ComponentNames.push_back(TCHAR_TO_UTF8(*ComponentName));
1566 return ComponentNames;
1570 BIND_SYNC(get_actor_bone_names) << [
this](
1571 cr::ActorId ActorId) ->
R<std::vector<std::string>>
1578 "get_actor_bone_names",
1579 ECarlaServerResponse::ActorNotFound,
1580 " Actor Id: " + FString::FromInt(ActorId));
1584 USkinnedMeshComponent* SkinnedMeshComponent = CarlaActor->
GetActor()->FindComponentByClass<USkinnedMeshComponent>();
1585 if(!SkinnedMeshComponent)
1588 "get_actor_bone_names",
1589 ECarlaServerResponse::ComponentNotFound,
1590 " Component Name: SkinnedMeshComponent ");
1594 TArray<FName> BoneNames;
1595 SkinnedMeshComponent->GetBoneNames(BoneNames);
1596 TArray<std::string> StringBoneNames;
1597 for (
const FName& Name : BoneNames)
1599 FString FBoneName = Name.ToString();
1600 std::string StringBoneName = TCHAR_TO_UTF8(*FBoneName);
1601 StringBoneNames.Add(StringBoneName);
1603 return MakeVectorFromTArray<std::string>(StringBoneNames);
1608 BIND_SYNC(get_actor_socket_world_transforms) << [
this](
1609 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1616 "get_actor_socket_world_transforms",
1617 ECarlaServerResponse::ActorNotFound,
1618 " Actor Id: " + FString::FromInt(ActorId));
1622 TArray<FTransform> SocketWorldTransforms;
1623 TArray<UActorComponent*> Components;
1624 CarlaActor->
GetActor()->GetComponents(Components);
1625 for(UActorComponent* ActorComponent : Components)
1627 if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
1629 const TArray<FName>& SocketNames = SceneComponent->GetAllSocketNames();
1630 for (
const FName& SocketName : SocketNames)
1632 FTransform SocketTransform = SceneComponent->GetSocketTransform(SocketName);
1633 SocketWorldTransforms.Add(SocketTransform);
1637 return MakeVectorFromTArray<cr::Transform>(SocketWorldTransforms);
1641 BIND_SYNC(get_actor_socket_relative_transforms) << [
this](
1642 cr::ActorId ActorId) ->
R<std::vector<cr::Transform>>
1649 "get_actor_socket_relative_transforms",
1650 ECarlaServerResponse::ActorNotFound,
1651 " Actor Id: " + FString::FromInt(ActorId));
1655 TArray<FTransform> SocketRelativeTransforms;
1656 TArray<UActorComponent*> Components;
1657 CarlaActor->
GetActor()->GetComponents(Components);
1658 for(UActorComponent* ActorComponent : Components)
1660 if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
1662 const TArray<FName>& SocketNames = SceneComponent->GetAllSocketNames();
1663 for (
const FName& SocketName : SocketNames)
1665 FTransform SocketTransform = SceneComponent->GetSocketTransform(SocketName, ERelativeTransformSpace::RTS_Actor);
1666 SocketRelativeTransforms.Add(SocketTransform);
1670 return MakeVectorFromTArray<cr::Transform>(SocketRelativeTransforms);
1674 BIND_SYNC(get_actor_socket_names) << [
this](
1675 cr::ActorId ActorId) ->
R<std::vector<std::string>>
1682 "get_actor_socket_names",
1683 ECarlaServerResponse::ActorNotFound,
1684 " Actor Id: " + FString::FromInt(ActorId));
1688 TArray<FName> SocketNames;
1689 std::vector<std::string> StringSocketNames;
1690 TArray<UActorComponent*> Components;
1691 CarlaActor->
GetActor()->GetComponents(Components);
1692 for(UActorComponent* ActorComponent : Components)
1694 if(USceneComponent* SceneComponent = Cast<USceneComponent>(ActorComponent))
1696 SocketNames = SceneComponent->GetAllSocketNames();
1697 for (
const FName& Name : SocketNames)
1699 FString FSocketName = Name.ToString();
1700 std::string StringSocketName = TCHAR_TO_UTF8(*FSocketName);
1701 StringSocketNames.push_back(StringSocketName);
1705 return StringSocketNames;
1710 BIND_SYNC(get_physics_control) << [
this](
1718 "get_physics_control",
1719 ECarlaServerResponse::ActorNotFound,
1720 " Actor Id: " + FString::FromInt(ActorId));
1725 if (Response != ECarlaServerResponse::Success)
1728 "get_physics_control",
1730 " Actor Id: " + FString::FromInt(ActorId));
1735 BIND_SYNC(get_vehicle_light_state) << [
this](
1743 "get_vehicle_light_state",
1744 ECarlaServerResponse::ActorNotFound,
1745 " Actor Id: " + FString::FromInt(ActorId));
1750 if (Response != ECarlaServerResponse::Success)
1753 "get_vehicle_light_state",
1755 " Actor Id: " + FString::FromInt(ActorId));
1760 BIND_SYNC(apply_physics_control) << [
this](
1761 cr::ActorId ActorId,
1769 "apply_physics_control",
1770 ECarlaServerResponse::ActorNotFound,
1771 " Actor Id: " + FString::FromInt(ActorId));
1775 if (Response != ECarlaServerResponse::Success)
1778 "apply_physics_control",
1780 " Actor Id: " + FString::FromInt(ActorId));
1785 BIND_SYNC(set_vehicle_light_state) << [
this](
1786 cr::ActorId ActorId,
1794 "set_vehicle_light_state",
1795 ECarlaServerResponse::ActorNotFound,
1796 " Actor Id: " + FString::FromInt(ActorId));
1800 if (Response != ECarlaServerResponse::Success)
1803 "set_vehicle_light_state",
1805 " Actor Id: " + FString::FromInt(ActorId));
1812 cr::ActorId ActorId,
1813 cr::VehicleDoor DoorIdx) ->
R<void>
1820 "open_vehicle_door",
1821 ECarlaServerResponse::ActorNotFound,
1822 " Actor Id: " + FString::FromInt(ActorId));
1826 if (Response != ECarlaServerResponse::Success)
1829 "open_vehicle_door",
1831 " Actor Id: " + FString::FromInt(ActorId));
1836 BIND_SYNC(close_vehicle_door) << [
this](
1837 cr::ActorId ActorId,
1838 cr::VehicleDoor DoorIdx) ->
R<void>
1845 "close_vehicle_door",
1846 ECarlaServerResponse::ActorNotFound,
1847 " Actor Id: " + FString::FromInt(ActorId));
1851 if (Response != ECarlaServerResponse::Success)
1854 "close_vehicle_door",
1856 " Actor Id: " + FString::FromInt(ActorId));
1861 BIND_SYNC(set_wheel_steer_direction) << [
this](
1862 cr::ActorId ActorId,
1863 cr::VehicleWheelLocation WheelLocation,
1870 "set_wheel_steer_direction",
1871 ECarlaServerResponse::ActorNotFound,
1872 " Actor Id: " + FString::FromInt(ActorId));
1877 if (Response != ECarlaServerResponse::Success)
1880 "set_wheel_steer_direction",
1882 " Actor Id: " + FString::FromInt(ActorId));
1887 BIND_SYNC(get_wheel_steer_angle) << [
this](
1888 const cr::ActorId ActorId,
1889 cr::VehicleWheelLocation WheelLocation) ->
R<float>
1895 "get_wheel_steer_angle",
1896 ECarlaServerResponse::ActorNotFound,
1897 " Actor Id: " + FString::FromInt(ActorId));
1903 if (Response != ECarlaServerResponse::Success)
1906 "get_wheel_steer_angle",
1908 " Actor Id: " + FString::FromInt(ActorId));
1913 BIND_SYNC(set_actor_simulate_physics) << [
this](
1914 cr::ActorId ActorId,
1922 "set_actor_simulate_physics",
1923 ECarlaServerResponse::ActorNotFound,
1924 " Actor Id: " + FString::FromInt(ActorId));
1928 if (Response != ECarlaServerResponse::Success)
1931 "set_actor_simulate_physics",
1933 " Actor Id: " + FString::FromInt(ActorId));
1938 BIND_SYNC(set_actor_collisions) << [
this](
1939 cr::ActorId ActorId,
1947 "set_actor_collisions",
1948 ECarlaServerResponse::ActorNotFound,
1949 " Actor Id: " + FString::FromInt(ActorId));
1953 if (Response != ECarlaServerResponse::Success)
1956 "set_actor_collisions",
1958 " Actor Id: " + FString::FromInt(ActorId));
1964 cr::ActorId ActorId) ->
R<void>
1972 ECarlaServerResponse::ActorNotFound,
1973 " Actor Id: " + FString::FromInt(ActorId));
1977 if (Response != ECarlaServerResponse::Success)
1982 " Actor Id: " + FString::FromInt(ActorId));
1987 BIND_SYNC(set_actor_enable_gravity) << [
this](
1988 cr::ActorId ActorId,
1996 "set_actor_enable_gravity",
1997 ECarlaServerResponse::ActorNotFound,
1998 " Actor Id: " + FString::FromInt(ActorId));
2002 if (Response != ECarlaServerResponse::Success)
2005 "set_actor_enable_gravity",
2007 " Actor Id: " + FString::FromInt(ActorId));
2014 BIND_SYNC(apply_control_to_vehicle) << [
this](
2015 cr::ActorId ActorId,
2023 "apply_control_to_vehicle",
2024 ECarlaServerResponse::ActorNotFound,
2025 " Actor Id: " + FString::FromInt(ActorId));
2029 if (Response != ECarlaServerResponse::Success)
2032 "apply_control_to_vehicle",
2034 " Actor Id: " + FString::FromInt(ActorId));
2039 BIND_SYNC(apply_ackermann_control_to_vehicle) << [
this](
2040 cr::ActorId ActorId,
2048 "apply_ackermann_control_to_vehicle",
2049 ECarlaServerResponse::ActorNotFound,
2050 " Actor Id: " + FString::FromInt(ActorId));
2054 if (Response != ECarlaServerResponse::Success)
2057 "apply_ackermann_control_to_vehicle",
2059 " Actor Id: " + FString::FromInt(ActorId));
2064 BIND_SYNC(get_ackermann_controller_settings) << [
this](
2072 "get_ackermann_controller_settings",
2073 ECarlaServerResponse::ActorNotFound,
2074 " Actor Id: " + FString::FromInt(ActorId));
2079 if (Response != ECarlaServerResponse::Success)
2082 "get_ackermann_controller_settings",
2084 " Actor Id: " + FString::FromInt(ActorId));
2086 return cr::AckermannControllerSettings(Settings);
2089 BIND_SYNC(apply_ackermann_controller_settings) << [
this](
2090 cr::ActorId ActorId,
2091 cr::AckermannControllerSettings AckermannSettings) ->
R<void>
2098 "apply_ackermann_controller_settings",
2099 ECarlaServerResponse::ActorNotFound,
2100 " Actor Id: " + FString::FromInt(ActorId));
2104 if (Response != ECarlaServerResponse::Success)
2107 "apply_ackermann_controller_settings",
2109 " Actor Id: " + FString::FromInt(ActorId));
2114 BIND_SYNC(apply_control_to_walker) << [
this](
2115 cr::ActorId ActorId,
2123 "apply_control_to_walker",
2124 ECarlaServerResponse::ActorNotFound,
2125 " Actor Id: " + FString::FromInt(ActorId));
2129 if (Response != ECarlaServerResponse::Success)
2132 "apply_control_to_walker",
2134 " Actor Id: " + FString::FromInt(ActorId));
2139 BIND_SYNC(get_bones_transform) << [
this](
2147 "get_bones_transform",
2148 ECarlaServerResponse::ActorNotFound,
2149 " Actor Id: " + FString::FromInt(ActorId));
2154 if (Response != ECarlaServerResponse::Success)
2157 "get_bones_transform",
2159 " Actor Id: " + FString::FromInt(ActorId));
2162 std::vector<carla::rpc::BoneTransformDataOut> BoneData;
2166 Data.
bone_name = std::string(TCHAR_TO_UTF8(*Bone.Get<0>()));
2171 BoneData.push_back(Data);
2176 BIND_SYNC(set_bones_transform) << [
this](
2177 cr::ActorId ActorId,
2185 "set_bones_transform",
2186 ECarlaServerResponse::ActorNotFound,
2187 " Actor Id: " + FString::FromInt(ActorId));
2192 if (Response != ECarlaServerResponse::Success)
2195 "set_bones_transform",
2197 " Actor Id: " + FString::FromInt(ActorId));
2204 cr::ActorId ActorId,
2213 ECarlaServerResponse::ActorNotFound,
2214 " Actor Id: " + FString::FromInt(ActorId));
2218 if (Response != ECarlaServerResponse::Success)
2223 " Actor Id: " + FString::FromInt(ActorId));
2229 BIND_SYNC(get_pose_from_animation) << [
this](
2230 cr::ActorId ActorId) ->
R<void>
2237 "get_pose_from_animation",
2238 ECarlaServerResponse::ActorNotFound,
2239 " Actor Id: " + FString::FromInt(ActorId));
2243 if (Response != ECarlaServerResponse::Success)
2246 "get_pose_from_animation",
2248 " Actor Id: " + FString::FromInt(ActorId));
2254 BIND_SYNC(set_actor_autopilot) << [
this](
2255 cr::ActorId ActorId,
2263 "set_actor_autopilot",
2264 ECarlaServerResponse::ActorNotFound,
2265 " Actor Id: " + FString::FromInt(ActorId));
2269 if (Response != ECarlaServerResponse::Success)
2272 "set_actor_autopilot",
2274 " Actor Id: " + FString::FromInt(ActorId));
2279 BIND_SYNC(get_telemetry_data) << [
this](
2287 "get_telemetry_data",
2288 ECarlaServerResponse::ActorNotFound,
2289 " Actor Id: " + FString::FromInt(ActorId));
2294 if (Response != ECarlaServerResponse::Success)
2297 "get_telemetry_data",
2299 " Actor Id: " + FString::FromInt(ActorId));
2301 return cr::VehicleTelemetryData(TelemetryData);
2304 BIND_SYNC(show_vehicle_debug_telemetry) << [
this](
2305 cr::ActorId ActorId,
2313 "show_vehicle_debug_telemetry",
2314 ECarlaServerResponse::ActorNotFound,
2315 " Actor Id: " + FString::FromInt(ActorId));
2319 if (Response != ECarlaServerResponse::Success)
2322 "show_vehicle_debug_telemetry",
2324 " Actor Id: " + FString::FromInt(ActorId));
2330 cr::ActorId ActorId,
2331 std::string SimfilePath) ->
R<void>
2339 ECarlaServerResponse::ActorNotFound,
2340 " Actor Id: " + FString::FromInt(ActorId));
2343 CarlaActor->
EnableCarSim(carla::rpc::ToFString(SimfilePath));
2344 if (Response != ECarlaServerResponse::Success)
2349 " Actor Id: " + FString::FromInt(ActorId));
2355 cr::ActorId ActorId,
2364 ECarlaServerResponse::ActorNotFound,
2365 " Actor Id: " + FString::FromInt(ActorId));
2369 if (Response != ECarlaServerResponse::Success)
2374 " Actor Id: " + FString::FromInt(ActorId));
2379 BIND_SYNC(enable_chrono_physics) << [
this](
2380 cr::ActorId ActorId,
2381 uint64_t MaxSubsteps,
2382 float MaxSubstepDeltaTime,
2383 std::string VehicleJSON,
2384 std::string PowertrainJSON,
2385 std::string TireJSON,
2386 std::string BaseJSONPath) ->
R<void>
2393 "enable_chrono_physics",
2394 ECarlaServerResponse::ActorNotFound,
2395 " Actor Id: " + FString::FromInt(ActorId));
2399 MaxSubsteps, MaxSubstepDeltaTime,
2400 cr::ToFString(VehicleJSON),
2401 cr::ToFString(PowertrainJSON),
2402 cr::ToFString(TireJSON),
2403 cr::ToFString(BaseJSONPath));
2404 if (Response != ECarlaServerResponse::Success)
2407 "enable_chrono_physics",
2409 " Actor Id: " + FString::FromInt(ActorId));
2414 BIND_SYNC(restore_physx_physics) << [
this](
2415 cr::ActorId ActorId) ->
R<void>
2422 "restore_physx_physics",
2423 ECarlaServerResponse::ActorNotFound,
2424 " Actor Id: " + FString::FromInt(ActorId));
2428 if (Response != ECarlaServerResponse::Success)
2431 "restore_physx_physics",
2433 " Actor Id: " + FString::FromInt(ActorId));
2440 BIND_SYNC(set_traffic_light_state) << [
this](
2441 cr::ActorId ActorId,
2442 cr::TrafficLightState trafficLightState) ->
R<void>
2449 "set_traffic_light_state",
2450 ECarlaServerResponse::ActorNotFound,
2451 " Actor Id: " + FString::FromInt(ActorId));
2456 if (Response != ECarlaServerResponse::Success)
2459 "set_traffic_light_state",
2461 " Actor Id: " + FString::FromInt(ActorId));
2466 BIND_SYNC(set_traffic_light_green_time) << [
this](
2467 cr::ActorId ActorId,
2475 "set_traffic_light_green_time",
2476 ECarlaServerResponse::ActorNotFound,
2477 " Actor Id: " + FString::FromInt(ActorId));
2481 if (Response != ECarlaServerResponse::Success)
2484 "set_traffic_light_green_time",
2486 " Actor Id: " + FString::FromInt(ActorId));
2491 BIND_SYNC(set_traffic_light_yellow_time) << [
this](
2492 cr::ActorId ActorId,
2500 "set_traffic_light_yellow_time",
2501 ECarlaServerResponse::ActorNotFound,
2502 " Actor Id: " + FString::FromInt(ActorId));
2506 if (Response != ECarlaServerResponse::Success)
2509 "set_traffic_light_yellow_time",
2511 " Actor Id: " + FString::FromInt(ActorId));
2516 BIND_SYNC(set_traffic_light_red_time) << [
this](
2517 cr::ActorId ActorId,
2525 "set_traffic_light_red_time",
2526 ECarlaServerResponse::ActorNotFound,
2527 " Actor Id: " + FString::FromInt(ActorId));
2531 if (Response != ECarlaServerResponse::Success)
2534 "set_traffic_light_red_time",
2536 " Actor Id: " + FString::FromInt(ActorId));
2541 BIND_SYNC(freeze_traffic_light) << [
this](
2542 cr::ActorId ActorId,
2550 "freeze_traffic_light",
2551 ECarlaServerResponse::ActorNotFound,
2552 " Actor Id: " + FString::FromInt(ActorId));
2556 if (Response != ECarlaServerResponse::Success)
2559 "freeze_traffic_light",
2561 " Actor Id: " + FString::FromInt(ActorId));
2566 BIND_SYNC(reset_traffic_light_group) << [
this](
2567 cr::ActorId ActorId) ->
R<void>
2574 "reset_traffic_light_group",
2575 ECarlaServerResponse::ActorNotFound,
2576 " Actor Id: " + FString::FromInt(ActorId));
2580 if (Response != ECarlaServerResponse::Success)
2583 "reset_traffic_light_group",
2585 " Actor Id: " + FString::FromInt(ActorId));
2593 for (TActorIterator<ATrafficLightGroup> It(
Episode->GetWorld()); It; ++It)
2600 BIND_SYNC(freeze_all_traffic_lights) << [
this]
2609 auto* TraffiLightManager = GameMode->GetTrafficLightManager();
2610 TraffiLightManager->SetFrozen(frozen);
2617 cr::VehicleLightStateList List;
2619 auto It =
Episode->GetActorRegistry().begin();
2620 for (; It !=
Episode->GetActorRegistry().
end(); ++It)
2632 if (!
Actor->IsPendingKill())
2637 cr::VehicleLightState(
Vehicle->GetVehicleLightState()).GetLightStateAsValue());
2645 BIND_SYNC(get_group_traffic_lights) << [
this](
2646 const cr::ActorId ActorId) ->
R<std::vector<cr::ActorId>>
2652 RESPOND_ERROR(
"unable to get group traffic lights: actor not found");
2657 return std::vector<cr::ActorId>();
2664 RESPOND_ERROR(
"unable to get group traffic lights: actor is not a traffic light");
2666 std::vector<cr::ActorId> Result;
2667 for (
auto* TLight :
TrafficLight->GetGroupTrafficLights())
2669 auto* View =
Episode->FindCarlaActor(TLight);
2672 Result.push_back(View->GetActorId());
2680 const cr::ActorId ActorId) ->
R<std::vector<cg::BoundingBox>>
2688 ECarlaServerResponse::ActorNotFound,
2689 " Actor Id: " + FString::FromInt(ActorId));
2695 ECarlaServerResponse::FunctionNotAvailiableWhenDormant,
2696 " Actor Id: " + FString::FromInt(ActorId));
2705 ECarlaServerResponse::NotATrafficLight,
2706 " Actor Id: " + FString::FromInt(ActorId));
2708 TArray<FBoundingBox> Result;
2709 TArray<uint8> OutTag;
2713 return MakeVectorFromTArray<cg::BoundingBox>(Result);
2718 BIND_SYNC(get_gbuffer_token) << [
this](
const cr::ActorId ActorId, uint32_t GBufferId) ->
R<std::vector<unsigned char>>
2725 "get_gbuffer_token",
2726 ECarlaServerResponse::ActorNotFound,
2727 " Actor Id: " + FString::FromInt(ActorId));
2732 "get_gbuffer_token",
2733 ECarlaServerResponse::FunctionNotAvailiableWhenDormant,
2734 " Actor Id: " + FString::FromInt(ActorId));
2740 "get_gbuffer_token",
2741 ECarlaServerResponse::ActorTypeMismatch,
2742 " Actor Id: " + FString::FromInt(ActorId));
2750 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2755 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2760 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2765 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2770 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2775 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2780 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2785 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2790 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2795 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2800 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2805 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2810 return std::vector<unsigned char>(std::begin(Token.data), std::end(Token.data));
2813 UE_LOG(LogCarla, Error, TEXT(
"Requested invalid GBuffer ID %u"), GBufferId);
2829 Episode->GetRecorder()->Stop();
2833 BIND_SYNC(show_recorder_file_info) << [
this](
2843 BIND_SYNC(show_recorder_collisions) << [
this](
2855 BIND_SYNC(show_recorder_actors_blocked) << [
this](
2883 BIND_SYNC(set_replayer_time_factor) << [
this](
double time_factor) ->
R<void>
2886 Episode->GetRecorder()->SetReplayerTimeFactor(time_factor);
2893 Episode->GetRecorder()->SetReplayerIgnoreHero(ignore_hero);
2897 BIND_SYNC(set_replayer_ignore_spectator) << [
this](
bool ignore_spectator) ->
R<void>
2900 Episode->GetRecorder()->SetReplayerIgnoreSpectator(ignore_spectator);
2907 Episode->GetRecorder()->StopReplayer(keep_actors);
2913 BIND_SYNC(draw_debug_shape) << [
this](
const cr::DebugShape &shape) ->
R<void>
2917 check(
World !=
nullptr);
2925 using C = cr::Command;
2926 using CR = cr::CommandResponse;
2929 auto parse_result = [](ActorId id,
const auto &response) {
2930 return response.HasError() ? CR{response.GetError()} : CR{
id};
2933#define MAKE_RESULT(operation) return parse_result(c.actor, operation);
2936 [=](
auto self,
const C::SpawnActor &c) -> CR {
2937 auto result = c.parent.has_value() ?
2938 spawn_actor_with_parent(
2942 cr::AttachmentType::Rigid,
2944 spawn_actor(c.description, c.transform);
2945 if (!result.HasError())
2947 ActorId id = result.Get().id;
2948 auto set_id = carla::Functional::MakeOverload(
2949 [](C::SpawnActor &) {},
2950 [](C::ConsoleCommand &) {},
2951 [
id](
auto &s) { s.actor = id; });
2952 for (
auto command : c.do_after)
2954 boost::variant2::visit(set_id, command.command);
2955 boost::variant2::visit(self, command.command);
2959 return result.GetError();
2961 [=](
auto,
const C::DestroyActor &c) {
MAKE_RESULT(destroy_actor(c.actor)); },
2962 [=](
auto,
const C::ApplyVehicleControl &c) {
MAKE_RESULT(apply_control_to_vehicle(c.actor, c.control)); },
2963 [=](
auto,
const C::ApplyVehicleAckermannControl &c) {
MAKE_RESULT(apply_ackermann_control_to_vehicle(c.actor, c.control)); },
2964 [=](
auto,
const C::ApplyWalkerControl &c) {
MAKE_RESULT(apply_control_to_walker(c.actor, c.control)); },
2965 [=](
auto,
const C::ApplyVehiclePhysicsControl &c) {
MAKE_RESULT(apply_physics_control(c.actor, c.physics_control)); },
2966 [=](
auto,
const C::ApplyTransform &c) {
MAKE_RESULT(set_actor_transform(c.actor, c.transform)); },
2967 [=](
auto,
const C::ApplyTargetVelocity &c) {
MAKE_RESULT(set_actor_target_velocity(c.actor, c.velocity)); },
2968 [=](
auto,
const C::ApplyTargetAngularVelocity &c) {
MAKE_RESULT(set_actor_target_angular_velocity(c.actor, c.angular_velocity)); },
2969 [=](
auto,
const C::ApplyImpulse &c) {
MAKE_RESULT(add_actor_impulse(c.actor, c.impulse)); },
2970 [=](
auto,
const C::ApplyForce &c) {
MAKE_RESULT(add_actor_force(c.actor, c.force)); },
2971 [=](
auto,
const C::ApplyAngularImpulse &c) {
MAKE_RESULT(add_actor_angular_impulse(c.actor, c.impulse)); },
2972 [=](
auto,
const C::ApplyTorque &c) {
MAKE_RESULT(add_actor_torque(c.actor, c.torque)); },
2973 [=](
auto,
const C::SetSimulatePhysics &c) {
MAKE_RESULT(set_actor_simulate_physics(c.actor, c.enabled)); },
2974 [=](
auto,
const C::SetEnableGravity &c) {
MAKE_RESULT(set_actor_enable_gravity(c.actor, c.enabled)); },
2976 [=](
auto,
const C::SetAutopilot &c) {
MAKE_RESULT(set_actor_autopilot(c.actor, c.enabled)); },
2977 [=](
auto,
const C::ShowDebugTelemetry &c) {
MAKE_RESULT(show_vehicle_debug_telemetry(c.actor, c.enabled)); },
2978 [=](
auto,
const C::SetVehicleLightState &c) {
MAKE_RESULT(set_vehicle_light_state(c.actor, c.light_state)); },
2981 [=](
auto,
const C::ApplyWalkerState &c) {
MAKE_RESULT(set_walker_state(c.actor, c.transform, c.speed)); },
2982 [=](
auto,
const C::ConsoleCommand& c) -> CR {
return console_command(c.cmd); },
2983 [=](
auto,
const C::SetTrafficLightState& c) {
MAKE_RESULT(set_traffic_light_state(c.actor, c.traffic_light_state)); },
2984 [=](
auto,
const C::ApplyLocation& c) {
MAKE_RESULT(set_actor_location(c.actor, c.location)); }
2990 const std::vector<cr::Command> &commands,
2993 std::vector<CR> result;
2994 result.reserve(commands.size());
2995 for (
const auto &command : commands)
2997 result.emplace_back(boost::variant2::visit(command_visitor, command.command));
3008 BIND_SYNC(query_lights_state) << [
this](std::string
client) ->
R<std::vector<cr::LightState>>
3011 std::vector<cr::LightState> result;
3012 auto *
World = Episode->GetWorld();
3020 BIND_SYNC(update_lights_state) << [
this]
3021 (std::string
client,
const std::vector<cr::LightState>& lights,
bool discard_client) ->
R<void>
3024 auto *
World = Episode->GetWorld();
3027 CarlaLightSubsystem->
SetLights(FString(
client.c_str()), lights, discard_client);
3032 BIND_SYNC(update_day_night_cycle) << [
this]
3036 auto *
World = Episode->GetWorld();
3048 (cr::Location
Location, cr::Vector3D Direction,
float SearchDistance)
3049 ->
R<std::pair<bool,cr::LabelledPoint>>
3052 auto *
World = Episode->GetWorld();
3053 constexpr float meter_to_centimeter = 100.0f;
3062 meter_to_centimeter * SearchDistance,
World);
3066 (cr::Location StartLocation, cr::Location EndLocation)
3067 ->
R<std::vector<cr::LabelledPoint>>
3070 auto *
World = Episode->GetWorld();
3071 FVector UEStartLocation = StartLocation;
3072 FVector UEEndLocation = EndLocation;
3091#undef REQUIRE_CARLA_EPISODE
3092#undef RESPOND_ERROR_FSTRING
3094#undef CARLA_ENSURE_GAME_THREAD
3108 Pimpl = MakeUnique<FPimpl>(RPCPort, StreamingPort, SecondaryPort);
3109 StreamingPort =
Pimpl->StreamingServer.GetLocalEndpoint().port();
3110 SecondaryPort =
Pimpl->SecondaryServer->GetLocalEndpoint().port();
3115 TEXT(
"Initialized CarlaServer: Ports(rpc=%d, streaming=%d, secondary=%d)"),
3119 return Pimpl->BroadcastStream;
3124 check(
Pimpl !=
nullptr);
3125 UE_LOG(LogCarlaServer, Log, TEXT(
"New episode '%s' started"), *Episode.GetMapName());
3126 Pimpl->Episode = &Episode;
3131 check(
Pimpl !=
nullptr);
3132 Pimpl->Episode =
nullptr;
3137 check(
Pimpl !=
nullptr);
3139 int ThreadsPerServer = std::max(2u, NumberOfWorkerThreads / 3u);
3141 int32_t StreamingThreads;
3142 int32_t SecondaryThreads;
3144 UE_LOG(LogCarla, Log, TEXT(
"FCommandLine %s"), FCommandLine::Get());
3146 if(!FParse::Value(FCommandLine::Get(), TEXT(
"-RPCThreads="), RPCThreads))
3148 RPCThreads = ThreadsPerServer;
3150 if(!FParse::Value(FCommandLine::Get(), TEXT(
"-StreamingThreads="), StreamingThreads))
3152 StreamingThreads = ThreadsPerServer;
3154 if(!FParse::Value(FCommandLine::Get(), TEXT(
"-SecondaryThreads="), SecondaryThreads))
3156 SecondaryThreads = ThreadsPerServer;
3159 UE_LOG(LogCarla, Log, TEXT(
"FCarlaServer AsyncRun %d, RPCThreads %d, StreamingThreads %d, SecondaryThreads %d"),
3160 NumberOfWorkerThreads, RPCThreads, StreamingThreads, SecondaryThreads);
3162 Pimpl->Server.AsyncRun(RPCThreads);
3163 Pimpl->StreamingServer.AsyncRun(StreamingThreads);
3164 Pimpl->SecondaryServer->AsyncRun(SecondaryThreads);
3169 TRACE_CPUPROFILER_EVENT_SCOPE_STR(__FUNCTION__);
3175 (void)
Pimpl->TickCuesReceived.fetch_add(1, std::memory_order_release);
3180 auto k =
Pimpl->TickCuesReceived.fetch_sub(1, std::memory_order_acquire);
3181 bool flag = (k > 0);
3183 (void)
Pimpl->TickCuesReceived.fetch_add(1, std::memory_order_release);
3191 Pimpl->Server.Stop();
3192 Pimpl->SecondaryServer->Stop();
3198 check(
Pimpl !=
nullptr);
3199 return Pimpl->StreamingServer.MakeStream();
3204 return Pimpl->GetSecondaryServer();
3209 return Pimpl->StreamingServer;
FVehicleLightState LightState
FVehiclePhysicsControl PhysicsControl
UE_LOG(LogCarla, Log, TEXT("UActorDispatcher::Destroying actor: '%s' %x"), *Id, Actor)
if(!Actor||!Actor->Destroy())
auto end() const noexcept
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld * World
TSharedPtr< const FActorInfo > carla::rpc::ActorState UWorld Actor
FString CarlaGetStringError(ECarlaServerResponse Response)
#define REQUIRE_CARLA_EPISODE()
#define MAKE_RESULT(operation)
#define RESPOND_ERROR(str)
#define RESPOND_ERROR_FSTRING(fstr)
carla::rpc::ResponseError RespondError(const FString &FuncName, const FString &ErrorMessage, const FString &ExtraInfo="")
static std::vector< T > MakeVectorFromTArray(const TArray< Other > &Array)
EVehicleDoor
Type of door to open/close
void UnLoadMapLayer(int32 MapLayers)
void EnableEnvironmentObjects(const TSet< uint64 > &EnvObjectIds, bool Enable)
TArray< FEnvironmentObject > GetEnvironmentObjects(uint8 QueriedTag=0xFF) const
AActor * FindActorByName(const FString &ActorName)
void LoadMapLayer(int32 MapLayers)
void ApplyTextureToActor(AActor *Actor, UTexture2D *Texture, const carla::rpc::MaterialParameter &TextureParam)
const FString GetFullMapPath() const
ALargeMapManager * GetLMManager() const
TArray< FString > GetNamesOfAllActors()
TArray< FBoundingBox > GetAllBBsOfLevel(uint8 TagQueried=0xFF) const
UTexture2D * CreateUETexture(const carla::rpc::TextureColor &Texture)
void Send(const FString message)
void ConsiderSpectatorAsEgo(bool _SpectatorAsEgo)
void OnActorSpawned(const FCarlaActor &CarlaActor)
FVector GlobalToLocalLocation(const FVector &InLocation) const
FTransform LocalToGlobalTransform(const FTransform &InTransform) const
FVector LocalToGlobalLocation(const FVector &InLocation) const
使用USceneCaptureComponent2D进行场景渲染的传感器基类 scene.
FCameraGBufferUint8 CustomDepth
FCameraGBufferUint8 GBufferD
struct ASceneCaptureSensor::@0 CameraGBuffers
FCameraGBufferUint8 GBufferE
FCameraGBufferUint8 GBufferF
FCameraGBufferUint8 GBufferA
FCameraGBufferUint8 SceneDepth
FCameraGBufferUint8 SceneStencil
FCameraGBufferUint8 GBufferC
FCameraGBufferUint8 CustomStencil
FCameraGBufferUint8 Velocity
FCameraGBufferUint8 SceneColor
FCameraGBufferUint8 GBufferB
ECarlaServerResponse AddActorImpulseAtLocation(const FVector &Impulse, const FVector &Location)
virtual ECarlaServerResponse GetPhysicsControl(FVehiclePhysicsControl &)
ECarlaServerResponse AddActorForceAtLocation(const FVector &Force, const FVector &Location)
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled)
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControlOut &)
virtual ECarlaServerResponse GetAckermannControllerSettings(FAckermannControllerSettings &)
virtual ECarlaServerResponse SetLightRedTime(float)
virtual ECarlaServerResponse ResetTrafficLightGroup()
ActorType GetActorType() const
virtual ECarlaServerResponse SetLightYellowTime(float)
virtual ECarlaServerResponse GetPoseFromAnimation()
virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState=false)
ECarlaServerResponse AddActorTorque(const FVector &Torque)
ECarlaServerResponse SetActorTargetAngularVelocity(const FVector &AngularVelocity)
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
virtual ECarlaServerResponse SetActorDead()
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
virtual ECarlaServerResponse GetWheelSteerAngle(const EVehicleWheelLocation &, float &)
virtual ECarlaServerResponse ApplyAckermannControllerSettings(const FAckermannControllerSettings &)
virtual ECarlaServerResponse SetActorCollisions(bool bEnabled)
virtual ECarlaServerResponse GetVehicleTelemetryData(FVehicleTelemetryData &)
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor)
virtual ECarlaServerResponse RestorePhysXPhysics()
virtual ECarlaServerResponse ApplyAckermannControlToVehicle(const FVehicleAckermannControl &, const EVehicleInputPriority &)
void SetParent(IdType InParentId)
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
virtual ECarlaServerResponse SetWalkerState(const FTransform &Transform, carla::rpc::WalkerControl WalkerControl)
virtual ECarlaServerResponse DisableActorConstantVelocity()
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &)
virtual ECarlaServerResponse SetBonesTransform(const FWalkerBoneControlIn &)
virtual ECarlaServerResponse FreezeTrafficLight(bool)
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
void SetActorState(carla::rpc::ActorState InState)
void SetActorGlobalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
virtual ECarlaServerResponse UseCarSimRoad(bool)
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl &)
virtual ECarlaServerResponse SetLightGreenTime(float)
void AddChildren(IdType ChildId)
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor)
const FActorInfo * GetActorInfo() const
IdType GetActorId() const
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector &)
virtual ECarlaServerResponse SetWheelSteerDirection(const EVehicleWheelLocation &, float)
virtual ECarlaServerResponse EnableCarSim(const FString &)
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
ECarlaServerResponse AddActorForce(const FVector &Force)
virtual ECarlaServerResponse BlendPose(float Blend)
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool)
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
virtual ECarlaServerResponse EnableChronoPhysics(uint64_t, float, const FString &, const FString &, const FString &, const FString &)
ECarlaServerResponse AddActorAngularImpulse(const FVector &AngularInpulse)
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
static uint64_t GetFrameCounter()
carla::streaming::Stream BroadcastStream
carla::streaming::Server StreamingServer
std::shared_ptr< carla::multigpu::Router > SecondaryServer
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
carla::rpc::Server Server
std::atomic_size_t TickCuesReceived
FPimpl(uint16_t RPCPort, uint16_t StreamingPort, uint16_t SecondaryPort)
std::map< uint16_t, std::string > TrafficManagerInfo
仿真中所有活动的交通管理器对 < port, ip > 的映射
std::shared_ptr< carla::multigpu::Router > GetSecondaryServer()
void RunSome(uint32 Milliseconds)
TUniquePtr< FPimpl > Pimpl
carla::streaming::Server & GetStreamingServer()
FDataStream OpenStream() const
void NotifyBeginEpisode(UCarlaEpisode &Episode)
FDataMultiStream Start(uint16_t RPCPort, uint16_t StreamingPort, uint16_t SecondaryPort)
void AsyncRun(uint32 NumberOfWorkerThreads)
void Draw(const carla::rpc::DebugShape &Shape)
static TArray< uint8 > Load(FString MapName)
Return the Navigation Mesh Binary associated to MapName, or empty if the such file wasn't serialized.
constexpr ServerBinder(const char *name, carla::rpc::Server &srv, bool sync)
auto operator<<(FuncT func)
carla::rpc::Server & _server
static void GetTrafficLightBoundingBox(const ATrafficLightBase *TrafficLight, TArray< FBoundingBox > &OutBB, TArray< uint8 > &OutTag, uint8 InTagQueried=0xFF)
void SetMapLayer(int32 MapLayer)
std::vector< carla::rpc::LightState > GetLights(FString Client)
void SetLights(FString Client, std::vector< carla::rpc::LightState > LightsToSet, bool DiscardClient=false)
void SetDayNightCycle(const bool active)
static UCarlaGameInstance * GetGameInstance(const UObject *WorldContextObject)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static TArray< FString > GetAllMapNames()
static ACarlaGameModeBase * GetGameMode(const UObject *WorldContextObject)
static FString GetXODR(const UWorld *World)
MapNameOpenDrive XMLҲļؿա
static std::pair< bool, carla::rpc::LabelledPoint > ProjectPoint(FVector StartLocation, FVector Direction, float MaxDistance, UWorld *World)
static std::vector< carla::rpc::LabelledPoint > CastRay(FVector StartLocation, FVector EndLocation, UWorld *World)
static auto MakeRecursiveOverload(FuncTs &&... fs)
创建递归重载调用对象
static std::shared_ptr< ROS2 > GetInstance()
一个RPC服务器,可以将功能绑定为同步或异步运行。
void BindSync(const std::string &name, FunctorT &&functor)
void BindAsync(const std::string &name, FunctorT &&functor)
token_type GetToken(stream_id sensor_id)
bool IsEnabledForROS(stream_id sensor_id)
void EnableForROS(stream_id sensor_id)
void DisableForROS(stream_id sensor_id)
void SetSynchronousMode(bool is_synchro)
Token token() const
与此流关联的 Token。客户端可使用该 Token 订阅此流。
constexpr size_t milliseconds() const noexcept
uint32_t stream_id_type
流ID的类型定义。
TMap< FString, FActorAttribute > Variations
用户选择了参与者的变化版本。请注意,此时是 由不可修改的属性表示
FActorDescription Description
static FString StatusToString(EActorSpawnResultStatus Status)
auto GetToken() const
Return the token that allows subscribing to this sensor's stream.
TMap< FString, FWalkerBoneControlOutData > BoneTransforms