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 
23 #include <carla/rpc/LightState.h>
24 #include <carla/rpc/MapInfo.h>
25 #include <carla/rpc/MapLayer.h>
36 
37 
40  AActor* Actor,
41  TSharedPtr<const FActorInfo> Info,
42  carla::rpc::ActorState InState,
43  UWorld* World)
44  : TheActor(Actor),
45  Info(std::move(Info)),
46  Id(ActorId),
47  State(InState),
48  World(World)
49 {
50 }
53  AActor* Actor,
54  TSharedPtr<const FActorInfo> Info,
55  carla::rpc::ActorState InState,
56  UWorld* World)
57  : FCarlaActor(ActorId, Actor, Info, InState, World)
58 {
60  ActorData = MakeShared<FVehicleData>();
61 }
64  AActor* Actor,
65  TSharedPtr<const FActorInfo> Info,
66  carla::rpc::ActorState InState,
67  UWorld* World)
68  : FCarlaActor(ActorId, Actor, Info, InState, World)
69 {
71  ActorData = MakeShared<FActorSensorData>();
72 }
75  AActor* Actor,
76  TSharedPtr<const FActorInfo> Info,
77  carla::rpc::ActorState InState,
78  UWorld* World)
79  : FCarlaActor(ActorId, Actor, Info, InState, World)
80 {
82  ActorData = MakeShared<FTrafficSignData>();
83 }
86  AActor* Actor,
87  TSharedPtr<const FActorInfo> Info,
88  carla::rpc::ActorState InState,
89  UWorld* World)
90  : FCarlaActor(ActorId, Actor, Info, InState, World)
91 {
93  ActorData = MakeShared<FTrafficLightData>();
94 }
97  AActor* Actor,
98  TSharedPtr<const FActorInfo> Info,
99  carla::rpc::ActorState InState,
100  UWorld* World)
101  : FCarlaActor(ActorId, Actor, Info, InState, World)
102 {
104  ActorData = MakeShared<FWalkerData>();
105 }
107  IdType ActorId,
108  AActor* Actor,
109  TSharedPtr<const FActorInfo> Info,
110  carla::rpc::ActorState InState,
111  UWorld* World)
112  : FCarlaActor(ActorId, Actor, Info, InState, World)
113 {
115  ActorData = MakeShared<FActorData>();
116 }
117 
118 TSharedPtr<FCarlaActor> FCarlaActor::ConstructCarlaActor(
119  IdType ActorId,
120  AActor* Actor,
121  TSharedPtr<const FActorInfo> Info,
122  ActorType Type,
123  carla::rpc::ActorState InState,
124  UWorld* World)
125 {
126  switch(Type)
127  {
129  return MakeShared<FTrafficSignActor>(ActorId, Actor, std::move(Info), InState, World);
130  break;
132  return MakeShared<FTrafficLightActor>(ActorId, Actor, std::move(Info), InState, World);
133  break;
134  case ActorType::Vehicle:
135  return MakeShared<FVehicleActor>(ActorId, Actor, std::move(Info), InState, World);
136  break;
137  case ActorType::Walker:
138  return MakeShared<FWalkerActor>(ActorId, Actor, std::move(Info), InState, World);
139  break;
140  case ActorType::Sensor:
141  return MakeShared<FSensorActor>(ActorId, Actor, std::move(Info), InState, World);
142  break;
143  default:
144  return MakeShared<FOtherActor>(ActorId, Actor, std::move(Info), InState, World);
145  break;
146  }
147 }
148 
149 // Base FCarlaActor functions ---------------------
150 
152 {
154  if (ActorData)
155  {
156  ActorData->RecordActorData(this, CarlaEpisode);
157  }
158  TheActor->Destroy();
159  TheActor = nullptr;
160 }
161 
163 {
164  TheActor = ActorData->RespawnActor(CarlaEpisode, *Info);
165  if (TheActor == nullptr)
166  {
167  UE_LOG(LogCarla, Error, TEXT("Could not wake up dormant actor %d at location %s"), GetActorId(), *(ActorData->GetLocalTransform(CarlaEpisode).GetLocation().ToString()));
168  return;
169  }
171  ActorData->RestoreActorData(this, CarlaEpisode);
172 }
173 
175 {
176  if (IsDormant())
177  {
178  FTransform Transform = FTransform(
179  ActorData->Rotation,
180  ActorData->Location.ToFVector(),
181  ActorData->Scale);
182  ALargeMapManager* LargeMap =
184  if (LargeMap)
185  {
186  Transform = LargeMap->GlobalToLocalTransform(Transform);
187  }
188  return Transform;
189  }
190  else
191  {
192  return GetActor()->GetActorTransform();
193  }
194 }
195 
197 {
198  if (IsDormant())
199  {
200  return FTransform(
201  ActorData->Rotation,
202  ActorData->Location.ToFVector(),
203  ActorData->Scale);
204  }
205  else
206  {
207  FTransform Transform = GetActor()->GetActorTransform();
208  ALargeMapManager* LargeMap =
210  if (LargeMap)
211  {
212  Transform = LargeMap->LocalToGlobalTransform(Transform);
213  }
214  return Transform;
215  }
216 }
217 
219 {
220  if (IsDormant())
221  {
222  FVector Location = ActorData->Location.ToFVector();
223  ALargeMapManager* LargeMap =
225  if (LargeMap)
226  {
227  Location = LargeMap->GlobalToLocalLocation(Location);
228  }
229  return Location;
230  }
231  else
232  {
233  return GetActor()->GetActorLocation();
234  }
235 }
236 
238 {
239  if (IsDormant())
240  {
241  return ActorData->Location.ToFVector();
242  }
243  else
244  {
245  FVector Location = GetActor()->GetActorLocation();
246  ALargeMapManager* LargeMap =
248  if (LargeMap)
249  {
250  Location = LargeMap->LocalToGlobalLocation(Location);
251  }
252  return Location;
253  }
254 }
255 
256 void FCarlaActor::SetActorLocalLocation(const FVector& Location, ETeleportType TeleportType)
257 {
258  if (IsDormant())
259  {
260  FVector GlobalLocation = Location;
261  ALargeMapManager* LargeMap =
263  if (LargeMap)
264  {
265  GlobalLocation = LargeMap->LocalToGlobalLocation(GlobalLocation);
266  }
267  ActorData->Location = FDVector(GlobalLocation);
268  }
269  else
270  {
271  GetActor()->SetActorRelativeLocation(
272  Location,
273  false,
274  nullptr,
275  TeleportType);
276  }
277 }
278 
280  const FVector& Location, ETeleportType TeleportType)
281 {
282  if (IsDormant())
283  {
284  ActorData->Location = FDVector(Location);;
285  }
286  else
287  {
288  FVector LocalLocation = Location;
289  ALargeMapManager* LargeMap =
291  if (LargeMap)
292  {
293  LocalLocation = LargeMap->GlobalToLocalLocation(Location);
294  }
295  GetActor()->SetActorRelativeLocation(
296  LocalLocation,
297  false,
298  nullptr,
299  TeleportType);
300  }
301 }
302 
304  const FTransform& Transform, ETeleportType TeleportType)
305 {
306  if (IsDormant())
307  {
308  FTransform GlobalTransform = Transform;
309  ALargeMapManager* LargeMap =
311  if (LargeMap)
312  {
313  GlobalTransform =
314  LargeMap->LocalToGlobalTransform(GlobalTransform);
315  }
316  ActorData->Location = FDVector(GlobalTransform.GetLocation());
317  ActorData->Rotation = GlobalTransform.GetRotation();
318  ActorData->Scale = GlobalTransform.GetScale3D();
319  }
320  else
321  {
322  GetActor()->SetActorRelativeTransform(
323  Transform,
324  false,
325  nullptr,
326  TeleportType);
327  }
328 }
329 
331  const FTransform& Transform, ETeleportType TeleportType)
332 {
333  if (IsDormant())
334  {
335  ActorData->Location = FDVector(Transform.GetLocation());
336  ActorData->Rotation = Transform.GetRotation();
337  ActorData->Scale = Transform.GetScale3D();
338  }
339  else
340  {
341  FTransform LocalTransform = Transform;
342  ALargeMapManager* LargeMap =
344  if (LargeMap)
345  {
346  LocalTransform =
347  LargeMap->GlobalToLocalTransform(LocalTransform);
348  }
349  GetActor()->SetActorRelativeTransform(
350  LocalTransform,
351  false,
352  nullptr,
353  TeleportType);
354  }
355 }
356 
358 {
359  if (IsDormant())
360  {
361  return ActorData->Velocity;
362  }
363  else
364  {
365  return GetActor()->GetVelocity();
366  }
367 }
368 
370 {
371  if (IsDormant())
372  {
373  return ActorData->AngularVelocity;
374  }
375  else
376  {
377  UPrimitiveComponent* Primitive =
378  Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
379  if (Primitive)
380  {
381  return Primitive->GetPhysicsAngularVelocityInDegrees();
382  }
383  }
384  return FVector();
385 }
386 
388 {
389  if (IsDormant())
390  {
391  ActorData->Velocity = Velocity;
392  }
393  else
394  {
395  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
396  if (RootComponent == nullptr)
397  {
399  }
400  RootComponent->SetPhysicsLinearVelocity(
401  Velocity,
402  false,
403  "None");
404  }
406 }
407 
409 {
410  if (IsDormant())
411  {
412  ActorData->AngularVelocity = AngularVelocity;
413  }
414  else
415  {
416  UPrimitiveComponent* RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
417  if (RootComponent == nullptr)
418  {
420  }
421  RootComponent->SetPhysicsAngularVelocityInDegrees(
422  AngularVelocity,
423  false,
424  "None");
425  }
427 }
428 
430 {
431  if (IsDormant())
432  {
433  }
434  else
435  {
436  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
437  if (RootComponent == nullptr)
438  {
440  }
441  RootComponent->AddImpulse(
442  Impulse,
443  "None",
444  false);
445  }
447 }
448 
450  const FVector& Impulse, const FVector& Location)
451 {
452  if (IsDormant())
453  {
454  }
455  else
456  {
457  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
458  if (RootComponent == nullptr)
459  {
461  }
462 
463  UE_LOG(LogCarla, Warning, TEXT("AddImpulseAtLocation: Experimental feature, use carefully."));
464 
465  RootComponent->AddImpulseAtLocation(
466  Impulse,
467  Location,
468  "None");
469  }
471 }
472 
474 {
475  if (IsDormant())
476  {
477  }
478  else
479  {
480  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
481  if (RootComponent == nullptr)
482  {
484  }
485  RootComponent->AddForce(
486  Force,
487  "None",
488  false);
489  }
491 }
492 
494  const FVector& Force, const FVector& Location)
495 {
496  if (IsDormant())
497  {
498  }
499  else
500  {
501  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
502  if (RootComponent == nullptr)
503  {
505  }
506 
507  UE_LOG(LogCarla, Warning, TEXT("AddForceAtLocation: Experimental feature, use carefully."));
508 
509  RootComponent->AddForceAtLocation(
510  Force,
511  Location,
512  "None");
513  }
515 }
516 
518 {
519  if (IsDormant())
520  {
521  }
522  else
523  {
524  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
525  if (RootComponent == nullptr)
526  {
528  }
529  RootComponent->AddAngularImpulseInDegrees(
530  AngularInpulse,
531  "None",
532  false);
533  }
535 }
536 
538 {
539  if (IsDormant())
540  {
541  }
542  else
543  {
544  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
545  if (RootComponent == nullptr)
546  {
548  }
549  RootComponent->AddTorqueInDegrees(
550  Torque,
551  "None",
552  false);
553  }
555 }
556 
558 {
559  if (IsDormant())
560  {
561  ActorData->bSimulatePhysics = bEnabled;
562  }
563  else
564  {
565  // In the rest of actors, the physics is controlled with the UPrimitiveComponent, so we use
566  // that for disable it.
567  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
568  if (RootComponent == nullptr)
569  {
571  }
572 
573  RootComponent->SetSimulatePhysics(bEnabled);
574  RootComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
575  }
577 }
578 
580 {
581  if (IsDormant())
582  {
583  }
584  else
585  {
586  auto RootComponent = Cast<UPrimitiveComponent>(GetActor()->GetRootComponent());
587  if (RootComponent == nullptr)
588  {
590  }
591  RootComponent->SetEnableGravity(bEnabled);
592  }
594 }
595 
596 // FVehicleActor functions ---------------------
597 
599 {
600  if (IsDormant())
601  {
602  }
603  else
604  {
605  auto CarlaVehicle = Cast<ACarlaWheeledVehicle>(GetActor());
606  if (CarlaVehicle == nullptr)
607  {
609  }
610  CarlaVehicle->ActivateVelocityControl(Velocity);
611  }
613 }
614 
616 {
617  if (IsDormant())
618  {
619  }
620  else
621  {
622  auto CarlaVehicle = Cast<ACarlaWheeledVehicle>(GetActor());
623  if (CarlaVehicle == nullptr)
624  {
626  }
627  CarlaVehicle->DeactivateVelocityControl();
628  }
630 }
631 
633 {
634  if (IsDormant())
635  {
636  FVehicleData* ActorData = GetActorData<FVehicleData>();
637  PhysicsControl = ActorData->PhysicsControl;
638  }
639  else
640  {
641  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
642  if (Vehicle == nullptr)
643  {
645  }
646  PhysicsControl = Vehicle->GetVehiclePhysicsControl();
647  }
649 }
650 
652 {
653  if (IsDormant())
654  {
655  FVehicleData* ActorData = GetActorData<FVehicleData>();
656  LightState = ActorData->LightState;
657  }
658  else
659  {
660  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
661  if (Vehicle == nullptr)
662  {
664  }
665 
666  LightState = Vehicle->GetVehicleLightState();
667  }
669 }
670 
672 {
673  if (!IsDormant())
674  {
675  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
676  if (Vehicle == nullptr)
677  {
679  }
680  Vehicle->OpenDoor(DoorIdx);
681  }
683 }
684 
686 {
687  if (!IsDormant())
688  {
689  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
690  if (Vehicle == nullptr)
691  {
693  }
694  Vehicle->CloseDoor(DoorIdx);
695  }
697 }
698 
701 {
702  if (IsDormant())
703  {
704  FVehicleData* ActorData = GetActorData<FVehicleData>();
705  ActorData->PhysicsControl = PhysicsControl;
706  }
707  else
708  {
709  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
710  if (Vehicle == nullptr)
711  {
713  }
714 
715  Vehicle->ApplyVehiclePhysicsControl(PhysicsControl);
716  }
718 }
719 
721  const FVehicleLightState& LightState)
722 {
723  if (IsDormant())
724  {
725  FVehicleData* ActorData = GetActorData<FVehicleData>();
726  ActorData->LightState = LightState;
727  }
728  else
729  {
730  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
731  if (Vehicle == nullptr)
732  {
734  }
735 
736  Vehicle->SetVehicleLightState(LightState);
737  }
739 }
740 
742  const EVehicleWheelLocation& WheelLocation, float AngleInDeg)
743 {
744  if (IsDormant())
745  {
746  }
747  else
748  {
749  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
750  if(Vehicle == nullptr){
752  }
753  Vehicle->SetWheelSteerDirection(WheelLocation, AngleInDeg);
754  }
756 }
757 
759  const EVehicleWheelLocation& WheelLocation, float& Angle)
760 {
761  if (IsDormant())
762  {
763  Angle = 0;
764  }
765  else
766  {
767  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
768  if(Vehicle == nullptr){
770  }
771 
772  Angle = Vehicle->GetWheelSteerAngle(WheelLocation);
773  }
775 }
776 
778 {
779  if (IsDormant())
780  {
781  ActorData->bSimulatePhysics = bEnabled;
782  }
783  else
784  {
785  auto* CarlaVehicle = Cast<ACarlaWheeledVehicle>(GetActor());
786  // The physics in the vehicles works in a different way so to disable them.
787  if (CarlaVehicle == nullptr){
789  }
790  CarlaVehicle->SetSimulatePhysics(bEnabled);
791  }
793 }
794 
796  const FVehicleControl& Control, const EVehicleInputPriority& Priority)
797 {
798  if (IsDormant())
799  {
800  FVehicleData* ActorData = GetActorData<FVehicleData>();
801  ActorData->Control = Control;
802  }
803  else
804  {
805  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
806  if (Vehicle == nullptr)
807  {
809  }
810  Vehicle->ApplyVehicleControl(Control, Priority);
811  }
813 }
814 
816 {
817  if (IsDormant())
818  {
819  FVehicleData* ActorData = GetActorData<FVehicleData>();
820  VehicleControl = ActorData->Control;
821  }
822  else
823  {
824  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
825  if (Vehicle == nullptr)
826  {
828  }
829  VehicleControl = Vehicle->GetVehicleControl();
830  }
832 }
833 
835 {
836  if (IsDormant())
837  {
838  }
839  else
840  {
841  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
842  if (Vehicle == nullptr)
843  {
845  }
846  auto Controller = Cast<AWheeledVehicleAIController>(Vehicle->GetController());
847  if (Controller == nullptr)
848  {
850  }
851  Controller->SetAutopilot(bEnabled, bKeepState);
852  }
854 }
855 
857 {
858  if (IsDormant())
859  {
860  }
861  else
862  {
863  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
864  if (Vehicle == nullptr)
865  {
867  }
868  Vehicle->ShowDebugTelemetry(bEnabled);
869  }
871 }
872 
874 {
875  if (IsDormant())
876  {
877  }
878  else
879  {
880  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
881  if (Vehicle == nullptr)
882  {
884  }
886  }
888 }
889 
891 {
892  if (IsDormant())
893  {
894  }
895  else
896  {
897  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
898  if (Vehicle == nullptr)
899  {
901  }
902  auto* CarSimComponent = Vehicle->GetCarlaMovementComponent<UCarSimManagerComponent>();
903  if(CarSimComponent)
904  {
905  CarSimComponent->UseCarSimRoad(bEnabled);
906  }
907  else
908  {
910  }
911  }
913 }
914 
916  uint64_t MaxSubsteps, float MaxSubstepDeltaTime,
917  const FString& VehicleJSON, const FString& PowertrainJSON,
918  const FString& TireJSON, const FString& BaseJSONPath)
919 {
920  if (IsDormant())
921  {
922  }
923  else
924  {
925  auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
926  if (Vehicle == nullptr)
927  {
929  }
931  Vehicle,
932  MaxSubsteps,
933  MaxSubstepDeltaTime,
934  VehicleJSON,
935  PowertrainJSON,
936  TireJSON,
937  BaseJSONPath);
938  }
940 }
941 
942 // FSensorActor functions ---------------------
943 
944 // FtrafficSignActor functions ---------------------
945 
946 // FTrafficLightActor functions ---------------------
947 
949 {
950  if (IsDormant())
951  {
952  FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
953  ActorData->LightState = State;
954  }
955  else
956  {
957  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
958  if (TrafficLight == nullptr)
959  {
961  }
962  TrafficLight->SetTrafficLightState(State);
963  }
965 }
966 
968 {
969  if (IsDormant())
970  {
971  const FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
972  return ActorData->LightState;
973  }
974  else
975  {
976  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
977  if (TrafficLight == nullptr)
978  {
979  return ETrafficLightState::Off;
980  }
981  return TrafficLight->GetTrafficLightState();
982  }
983 }
984 
986 {
987  if (IsDormant())
988  {
989  FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
990  return ActorData->Controller;
991  }
992  else
993  {
994  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
995  if (TrafficLight == nullptr)
996  {
997  return nullptr;
998  }
999  return TrafficLight->GetTrafficLightComponent()->GetController();
1000  }
1001 }
1002 
1004 {
1005  if (IsDormant())
1006  {
1007  // Todo: implement
1008  }
1009  else
1010  {
1011  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1012  if (TrafficLight == nullptr)
1013  {
1015  }
1016  TrafficLight->SetGreenTime(time);
1017  }
1019 }
1020 
1022 {
1023  if (IsDormant())
1024  {
1025  // Todo: implement
1026  }
1027  else
1028  {
1029  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1030  if (TrafficLight == nullptr)
1031  {
1033  }
1034  TrafficLight->SetYellowTime(time);
1035  }
1037 }
1038 
1040 {
1041  if (IsDormant())
1042  {
1043  // Todo: implement
1044  }
1045  else
1046  {
1047  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1048  if (TrafficLight == nullptr)
1049  {
1051  }
1052  TrafficLight->SetRedTime(time);
1053  }
1055 }
1056 
1058 {
1059  if (IsDormant())
1060  {
1061  // Todo: implement
1062  }
1063  else
1064  {
1065  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1066  if (TrafficLight == nullptr)
1067  {
1069  }
1070  TrafficLight->SetTimeIsFrozen(bFreeze);
1071  }
1073 }
1074 
1076 {
1077  if (IsDormant())
1078  {
1079  // Todo: implement
1080  }
1081  else
1082  {
1083  auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1084  if (TrafficLight == nullptr)
1085  {
1087  }
1088  TrafficLight->GetTrafficLightComponent()->GetGroup()->ResetGroup();
1089  }
1091 }
1092 
1093 // FWalkerActor functions ---------------------
1094 
1096  const FTransform& Transform,
1097  carla::rpc::WalkerControl WalkerControl)
1098 {
1099  FVector NewLocation = Transform.GetLocation();
1100  FVector CurrentLocation = GetActorGlobalLocation();
1101  NewLocation.Z += 90.0f; // move point up because in Unreal walker is centered in the middle height
1102 
1103  // if difference between Z position is small, then we keep current, otherwise we set the new one
1104  // (to avoid Z fighting position and falling pedestrians)
1105  if (NewLocation.Z - CurrentLocation.Z < 100.0f)
1106  NewLocation.Z = CurrentLocation.Z;
1107 
1108  FTransform NewTransform = Transform;
1109  NewTransform.SetLocation(NewLocation);
1110 
1111  if (IsDormant())
1112  {
1113  FWalkerData* WalkerData = GetActorData<FWalkerData>();
1114  WalkerData->WalkerControl = WalkerControl;
1115  }
1116  else
1117  {
1118  auto * Walker = Cast<AWalkerBase>(GetActor());
1119  if (Walker && !Walker->bAlive)
1120  {
1122  }
1123 
1124  // apply walker speed
1125  auto Pawn = Cast<APawn>(GetActor());
1126  if (Pawn == nullptr)
1127  {
1129  }
1130  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1131  if (Controller == nullptr)
1132  {
1134  }
1135  Controller->ApplyWalkerControl(WalkerControl);
1136  }
1137  SetActorGlobalTransform(NewTransform);
1139 }
1140 
1142  FWalkerControl& Control)
1143 {
1144  if (IsDormant())
1145  {
1146  FWalkerData* WalkerData = GetActorData<FWalkerData>();
1147  Control = WalkerData->WalkerControl;
1148  }
1149  else
1150  {
1151  auto * Walker = Cast<AWalkerBase>(GetActor());
1152  if (Walker && !Walker->bAlive)
1153  {
1155  }
1156 
1157  // apply walker speed
1158  auto Pawn = Cast<APawn>(GetActor());
1159  if (Pawn == nullptr)
1160  {
1162  }
1163  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1164  if (Controller == nullptr)
1165  {
1167  }
1168  Control = Controller->GetWalkerControl();
1169  }
1171 }
1172 
1174 {
1175  if (IsDormant())
1176  {
1177  ActorData->bSimulatePhysics = bEnabled;
1178  }
1179  else
1180  {
1181  auto* Character = Cast<ACharacter>(GetActor());
1182  // The physics in the walkers also works in a different way so to disable them,
1183  // we need to do it in the UCharacterMovementComponent.
1184  if (Character == nullptr)
1185  {
1187  }
1188  auto CharacterMovement = Cast<UCharacterMovementComponent>(Character->GetCharacterMovement());
1189  if(bEnabled) {
1190  CharacterMovement->SetDefaultMovementMode();
1191  }
1192  else {
1193  CharacterMovement->DisableMovement();
1194  }
1195  }
1197 }
1198 
1200 {
1201  if (IsDormant())
1202  {
1203  }
1204  else
1205  {
1206  auto Character = Cast<ACharacter>(GetActor());
1207  // The physics in the walkers works in a different way so to disable them,
1208  // we need to do it in the UCharacterMovementComponent.
1209  if (Character == nullptr)
1210  {
1212  }
1213  auto CharacterMovement = Cast<UCharacterMovementComponent>(Character->GetCharacterMovement());
1214 
1215  if(bEnabled) {
1216  CharacterMovement->SetDefaultMovementMode();
1217  }
1218  else {
1219  if (CharacterMovement->IsFlying() || CharacterMovement->IsFalling())
1220  CharacterMovement->DisableMovement();
1221  }
1222  }
1224 }
1225 
1227  const FWalkerControl& Control)
1228 {
1229  if (IsDormant())
1230  {
1231  FWalkerData* ActorData = GetActorData<FWalkerData>();
1232  ActorData->WalkerControl = Control;
1233  }
1234  else
1235  {
1236  auto Pawn = Cast<APawn>(GetActor());
1237  if (Pawn == nullptr)
1238  {
1240  }
1241  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1242  if (Controller == nullptr)
1243  {
1245  }
1246  Controller->ApplyWalkerControl(Control);
1247  }
1249 }
1250 
1252 {
1253  if (IsDormant())
1254  {
1255  }
1256  else
1257  {
1258  auto Pawn = Cast<APawn>(GetActor());
1259  if (Pawn == nullptr)
1260  {
1262  }
1263  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1264  if (Controller == nullptr)
1265  {
1267  }
1268  Controller->GetBonesTransform(Bones);
1269  }
1271 }
1272 
1274 {
1275  if (IsDormant())
1276  {
1277  }
1278  else
1279  {
1280  auto Pawn = Cast<APawn>(GetActor());
1281  if (Pawn == nullptr)
1282  {
1284  }
1285  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1286  if (Controller == nullptr)
1287  {
1289  }
1290  Controller->SetBonesTransform(Bones);
1291  }
1293 }
1294 
1296 {
1297  if (IsDormant())
1298  {
1299  }
1300  else
1301  {
1302  auto Pawn = Cast<APawn>(GetActor());
1303  if (Pawn == nullptr)
1304  {
1306  }
1307  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1308  if (Controller == nullptr)
1309  {
1311  }
1312  Controller->BlendPose(Blend);
1313  }
1315 }
1316 
1318 {
1319  if (IsDormant())
1320  {
1321  }
1322  else
1323  {
1324  auto Pawn = Cast<APawn>(GetActor());
1325  if (Pawn == nullptr)
1326  {
1328  }
1329  auto Controller = Cast<AWalkerController>(Pawn->GetController());
1330  if (Controller == nullptr)
1331  {
1333  }
1334  Controller->GetPoseFromAnimation();
1335  }
1337 }
carla::rpc::ActorState State
Definition: CarlaActor.h:422
virtual ECarlaServerResponse GetPoseFromAnimation()
virtual ECarlaServerResponse GetWheelSteerAngle(const EVehicleWheelLocation &WheelLocation, float &Angle)
Definition: CarlaActor.cpp:758
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor DoorIdx) final
Definition: CarlaActor.cpp:671
FTrafficSignActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:73
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final
void WakeActorUp(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:162
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final
Definition: CarlaActor.cpp:856
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &) final
Definition: CarlaActor.cpp:815
FVector GetActorAngularVelocity() const
Definition: CarlaActor.cpp:369
void PutActorToSleep(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:151
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector &Velocity) final
Definition: CarlaActor.cpp:598
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &) final
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled)
Definition: CarlaActor.cpp:579
AActor * GetActor()
Definition: CarlaActor.h:90
FVector GlobalToLocalLocation(const FVector &InLocation) const
carla::rpc::WalkerControl WalkerControl
Definition: ActorData.h:73
ActorType Type
Definition: CarlaActor.h:430
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &State) final
Definition: CarlaActor.cpp:948
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:62
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:106
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl &PhysicsControl) final
Definition: CarlaActor.cpp:699
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &) final
Definition: CarlaActor.cpp:795
uint32 IdType
Definition: CarlaActor.h:27
FVehicleControl Control
Definition: ActorData.h:58
virtual ECarlaServerResponse EnableCarSim(const FString &SimfilePath) final
Definition: CarlaActor.cpp:873
virtual ECarlaServerResponse SetLightYellowTime(float time) final
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &LightState) final
Definition: CarlaActor.cpp:651
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:279
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final
Definition: CarlaActor.cpp:777
virtual ETrafficLightState GetTrafficLightState() const final
Definition: CarlaActor.cpp:967
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
Definition: CarlaActor.cpp:429
ECarlaServerResponse SetActorTargetAngularVelocity(const FVector &AngularVelocity)
Definition: CarlaActor.cpp:408
ECarlaServerResponse AddActorForceAtLocation(const FVector &Force, const FVector &Location)
Definition: CarlaActor.cpp:493
ECarlaServerResponse AddActorTorque(const FVector &Torque)
Definition: CarlaActor.cpp:537
FVehiclePhysicsControl PhysicsControl
Definition: ActorData.h:56
ECarlaServerResponse
carla::SharedPtr< cc::Actor > Actor
A simulation episode.
Definition: CarlaEpisode.h:34
FWalkerActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:95
TSharedPtr< const FActorInfo > Info
Definition: CarlaActor.h:416
void SetActorLocalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:256
virtual ECarlaServerResponse SetWheelSteerDirection(const EVehicleWheelLocation &WheelLocation, float AngleInDeg) final
Definition: CarlaActor.cpp:741
virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState=false) final
Definition: CarlaActor.cpp:834
FTransform GetActorLocalTransform() const
Definition: CarlaActor.cpp:174
UWorld * World
Definition: CarlaActor.h:434
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled) final
FVector GetActorVelocity() const
Definition: CarlaActor.cpp:357
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:104
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
Definition: CarlaActor.cpp:387
EVehicleWheelLocation
virtual ECarlaServerResponse EnableChronoPhysics(uint64_t MaxSubsteps, float MaxSubstepDeltaTime, const FString &VehicleJSON, const FString &PowertrainJSON, const FString &TireJSON, const FString &BaseJSONPath) final
Definition: CarlaActor.cpp:915
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
ECarlaServerResponse AddActorImpulseAtLocation(const FVector &Impulse, const FVector &Location)
Definition: CarlaActor.cpp:449
FCarlaActor()=default
void SetActorLocalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:303
FVehicleActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:51
FTransform GetActorGlobalTransform() const
Definition: CarlaActor.cpp:196
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor DoorIdx) final
Definition: CarlaActor.cpp:685
bool IsDormant() const
Definition: CarlaActor.h:70
virtual ECarlaServerResponse SetBonesTransform(const FWalkerBoneControlIn &) final
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
Definition: CarlaActor.cpp:557
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControlOut &) final
IdType GetActorId() const
Definition: CarlaActor.h:80
EVehicleDoor
Type of door to open/close.
ECarlaServerResponse AddActorForce(const FVector &Force)
Definition: CarlaActor.cpp:473
virtual UTrafficLightController * GetTrafficLightController() final
Definition: CarlaActor.cpp:985
FVector GetActorLocalLocation() const
Definition: CarlaActor.cpp:218
TSharedPtr< FActorData > ActorData
Definition: CarlaActor.h:432
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &LightState) final
Definition: CarlaActor.cpp:720
Maps a controller from OpenDrive.
FTrafficLightActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:84
UTrafficLightController * Controller
Definition: ActorData.h:102
static TSharedPtr< FCarlaActor > ConstructCarlaActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, ActorType Type, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:118
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:330
ECarlaServerResponse AddActorAngularImpulse(const FVector &AngularInpulse)
Definition: CarlaActor.cpp:517
FVehicleLightState LightState
Definition: ActorData.h:60
virtual ECarlaServerResponse DisableActorConstantVelocity() final
Definition: CarlaActor.cpp:615
geom::Transform Transform
Definition: rpc/Transform.h:16
FVector LocalToGlobalLocation(const FVector &InLocation) const
FVector GetActorGlobalLocation() const
Definition: CarlaActor.cpp:237
virtual ECarlaServerResponse GetPhysicsControl(FVehiclePhysicsControl &PhysicsControl) final
Definition: CarlaActor.cpp:632
A view over an actor and its properties.
Definition: CarlaActor.h:23
virtual ECarlaServerResponse UseCarSimRoad(bool bEnabled) final
Definition: CarlaActor.cpp:890
AActor * TheActor
Definition: CarlaActor.h:414