CARLA
 
载入中...
搜索中...
未找到
CarlaActor.cpp
浏览该文件的文档.
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
26#include <carla/rpc/MapInfo.h>
27#include <carla/rpc/MapLayer.h>
39
40
42 IdType ActorId,
43 AActor* Actor,
44 TSharedPtr<const FActorInfo> Info,
46 UWorld* World)
47 : TheActor(Actor),
48 Info(std::move(Info)),
49 Id(ActorId),
50 State(InState),
51 World(World)
52{
53}
55 IdType ActorId,
56 AActor* Actor,
57 TSharedPtr<const FActorInfo> Info,
59 UWorld* World)
60 : FCarlaActor(ActorId, Actor, Info, InState, World)
61{
62 Type = ActorType::Vehicle;
63 ActorData = MakeShared<FVehicleData>();
64}
66 IdType ActorId,
67 AActor* Actor,
68 TSharedPtr<const FActorInfo> Info,
70 UWorld* World)
71 : FCarlaActor(ActorId, Actor, Info, InState, World)
72{
73 Type = ActorType::Sensor;
74 ActorData = MakeShared<FActorSensorData>();
75}
77 IdType ActorId,
78 AActor* Actor,
79 TSharedPtr<const FActorInfo> Info,
81 UWorld* World)
82 : FCarlaActor(ActorId, Actor, Info, InState, World)
83{
85 ActorData = MakeShared<FTrafficSignData>();
86}
88 IdType ActorId,
89 AActor* Actor,
90 TSharedPtr<const FActorInfo> Info,
92 UWorld* World)
93 : FCarlaActor(ActorId, Actor, Info, InState, World)
94{
96 ActorData = MakeShared<FTrafficLightData>();
97}
99 IdType ActorId,
100 AActor* Actor,
101 TSharedPtr<const FActorInfo> Info,
103 UWorld* World)
104 : FCarlaActor(ActorId, Actor, Info, InState, World)
105{
106 Type = ActorType::Walker;
107 ActorData = MakeShared<FWalkerData>();
108}
110 IdType ActorId,
111 AActor* Actor,
112 TSharedPtr<const FActorInfo> Info,
114 UWorld* World)
115 : FCarlaActor(ActorId, Actor, Info, InState, World)
116{
117 Type = ActorType::Other;
118 ActorData = MakeShared<FActorData>();
119}
120
121TSharedPtr<FCarlaActor> FCarlaActor::ConstructCarlaActor(
122 IdType ActorId,
123 AActor* Actor,
124 TSharedPtr<const FActorInfo> Info,
125 ActorType Type,
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;
138 return MakeShared<FVehicleActor>(ActorId, Actor, std::move(Info), InState, World);
139 break;
141 return MakeShared<FWalkerActor>(ActorId, Actor, std::move(Info), InState, World);
142 break;
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
259void 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 FVehicleTelemetryData EmptyTelemetryData;
977 TelemetryData = EmptyTelemetryData;
978 }
979 else
980 {
981 auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
982 if (Vehicle == nullptr)
983 {
985 }
986 TelemetryData = Vehicle->GetVehicleTelemetryData();
987 }
989}
990
992{
993 if (IsDormant())
994 {
995 }
996 else
997 {
998 auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
999 if (Vehicle == nullptr)
1000 {
1002 }
1003 Vehicle->ShowDebugTelemetry(bEnabled);
1004 }
1006}
1007
1009{
1010 if (IsDormant())
1011 {
1012 }
1013 else
1014 {
1015 auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
1016 if (Vehicle == nullptr)
1017 {
1019 }
1021 }
1023}
1024
1026{
1027 if (IsDormant())
1028 {
1029 }
1030 else
1031 {
1032 auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
1033 if (Vehicle == nullptr)
1034 {
1036 }
1037 auto* CarSimComponent = Vehicle->GetCarlaMovementComponent<UCarSimManagerComponent>();
1038 if(CarSimComponent)
1039 {
1040 CarSimComponent->UseCarSimRoad(bEnabled);
1041 }
1042 else
1043 {
1045 }
1046 }
1048}
1049
1051 uint64_t MaxSubsteps, float MaxSubstepDeltaTime,
1052 const FString& VehicleJSON, const FString& PowertrainJSON,
1053 const FString& TireJSON, const FString& BaseJSONPath)
1054{
1055 if (IsDormant())
1056 {
1057 }
1058 else
1059 {
1060 auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
1061 if (Vehicle == nullptr)
1062 {
1064 }
1066 Vehicle,
1067 MaxSubsteps,
1068 MaxSubstepDeltaTime,
1069 VehicleJSON,
1070 PowertrainJSON,
1071 TireJSON,
1072 BaseJSONPath);
1073 }
1075}
1076
1078{
1079 if (IsDormant())
1080 {
1081 }
1082 else
1083 {
1084 auto Vehicle = Cast<ACarlaWheeledVehicle>(GetActor());
1085 if (Vehicle == nullptr)
1086 {
1088 }
1089 UBaseCarlaMovementComponent* MovementComponent =
1090 Vehicle->GetCarlaMovementComponent<UBaseCarlaMovementComponent>();
1091 if(MovementComponent)
1092 {
1093 MovementComponent->DisableSpecialPhysics();
1094 }
1095 }
1097}
1098
1099// FSensorActor functions ---------------------
1100
1101// FtrafficSignActor functions ---------------------
1102
1103// FTrafficLightActor functions ---------------------
1104
1106{
1107 if (IsDormant())
1108 {
1109 FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
1110 ActorData->LightState = State;
1111 }
1112 else
1113 {
1114 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1115 if (TrafficLight == nullptr)
1116 {
1118 }
1119 TrafficLight->SetTrafficLightState(State);
1120 }
1122}
1123
1125{
1126 if (IsDormant())
1127 {
1128 const FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
1129 return ActorData->LightState;
1130 }
1131 else
1132 {
1133 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1134 if (TrafficLight == nullptr)
1135 {
1136 return ETrafficLightState::Off;
1137 }
1138 return TrafficLight->GetTrafficLightState();
1139 }
1140}
1141
1143{
1144 if (IsDormant())
1145 {
1146 FTrafficLightData* ActorData = GetActorData<FTrafficLightData>();
1147 return ActorData->Controller;
1148 }
1149 else
1150 {
1151 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1152 if (TrafficLight == nullptr)
1153 {
1154 return nullptr;
1155 }
1156 return TrafficLight->GetTrafficLightComponent()->GetController();
1157 }
1158}
1159
1161{
1162 if (IsDormant())
1163 {
1164 // Todo: implement
1165 }
1166 else
1167 {
1168 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1169 if (TrafficLight == nullptr)
1170 {
1172 }
1173 TrafficLight->SetGreenTime(time);
1174 }
1176}
1177
1179{
1180 if (IsDormant())
1181 {
1182 // Todo: implement
1183 }
1184 else
1185 {
1186 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1187 if (TrafficLight == nullptr)
1188 {
1190 }
1191 TrafficLight->SetYellowTime(time);
1192 }
1194}
1195
1197{
1198 if (IsDormant())
1199 {
1200 // Todo: implement
1201 }
1202 else
1203 {
1204 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1205 if (TrafficLight == nullptr)
1206 {
1208 }
1209 TrafficLight->SetRedTime(time);
1210 }
1212}
1213
1215{
1216 if (IsDormant())
1217 {
1218 // Todo: implement
1219 }
1220 else
1221 {
1222 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1223 if (TrafficLight == nullptr)
1224 {
1226 }
1227 TrafficLight->SetTimeIsFrozen(bFreeze);
1228 }
1230}
1231
1233{
1234 if (IsDormant())
1235 {
1236 // Todo: implement
1237 }
1238 else
1239 {
1240 auto TrafficLight = Cast<ATrafficLightBase>(GetActor());
1241 if (TrafficLight == nullptr)
1242 {
1244 }
1245 TrafficLight->GetTrafficLightComponent()->GetGroup()->ResetGroup();
1246 }
1248}
1249
1250// FWalkerActor functions ---------------------
1251
1253 const FTransform& Transform,
1254 carla::rpc::WalkerControl WalkerControl)
1255{
1256 FVector NewLocation = Transform.GetLocation();
1257 FVector CurrentLocation = GetActorGlobalLocation();
1258
1259 // adjust position up by half of capsule height
1260 // (because in Unreal walker is centered at the capsule middle,
1261 // while Recast uses the bottom point)
1262 UCapsuleComponent* Capsule = Cast<UCapsuleComponent>(GetActor()->GetRootComponent());
1263 if (Capsule)
1264 {
1265 NewLocation.Z += Capsule->GetScaledCapsuleHalfHeight();
1266 }
1267
1268 FTransform NewTransform = Transform;
1269 NewTransform.SetLocation(NewLocation);
1270
1271 if (IsDormant())
1272 {
1273 FWalkerData* WalkerData = GetActorData<FWalkerData>();
1274 WalkerData->WalkerControl = WalkerControl;
1275 }
1276 else
1277 {
1278 auto * Walker = Cast<AWalkerBase>(GetActor());
1279 if (Walker && !Walker->bAlive)
1280 {
1282 }
1283
1284 // apply walker speed
1285 auto Pawn = Cast<APawn>(GetActor());
1286 if (Pawn == nullptr)
1287 {
1289 }
1290 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1291 if (Controller == nullptr)
1292 {
1294 }
1295 Controller->ApplyWalkerControl(WalkerControl);
1296 }
1297 SetActorGlobalTransform(NewTransform);
1299}
1300
1302 FWalkerControl& Control)
1303{
1304 if (IsDormant())
1305 {
1306 FWalkerData* WalkerData = GetActorData<FWalkerData>();
1307 Control = WalkerData->WalkerControl;
1308 }
1309 else
1310 {
1311 auto * Walker = Cast<AWalkerBase>(GetActor());
1312 if (Walker && !Walker->bAlive)
1313 {
1315 }
1316
1317 // apply walker speed
1318 auto Pawn = Cast<APawn>(GetActor());
1319 if (Pawn == nullptr)
1320 {
1322 }
1323 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1324 if (Controller == nullptr)
1325 {
1327 }
1328 Control = Controller->GetWalkerControl();
1329 }
1331}
1332
1334{
1335 if (IsDormant())
1336 {
1337 ActorData->bSimulatePhysics = bEnabled;
1338 }
1339 else
1340 {
1341 auto* Character = Cast<ACharacter>(GetActor());
1342 // The physics in the walkers also works in a different way so to disable them,
1343 // we need to do it in the UCharacterMovementComponent.
1344 if (Character == nullptr)
1345 {
1347 }
1348 auto CharacterMovement = Cast<UCharacterMovementComponent>(Character->GetCharacterMovement());
1349 if(bEnabled) {
1350 CharacterMovement->SetDefaultMovementMode();
1351 }
1352 else {
1353 CharacterMovement->DisableMovement();
1354 }
1355 }
1357}
1358
1360{
1361 if (IsDormant())
1362 {
1363 }
1364 else
1365 {
1366 auto Character = Cast<ACharacter>(GetActor());
1367 // The physics in the walkers works in a different way so to disable them,
1368 // we need to do it in the UCharacterMovementComponent.
1369 if (Character == nullptr)
1370 {
1372 }
1373 auto CharacterMovement = Cast<UCharacterMovementComponent>(Character->GetCharacterMovement());
1374
1375 if(bEnabled) {
1376 CharacterMovement->SetDefaultMovementMode();
1377 }
1378 else {
1379 if (CharacterMovement->IsFlying() || CharacterMovement->IsFalling())
1380 CharacterMovement->DisableMovement();
1381 }
1382 }
1384}
1385
1387 const FWalkerControl& Control)
1388{
1389 if (IsDormant())
1390 {
1391 FWalkerData* ActorData = GetActorData<FWalkerData>();
1392 ActorData->WalkerControl = Control;
1393 }
1394 else
1395 {
1396 auto Pawn = Cast<APawn>(GetActor());
1397 if (Pawn == nullptr)
1398 {
1400 }
1401 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1402 if (Controller == nullptr)
1403 {
1405 }
1406 Controller->ApplyWalkerControl(Control);
1407 }
1409}
1410
1412{
1413 if (IsDormant())
1414 {
1415 }
1416 else
1417 {
1418 auto Pawn = Cast<APawn>(GetActor());
1419 if (Pawn == nullptr)
1420 {
1422 }
1423 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1424 if (Controller == nullptr)
1425 {
1427 }
1428 Controller->GetBonesTransform(Bones);
1429 }
1431}
1432
1434{
1435 if (IsDormant())
1436 {
1437 }
1438 else
1439 {
1440 auto Pawn = Cast<APawn>(GetActor());
1441 if (Pawn == nullptr)
1442 {
1444 }
1445 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1446 if (Controller == nullptr)
1447 {
1449 }
1450 Controller->SetBonesTransform(Bones);
1451 }
1453}
1454
1456{
1457 if (IsDormant())
1458 {
1459 }
1460 else
1461 {
1462 auto Pawn = Cast<APawn>(GetActor());
1463 if (Pawn == nullptr)
1464 {
1466 }
1467 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1468 if (Controller == nullptr)
1469 {
1471 }
1472 Controller->BlendPose(Blend);
1473 }
1475}
1476
1478{
1479 if (IsDormant())
1480 {
1481 }
1482 else
1483 {
1484 auto Pawn = Cast<APawn>(GetActor());
1485 if (Pawn == nullptr)
1486 {
1488 }
1489 auto Controller = Cast<AWalkerController>(Pawn->GetController());
1490 if (Controller == nullptr)
1491 {
1493 }
1494 Controller->GetPoseFromAnimation();
1495 }
1497}
1498
1500{
1501 if (IsDormant())
1502 {
1503 }
1504 else
1505 {
1506 auto Pawn = Cast<APawn>(GetActor());
1507 if (Pawn == nullptr)
1508 {
1510 }
1511 auto Walker = Cast<AWalkerBase>(Pawn);
1512 if (Walker == nullptr)
1513 {
1515 }
1516 Walker->StartDeathLifeSpan();
1517 UE_LOG(LogCarla, Warning, TEXT("Walker starting life span by dead"));
1518 }
1520}
ECarlaServerResponse
EVehicleWheelLocation
EVehicleDoor
Type of door to open/close
EVehicleInputPriority
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.
Definition CarlaActor.h:25
carla::rpc::ActorState State
Definition CarlaActor.h:466
UWorld * World
Definition CarlaActor.h:478
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)
bool IsDormant() const
Definition CarlaActor.h:71
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
AActor * GetActor()
Definition CarlaActor.h:91
uint32 IdType
Definition CarlaActor.h:28
virtual ECarlaServerResponse SetActorCollisions(bool bEnabled)
AActor * TheActor
Definition CarlaActor.h:458
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
Definition CarlaActor.h:460
FVector GetActorGlobalLocation() const
void SetActorLocalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
TSharedPtr< FActorData > ActorData
Definition CarlaActor.h:476
IdType GetActorId() const
Definition CarlaActor.h:81
FTransform GetActorLocalTransform() const
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
ECarlaServerResponse AddActorForce(const FVector &Force)
FCarlaActor()=default
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
Definition ActorData.h:84
static void CreateCarsimComponent(ACarlaWheeledVehicle *Vehicle, FString Simfile)
A simulation episode.
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.