Added functions to interface the FCarlaActor object with recorder. Started adapting recorder to new FCarlaActor object.

This commit is contained in:
Axel 2021-06-02 17:18:53 +02:00 committed by bernat
parent 3b8fda28db
commit bd1725b2d2
8 changed files with 451 additions and 199 deletions

View File

@ -183,7 +183,10 @@ TSharedPtr<FCarlaActor> FActorRegistry::MakeCarlaActor(
}
auto Type = FActorRegistry_GetActorType(&Actor);
TSharedPtr<FCarlaActor> CarlaActor =
FCarlaActor::ConstructCarlaActor(Id, &Actor, std::move(Info), Type, InState);
FCarlaActor::ConstructCarlaActor(
Id, &Actor,
std::move(Info), Type,
InState, Actor.GetWorld());
return CarlaActor;
}

View File

@ -16,6 +16,7 @@
#include "Carla/Vehicle/MovementComponents/CarSimManagerComponent.h"
#include "Carla/Vehicle/MovementComponents/ChronoMovementComponent.h"
#include "Carla/Traffic/TrafficLightBase.h"
#include "Carla/Game/CarlaStatics.h"
#include <compiler/disable-ue4-macros.h>
#include "carla/rpc/LabelledPoint.h"
@ -37,19 +38,22 @@ FCarlaActor::FCarlaActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
carla::rpc::ActorState InState,
UWorld* World)
: TheActor(Actor),
Info(std::move(Info)),
Id(ActorId),
State(InState)
State(InState),
World(World)
{
}
FVehicleActor::FVehicleActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
: FCarlaActor(ActorId, Actor, Info, InState)
carla::rpc::ActorState InState,
UWorld* World)
: FCarlaActor(ActorId, Actor, Info, InState, World)
{
Type = ActorType::Vehicle;
ActorData = MakeShared<FVehicleData>();
@ -58,8 +62,9 @@ FSensorActor::FSensorActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
: FCarlaActor(ActorId, Actor, Info, InState)
carla::rpc::ActorState InState,
UWorld* World)
: FCarlaActor(ActorId, Actor, Info, InState, World)
{
Type = ActorType::Sensor;
ActorData = MakeShared<FActorSensorData>();
@ -68,8 +73,9 @@ FTrafficSignActor::FTrafficSignActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
: FCarlaActor(ActorId, Actor, Info, InState)
carla::rpc::ActorState InState,
UWorld* World)
: FCarlaActor(ActorId, Actor, Info, InState, World)
{
Type = ActorType::TrafficSign;
ActorData = MakeShared<FTrafficSignData>();
@ -78,8 +84,9 @@ FTrafficLightActor::FTrafficLightActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
: FCarlaActor(ActorId, Actor, Info, InState)
carla::rpc::ActorState InState,
UWorld* World)
: FCarlaActor(ActorId, Actor, Info, InState, World)
{
Type = ActorType::TrafficLight;
ActorData = MakeShared<FTrafficLightData>();
@ -88,8 +95,9 @@ FWalkerActor::FWalkerActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
: FCarlaActor(ActorId, Actor, Info, InState)
carla::rpc::ActorState InState,
UWorld* World)
: FCarlaActor(ActorId, Actor, Info, InState, World)
{
Type = ActorType::Walker;
ActorData = MakeShared<FWalkerData>();
@ -98,8 +106,9 @@ FOtherActor::FOtherActor(
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState)
: FCarlaActor(ActorId, Actor, Info, InState)
carla::rpc::ActorState InState,
UWorld* World)
: FCarlaActor(ActorId, Actor, Info, InState, World)
{
Type = ActorType::Other;
ActorData = MakeShared<FActorData>();
@ -110,27 +119,28 @@ TSharedPtr<FCarlaActor> FCarlaActor::ConstructCarlaActor(
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
ActorType Type,
carla::rpc::ActorState InState)
carla::rpc::ActorState InState,
UWorld* World)
{
switch(Type)
{
case ActorType::TrafficSign:
return MakeShared<FTrafficSignActor>(ActorId, Actor, std::move(Info), InState);
return MakeShared<FTrafficSignActor>(ActorId, Actor, std::move(Info), InState, World);
break;
case ActorType::TrafficLight:
return MakeShared<FTrafficLightActor>(ActorId, Actor, std::move(Info), InState);
return MakeShared<FTrafficLightActor>(ActorId, Actor, std::move(Info), InState, World);
break;
case ActorType::Vehicle:
return MakeShared<FVehicleActor>(ActorId, Actor, std::move(Info), InState);
return MakeShared<FVehicleActor>(ActorId, Actor, std::move(Info), InState, World);
break;
case ActorType::Walker:
return MakeShared<FWalkerActor>(ActorId, Actor, std::move(Info), InState);
return MakeShared<FWalkerActor>(ActorId, Actor, std::move(Info), InState, World);
break;
case ActorType::Sensor:
return MakeShared<FSensorActor>(ActorId, Actor, std::move(Info), InState);
return MakeShared<FSensorActor>(ActorId, Actor, std::move(Info), InState, World);
break;
default:
return MakeShared<FOtherActor>(ActorId, Actor, std::move(Info), InState);
return MakeShared<FOtherActor>(ActorId, Actor, std::move(Info), InState, World);
break;
}
}
@ -161,11 +171,100 @@ void FCarlaActor::WakeActorUp(UCarlaEpisode* CarlaEpisode)
ActorData->RestoreActorData(TheActor, CarlaEpisode);
}
ECarlaServerResponse FCarlaActor::SetActorLocation(const FVector& Location, ETeleportType TeleportType)
FTransform FCarlaActor::GetActorLocalTransform() const
{
if (IsDormant())
{
ActorData->Location = FDVector(Location);
FTransform Transform = FTransform(
ActorData->Rotation,
ActorData->Location.ToFVector(),
ActorData->Scale);
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
Transform = LargeMap->GlobalToLocalTransform(Transform);
}
return Transform;
}
else
{
return GetActor()->GetActorTransform();
}
}
FTransform FCarlaActor::GetActorGlobalTransform() const
{
if (IsDormant())
{
return FTransform(
ActorData->Rotation,
ActorData->Location.ToFVector(),
ActorData->Scale);
}
else
{
FTransform Transform = GetActor()->GetActorTransform();
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
Transform = LargeMap->LocalToGlobalTransform(Transform);
}
return Transform;
}
}
FVector FCarlaActor::GetActorLocalLocation() const
{
if (IsDormant())
{
FVector Location = ActorData->Location.ToFVector();
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
Location = LargeMap->GlobalToLocalLocation(Location);
}
return Location;
}
else
{
return GetActor()->GetActorLocation();
}
}
FVector FCarlaActor::GetActorGlobalLocation() const
{
if (IsDormant())
{
return ActorData->Location.ToFVector();
}
else
{
FVector Location = GetActor()->GetActorLocation();
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
Location = LargeMap->LocalToGlobalLocation(Location);
}
return Location;
}
}
void FCarlaActor::SetActorLocalLocation(const FVector& Location, ETeleportType TeleportType)
{
if (IsDormant())
{
FVector GlobalLocation = Location;
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
GlobalLocation = LargeMap->LocalToGlobalLocation(GlobalLocation);
}
ActorData->Location = FDVector(GlobalLocation);
}
else
{
@ -175,16 +274,48 @@ ECarlaServerResponse FCarlaActor::SetActorLocation(const FVector& Location, ETel
nullptr,
TeleportType);
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FCarlaActor::SetActorTransform(const FTransform& Transform, ETeleportType TeleportType)
void FCarlaActor::SetActorGlobalLocation(
const FVector& Location, ETeleportType TeleportType)
{
if (IsDormant())
{
ActorData->Location = FDVector(Transform.GetLocation());
ActorData->Rotation = Transform.GetRotation();
ActorData->Scale = Transform.GetScale3D();
ActorData->Location = FDVector(Location);;
}
else
{
FVector LocalLocation = Location;
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
LocalLocation = LargeMap->GlobalToLocalLocation(Location);
}
GetActor()->SetActorRelativeLocation(
LocalLocation,
false,
nullptr,
TeleportType);
}
}
void FCarlaActor::SetActorLocalTransform(
const FTransform& Transform, ETeleportType TeleportType)
{
if (IsDormant())
{
FTransform GlobalTransform = Transform;
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
GlobalTransform =
LargeMap->LocalToGlobalTransform(GlobalTransform);
}
ActorData->Location = FDVector(GlobalTransform.GetLocation());
ActorData->Rotation = GlobalTransform.GetRotation();
ActorData->Scale = GlobalTransform.GetScale3D();
}
else
{
@ -194,7 +325,63 @@ ECarlaServerResponse FCarlaActor::SetActorTransform(const FTransform& Transform,
nullptr,
TeleportType);
}
return ECarlaServerResponse::Success;
}
void FCarlaActor::SetActorGlobalTransform(
const FTransform& Transform, ETeleportType TeleportType)
{
if (IsDormant())
{
ActorData->Location = FDVector(Transform.GetLocation());
ActorData->Rotation = Transform.GetRotation();
ActorData->Scale = Transform.GetScale3D();
}
else
{
FTransform LocalTransform = Transform;
ALargeMapManager* LargeMap =
UCarlaStatics::GetLargeMapManager(World);
if (LargeMap)
{
LocalTransform =
LargeMap->GlobalToLocalTransform(LocalTransform);
}
GetActor()->SetActorRelativeTransform(
LocalTransform,
false,
nullptr,
TeleportType);
}
}
FVector FCarlaActor::GetActorVelocity() const
{
if (IsDormant())
{
return ActorData->Velocity;
}
else
{
return GetActor()->GetVelocity();
}
}
FVector FCarlaActor::GetActorAngularVelocity() const
{
if (IsDormant())
{
return ActorData->AngularVelocity;
}
else
{
UPrimitiveComponent* Primitive =
Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
if (Primitive)
{
return Primitive->GetPhysicsAngularVelocityInDegrees();
}
}
return FVector();
}
ECarlaServerResponse FCarlaActor::SetActorTargetVelocity(const FVector& Velocity)
@ -597,6 +784,25 @@ ECarlaServerResponse FVehicleActor::ApplyControlToVehicle(
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::GetVehicleControl(FVehicleControl& VehicleControl)
{
if (IsDormant())
{
FVehicleData* ActorData = GetActorData<FVehicleData>();
VehicleControl = ActorData->Control;
}
else
{
auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
if (Vehicle == nullptr)
{
return ECarlaServerResponse::NotAVehicle;
}
VehicleControl = Vehicle->GetVehicleControl();
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FVehicleActor::SetActorAutopilot(bool bEnabled)
{
if (IsDormant())
@ -712,6 +918,24 @@ ECarlaServerResponse FTrafficLightActor::SetTrafficLightState(const ETrafficLigh
return ECarlaServerResponse::Success;
}
UTrafficLightController* FTrafficLightActor::GetTrafficLightController()
{
if (IsDormant())
{
FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
return ActorData->Controller;
}
else
{
auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
if (TrafficLight == nullptr)
{
return nullptr;
}
return TrafficLight->GetTrafficLightComponent()->GetController();
}
}
ECarlaServerResponse FTrafficLightActor::SetLightGreenTime(float time)
{
if (IsDormant())
@ -806,16 +1030,24 @@ ECarlaServerResponse FTrafficLightActor::ResetTrafficLightGroup()
ECarlaServerResponse FWalkerActor::SetWalkerState(
const FTransform& Transform,
carla::rpc::WalkerControl WalkerControl,
float Speed)
carla::rpc::WalkerControl WalkerControl)
{
FVector NewLocation = Transform.GetLocation();
FVector CurrentLocation = GetActorGlobalLocation();
NewLocation.Z += 90.0f; // move point up because in Unreal walker is centered in the middle height
// if difference between Z position is small, then we keep current, otherwise we set the new one
// (to avoid Z fighting position and falling pedestrians)
if (NewLocation.Z - CurrentLocation.Z < 100.0f)
NewLocation.Z = CurrentLocation.Z;
FTransform NewTransform = Transform;
NewTransform.SetLocation(NewLocation);
SetActorGlobalTransform(NewTransform);
if (IsDormant())
{
FWalkerData* WalkerData = GetActorData<FWalkerData>();
WalkerData->WalkerControl = WalkerControl;
WalkerData->Location = FDVector(Transform.GetLocation());
WalkerData->Rotation = Transform.GetRotation();
WalkerData->Scale = Transform.GetScale3D();
}
else
{
@ -824,11 +1056,6 @@ ECarlaServerResponse FWalkerActor::SetWalkerState(
{
return ECarlaServerResponse::WalkerDead;
}
GetActor()->SetActorRelativeTransform(
Transform,
false,
nullptr,
ETeleportType::TeleportPhysics);
// apply walker speed
auto Pawn = Cast<APawn>(GetActor());
@ -846,6 +1073,38 @@ ECarlaServerResponse FWalkerActor::SetWalkerState(
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FWalkerActor::GetWalkerControl(
FWalkerControl& Control)
{
if (IsDormant())
{
FWalkerData* WalkerData = GetActorData<FWalkerData>();
Control = WalkerData->WalkerControl;
}
else
{
auto * Walker = Cast<AWalkerBase>(GetActor());
if (Walker && !Walker->bAlive)
{
return ECarlaServerResponse::WalkerDead;
}
// apply walker speed
auto Pawn = Cast<APawn>(GetActor());
if (Pawn == nullptr)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
auto Controller = Cast<AWalkerController>(Pawn->GetController());
if (Controller == nullptr)
{
return ECarlaServerResponse::WalkerIncompatibleController;
}
Control = Controller->GetWalkerControl();
}
return ECarlaServerResponse::Success;
}
ECarlaServerResponse FWalkerActor::SetActorSimulatePhysics(bool bEnabled)
{
if (IsDormant())

View File

@ -45,7 +45,8 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
virtual ~FCarlaActor() {};
@ -171,9 +172,34 @@ public:
// Actor function interface ----------------------
// General functions
ECarlaServerResponse SetActorLocation(const FVector& Location, ETeleportType Teleport);
ECarlaServerResponse SetActorTransform(const FTransform& Transform, ETeleportType Teleport);
FTransform GetActorLocalTransform() const;
FTransform GetActorGlobalTransform() const;
FVector GetActorLocalLocation() const;
FVector GetActorGlobalLocation() const;
void SetActorLocalLocation(
const FVector& Location,
ETeleportType Teleport = ETeleportType::TeleportPhysics);
void SetActorGlobalLocation(
const FVector& Location,
ETeleportType Teleport = ETeleportType::TeleportPhysics);
void SetActorLocalTransform(
const FTransform& Transform,
ETeleportType Teleport = ETeleportType::TeleportPhysics);
void SetActorGlobalTransform(
const FTransform& Transform,
ETeleportType Teleport = ETeleportType::TeleportPhysics);
FVector GetActorVelocity() const;
FVector GetActorAngularVelocity() const;
ECarlaServerResponse SetActorTargetVelocity(const FVector& Velocity);
@ -242,6 +268,11 @@ public:
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl&)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse SetActorAutopilot(bool)
{
return ECarlaServerResponse::ActorTypeMismatch;
@ -270,6 +301,11 @@ public:
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual UTrafficLightController* GetTrafficLightController()
{
return nullptr;
}
virtual ECarlaServerResponse SetLightGreenTime(float)
{
return ECarlaServerResponse::ActorTypeMismatch;
@ -290,8 +326,7 @@ public:
// Walker functions
virtual ECarlaServerResponse SetWalkerState(
const FTransform& Transform,
carla::rpc::WalkerControl WalkerControl,
float Speed)
carla::rpc::WalkerControl WalkerControl)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
@ -301,6 +336,11 @@ public:
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl&)
{
return ECarlaServerResponse::ActorTypeMismatch;
}
virtual ECarlaServerResponse ApplyBoneControlToWalker(const FWalkerBoneControl&)
{
return ECarlaServerResponse::ActorTypeMismatch;
@ -323,7 +363,8 @@ public:
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
ActorType Type,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
private:
@ -349,6 +390,8 @@ protected:
TSharedPtr<FActorData> ActorData = nullptr;
UWorld *World = nullptr;
};
class FVehicleActor : public FCarlaActor
@ -358,7 +401,8 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector& Velocity) final;
@ -385,6 +429,8 @@ public:
virtual ECarlaServerResponse ApplyControlToVehicle(
const FVehicleControl&, const EVehicleInputPriority&) final;
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl&) final;
virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled) final;
virtual ECarlaServerResponse EnableCarSim(const FString& SimfilePath) final;
@ -404,7 +450,8 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
};
@ -415,7 +462,8 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
};
class FTrafficLightActor : public FCarlaActor
@ -425,10 +473,13 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState& State) final;
virtual UTrafficLightController* GetTrafficLightController() final;
virtual ECarlaServerResponse SetLightGreenTime(float time) final;
virtual ECarlaServerResponse SetLightYellowTime(float time) final;
@ -448,12 +499,12 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
virtual ECarlaServerResponse SetWalkerState(
const FTransform& Transform,
carla::rpc::WalkerControl WalkerControl,
float Speed) final;
carla::rpc::WalkerControl WalkerControl) final;
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final;
@ -461,6 +512,8 @@ public:
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl&) final;
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl&) final;
virtual ECarlaServerResponse ApplyBoneControlToWalker(const FWalkerBoneControl&) final;
};
@ -471,6 +524,7 @@ public:
IdType ActorId,
AActor* Actor,
TSharedPtr<const FActorInfo> Info,
carla::rpc::ActorState InState);
carla::rpc::ActorState InState,
UWorld* World);
};

View File

@ -129,6 +129,10 @@ void ALargeMapManager::RegisterInitialObjects()
const FActorRegistry& ActorRegistry = CurrentEpisode->GetActorRegistry();
for (const auto& CarlaActorPair : ActorRegistry)
{
if (CarlaActorPair.Value->GetActorInfo()->Description.Id == "spectator")
{
continue;
}
OnActorSpawned(*CarlaActorPair.Value.Get());
}
}
@ -512,7 +516,7 @@ ULevelStreamingDynamic* ALargeMapManager::AddNewTile(FString TileName, FVector T
FString LongLevelPackageName = FPackageName::FilenameToLongPackageName(PackageFileName);
FString UniqueLevelPackageName = LongLevelPackageName + TileName;
ULevelStreamingDynamic* StreamingLevel = NewObject<ULevelStreamingDynamic>(World, *TileName, RF_Transient);
ULevelStreamingDynamic* StreamingLevel = NewObject<ULevelStreamingDynamic>(World, *TileName);
check(StreamingLevel);
StreamingLevel->SetWorldAssetByPackageName(*UniqueLevelPackageName);

View File

@ -86,9 +86,9 @@ void ACarlaRecorder::Ticking(float DeltaSeconds)
// through all actors in registry
for (auto It = Registry.begin(); It != Registry.end(); ++It)
{
FCarlaActor& View = *It.Value().Get();
FCarlaActor* View = It.Value().Get();
switch (View.GetActorType())
switch (View->GetActorType())
{
// save the transform for props
case FCarlaActor::ActorType::Other:
@ -145,41 +145,35 @@ void ACarlaRecorder::Disable(void)
Enabled = false;
}
void ACarlaRecorder::AddActorPosition(FCarlaActor &View)
void ACarlaRecorder::AddActorPosition(FCarlaActor *CarlaActor)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
check(CarlaActor != nullptr);
FTransform Transform = CarlaActor->GetActorGlobalTransform();
// get position of the vehicle
AddPosition(CarlaRecorderPosition
{
View.GetActorId(),
Actor->GetTransform().GetTranslation(),
Actor->GetTransform().GetRotation().Euler()
CarlaActor->GetActorId(),
Transform.GetTranslation(),
Transform.GetRotation().Euler()
});
}
void ACarlaRecorder::AddVehicleAnimation(FCarlaActor &View)
void ACarlaRecorder::AddVehicleAnimation(FCarlaActor *CarlaActor)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
check(CarlaActor != nullptr);
if (Actor->IsPendingKill())
if (CarlaActor->IsPendingKill())
{
return;
}
auto Vehicle = Cast<ACarlaWheeledVehicle>(Actor);
if (Vehicle == nullptr)
{
return;
}
FVehicleControl Control = Vehicle->GetVehicleControl();
FVehicleControl Control;
CarlaActor->GetVehicleControl(Control);
// save
CarlaRecorderAnimVehicle Record;
Record.DatabaseId = View.GetActorId();
Record.DatabaseId = CarlaActor->GetActorId();
Record.Steering = Control.Steer;
Record.Throttle = Control.Throttle;
Record.Brake = Control.Brake;
@ -188,112 +182,81 @@ void ACarlaRecorder::AddVehicleAnimation(FCarlaActor &View)
AddAnimVehicle(Record);
}
void ACarlaRecorder::AddWalkerAnimation(FCarlaActor &View)
void ACarlaRecorder::AddWalkerAnimation(FCarlaActor *CarlaActor)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
check(CarlaActor != nullptr);
if (!Actor->IsPendingKill())
if (!CarlaActor->IsPendingKill())
{
// check to set speed in walkers
auto Walker = Cast<APawn>(Actor);
if (Walker)
FWalkerControl Control;
CarlaActor->GetWalkerControl(Control);
AddAnimWalker(CarlaRecorderAnimWalker
{
auto Controller = Cast<AWalkerController>(Walker->GetController());
if (Controller != nullptr)
{
AddAnimWalker(CarlaRecorderAnimWalker
{
View.GetActorId(),
Controller->GetWalkerControl().Speed
});
}
}
}
}
void ACarlaRecorder::AddTrafficLightState(FCarlaActor &View)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
// get states
auto TrafficLight = Cast<ATrafficLightBase>(Actor);
if (TrafficLight != nullptr)
{
AddState(CarlaRecorderStateTrafficLight
{
View.GetActorId(),
TrafficLight->GetTimeIsFrozen(),
TrafficLight->GetElapsedTime(),
static_cast<char>(TrafficLight->GetTrafficLightState())
CarlaActor->GetActorId(),
Control.Speed
});
}
}
void ACarlaRecorder::AddVehicleLight(FCarlaActor &View)
void ACarlaRecorder::AddTrafficLightState(FCarlaActor *CarlaActor)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
check(CarlaActor != nullptr);
if (Actor->IsPendingKill())
// get states
UTrafficLightController* Controller =
CarlaActor->GetTrafficLightController();
if (Controller != nullptr)
{
return;
auto* Group = Controller->GetGroup();
if (Group)
{
AddState(CarlaRecorderStateTrafficLight
{
CarlaActor->GetActorId(),
Group->IsFrozen(),
Controller->GetElapsedTime(),
static_cast<char>(Controller->GetCurrentState().State)
});
}
}
}
auto Vehicle = Cast<ACarlaWheeledVehicle>(Actor);
if (Vehicle == nullptr)
{
return;
}
void ACarlaRecorder::AddVehicleLight(FCarlaActor *CarlaActor)
{
check(CarlaActor != nullptr);
FVehicleLightState LightState;
CarlaActor->GetVehicleLightState(LightState);
CarlaRecorderLightVehicle LightVehicle;
LightVehicle.DatabaseId = View.GetActorId();
auto LightState = Vehicle->GetVehicleLightState();
LightVehicle.DatabaseId = CarlaActor->GetActorId();
LightVehicle.State = carla::rpc::VehicleLightState(LightState).light_state;
AddLightVehicle(LightVehicle);
}
void ACarlaRecorder::AddActorKinematics(FCarlaActor &View)
void ACarlaRecorder::AddActorKinematics(FCarlaActor *CarlaActor)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
if (Actor->IsPendingKill())
{
return;
}
check(CarlaActor != nullptr);
FVector Velocity, AngularVelocity;
constexpr float TO_METERS = 1e-2;
Velocity = TO_METERS * Actor->GetVelocity();
UPrimitiveComponent* Primitive = Cast<UPrimitiveComponent>(Actor->GetRootComponent());
if (Primitive)
{
AngularVelocity = Primitive->GetPhysicsAngularVelocityInDegrees();
}
Velocity = TO_METERS* CarlaActor->GetActorVelocity();
AngularVelocity = CarlaActor->GetActorAngularVelocity();
CarlaRecorderKinematics Kinematic =
{
View.GetActorId(),
CarlaActor->GetActorId(),
Velocity,
AngularVelocity
};
AddKinematics(Kinematic);
}
void ACarlaRecorder::AddActorBoundingBox(FCarlaActor &View)
void ACarlaRecorder::AddActorBoundingBox(FCarlaActor *CarlaActor)
{
AActor *Actor = View.GetActor();
check(Actor != nullptr);
check(CarlaActor != nullptr);
if (Actor->IsPendingKill())
{
return;
}
const auto &Box = View.GetActorInfo()->BoundingBox;
const auto &Box = CarlaActor->GetActorInfo()->BoundingBox;
CarlaRecorderActorBoundingBox BoundingBox =
{
View.GetActorId(),
CarlaActor->GetActorId(),
{Box.Origin, Box.Extent}
};
@ -599,16 +562,16 @@ void ACarlaRecorder::AddExistingActors(void)
FActorRegistry Registry = Episode->GetActorRegistry();
for (auto& It : Registry)
{
const FCarlaActor& View = *It.Value.Get();
const AActor *Actor = View.GetActor();
const FCarlaActor* View = It.Value.Get();
const AActor *Actor = View->GetActor();
if (Actor != nullptr)
{
// create event
CreateRecorderEventAdd(
View.GetActorId(),
static_cast<uint8_t>(View.GetActorType()),
View->GetActorId(),
static_cast<uint8_t>(View->GetActorType()),
Actor->GetActorTransform(),
View.GetActorInfo()->Description);
View->GetActorInfo()->Description);
}
}
@ -686,6 +649,6 @@ void ACarlaRecorder::CreateRecorderEventAdd(
else
{
// Bounding box in local coordinates
AddActorBoundingBox(*CarlaActor);
AddActorBoundingBox(CarlaActor);
}
}

View File

@ -197,11 +197,11 @@ private:
CarlaRecorderQuery Query;
void AddExistingActors(void);
void AddActorPosition(FCarlaActor &View);
void AddWalkerAnimation(FCarlaActor &View);
void AddVehicleAnimation(FCarlaActor &View);
void AddTrafficLightState(FCarlaActor &View);
void AddVehicleLight(FCarlaActor &View);
void AddActorKinematics(FCarlaActor &View);
void AddActorBoundingBox(FCarlaActor &View);
void AddActorPosition(FCarlaActor *CarlaActor);
void AddWalkerAnimation(FCarlaActor *CarlaActor);
void AddVehicleAnimation(FCarlaActor *CarlaActor);
void AddTrafficLightState(FCarlaActor *CarlaActor);
void AddVehicleLight(FCarlaActor *CarlaActor);
void AddActorKinematics(FCarlaActor *CarlaActor);
void AddActorBoundingBox(FCarlaActor *CarlaActor);
};

View File

@ -617,14 +617,9 @@ void FCarlaServer::FPimpl::BindActions()
ECarlaServerResponse::ActorNotFound,
" Actor Id: " + FString::FromInt(ActorId));
}
FVector UELocation = Location;
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
ALargeMapManager* LargeMap = GameMode->GetLMManager();
if (LargeMap)
{
UELocation = LargeMap->GlobalToLocalLocation(UELocation);
}
CarlaActor->SetActorGlobalLocation(
Location, ETeleportType::TeleportPhysics);
return R<void>::Success();
};
@ -642,15 +637,8 @@ void FCarlaServer::FPimpl::BindActions()
" Actor Id: " + FString::FromInt(ActorId));
}
FTransform UETransform = Transform;
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
ALargeMapManager* LargeMap = GameMode->GetLMManager();
if (LargeMap)
{
UETransform = LargeMap->GlobalToLocalTransform(UETransform);
}
CarlaActor->SetActorTransform(UETransform, ETeleportType::TeleportPhysics);
CarlaActor->SetActorGlobalTransform(
Transform, ETeleportType::TeleportPhysics);
return R<void>::Success();
};
@ -670,31 +658,11 @@ void FCarlaServer::FPimpl::BindActions()
}
// apply walker transform
FTransform NewTransform = Transform;
ACarlaGameModeBase* GameMode = UCarlaStatics::GetGameMode(Episode->GetWorld());
ALargeMapManager* LargeMap = GameMode->GetLMManager();
if (LargeMap)
{
NewTransform = LargeMap->GlobalToLocalTransform(NewTransform);
}
FVector NewLocation = NewTransform.GetLocation();
FTransform CurrentTransform = CarlaActor->GetActor()->GetTransform();
FVector CurrentLocation = CurrentTransform.GetLocation();
NewLocation.Z += 90.0f; // move point up because in Unreal walker is centered in the middle height
// if difference between Z position is small, then we keep current, otherwise we set the new one
// (to avoid Z fighting position and falling pedestrians)
if (NewLocation.Z - CurrentLocation.Z < 100.0f)
NewLocation.Z = CurrentLocation.Z;
NewTransform.SetLocation(NewLocation);
ECarlaServerResponse Response =
CarlaActor->SetWalkerState(
NewTransform,
cr::WalkerControl(Transform.GetForwardVector(), Speed, false),
Speed);
Transform,
cr::WalkerControl(
Transform.GetForwardVector(), Speed, false));
if (Response != ECarlaServerResponse::Success)
{
return RespondError(

View File

@ -429,6 +429,7 @@ void ATrafficLightManager::SpawnTrafficLights()
const auto& SignalId = SignalPair.first;
const auto& Signal = SignalPair.second;
if(!Signal->GetControllers().size() &&
!GetMap()->IsJunction(Signal->GetRoadId()) &&
carla::road::SignalType::IsTrafficLight(Signal->GetType()) &&
!SignalsToSpawn.count(SignalId))
{