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 SetActorEnableGravity(bool bEnabled);
229 
230  // Vehicle functions
232  {
234  }
235 
237  {
239  }
240 
242  {
244  }
245 
247  {
249  }
250 
252  {
254  }
255 
257  {
259  }
260 
262  {
264  }
265 
267  {
269  }
270 
272  {
274  }
275 
277  {
279  }
280 
282  {
284  }
285 
287  const FVehicleControl&, const EVehicleInputPriority&)
288  {
290  }
291 
294  {
296  }
297 
299  {
301  }
302 
304  {
306  }
307 
309  {
311  }
312 
314  {
316  }
317 
318  virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState = false)
319  {
321  }
322 
324  {
326  }
327 
328  virtual ECarlaServerResponse EnableCarSim(const FString&)
329  {
331  }
332 
334  {
336  }
337 
338  virtual ECarlaServerResponse EnableChronoPhysics(uint64_t, float,
339  const FString&, const FString&, const FString&, const FString&)
340  {
342  }
343 
344  // Traffic light functions
345 
347  {
349  }
350 
352  {
353  return ETrafficLightState::Off;
354  }
355 
357  {
358  return nullptr;
359  }
360 
362  {
364  }
365 
367  {
369  }
370 
372  {
374  }
375 
376  // Traffic sign functions
377 
378  // Walker functions
380  const FTransform& Transform,
381  carla::rpc::WalkerControl WalkerControl)
382  {
384  }
385 
387  {
389  }
390 
392  {
394  }
395 
397  {
399  }
400 
402  {
404  }
405 
406  virtual ECarlaServerResponse BlendPose(float Blend)
407  {
409  }
410 
412  {
414  }
415 
417  {
419  }
420 
422  {
424  }
425 
426  // Sensor functions
427 
428  static TSharedPtr<FCarlaActor> ConstructCarlaActor(
429  IdType ActorId,
430  AActor* Actor,
431  TSharedPtr<const FActorInfo> Info,
432  ActorType Type,
433  carla::rpc::ActorState InState,
434  UWorld* World);
435 
436 private:
437 
438  friend class FActorRegistry;
439 
440  AActor *TheActor = nullptr;
441 
442  TSharedPtr<const FActorInfo> Info = nullptr;
443 
444  IdType Id = 0u;
445 
447 
449 
451 
452  TArray<IdType> Children;
453 
454 protected:
455 
457 
458  TSharedPtr<FActorData> ActorData = nullptr;
459 
460  UWorld *World = nullptr;
461 
462 };
463 
465 {
466 public:
468  IdType ActorId,
469  AActor* Actor,
470  TSharedPtr<const FActorInfo> Info,
471  carla::rpc::ActorState InState,
472  UWorld* World);
473 
474  virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector& Velocity) final;
475 
477 
479 
481 
483 
484  virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor DoorIdx) final;
485 
486  virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor DoorIdx) final;
487 
489  const FVehiclePhysicsControl& PhysicsControl) final;
490 
492  const FVehicleLightState& LightState) final;
493 
495  const EVehicleWheelLocation& WheelLocation, float AngleInDeg) final;
496 
498  const EVehicleWheelLocation& WheelLocation, float& Angle);
499 
500  virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final;
501 
503  const FVehicleControl&, const EVehicleInputPriority&) final;
504 
506  const FVehicleAckermannControl&, const EVehicleInputPriority&) final;
507 
509 
511 
513 
515 
516  virtual ECarlaServerResponse SetActorAutopilot(bool bEnabled, bool bKeepState = false) final;
517 
518  virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool bEnabled) final;
519 
520  virtual ECarlaServerResponse EnableCarSim(const FString& SimfilePath) final;
521 
522  virtual ECarlaServerResponse UseCarSimRoad(bool bEnabled) final;
523 
525  uint64_t MaxSubsteps, float MaxSubstepDeltaTime,
526  const FString& VehicleJSON, const FString& PowertrainJSON,
527  const FString& TireJSON, const FString& BaseJSONPath) final;
528 };
529 
530 class FSensorActor : public FCarlaActor
531 {
532 public:
533  FSensorActor(
534  IdType ActorId,
535  AActor* Actor,
536  TSharedPtr<const FActorInfo> Info,
537  carla::rpc::ActorState InState,
538  UWorld* World);
539 
540 };
541 
543 {
544 public:
546  IdType ActorId,
547  AActor* Actor,
548  TSharedPtr<const FActorInfo> Info,
549  carla::rpc::ActorState InState,
550  UWorld* World);
551 };
552 
554 {
555 public:
557  IdType ActorId,
558  AActor* Actor,
559  TSharedPtr<const FActorInfo> Info,
560  carla::rpc::ActorState InState,
561  UWorld* World);
562 
564 
565  virtual ETrafficLightState GetTrafficLightState() const final;
566 
568 
569  virtual ECarlaServerResponse SetLightGreenTime(float time) final;
570 
571  virtual ECarlaServerResponse SetLightYellowTime(float time) final;
572 
573  virtual ECarlaServerResponse SetLightRedTime(float time) final;
574 
575  virtual ECarlaServerResponse FreezeTrafficLight(bool bFreeze) final;
576 
578 
579 };
580 
581 class FWalkerActor : public FCarlaActor
582 {
583 public:
584  FWalkerActor(
585  IdType ActorId,
586  AActor* Actor,
587  TSharedPtr<const FActorInfo> Info,
588  carla::rpc::ActorState InState,
589  UWorld* World);
590 
592  const FTransform& Transform,
593  carla::rpc::WalkerControl WalkerControl) final;
594 
595  virtual ECarlaServerResponse SetActorSimulatePhysics(bool bSimulatePhysics) final;
596 
597  virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled) final;
598 
600 
602 
604 
606 
607  virtual ECarlaServerResponse BlendPose(float Blend);
608 
610 };
611 
612 class FOtherActor : public FCarlaActor
613 {
614 public:
615  FOtherActor(
616  IdType ActorId,
617  AActor* Actor,
618  TSharedPtr<const FActorInfo> Info,
619  carla::rpc::ActorState InState,
620  UWorld* World);
621 
622 };
carla::rpc::ActorState State
Definition: CarlaActor.h:448
carla::rpc::AttachmentType GetAttachmentType() const
Definition: CarlaActor.h:145
virtual ECarlaServerResponse SetVehicleLightState(const FVehicleLightState &)
Definition: CarlaActor.h:271
void WakeActorUp(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:164
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:371
bool IsInValid() const
Definition: CarlaActor.h:54
virtual ECarlaServerResponse SetWheelSteerDirection(const EVehicleWheelLocation &, float)
Definition: CarlaActor.h:276
virtual ETrafficLightState GetTrafficLightState() const
Definition: CarlaActor.h:351
virtual ECarlaServerResponse GetWalkerControl(FWalkerControl &)
Definition: CarlaActor.h:391
void PutActorToSleep(UCarlaEpisode *CarlaEpisode)
Definition: CarlaActor.cpp:153
void RemoveChildren(IdType ChildId)
Definition: CarlaActor.h:130
virtual ECarlaServerResponse SetActorEnableGravity(bool bEnabled)
Definition: CarlaActor.cpp:581
AActor * GetActor()
Definition: CarlaActor.h:90
virtual ECarlaServerResponse SetBonesTransform(const FWalkerBoneControlIn &)
Definition: CarlaActor.h:401
virtual ~FCarlaActor()
Definition: CarlaActor.h:51
ActorType Type
Definition: CarlaActor.h:456
carla::rpc::AttachmentType Attachment
Definition: CarlaActor.h:450
virtual ECarlaServerResponse DisableActorConstantVelocity()
Definition: CarlaActor.h:236
T * GetActorData()
Definition: CarlaActor.h:167
uint32 IdType
Definition: CarlaActor.h:27
virtual ECarlaServerResponse BlendPose(float Blend)
Definition: CarlaActor.h:406
virtual ECarlaServerResponse GetPhysicsControl(FVehiclePhysicsControl &)
Definition: CarlaActor.h:241
virtual ECarlaServerResponse ApplyAckermannControllerSettings(const FAckermannControllerSettings &)
Definition: CarlaActor.h:313
virtual ECarlaServerResponse ApplyControlToVehicle(const FVehicleControl &, const EVehicleInputPriority &)
Definition: CarlaActor.h:286
const AActor * GetActor() const
Definition: CarlaActor.h:95
virtual ECarlaServerResponse SetTrafficLightState(const ETrafficLightState &)
Definition: CarlaActor.h:346
virtual ECarlaServerResponse EnableChronoPhysics(uint64_t, float, const FString &, const FString &, const FString &, const FString &)
Definition: CarlaActor.h:338
geom::Location Location
Definition: rpc/Location.h:14
void SetActorGlobalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:281
ECarlaServerResponse AddActorImpulse(const FVector &Impulse)
Definition: CarlaActor.cpp:431
ECarlaServerResponse SetActorTargetAngularVelocity(const FVector &AngularVelocity)
Definition: CarlaActor.cpp:410
virtual ECarlaServerResponse CloseVehicleDoor(const EVehicleDoor)
Definition: CarlaActor.h:261
ECarlaServerResponse AddActorForceAtLocation(const FVector &Force, const FVector &Location)
Definition: CarlaActor.cpp:495
ECarlaServerResponse AddActorTorque(const FVector &Torque)
Definition: CarlaActor.cpp:539
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:416
virtual ECarlaServerResponse EnableActorConstantVelocity(const FVector &)
Definition: CarlaActor.h:231
A simulation episode.
Definition: CarlaEpisode.h:37
virtual ECarlaServerResponse GetPoseFromAnimation()
Definition: CarlaActor.h:411
TSharedPtr< const FActorInfo > Info
Definition: CarlaActor.h:442
void SetActorState(carla::rpc::ActorState InState)
Definition: CarlaActor.h:110
virtual ECarlaServerResponse ResetTrafficLightGroup()
Definition: CarlaActor.h:421
void SetAttachmentType(carla::rpc::AttachmentType InAttachmentType)
Definition: CarlaActor.h:140
void SetActorLocalLocation(const FVector &Location, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:258
virtual ECarlaServerResponse GetBonesTransform(FWalkerBoneControlOut &)
Definition: CarlaActor.h:396
virtual ECarlaServerResponse ApplyControlToWalker(const FWalkerControl &)
Definition: CarlaActor.h:386
virtual ECarlaServerResponse GetVehicleAckermannControl(FVehicleAckermannControl &)
Definition: CarlaActor.h:303
bool IsActive() const
Definition: CarlaActor.h:65
FTransform GetActorLocalTransform() const
Definition: CarlaActor.cpp:176
UWorld * World
Definition: CarlaActor.h:460
void BuildActorData()
FVector GetActorVelocity() const
Definition: CarlaActor.cpp:359
virtual ECarlaServerResponse SetLightGreenTime(float)
Definition: CarlaActor.h:361
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:366
virtual ECarlaServerResponse SetLightRedTime(float)
Definition: CarlaActor.h:371
virtual ECarlaServerResponse SetActorAutopilot(bool, bool bKeepState=false)
Definition: CarlaActor.h:318
ECarlaServerResponse SetActorTargetVelocity(const FVector &Velocity)
Definition: CarlaActor.cpp:389
virtual ECarlaServerResponse OpenVehicleDoor(const EVehicleDoor)
Definition: CarlaActor.h:256
EVehicleWheelLocation
virtual ECarlaServerResponse EnableCarSim(const FString &)
Definition: CarlaActor.h:328
IdType Id
Definition: CarlaActor.h:444
void AddChildren(IdType ChildId)
Definition: CarlaActor.h:125
virtual UTrafficLightController * GetTrafficLightController()
Definition: CarlaActor.h:356
virtual ECarlaServerResponse UseCarSimRoad(bool)
Definition: CarlaActor.h:333
const FActorData * GetActorData() const
Definition: CarlaActor.h:161
ECarlaServerResponse AddActorImpulseAtLocation(const FVector &Impulse, const FVector &Location)
Definition: CarlaActor.cpp:451
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:305
FTransform GetActorGlobalTransform() const
Definition: CarlaActor.cpp:198
bool IsDormant() const
Definition: CarlaActor.h:70
virtual ECarlaServerResponse SetActorSimulatePhysics(bool bEnabled)
Definition: CarlaActor.cpp:559
virtual ECarlaServerResponse GetVehicleLightState(FVehicleLightState &)
Definition: CarlaActor.h:251
void SetParent(IdType InParentId)
Definition: CarlaActor.h:115
virtual ECarlaServerResponse GetVehicleControl(FVehicleControl &)
Definition: CarlaActor.h:298
IdType GetActorId() const
Definition: CarlaActor.h:80
EVehicleDoor
Type of door to open/close.
virtual ECarlaServerResponse ApplyAckermannControlToVehicle(const FVehicleAckermannControl &, const EVehicleInputPriority &)
Definition: CarlaActor.h:292
ECarlaServerResponse AddActorForce(const FVector &Force)
Definition: CarlaActor.cpp:475
IdType ParentId
Definition: CarlaActor.h:446
virtual ECarlaServerResponse ApplyPhysicsControl(const FVehiclePhysicsControl &)
Definition: CarlaActor.h:266
FVector GetActorLocalLocation() const
Definition: CarlaActor.cpp:220
TSharedPtr< FActorData > ActorData
Definition: CarlaActor.h:458
virtual ECarlaServerResponse GetWheelSteerAngle(const EVehicleWheelLocation &, float &)
Definition: CarlaActor.h:281
Maps a controller from OpenDrive.
virtual ECarlaServerResponse GetAckermannControllerSettings(FAckermannControllerSettings &)
Definition: CarlaActor.h:308
static TSharedPtr< FCarlaActor > ConstructCarlaActor(IdType ActorId, AActor *Actor, TSharedPtr< const FActorInfo > Info, ActorType Type, carla::rpc::ActorState InState, UWorld *World)
Definition: CarlaActor.cpp:120
void SetActorGlobalTransform(const FTransform &Transform, ETeleportType Teleport=ETeleportType::TeleportPhysics)
Definition: CarlaActor.cpp:332
ECarlaServerResponse AddActorAngularImpulse(const FVector &AngularInpulse)
Definition: CarlaActor.cpp:519
geom::Transform Transform
Definition: rpc/Transform.h:16
virtual ECarlaServerResponse ShowVehicleDebugTelemetry(bool)
Definition: CarlaActor.h:323
virtual ECarlaServerResponse SetWalkerState(const FTransform &Transform, carla::rpc::WalkerControl WalkerControl)
Definition: CarlaActor.h:379
FVector GetActorGlobalLocation() const
Definition: CarlaActor.cpp:239
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:452
AActor * TheActor
Definition: CarlaActor.h:440
virtual ECarlaServerResponse GetFailureState(carla::rpc::VehicleFailureState &)
Definition: CarlaActor.h:246
IdType GetParent() const
Definition: CarlaActor.h:120