14#include "GameFramework/CharacterMovementComponent.h"
20#include "Components/CapsuleComponent.h"
44 TSharedPtr<const FActorInfo> Info,
48 Info(
std::move(Info)),
57 TSharedPtr<const FActorInfo> Info,
68 TSharedPtr<const FActorInfo> Info,
74 ActorData = MakeShared<FActorSensorData>();
79 TSharedPtr<const FActorInfo> Info,
85 ActorData = MakeShared<FTrafficSignData>();
90 TSharedPtr<const FActorInfo> Info,
96 ActorData = MakeShared<FTrafficLightData>();
101 TSharedPtr<const FActorInfo> Info,
104 :
FCarlaActor(ActorId, Actor, Info, InState, World)
112 TSharedPtr<const FActorInfo> Info,
115 :
FCarlaActor(ActorId, Actor, Info, InState, World)
124 TSharedPtr<const FActorInfo> Info,
132 return MakeShared<FTrafficSignActor>(ActorId, Actor, std::move(
Info), InState,
World);
135 return MakeShared<FTrafficLightActor>(ActorId, Actor, std::move(
Info), InState,
World);
138 return MakeShared<FVehicleActor>(ActorId, Actor, std::move(
Info), InState,
World);
141 return MakeShared<FWalkerActor>(ActorId, Actor, std::move(
Info), InState,
World);
144 return MakeShared<FSensorActor>(ActorId, Actor, std::move(
Info), InState,
World);
147 return MakeShared<FOtherActor>(ActorId, Actor, std::move(
Info), InState,
World);
159 ActorData->RecordActorData(
this, CarlaEpisode);
170 UE_LOG(LogCarla, Error, TEXT(
"Could not wake up dormant actor %d at location %s"),
GetActorId(), *(
ActorData->GetLocalTransform(CarlaEpisode).GetLocation().ToString()));
174 ActorData->RestoreActorData(
this, CarlaEpisode);
181 FTransform Transform = FTransform(
195 return GetActor()->GetActorTransform();
210 FTransform Transform =
GetActor()->GetActorTransform();
225 FVector Location =
ActorData->Location.ToFVector();
236 return GetActor()->GetActorLocation();
248 FVector Location =
GetActor()->GetActorLocation();
263 FVector GlobalLocation = Location;
274 GetActor()->SetActorRelativeLocation(
283 const FVector& Location, ETeleportType TeleportType)
291 FVector LocalLocation = Location;
298 GetActor()->SetActorRelativeLocation(
307 const FTransform& Transform, ETeleportType TeleportType)
311 FTransform GlobalTransform = Transform;
320 ActorData->Rotation = GlobalTransform.GetRotation();
321 ActorData->Scale = GlobalTransform.GetScale3D();
325 GetActor()->SetActorRelativeTransform(
334 const FTransform& Transform, ETeleportType TeleportType)
339 ActorData->Rotation = Transform.GetRotation();
340 ActorData->Scale = Transform.GetScale3D();
344 FTransform LocalTransform = Transform;
352 GetActor()->SetActorRelativeTransform(
381 Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
384 return Primitive->GetPhysicsAngularVelocityInDegrees();
398 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
399 if (RootComponent ==
nullptr)
403 RootComponent->SetPhysicsLinearVelocity(
415 ActorData->AngularVelocity = AngularVelocity;
420 if (RootComponent ==
nullptr)
424 RootComponent->SetPhysicsAngularVelocityInDegrees(
439 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
440 if (RootComponent ==
nullptr)
444 RootComponent->AddImpulse(
453 const FVector& Impulse,
const FVector& Location)
460 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
461 if (RootComponent ==
nullptr)
466 UE_LOG(LogCarla, Warning, TEXT(
"AddImpulseAtLocation: Experimental feature, use carefully."));
468 RootComponent->AddImpulseAtLocation(
483 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
484 if (RootComponent ==
nullptr)
488 RootComponent->AddForce(
497 const FVector& Force,
const FVector& Location)
504 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
505 if (RootComponent ==
nullptr)
510 UE_LOG(LogCarla, Warning, TEXT(
"AddForceAtLocation: Experimental feature, use carefully."));
512 RootComponent->AddForceAtLocation(
527 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
528 if (RootComponent ==
nullptr)
532 RootComponent->AddAngularImpulseInDegrees(
547 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
548 if (RootComponent ==
nullptr)
552 RootComponent->AddTorqueInDegrees(
570 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
571 if (RootComponent ==
nullptr)
576 RootComponent->SetSimulatePhysics(bEnabled);
577 RootComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
589 GetActor()->SetActorEnableCollision(bEnabled);
601 auto RootComponent = Cast<UPrimitiveComponent>(
GetActor()->GetRootComponent());
602 if (RootComponent ==
nullptr)
606 RootComponent->SetEnableGravity(bEnabled);
620 auto CarlaVehicle = Cast<ACarlaWheeledVehicle>(
GetActor());
621 if (CarlaVehicle ==
nullptr)
625 CarlaVehicle->ActivateVelocityControl(Velocity);
637 auto CarlaVehicle = Cast<ACarlaWheeledVehicle>(
GetActor());
638 if (CarlaVehicle ==
nullptr)
642 CarlaVehicle->DeactivateVelocityControl();
680 FailureState =
Vehicle->GetFailureState();
700 LightState =
Vehicle->GetVehicleLightState();
770 Vehicle->SetVehicleLightState(LightState);
787 Vehicle->SetWheelSteerDirection(WheelLocation, AngleInDeg);
806 Angle =
Vehicle->GetWheelSteerAngle(WheelLocation);
819 auto* CarlaVehicle = Cast<ACarlaWheeledVehicle>(
GetActor());
821 if (CarlaVehicle ==
nullptr){
824 CarlaVehicle->SetSimulatePhysics(bEnabled);
836 ActorData->bAckermannControlActive =
false;
845 Vehicle->ApplyVehicleControl(Control, Priority);
856 ActorData->AckermannControl = AckermannControl;
857 ActorData->bAckermannControlActive =
true;
866 Vehicle->ApplyVehicleAckermannControl(AckermannControl, Priority);
885 VehicleControl =
Vehicle->GetVehicleControl();
895 VehicleAckermannControl =
ActorData->AckermannControl;
904 VehicleAckermannControl =
Vehicle->GetVehicleAckermannControl();
915 AckermannSettings =
ActorData->AckermannControllerSettings;
924 AckermannSettings =
Vehicle->GetAckermannControllerSettings();
935 ActorData->AckermannControllerSettings = AckermannSettings;
945 Vehicle->ApplyAckermannControllerSettings(AckermannSettings);
962 auto Controller = Cast<AWheeledVehicleAIController>(
Vehicle->GetController());
963 if (Controller ==
nullptr)
967 Controller->SetAutopilot(bEnabled, bKeepState);
977 TelemetryData = EmptyTelemetryData;
986 TelemetryData =
Vehicle->GetVehicleTelemetryData();
1003 Vehicle->ShowDebugTelemetry(bEnabled);
1051 uint64_t MaxSubsteps,
float MaxSubstepDeltaTime,
1052 const FString& VehicleJSON,
const FString& PowertrainJSON,
1053 const FString& TireJSON,
const FString& BaseJSONPath)
1068 MaxSubstepDeltaTime,
1091 if(MovementComponent)
1136 return ETrafficLightState::Off;
1156 return TrafficLight->GetTrafficLightComponent()->GetController();
1245 TrafficLight->GetTrafficLightComponent()->GetGroup()->ResetGroup();
1253 const FTransform& Transform,
1256 FVector NewLocation = Transform.GetLocation();
1262 UCapsuleComponent* Capsule = Cast<UCapsuleComponent>(
GetActor()->GetRootComponent());
1265 NewLocation.Z += Capsule->GetScaledCapsuleHalfHeight();
1268 FTransform NewTransform = Transform;
1269 NewTransform.SetLocation(NewLocation);
1273 FWalkerData* WalkerData = GetActorData<FWalkerData>();
1285 auto Pawn = Cast<APawn>(
GetActor());
1286 if (Pawn ==
nullptr)
1290 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1291 if (Controller ==
nullptr)
1295 Controller->ApplyWalkerControl(WalkerControl);
1306 FWalkerData* WalkerData = GetActorData<FWalkerData>();
1318 auto Pawn = Cast<APawn>(
GetActor());
1319 if (Pawn ==
nullptr)
1323 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1324 if (Controller ==
nullptr)
1328 Control = Controller->GetWalkerControl();
1348 auto CharacterMovement = Cast<UCharacterMovementComponent>(
Character->GetCharacterMovement());
1350 CharacterMovement->SetDefaultMovementMode();
1353 CharacterMovement->DisableMovement();
1373 auto CharacterMovement = Cast<UCharacterMovementComponent>(
Character->GetCharacterMovement());
1376 CharacterMovement->SetDefaultMovementMode();
1379 if (CharacterMovement->IsFlying() || CharacterMovement->IsFalling())
1380 CharacterMovement->DisableMovement();
1396 auto Pawn = Cast<APawn>(
GetActor());
1397 if (Pawn ==
nullptr)
1401 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1402 if (Controller ==
nullptr)
1406 Controller->ApplyWalkerControl(Control);
1418 auto Pawn = Cast<APawn>(
GetActor());
1419 if (Pawn ==
nullptr)
1423 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1424 if (Controller ==
nullptr)
1428 Controller->GetBonesTransform(Bones);
1440 auto Pawn = Cast<APawn>(
GetActor());
1441 if (Pawn ==
nullptr)
1445 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1446 if (Controller ==
nullptr)
1450 Controller->SetBonesTransform(Bones);
1462 auto Pawn = Cast<APawn>(
GetActor());
1463 if (Pawn ==
nullptr)
1467 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1468 if (Controller ==
nullptr)
1472 Controller->BlendPose(Blend);
1484 auto Pawn = Cast<APawn>(
GetActor());
1485 if (Pawn ==
nullptr)
1489 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1490 if (Controller ==
nullptr)
1494 Controller->GetPoseFromAnimation();
1506 auto Pawn = Cast<APawn>(
GetActor());
1507 if (Pawn ==
nullptr)
1511 auto Walker = Cast<AWalkerBase>(Pawn);
1516 Walker->StartDeathLifeSpan();
1517 UE_LOG(LogCarla, Warning, TEXT(
"Walker starting life span by dead"));
@ WalkerIncompatibleController
EVehicleDoor
Type of door to open/close
FTransform GlobalToLocalTransform(const FTransform &InTransform) const
FVector GlobalToLocalLocation(const FVector &InLocation) const
FTransform LocalToGlobalTransform(const FTransform &InTransform) const
FVector LocalToGlobalLocation(const FVector &InLocation) const
A view over an actor and its properties.
carla::rpc::ActorState State
ECarlaServerResponse AddActorImpulseAtLocation(const FVector &Impulse, const FVector &Location)
static TSharedPtr< FCarlaActor > ConstructCarlaActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, ActorType Type, carla::rpc::ActorState InState, UWorld *World)
ECarlaServerResponse AddActorForceAtLocation(const FVector &Force, const FVector &Location)
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled)
FVector GetActorLocalLocation() const
void SetActorLocalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
ECarlaServerResponse AddActorTorque(const FVector &Torque)
ECarlaServerResponse SetActorTargetAngularVelocity(const FVector &AngularVelocity)
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
virtual ECarlaServerResponse SetActorCollisions(bool bEnabled)
FVector GetActorAngularVelocity() const
FTransform GetActorGlobalTransform() const
FVector GetActorVelocity() const
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
void SetActorGlobalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
TSharedPtr< const FActorInfo > Info
FVector GetActorGlobalLocation() const
void SetActorLocalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
TSharedPtr< FActorData > ActorData
IdType GetActorId() const
FTransform GetActorLocalTransform() const
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
ECarlaServerResponse AddActorForce(const FVector &Force)
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
void WakeActorUp(UCarlaEpisode *CarlaEpisode)
ECarlaServerResponse AddActorAngularImpulse(const FVector &AngularInpulse)
void PutActorToSleep(UCarlaEpisode *CarlaEpisode)
FOtherActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
FSensorActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
virtual ECarlaServerResponse SetLightGreenTime(float time) final
virtual ECarlaServerResponse FreezeTrafficLight(bool bFreeze) final
virtual ETrafficLightState GetTrafficLightState() const final
FTrafficLightActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &State) final
virtual ECarlaServerResponse ResetTrafficLightGroup() final
virtual UTrafficLightController * GetTrafficLightController() final
virtual ECarlaServerResponse SetLightRedTime(float time) final
virtual ECarlaServerResponse SetLightYellowTime(float time) final
FTrafficSignActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState=false) final
virtual ECarlaServerResponse EnableChronoPhysics(uint64_t MaxSubsteps, float MaxSubstepDeltaTime, const FString &VehicleJSON, const FString &PowertrainJSON, const FString &TireJSON, const FString &BaseJSONPath) final
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final
FVehicleActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
virtual ECarlaServerResponse DisableActorConstantVelocity() final
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &LightState) final
virtual ECarlaServerResponse GetFailureState(carla::rpc::VehicleFailureState &) final
virtual ECarlaServerResponse GetWheelSteerAngle(const EVehicleWheelLocation &WheelLocation, float &Angle)
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &) final
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector &Velocity) final
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &LightState) final
virtual ECarlaServerResponse EnableCarSim(const FString &SimfilePath) final
virtual ECarlaServerResponse GetPhysicsControl(FVehiclePhysicsControl &PhysicsControl) final
virtual ECarlaServerResponse SetWheelSteerDirection(const EVehicleWheelLocation &WheelLocation, float AngleInDeg) final
virtual ECarlaServerResponse UseCarSimRoad(bool bEnabled) final
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &) final
virtual ECarlaServerResponse ApplyAckermannControllerSettings(const FAckermannControllerSettings &) final
virtual ECarlaServerResponse GetVehicleTelemetryData(FVehicleTelemetryData &) final
virtual ECarlaServerResponse ApplyAckermannControlToVehicle(const FVehicleAckermannControl &, const EVehicleInputPriority &) final
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl &PhysicsControl) final
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor DoorIdx) final
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor DoorIdx) final
virtual ECarlaServerResponse GetVehicleAckermannControl(FVehicleAckermannControl &) final
virtual ECarlaServerResponse RestorePhysXPhysics()
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final
virtual ECarlaServerResponse GetAckermannControllerSettings(FAckermannControllerSettings &) final
virtual ECarlaServerResponse BlendPose(float Blend)
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled) final
virtual ECarlaServerResponse GetPoseFromAnimation()
FWalkerActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
virtual ECarlaServerResponse SetBonesTransform(const FWalkerBoneControlIn &) final
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &) final
virtual ECarlaServerResponse SetWalkerState(const FTransform &Transform, carla::rpc::WalkerControl WalkerControl) final
virtual ECarlaServerResponse SetActorDead()
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &) final
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControlOut &) final
carla::rpc::WalkerControl WalkerControl
virtual void DisableSpecialPhysics()
static void CreateCarsimComponent(ACarlaWheeledVehicle *Vehicle, FString Simfile)
void UseCarSimRoad(bool bEnabled)
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
static void CreateChronoMovementComponent(ACarlaWheeledVehicle *Vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, FString VehicleJSON="", FString PowertrainJSON="", FString TireJSON="", FString BaseJSONPath="")
Maps a controller from OpenDrive.