CARLA
CarlaActor.h
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 #pragma once
8 
10 #include "Carla/Actor/ActorData.h"
14 
15 #include "carla/rpc/ActorState.h"
17 
19 
20 class AActor;
21 
22 /// A view over an actor and its properties.
24 {
25 public:
26 
27  using IdType = uint32;
28 
29  enum class ActorType : uint8
30  {
31  Other,
32  Vehicle,
33  Walker,
36  Sensor,
37  INVALID
38  };
39 
40  FCarlaActor() = default;
41  // FCarlaActor(const FCarlaActor &) = default;
42  // FCarlaActor(FCarlaActor &&) = default;
43 
46  AActor* Actor,
47  TSharedPtr<const FActorInfo> Info,
48  carla::rpc::ActorState InState,
49  UWorld* World);
50 
51  virtual ~FCarlaActor() {};
52 
53 
54  bool IsInValid() const
55  {
57  }
58 
59  bool IsAlive() const
60  {
63  }
64 
65  bool IsActive() const
66  {
68  }
69 
70  bool IsDormant() const
71  {
73  }
74 
75  bool IsPendingKill() const
76  {
78  }
79 
81  {
82  return Id;
83  }
84 
86  {
87  return Type;
88  }
89 
91  {
92  return TheActor;
93  }
94 
95  const AActor *GetActor() const
96  {
97  return TheActor;
98  }
99 
100  const FActorInfo *GetActorInfo() const
101  {
102  return Info.Get();
103  }
104 
106  {
107  return State;
108  }
109 
111  {
112  State = InState;
113  }
114 
115  void SetParent(IdType InParentId)
116  {
117  ParentId = InParentId;
118  }
119 
121  {
122  return ParentId;
123  }
124 
125  void AddChildren(IdType ChildId)
126  {
127  Children.Add(ChildId);
128  }
129 
130  void RemoveChildren(IdType ChildId)
131  {
132  Children.Remove(ChildId);
133  }
134 
135  const TArray<IdType>& GetChildren() const
136  {
137  return Children;
138  }
139 
141  {
142  Attachment = InAttachmentType;
143  }
144 
146  {
147  return Attachment;
148  }
149 
150  void BuildActorData();
151 
152  void PutActorToSleep(UCarlaEpisode* CarlaEpisode);
153 
154  void WakeActorUp(UCarlaEpisode* CarlaEpisode);
155 
157  {
158  return ActorData.Get();
159  }
160 
161  const FActorData* GetActorData() const
162  {
163  return ActorData.Get();
164  }
165 
166  template<typename T>
168  {
169  return dynamic_cast<T*>(ActorData.Get());
170  }
171 
172  template<typename T>
173  const T* GetActorData() const
174  {
175  return dynamic_cast<T*>(ActorData.Get());
176  }
177 
178  // Actor function interface ----------------------
179 
180  // General functions
181 
182  FTransform GetActorLocalTransform() const;
183 
184  FTransform GetActorGlobalTransform() const;
185 
186  FVector GetActorLocalLocation() const;
187 
188  FVector GetActorGlobalLocation() const;
189 
191  const FVector& Location,
192  ETeleportType Teleport = ETeleportType::TeleportPhysics);
193 
195  const FVector& Location,
196  ETeleportType Teleport = ETeleportType::TeleportPhysics);
197 
199  const FTransform& Transform,
200  ETeleportType Teleport = ETeleportType::TeleportPhysics);
201 
203  const FTransform& Transform,
204  ETeleportType Teleport = ETeleportType::TeleportPhysics);
205 
206  FVector GetActorVelocity() const;
207 
208  FVector GetActorAngularVelocity() const;
209 
210  ECarlaServerResponse SetActorTargetVelocity(const FVector& Velocity);
211 
212  ECarlaServerResponse SetActorTargetAngularVelocity(const FVector& AngularVelocity);
213 
214  ECarlaServerResponse AddActorImpulse(const FVector& Impulse);
215 
216  ECarlaServerResponse AddActorImpulseAtLocation(const FVector& Impulse, const FVector& Location);
217 
218  ECarlaServerResponse AddActorForce(const FVector& Force);
219 
220  ECarlaServerResponse AddActorForceAtLocation(const FVector& Force, const FVector& Location);
221 
222  ECarlaServerResponse AddActorAngularImpulse(const FVector& AngularInpulse);
223 
224  ECarlaServerResponse AddActorTorque(const FVector& Torque);
225 
226  virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled);
227 
228  virtual ECarlaServerResponse SetActorCollisions(bool bEnabled);
229 
230  virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled);
231 
232  // Vehicle functions
234  {
236  }
237 
239  {
241  }
242 
244  {
246  }
247 
249  {
251  }
252 
254  {
256  }
257 
259  {
261  }
262 
264  {
266  }
267 
269  {
271  }
272 
274  {
276  }
277 
279  {
281  }
282 
284  {
286  }
287 
289  const FVehicleControl&, const EVehicleInputPriority&)
290  {
292  }
293 
296  {
298  }
299 
301  {
303  }
304 
306  {
308  }
309 
311  {
313  }
314 
316  {
318  }
319 
320  virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState = false)
321  {
323  }
324 
326  {
328  }
329 
330  virtual ECarlaServerResponse EnableCarSim(const FString&)
331  {
333  }
334 
336  {
338  }
339 
340  virtual ECarlaServerResponse EnableChronoPhysics(uint64_t, float,
341  const FString&, const FString&, const FString&, const FString&)
342  {
344  }
345 
346  // Traffic light functions
347 
349  {
351  }
352 
354  {
355  return ETrafficLightState::Off;
356  }
357 
359  {
360  return nullptr;
361  }
362 
364  {
366  }
367 
369  {
371  }
372 
374  {
376  }
377 
378  // Traffic sign functions
379 
380  // Walker functions
382  const FTransform& Transform,
383  carla::rpc::WalkerControl WalkerControl)
384  {
386  }
387 
389  {
391  }
392 
394  {
396  }
397 
399  {
401  }
402 
404  {
406  }
407 
408  virtual ECarlaServerResponse BlendPose(float Blend)
409  {
411  }
412 
414  {
416  }
417 
419  {
421  }
422 
424  {
426  }
427 
429  {
431  }
432 
433  // Sensor functions
434 
435  static TSharedPtr<FCarlaActor> ConstructCarlaActor(
436  IdType ActorId,
437  AActor* Actor,
438  TSharedPtr<const FActorInfo> Info,
439  ActorType Type,
440  carla::rpc::ActorState InState,
441  UWorld* World);
442 
443 private:
444 
445  friend class FActorRegistry;
446 
447  AActor *TheActor = nullptr;
448 
449  TSharedPtr<const FActorInfo> Info = nullptr;
450 
451  IdType Id = 0u;
452 
454 
456 
458 
459  TArray<IdType> Children;
460 
461 protected:
462 
464 
465  TSharedPtr<FActorData> ActorData = nullptr;
466 
467  UWorld *World = nullptr;
468 
469 };
470 
472 {
473 public:
475  IdType ActorId,
476  AActor* Actor,
477  TSharedPtr<const FActorInfo> Info,
478  carla::rpc::ActorState InState,
479  UWorld* World);
480 
481  virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector& Velocity) final;
482 
484 
486 
488 
490 
491  virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor DoorIdx) final;
492 
493  virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor DoorIdx) final;
494 
496  const FVehiclePhysicsControl& PhysicsControl) final;
497 
499  const FVehicleLightState& LightState) final;
500 
502  const EVehicleWheelLocation& WheelLocation, float AngleInDeg) final;
503 
505  const EVehicleWheelLocation& WheelLocation, float& Angle);
506 
507  virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final;
508 
510  const FVehicleControl&, const EVehicleInputPriority&) final;
511 
513  const FVehicleAckermannControl&, const EVehicleInputPriority&) final;
514 
516 
518 
520 
522 
523  virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState = false) final;
524 
525  virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final;
526 
527  virtual ECarlaServerResponse EnableCarSim(const FString& SimfilePath) final;
528 
529  virtual ECarlaServerResponse UseCarSimRoad(bool bEnabled) final;
530 
532  uint64_t MaxSubsteps, float MaxSubstepDeltaTime,
533  const FString& VehicleJSON, const FString& PowertrainJSON,
534  const FString& TireJSON, const FString& BaseJSONPath) final;
535 };
536 
537 class FSensorActor : public FCarlaActor
538 {
539 public:
540  FSensorActor(
541  IdType ActorId,
542  AActor* Actor,
543  TSharedPtr<const FActorInfo> Info,
544  carla::rpc::ActorState InState,
545  UWorld* World);
546 
547 };
548 
550 {
551 public:
553  IdType ActorId,
554  AActor* Actor,
555  TSharedPtr<const FActorInfo> Info,
556  carla::rpc::ActorState InState,
557  UWorld* World);
558 };
559 
561 {
562 public:
564  IdType ActorId,
565  AActor* Actor,
566  TSharedPtr<const FActorInfo> Info,
567  carla::rpc::ActorState InState,
568  UWorld* World);
569 
571 
572  virtual ETrafficLightState GetTrafficLightState() const final;
573 
575 
576  virtual ECarlaServerResponse SetLightGreenTime(float time) final;
577 
578  virtual ECarlaServerResponse SetLightYellowTime(float time) final;
579 
580  virtual ECarlaServerResponse SetLightRedTime(float time) final;
581 
582  virtual ECarlaServerResponse FreezeTrafficLight(bool bFreeze) final;
583 
585 
586 };
587 
588 class FWalkerActor : public FCarlaActor
589 {
590 public:
591  FWalkerActor(
592  IdType ActorId,
593  AActor* Actor,
594  TSharedPtr<const FActorInfo> Info,
595  carla::rpc::ActorState InState,
596  UWorld* World);
597 
599  const FTransform& Transform,
600  carla::rpc::WalkerControl WalkerControl) final;
601 
602  virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final;
603 
604  virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled) final;
605 
607 
609 
611 
613 
614  virtual ECarlaServerResponse BlendPose(float Blend);
615 
617 
619 };
620 
621 class FOtherActor : public FCarlaActor
622 {
623 public:
624  FOtherActor(
625  IdType ActorId,
626  AActor* Actor,
627  TSharedPtr<const FActorInfo> Info,
628  carla::rpc::ActorState InState,
629  UWorld* World);
630 
631 };
carla::rpc::ActorState State
Definition: CarlaActor.h:455
carla::rpc::AttachmentType GetAttachmentType() const
Definition: CarlaActor.h:145
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
Definition: CarlaActor.h:273
void WakeActorUp(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:165
A registry of all the Carla actors.
Definition: ActorRegistry.h:20
carla::rpc::ActorState GetActorState() const
Definition: CarlaActor.h:105
FVector GetActorAngularVelocity() const
Definition: CarlaActor.cpp:372
bool IsInValid() const
Definition: CarlaActor.h:54
virtual ECarlaServerResponse SetWheelSteerDirection(const EVehicleWheelLocation &, float)
Definition: CarlaActor.h:278
virtual ETrafficLightState GetTrafficLightState() const
Definition: CarlaActor.h:353
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &)
Definition: CarlaActor.h:393
void PutActorToSleep(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:154
void RemoveChildren(IdType ChildId)
Definition: CarlaActor.h:130
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled)
Definition: CarlaActor.cpp:594
AActor * GetActor()
Definition: CarlaActor.h:90
virtual ECarlaServerResponse SetActorCollisions(bool bEnabled)
Definition: CarlaActor.cpp:582
virtual ECarlaServerResponse SetBonesTransform(const FWalkerBoneControlIn &)
Definition: CarlaActor.h:403
virtual ~FCarlaActor()
Definition: CarlaActor.h:51
ActorType Type
Definition: CarlaActor.h:463
carla::rpc::AttachmentType Attachment
Definition: CarlaActor.h:457
virtual ECarlaServerResponse DisableActorConstantVelocity()
Definition: CarlaActor.h:238
T * GetActorData()
Definition: CarlaActor.h:167
uint32 IdType
Definition: CarlaActor.h:27
virtual ECarlaServerResponse BlendPose(float Blend)
Definition: CarlaActor.h:408
virtual ECarlaServerResponse GetPhysicsControl(FVehiclePhysicsControl &)
Definition: CarlaActor.h:243
virtual ECarlaServerResponse ApplyAckermannControllerSettings(const FAckermannControllerSettings &)
Definition: CarlaActor.h:315
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
Definition: CarlaActor.h:288
const AActor * GetActor() const
Definition: CarlaActor.h:95
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
Definition: CarlaActor.h:348
virtual ECarlaServerResponse EnableChronoPhysics(uint64_t, float, const FString &, const FString &, const FString &, const FString &)
Definition: CarlaActor.h:340
geom::Location Location
Definition: rpc/Location.h:14
void SetActorGlobalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:282
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
Definition: CarlaActor.cpp:432
ECarlaServerResponse SetActorTargetAngularVelocity(const FVector &AngularVelocity)
Definition: CarlaActor.cpp:411
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor)
Definition: CarlaActor.h:263
ECarlaServerResponse AddActorForceAtLocation(const FVector &Force, const FVector &Location)
Definition: CarlaActor.cpp:496
ECarlaServerResponse AddActorTorque(const FVector &Torque)
Definition: CarlaActor.cpp:540
const TArray< IdType > & GetChildren() const
Definition: CarlaActor.h:135
FActorData * GetActorData()
Definition: CarlaActor.h:156
ECarlaServerResponse
carla::SharedPtr< cc::Actor > Actor
virtual ECarlaServerResponse FreezeTrafficLight(bool)
Definition: CarlaActor.h:423
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector &)
Definition: CarlaActor.h:233
A simulation episode.
Definition: CarlaEpisode.h:38
virtual ECarlaServerResponse GetPoseFromAnimation()
Definition: CarlaActor.h:413
TSharedPtr< const FActorInfo > Info
Definition: CarlaActor.h:449
void SetActorState(carla::rpc::ActorState InState)
Definition: CarlaActor.h:110
virtual ECarlaServerResponse ResetTrafficLightGroup()
Definition: CarlaActor.h:428
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
Definition: CarlaActor.h:140
void SetActorLocalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:259
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControlOut &)
Definition: CarlaActor.h:398
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
Definition: CarlaActor.h:388
virtual ECarlaServerResponse GetVehicleAckermannControl(FVehicleAckermannControl &)
Definition: CarlaActor.h:305
bool IsActive() const
Definition: CarlaActor.h:65
FTransform GetActorLocalTransform() const
Definition: CarlaActor.cpp:177
UWorld * World
Definition: CarlaActor.h:467
void BuildActorData()
FVector GetActorVelocity() const
Definition: CarlaActor.cpp:360
virtual ECarlaServerResponse SetLightGreenTime(float)
Definition: CarlaActor.h:363
bool IsAlive() const
Definition: CarlaActor.h:59
uint32_t ActorId
Definition: ActorId.h:14
const FActorInfo * GetActorInfo() const
Definition: CarlaActor.h:100
bool IsPendingKill() const
Definition: CarlaActor.h:75
EVehicleInputPriority
const T * GetActorData() const
Definition: CarlaActor.h:173
virtual ECarlaServerResponse SetLightYellowTime(float)
Definition: CarlaActor.h:368
virtual ECarlaServerResponse SetActorDead()
Definition: CarlaActor.h:418
virtual ECarlaServerResponse SetLightRedTime(float)
Definition: CarlaActor.h:373
virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState=false)
Definition: CarlaActor.h:320
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
Definition: CarlaActor.cpp:390
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor)
Definition: CarlaActor.h:258
EVehicleWheelLocation
virtual ECarlaServerResponse EnableCarSim(const FString &)
Definition: CarlaActor.h:330
IdType Id
Definition: CarlaActor.h:451
void AddChildren(IdType ChildId)
Definition: CarlaActor.h:125
virtual UTrafficLightController * GetTrafficLightController()
Definition: CarlaActor.h:358
virtual ECarlaServerResponse UseCarSimRoad(bool)
Definition: CarlaActor.h:335
const FActorData * GetActorData() const
Definition: CarlaActor.h:161
ECarlaServerResponse AddActorImpulseAtLocation(const FVector &Impulse, const FVector &Location)
Definition: CarlaActor.cpp:452
FCarlaActor()=default
A view over an actor and its properties.
Definition: ActorInfo.h:22
void SetActorLocalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:306
FTransform GetActorGlobalTransform() const
Definition: CarlaActor.cpp:199
bool IsDormant() const
Definition: CarlaActor.h:70
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
Definition: CarlaActor.cpp:560
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &)
Definition: CarlaActor.h:253
void SetParent(IdType InParentId)
Definition: CarlaActor.h:115
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &)
Definition: CarlaActor.h:300
IdType GetActorId() const
Definition: CarlaActor.h:80
EVehicleDoor
Type of door to open/close.
virtual ECarlaServerResponse ApplyAckermannControlToVehicle(const FVehicleAckermannControl &, const EVehicleInputPriority &)
Definition: CarlaActor.h:294
ECarlaServerResponse AddActorForce(const FVector &Force)
Definition: CarlaActor.cpp:476
IdType ParentId
Definition: CarlaActor.h:453
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl &)
Definition: CarlaActor.h:268
FVector GetActorLocalLocation() const
Definition: CarlaActor.cpp:221
TSharedPtr< FActorData > ActorData
Definition: CarlaActor.h:465
virtual ECarlaServerResponse GetWheelSteerAngle(const EVehicleWheelLocation &, float &)
Definition: CarlaActor.h:283
Maps a controller from OpenDrive.
virtual ECarlaServerResponse GetAckermannControllerSettings(FAckermannControllerSettings &)
Definition: CarlaActor.h:310
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
geom::Transform Transform
Definition: rpc/Transform.h:16
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool)
Definition: CarlaActor.h:325
virtual ECarlaServerResponse SetWalkerState(const FTransform &Transform, carla::rpc::WalkerControl WalkerControl)
Definition: CarlaActor.h:381
FVector GetActorGlobalLocation() const
Definition: CarlaActor.cpp:240
ActorType GetActorType() const
Definition: CarlaActor.h:85
A view over an actor and its properties.
Definition: CarlaActor.h:23
TArray< IdType > Children
Definition: CarlaActor.h:459
AActor * TheActor
Definition: CarlaActor.h:447
virtual ECarlaServerResponse GetFailureState(carla::rpc::VehicleFailureState &)
Definition: CarlaActor.h:248
IdType GetParent() const
Definition: CarlaActor.h:120