CARLA
CarlaActor.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #include "CarlaActor.h"
8 
14 #include "GameFramework/CharacterMovementComponent.h"
15 #include "Carla/Game/Tagger.h"
20 #include "Components/CapsuleComponent.h"
21 
25 #include <carla/rpc/LightState.h>
26 #include <carla/rpc/MapInfo.h>
27 #include <carla/rpc/MapLayer.h>
39 
40 
43  AActor* Actor,
44  TSharedPtr<const FActorInfo> Info,
45  carla::rpc::ActorState InState,
46  UWorld* World)
47  : TheActor(Actor),
48  Info(std::move(Info)),
49  Id(ActorId),
50  State(InState),
51  World(World)
52 {
53 }
56  AActor* Actor,
57  TSharedPtr<const FActorInfo> Info,
58  carla::rpc::ActorState InState,
59  UWorld* World)
60  : FCarlaActor(ActorId, Actor, Info, InState, World)
61 {
63  ActorData = MakeShared<FVehicleData>();
64 }
67  AActor* Actor,
68  TSharedPtr<const FActorInfo> Info,
69  carla::rpc::ActorState InState,
70  UWorld* World)
71  : FCarlaActor(ActorId, Actor, Info, InState, World)
72 {
74  ActorData = MakeShared<FActorSensorData>();
75 }
78  AActor* Actor,
79  TSharedPtr<const FActorInfo> Info,
80  carla::rpc::ActorState InState,
81  UWorld* World)
82  : FCarlaActor(ActorId, Actor, Info, InState, World)
83 {
85  ActorData = MakeShared<FTrafficSignData>();
86 }
89  AActor* Actor,
90  TSharedPtr<const FActorInfo> Info,
91  carla::rpc::ActorState InState,
92  UWorld* World)
93  : FCarlaActor(ActorId, Actor, Info, InState, World)
94 {
96  ActorData = MakeShared<FTrafficLightData>();
97 }
100  AActor* Actor,
101  TSharedPtr<const FActorInfo> Info,
102  carla::rpc::ActorState InState,
103  UWorld* World)
104  : FCarlaActor(ActorId, Actor, Info, InState, World)
105 {
107  ActorData = MakeShared<FWalkerData>();
108 }
110  IdType ActorId,
111  AActor* Actor,
112  TSharedPtr<const FActorInfo> Info,
113  carla::rpc::ActorState InState,
114  UWorld* World)
115  : FCarlaActor(ActorId, Actor, Info, InState, World)
116 {
118  ActorData = MakeShared<FActorData>();
119 }
120 
121 TSharedPtr<FCarlaActor> FCarlaActor::ConstructCarlaActor(
122  IdType ActorId,
123  AActor* Actor,
124  TSharedPtr<const FActorInfo> Info,
125  ActorType Type,
126  carla::rpc::ActorState InState,
127  UWorld* World)
128 {
129  switch(Type)
130  {
132  return MakeShared<FTrafficSignActor>(ActorId, Actor, std::move(Info), InState, World);
133  break;
135  return MakeShared<FTrafficLightActor>(ActorId, Actor, std::move(Info), InState, World);
136  break;
137  case ActorType::Vehicle:
138  return MakeShared<FVehicleActor>(ActorId, Actor, std::move(Info), InState, World);
139  break;
140  case ActorType::Walker:
141  return MakeShared<FWalkerActor>(ActorId, Actor, std::move(Info), InState, World);
142  break;
143  case ActorType::Sensor:
144  return MakeShared<FSensorActor>(ActorId, Actor, std::move(Info), InState, World);
145  break;
146  default:
147  return MakeShared<FOtherActor>(ActorId, Actor, std::move(Info), InState, World);
148  break;
149  }
150 }
151 
152 // Base FCarlaActor functions ---------------------
153 
155 {
157  if (ActorData)
158  {
159  ActorData->RecordActorData(this, CarlaEpisode);
160  }
161  TheActor->Destroy();
162  TheActor = nullptr;
163 }
164 
166 {
167  TheActor = ActorData->RespawnActor(CarlaEpisode, *Info);
168  if (TheActor == nullptr)
169  {
170  UE_LOG(LogCarla, Error, TEXT("Could not wake up dormant actor %d at location %s"), GetActorId(), *(ActorData->GetLocalTransform(CarlaEpisode).GetLocation().ToString()));
171  return;
172  }
174  ActorData->RestoreActorData(this, CarlaEpisode);
175 }
176 
178 {
179  if (IsDormant())
180  {
181  FTransform Transform = FTransform(
182  ActorData->Rotation,
183  ActorData->Location.ToFVector(),
184  ActorData->Scale);
185  ALargeMapManager* LargeMap =
187  if (LargeMap)
188  {
189  Transform = LargeMap->GlobalToLocalTransform(Transform);
190  }
191  return Transform;
192  }
193  else
194  {
195  return GetActor()->GetActorTransform();
196  }
197 }
198 
200 {
201  if (IsDormant())
202  {
203  return FTransform(
204  ActorData->Rotation,
205  ActorData->Location.ToFVector(),
206  ActorData->Scale);
207  }
208  else
209  {
210  FTransform Transform = GetActor()->GetActorTransform();
211  ALargeMapManager* LargeMap =
213  if (LargeMap)
214  {
215  Transform = LargeMap->LocalToGlobalTransform(Transform);
216  }
217  return Transform;
218  }
219 }
220 
222 {
223  if (IsDormant())
224  {
225  FVector Location = ActorData->Location.ToFVector();
226  ALargeMapManager* LargeMap =
228  if (LargeMap)
229  {
230  Location = LargeMap->GlobalToLocalLocation(Location);
231  }
232  return Location;
233  }
234  else
235  {
236  return GetActor()->GetActorLocation();
237  }
238 }
239 
241 {
242  if (IsDormant())
243  {
244  return ActorData->Location.ToFVector();
245  }
246  else
247  {
248  FVector Location = GetActor()->GetActorLocation();
249  ALargeMapManager* LargeMap =
251  if (LargeMap)
252  {
253  Location = LargeMap->LocalToGlobalLocation(Location);
254  }
255  return Location;
256  }
257 }
258 
259 void FCarlaActor::SetActorLocalLocation(const FVector& Location, ETeleportType TeleportType)
260 {
261  if (IsDormant())
262  {
263  FVector GlobalLocation = Location;
264  ALargeMapManager* LargeMap =
266  if (LargeMap)
267  {
268  GlobalLocation = LargeMap->LocalToGlobalLocation(GlobalLocation);
269  }
270  ActorData->Location = FDVector(GlobalLocation);
271  }
272  else
273  {
274  GetActor()->SetActorRelativeLocation(
275  Location,
276  false,
277  nullptr,
278  TeleportType);
279  }
280 }
281 
283  const FVector& Location, ETeleportType TeleportType)
284 {
285  if (IsDormant())
286  {
287  ActorData->Location = FDVector(Location);;
288  }
289  else
290  {
291  FVector LocalLocation = Location;
292  ALargeMapManager* LargeMap =
294  if (LargeMap)
295  {
296  LocalLocation = LargeMap->GlobalToLocalLocation(Location);
297  }
298  GetActor()->SetActorRelativeLocation(
299  LocalLocation,
300  false,
301  nullptr,
302  TeleportType);
303  }
304 }
305 
307  const FTransform& Transform, ETeleportType TeleportType)
308 {
309  if (IsDormant())
310  {
311  FTransform GlobalTransform = Transform;
312  ALargeMapManager* LargeMap =
314  if (LargeMap)
315  {
316  GlobalTransform =
317  LargeMap->LocalToGlobalTransform(GlobalTransform);
318  }
319  ActorData->Location = FDVector(GlobalTransform.GetLocation());
320  ActorData->Rotation = GlobalTransform.GetRotation();
321  ActorData->Scale = GlobalTransform.GetScale3D();
322  }
323  else
324  {
325  GetActor()->SetActorRelativeTransform(
326  Transform,
327  false,
328  nullptr,
329  TeleportType);
330  }
331 }
332 
334  const FTransform& Transform, ETeleportType TeleportType)
335 {
336  if (IsDormant())
337  {
338  ActorData->Location = FDVector(Transform.GetLocation());
339  ActorData->Rotation = Transform.GetRotation();
340  ActorData->Scale = Transform.GetScale3D();
341  }
342  else
343  {
344  FTransform LocalTransform = Transform;
345  ALargeMapManager* LargeMap =
347  if (LargeMap)
348  {
349  LocalTransform =
350  LargeMap->GlobalToLocalTransform(LocalTransform);
351  }
352  GetActor()->SetActorRelativeTransform(
353  LocalTransform,
354  false,
355  nullptr,
356  TeleportType);
357  }
358 }
359 
361 {
362  if (IsDormant())
363  {
364  return ActorData->Velocity;
365  }
366  else
367  {
368  return GetActor()->GetVelocity();
369  }
370 }
371 
373 {
374  if (IsDormant())
375  {
376  return ActorData->AngularVelocity;
377  }
378  else
379  {
380  UPrimitiveComponent* Primitive =
381  Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
382  if (Primitive)
383  {
384  return Primitive->GetPhysicsAngularVelocityInDegrees();
385  }
386  }
387  return FVector();
388 }
389 
391 {
392  if (IsDormant())
393  {
394  ActorData->Velocity = Velocity;
395  }
396  else
397  {
398  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
399  if (RootComponent == nullptr)
400  {
402  }
403  RootComponent->SetPhysicsLinearVelocity(
404  Velocity,
405  false,
406  "None");
407  }
409 }
410 
412 {
413  if (IsDormant())
414  {
415  ActorData->AngularVelocity = AngularVelocity;
416  }
417  else
418  {
419  UPrimitiveComponent* RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
420  if (RootComponent == nullptr)
421  {
423  }
424  RootComponent->SetPhysicsAngularVelocityInDegrees(
425  AngularVelocity,
426  false,
427  "None");
428  }
430 }
431 
433 {
434  if (IsDormant())
435  {
436  }
437  else
438  {
439  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
440  if (RootComponent == nullptr)
441  {
443  }
444  RootComponent->AddImpulse(
445  Impulse,
446  "None",
447  false);
448  }
450 }
451 
453  const FVector& Impulse, const FVector& Location)
454 {
455  if (IsDormant())
456  {
457  }
458  else
459  {
460  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
461  if (RootComponent == nullptr)
462  {
464  }
465 
466  UE_LOG(LogCarla, Warning, TEXT("AddImpulseAtLocation: Experimental feature, use carefully."));
467 
468  RootComponent->AddImpulseAtLocation(
469  Impulse,
470  Location,
471  "None");
472  }
474 }
475 
477 {
478  if (IsDormant())
479  {
480  }
481  else
482  {
483  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
484  if (RootComponent == nullptr)
485  {
487  }
488  RootComponent->AddForce(
489  Force,
490  "None",
491  false);
492  }
494 }
495 
497  const FVector& Force, const FVector& Location)
498 {
499  if (IsDormant())
500  {
501  }
502  else
503  {
504  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
505  if (RootComponent == nullptr)
506  {
508  }
509 
510  UE_LOG(LogCarla, Warning, TEXT("AddForceAtLocation: Experimental feature, use carefully."));
511 
512  RootComponent->AddForceAtLocation(
513  Force,
514  Location,
515  "None");
516  }
518 }
519 
521 {
522  if (IsDormant())
523  {
524  }
525  else
526  {
527  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
528  if (RootComponent == nullptr)
529  {
531  }
532  RootComponent->AddAngularImpulseInDegrees(
533  AngularInpulse,
534  "None",
535  false);
536  }
538 }
539 
541 {
542  if (IsDormant())
543  {
544  }
545  else
546  {
547  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
548  if (RootComponent == nullptr)
549  {
551  }
552  RootComponent->AddTorqueInDegrees(
553  Torque,
554  "None",
555  false);
556  }
558 }
559 
561 {
562  if (IsDormant())
563  {
564  ActorData->bSimulatePhysics = bEnabled;
565  }
566  else
567  {
568  // In the rest of actors, the physics is controlled with the UPrimitiveComponent, so we use
569  // that for disable it.
570  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
571  if (RootComponent == nullptr)
572  {
574  }
575 
576  RootComponent->SetSimulatePhysics(bEnabled);
577  RootComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
578  }
580 }
581 
583 {
584  if (IsDormant())
585  {
586  }
587  else
588  {
589  GetActor()->SetActorEnableCollision(bEnabled);
590  }
592 }
593 
595 {
596  if (IsDormant())
597  {
598  }
599  else
600  {
601  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
602  if (RootComponent == nullptr)
603  {
605  }
606  RootComponent->SetEnableGravity(bEnabled);
607  }
609 }
610 
611 // FVehicleActor functions ---------------------
612 
614 {
615  if (IsDormant())
616  {
617  }
618  else
619  {
620  auto CarlaVehicle = Cast<ACarlaWheeledVehicle>(GetActor());
621  if (CarlaVehicle == nullptr)
622  {
624  }
625  CarlaVehicle->ActivateVelocityControl(Velocity);
626  }
628 }
629 
631 {
632  if (IsDormant())
633  {
634  }
635  else
636  {
637  auto CarlaVehicle = Cast<ACarlaWheeledVehicle>(GetActor());
638  if (CarlaVehicle == nullptr)
639  {
641  }
642  CarlaVehicle->DeactivateVelocityControl();
643  }
645 }
646 
648 {
649  if (IsDormant())
650  {
651  FVehicleData* ActorData = GetActorData<FVehicleData>();
652  PhysicsControl = ActorData->PhysicsControl;
653  }
654  else
655  {
656  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
657  if (Vehicle == nullptr)
658  {
660  }
661  PhysicsControl = Vehicle->GetVehiclePhysicsControl();
662  }
664 }
665 
667 {
668  if (IsDormant())
669  {
670  FVehicleData* ActorData = GetActorData<FVehicleData>();
671  FailureState = ActorData->FailureState;
672  }
673  else
674  {
675  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
676  if (Vehicle == nullptr)
677  {
679  }
680  FailureState = Vehicle->GetFailureState();
681  }
683 }
684 
686 {
687  if (IsDormant())
688  {
689  FVehicleData* ActorData = GetActorData<FVehicleData>();
690  LightState = ActorData->LightState;
691  }
692  else
693  {
694  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
695  if (Vehicle == nullptr)
696  {
698  }
699 
700  LightState = Vehicle->GetVehicleLightState();
701  }
703 }
704 
706 {
707  if (!IsDormant())
708  {
709  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
710  if (Vehicle == nullptr)
711  {
713  }
714  Vehicle->OpenDoor(DoorIdx);
715  }
717 }
718 
720 {
721  if (!IsDormant())
722  {
723  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
724  if (Vehicle == nullptr)
725  {
727  }
728  Vehicle->CloseDoor(DoorIdx);
729  }
731 }
732 
735 {
736  if (IsDormant())
737  {
738  FVehicleData* ActorData = GetActorData<FVehicleData>();
739  ActorData->PhysicsControl = PhysicsControl;
740  }
741  else
742  {
743  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
744  if (Vehicle == nullptr)
745  {
747  }
748 
749  Vehicle->ApplyVehiclePhysicsControl(PhysicsControl);
750  }
752 }
753 
755  const FVehicleLightState& LightState)
756 {
757  if (IsDormant())
758  {
759  FVehicleData* ActorData = GetActorData<FVehicleData>();
760  ActorData->LightState = LightState;
761  }
762  else
763  {
764  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
765  if (Vehicle == nullptr)
766  {
768  }
769 
770  Vehicle->SetVehicleLightState(LightState);
771  }
773 }
774 
776  const EVehicleWheelLocation& WheelLocation, float AngleInDeg)
777 {
778  if (IsDormant())
779  {
780  }
781  else
782  {
783  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
784  if(Vehicle == nullptr){
786  }
787  Vehicle->SetWheelSteerDirection(WheelLocation, AngleInDeg);
788  }
790 }
791 
793  const EVehicleWheelLocation& WheelLocation, float& Angle)
794 {
795  if (IsDormant())
796  {
797  Angle = 0;
798  }
799  else
800  {
801  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
802  if(Vehicle == nullptr){
804  }
805 
806  Angle = Vehicle->GetWheelSteerAngle(WheelLocation);
807  }
809 }
810 
812 {
813  if (IsDormant())
814  {
815  ActorData->bSimulatePhysics = bEnabled;
816  }
817  else
818  {
819  auto* CarlaVehicle = Cast<ACarlaWheeledVehicle>(GetActor());
820  // The physics in the vehicles works in a different way so to disable them.
821  if (CarlaVehicle == nullptr){
823  }
824  CarlaVehicle->SetSimulatePhysics(bEnabled);
825  }
827 }
828 
830  const FVehicleControl& Control, const EVehicleInputPriority& Priority)
831 {
832  if (IsDormant())
833  {
834  FVehicleData* ActorData = GetActorData<FVehicleData>();
835  ActorData->Control = Control;
836  ActorData->bAckermannControlActive = false;
837  }
838  else
839  {
840  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
841  if (Vehicle == nullptr)
842  {
844  }
845  Vehicle->ApplyVehicleControl(Control, Priority);
846  }
848 }
849 
851  const FVehicleAckermannControl& AckermannControl, const EVehicleInputPriority& Priority)
852 {
853  if (IsDormant())
854  {
855  FVehicleData* ActorData = GetActorData<FVehicleData>();
856  ActorData->AckermannControl = AckermannControl;
857  ActorData->bAckermannControlActive = true;
858  }
859  else
860  {
861  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
862  if (Vehicle == nullptr)
863  {
865  }
866  Vehicle->ApplyVehicleAckermannControl(AckermannControl, Priority);
867  }
869 }
870 
872 {
873  if (IsDormant())
874  {
875  FVehicleData* ActorData = GetActorData<FVehicleData>();
876  VehicleControl = ActorData->Control;
877  }
878  else
879  {
880  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
881  if (Vehicle == nullptr)
882  {
884  }
885  VehicleControl = Vehicle->GetVehicleControl();
886  }
888 }
889 
891 {
892  if (IsDormant())
893  {
894  FVehicleData* ActorData = GetActorData<FVehicleData>();
895  VehicleAckermannControl = ActorData->AckermannControl;
896  }
897  else
898  {
899  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
900  if (Vehicle == nullptr)
901  {
903  }
904  VehicleAckermannControl = Vehicle->GetVehicleAckermannControl();
905  }
907 }
908 
910  FAckermannControllerSettings& AckermannSettings)
911 {
912  if (IsDormant())
913  {
914  FVehicleData* ActorData = GetActorData<FVehicleData>();
915  AckermannSettings = ActorData->AckermannControllerSettings;
916  }
917  else
918  {
919  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
920  if (Vehicle == nullptr)
921  {
923  }
924  AckermannSettings = Vehicle->GetAckermannControllerSettings();
925  }
927 }
928 
930  const FAckermannControllerSettings& AckermannSettings)
931 {
932  if (IsDormant())
933  {
934  FVehicleData* ActorData = GetActorData<FVehicleData>();
935  ActorData->AckermannControllerSettings = AckermannSettings;
936  }
937  else
938  {
939  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
940  if (Vehicle == nullptr)
941  {
943  }
944 
945  Vehicle->ApplyAckermannControllerSettings(AckermannSettings);
946  }
948 }
949 
951 {
952  if (IsDormant())
953  {
954  }
955  else
956  {
957  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
958  if (Vehicle == nullptr)
959  {
961  }
962  auto Controller = Cast<AWheeledVehicleAIController>(Vehicle->GetController());
963  if (Controller == nullptr)
964  {
966  }
967  Controller->SetAutopilot(bEnabled, bKeepState);
968  }
970 }
971 
973 {
974  if (IsDormant())
975  {
976  }
977  else
978  {
979  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
980  if (Vehicle == nullptr)
981  {
983  }
984  Vehicle->ShowDebugTelemetry(bEnabled);
985  }
987 }
988 
990 {
991  if (IsDormant())
992  {
993  }
994  else
995  {
996  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
997  if (Vehicle == nullptr)
998  {
1000  }
1002  }
1004 }
1005 
1007 {
1008  if (IsDormant())
1009  {
1010  }
1011  else
1012  {
1013  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
1014  if (Vehicle == nullptr)
1015  {
1017  }
1018  auto* CarSimComponent = Vehicle->GetCarlaMovementComponent<UCarSimManagerComponent>();
1019  if(CarSimComponent)
1020  {
1021  CarSimComponent->UseCarSimRoad(bEnabled);
1022  }
1023  else
1024  {
1026  }
1027  }
1029 }
1030 
1032  uint64_t MaxSubsteps, float MaxSubstepDeltaTime,
1033  const FString& VehicleJSON, const FString& PowertrainJSON,
1034  const FString& TireJSON, const FString& BaseJSONPath)
1035 {
1036  if (IsDormant())
1037  {
1038  }
1039  else
1040  {
1041  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
1042  if (Vehicle == nullptr)
1043  {
1045  }
1047  Vehicle,
1048  MaxSubsteps,
1049  MaxSubstepDeltaTime,
1050  VehicleJSON,
1051  PowertrainJSON,
1052  TireJSON,
1053  BaseJSONPath);
1054  }
1056 }
1057 
1058 // FSensorActor functions ---------------------
1059 
1060 // FtrafficSignActor functions ---------------------
1061 
1062 // FTrafficLightActor functions ---------------------
1063 
1065 {
1066  if (IsDormant())
1067  {
1068  FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
1069  ActorData->LightState = State;
1070  }
1071  else
1072  {
1073  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1074  if (TrafficLight == nullptr)
1075  {
1077  }
1078  TrafficLight->SetTrafficLightState(State);
1079  }
1081 }
1082 
1084 {
1085  if (IsDormant())
1086  {
1087  const FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
1088  return ActorData->LightState;
1089  }
1090  else
1091  {
1092  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1093  if (TrafficLight == nullptr)
1094  {
1095  return ETrafficLightState::Off;
1096  }
1097  return TrafficLight->GetTrafficLightState();
1098  }
1099 }
1100 
1102 {
1103  if (IsDormant())
1104  {
1105  FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
1106  return ActorData->Controller;
1107  }
1108  else
1109  {
1110  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1111  if (TrafficLight == nullptr)
1112  {
1113  return nullptr;
1114  }
1115  return TrafficLight->GetTrafficLightComponent()->GetController();
1116  }
1117 }
1118 
1120 {
1121  if (IsDormant())
1122  {
1123  // Todo: implement
1124  }
1125  else
1126  {
1127  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1128  if (TrafficLight == nullptr)
1129  {
1131  }
1132  TrafficLight->SetGreenTime(time);
1133  }
1135 }
1136 
1138 {
1139  if (IsDormant())
1140  {
1141  // Todo: implement
1142  }
1143  else
1144  {
1145  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1146  if (TrafficLight == nullptr)
1147  {
1149  }
1150  TrafficLight->SetYellowTime(time);
1151  }
1153 }
1154 
1156 {
1157  if (IsDormant())
1158  {
1159  // Todo: implement
1160  }
1161  else
1162  {
1163  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1164  if (TrafficLight == nullptr)
1165  {
1167  }
1168  TrafficLight->SetRedTime(time);
1169  }
1171 }
1172 
1174 {
1175  if (IsDormant())
1176  {
1177  // Todo: implement
1178  }
1179  else
1180  {
1181  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1182  if (TrafficLight == nullptr)
1183  {
1185  }
1186  TrafficLight->SetTimeIsFrozen(bFreeze);
1187  }
1189 }
1190 
1192 {
1193  if (IsDormant())
1194  {
1195  // Todo: implement
1196  }
1197  else
1198  {
1199  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1200  if (TrafficLight == nullptr)
1201  {
1203  }
1204  TrafficLight->GetTrafficLightComponent()->GetGroup()->ResetGroup();
1205  }
1207 }
1208 
1209 // FWalkerActor functions ---------------------
1210 
1212  const FTransform& Transform,
1213  carla::rpc::WalkerControl WalkerControl)
1214 {
1215  FVector NewLocation = Transform.GetLocation();
1216  FVector CurrentLocation = GetActorGlobalLocation();
1217 
1218  // adjust position up by half of capsule height
1219  // (because in Unreal walker is centered at the capsule middle,
1220  // while Recast uses the bottom point)
1221  UCapsuleComponent* Capsule = Cast<UCapsuleComponent>(GetActor()->GetRootComponent());
1222  if (Capsule)
1223  {
1224  NewLocation.Z += Capsule->GetScaledCapsuleHalfHeight();
1225  }
1226 
1227  FTransform NewTransform = Transform;
1228  NewTransform.SetLocation(NewLocation);
1229 
1230  if (IsDormant())
1231  {
1232  FWalkerData* WalkerData = GetActorData<FWalkerData>();
1233  WalkerData->WalkerControl = WalkerControl;
1234  }
1235  else
1236  {
1237  auto * Walker = Cast<AWalkerBase>(GetActor());
1238  if (Walker && !Walker->bAlive)
1239  {
1241  }
1242 
1243  // apply walker speed
1244  auto Pawn = Cast<APawn>(GetActor());
1245  if (Pawn == nullptr)
1246  {
1248  }
1249  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1250  if (Controller == nullptr)
1251  {
1253  }
1254  Controller->ApplyWalkerControl(WalkerControl);
1255  }
1256  SetActorGlobalTransform(NewTransform);
1258 }
1259 
1261  FWalkerControl& Control)
1262 {
1263  if (IsDormant())
1264  {
1265  FWalkerData* WalkerData = GetActorData<FWalkerData>();
1266  Control = WalkerData->WalkerControl;
1267  }
1268  else
1269  {
1270  auto * Walker = Cast<AWalkerBase>(GetActor());
1271  if (Walker && !Walker->bAlive)
1272  {
1274  }
1275 
1276  // apply walker speed
1277  auto Pawn = Cast<APawn>(GetActor());
1278  if (Pawn == nullptr)
1279  {
1281  }
1282  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1283  if (Controller == nullptr)
1284  {
1286  }
1287  Control = Controller->GetWalkerControl();
1288  }
1290 }
1291 
1293 {
1294  if (IsDormant())
1295  {
1296  ActorData->bSimulatePhysics = bEnabled;
1297  }
1298  else
1299  {
1300  auto* Character = Cast<ACharacter>(GetActor());
1301  // The physics in the walkers also works in a different way so to disable them,
1302  // we need to do it in the UCharacterMovementComponent.
1303  if (Character == nullptr)
1304  {
1306  }
1307  auto CharacterMovement = Cast<UCharacterMovementComponent>(Character->GetCharacterMovement());
1308  if(bEnabled) {
1309  CharacterMovement->SetDefaultMovementMode();
1310  }
1311  else {
1312  CharacterMovement->DisableMovement();
1313  }
1314  }
1316 }
1317 
1319 {
1320  if (IsDormant())
1321  {
1322  }
1323  else
1324  {
1325  auto Character = Cast<ACharacter>(GetActor());
1326  // The physics in the walkers works in a different way so to disable them,
1327  // we need to do it in the UCharacterMovementComponent.
1328  if (Character == nullptr)
1329  {
1331  }
1332  auto CharacterMovement = Cast<UCharacterMovementComponent>(Character->GetCharacterMovement());
1333 
1334  if(bEnabled) {
1335  CharacterMovement->SetDefaultMovementMode();
1336  }
1337  else {
1338  if (CharacterMovement->IsFlying() || CharacterMovement->IsFalling())
1339  CharacterMovement->DisableMovement();
1340  }
1341  }
1343 }
1344 
1346  const FWalkerControl& Control)
1347 {
1348  if (IsDormant())
1349  {
1350  FWalkerData* ActorData = GetActorData<FWalkerData>();
1351  ActorData->WalkerControl = Control;
1352  }
1353  else
1354  {
1355  auto Pawn = Cast<APawn>(GetActor());
1356  if (Pawn == nullptr)
1357  {
1359  }
1360  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1361  if (Controller == nullptr)
1362  {
1364  }
1365  Controller->ApplyWalkerControl(Control);
1366  }
1368 }
1369 
1371 {
1372  if (IsDormant())
1373  {
1374  }
1375  else
1376  {
1377  auto Pawn = Cast<APawn>(GetActor());
1378  if (Pawn == nullptr)
1379  {
1381  }
1382  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1383  if (Controller == nullptr)
1384  {
1386  }
1387  Controller->GetBonesTransform(Bones);
1388  }
1390 }
1391 
1393 {
1394  if (IsDormant())
1395  {
1396  }
1397  else
1398  {
1399  auto Pawn = Cast<APawn>(GetActor());
1400  if (Pawn == nullptr)
1401  {
1403  }
1404  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1405  if (Controller == nullptr)
1406  {
1408  }
1409  Controller->SetBonesTransform(Bones);
1410  }
1412 }
1413 
1415 {
1416  if (IsDormant())
1417  {
1418  }
1419  else
1420  {
1421  auto Pawn = Cast<APawn>(GetActor());
1422  if (Pawn == nullptr)
1423  {
1425  }
1426  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1427  if (Controller == nullptr)
1428  {
1430  }
1431  Controller->BlendPose(Blend);
1432  }
1434 }
1435 
1437 {
1438  if (IsDormant())
1439  {
1440  }
1441  else
1442  {
1443  auto Pawn = Cast<APawn>(GetActor());
1444  if (Pawn == nullptr)
1445  {
1447  }
1448  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1449  if (Controller == nullptr)
1450  {
1452  }
1453  Controller->GetPoseFromAnimation();
1454  }
1456 }
1457 
1459 {
1460  if (IsDormant())
1461  {
1462  }
1463  else
1464  {
1465  auto Pawn = Cast<APawn>(GetActor());
1466  if (Pawn == nullptr)
1467  {
1469  }
1470  auto Walker = Cast<AWalkerBase>(Pawn);
1471  if (Walker == nullptr)
1472  {
1474  }
1475  Walker->StartDeathLifeSpan();
1476  UE_LOG(LogCarla, Warning, TEXT("Walker starting life span by dead"));
1477  }
1479 }
carla::rpc::ActorState State
Definition: CarlaActor.h:455
virtual ECarlaServerResponse GetPoseFromAnimation()
virtual ECarlaServerResponse GetWheelSteerAngle(const EVehicleWheelLocation &WheelLocation, float &Angle)
Definition: CarlaActor.cpp:792
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor DoorIdx) final
Definition: CarlaActor.cpp:705
FTrafficSignActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:76
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final
virtual ECarlaServerResponse ApplyAckermannControllerSettings(const FAckermannControllerSettings &) final
Definition: CarlaActor.cpp:929
void WakeActorUp(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:165
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final
Definition: CarlaActor.cpp:972
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &) final
Definition: CarlaActor.cpp:871
FVector GetActorAngularVelocity() const
Definition: CarlaActor.cpp:372
FVehicleAckermannControl AckermannControl
Definition: ActorData.h:63
void PutActorToSleep(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:154
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector &Velocity) final
Definition: CarlaActor.cpp:613
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &) final
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled)
Definition: CarlaActor.cpp:594
AActor * GetActor()
Definition: CarlaActor.h:90
FVector GlobalToLocalLocation(const FVector &InLocation) const
virtual ECarlaServerResponse SetActorCollisions(bool bEnabled)
Definition: CarlaActor.cpp:582
carla::rpc::WalkerControl WalkerControl
Definition: ActorData.h:84
ActorType Type
Definition: CarlaActor.h:463
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &State) final
virtual ECarlaServerResponse SetLightRedTime(float time) final
virtual ECarlaServerResponse SetLightGreenTime(float time) final
FSensorActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:65
static void CreateCarsimComponent(ACarlaWheeledVehicle *Vehicle, FString Simfile)
FOtherActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:109
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl &PhysicsControl) final
Definition: CarlaActor.cpp:733
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &) final
Definition: CarlaActor.cpp:829
uint32 IdType
Definition: CarlaActor.h:27
virtual ECarlaServerResponse SetActorDead()
FVehicleControl Control
Definition: ActorData.h:61
virtual ECarlaServerResponse EnableCarSim(const FString &SimfilePath) final
Definition: CarlaActor.cpp:989
virtual ECarlaServerResponse SetLightYellowTime(float time) final
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &LightState) final
Definition: CarlaActor.cpp:685
virtual ECarlaServerResponse FreezeTrafficLight(bool bFreeze) final
virtual ECarlaServerResponse BlendPose(float Blend)
geom::Location Location
Definition: rpc/Location.h:14
void SetActorGlobalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:282
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final
Definition: CarlaActor.cpp:811
virtual ETrafficLightState GetTrafficLightState() const final
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
Definition: CarlaActor.cpp:432
ECarlaServerResponse SetActorTargetAngularVelocity(const FVector &AngularVelocity)
Definition: CarlaActor.cpp:411
ECarlaServerResponse AddActorForceAtLocation(const FVector &Force, const FVector &Location)
Definition: CarlaActor.cpp:496
ECarlaServerResponse AddActorTorque(const FVector &Torque)
Definition: CarlaActor.cpp:540
FVehiclePhysicsControl PhysicsControl
Definition: ActorData.h:59
ECarlaServerResponse
carla::SharedPtr< cc::Actor > Actor
A simulation episode.
Definition: CarlaEpisode.h:38
FWalkerActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:98
TSharedPtr< const FActorInfo > Info
Definition: CarlaActor.h:449
void SetActorLocalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:259
virtual ECarlaServerResponse SetWheelSteerDirection(const EVehicleWheelLocation &WheelLocation, float AngleInDeg) final
Definition: CarlaActor.cpp:775
virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState=false) final
Definition: CarlaActor.cpp:950
FTransform GetActorLocalTransform() const
Definition: CarlaActor.cpp:177
UWorld * World
Definition: CarlaActor.h:467
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled) final
FVector GetActorVelocity() const
Definition: CarlaActor.cpp:360
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &) final
uint32_t ActorId
Definition: ActorId.h:14
virtual ECarlaServerResponse ResetTrafficLightGroup() final
static void CreateChronoMovementComponent(ACarlaWheeledVehicle *Vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, FString VehicleJSON="", FString PowertrainJSON="", FString TireJSON="", FString BaseJSONPath="")
EVehicleInputPriority
ETrafficLightState LightState
Definition: ActorData.h:115
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
Definition: CarlaActor.cpp:390
EVehicleWheelLocation
virtual ECarlaServerResponse EnableChronoPhysics(uint64_t MaxSubsteps, float MaxSubstepDeltaTime, const FString &VehicleJSON, const FString &PowertrainJSON, const FString &TireJSON, const FString &BaseJSONPath) final
FTransform LocalToGlobalTransform(const FTransform &InTransform) const
virtual ECarlaServerResponse SetWalkerState(const FTransform &Transform, carla::rpc::WalkerControl WalkerControl) final
FTransform GlobalToLocalTransform(const FTransform &InTransform) const
static ALargeMapManager * GetLargeMapManager(const UObject *WorldContextObject)
Definition: CarlaStatics.h:100
bool bAckermannControlActive
Definition: ActorData.h:65
ECarlaServerResponse AddActorImpulseAtLocation(const FVector &Impulse, const FVector &Location)
Definition: CarlaActor.cpp:452
FCarlaActor()=default
void SetActorLocalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:306
FVehicleActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:54
FTransform GetActorGlobalTransform() const
Definition: CarlaActor.cpp:199
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor DoorIdx) final
Definition: CarlaActor.cpp:719
virtual ECarlaServerResponse GetVehicleAckermannControl(FVehicleAckermannControl &) final
Definition: CarlaActor.cpp:890
bool IsDormant() const
Definition: CarlaActor.h:70
virtual ECarlaServerResponse SetBonesTransform(const FWalkerBoneControlIn &) final
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
Definition: CarlaActor.cpp:560
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControlOut &) final
IdType GetActorId() const
Definition: CarlaActor.h:80
EVehicleDoor
Type of door to open/close.
FAckermannControllerSettings AckermannControllerSettings
Definition: ActorData.h:67
ECarlaServerResponse AddActorForce(const FVector &Force)
Definition: CarlaActor.cpp:476
virtual UTrafficLightController * GetTrafficLightController() final
FVector GetActorLocalLocation() const
Definition: CarlaActor.cpp:221
TSharedPtr< FActorData > ActorData
Definition: CarlaActor.h:465
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &LightState) final
Definition: CarlaActor.cpp:754
Maps a controller from OpenDrive.
FTrafficLightActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:87
UTrafficLightController * Controller
Definition: ActorData.h:113
carla::rpc::VehicleFailureState FailureState
Definition: ActorData.h:73
static TSharedPtr< FCarlaActor > ConstructCarlaActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, ActorType Type, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:121
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:333
ECarlaServerResponse AddActorAngularImpulse(const FVector &AngularInpulse)
Definition: CarlaActor.cpp:520
FVehicleLightState LightState
Definition: ActorData.h:69
virtual ECarlaServerResponse DisableActorConstantVelocity() final
Definition: CarlaActor.cpp:630
geom::Transform Transform
Definition: rpc/Transform.h:16
virtual ECarlaServerResponse ApplyAckermannControlToVehicle(const FVehicleAckermannControl &, const EVehicleInputPriority &) final
Definition: CarlaActor.cpp:850
FVector LocalToGlobalLocation(const FVector &InLocation) const
FVector GetActorGlobalLocation() const
Definition: CarlaActor.cpp:240
virtual ECarlaServerResponse GetPhysicsControl(FVehiclePhysicsControl &PhysicsControl) final
Definition: CarlaActor.cpp:647
virtual ECarlaServerResponse GetAckermannControllerSettings(FAckermannControllerSettings &) final
Definition: CarlaActor.cpp:909
virtual ECarlaServerResponse GetFailureState(carla::rpc::VehicleFailureState &) final
Definition: CarlaActor.cpp:666
A view over an actor and its properties.
Definition: CarlaActor.h:23
virtual ECarlaServerResponse UseCarSimRoad(bool bEnabled) final
AActor * TheActor
Definition: CarlaActor.h:447