CARLA
client/Actor.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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 
9 #include "carla/Debug.h"
10 #include "carla/Memory.h"
13 
14 namespace carla {
15 namespace client {
16 
17  /// Represents an actor in the simulation.
18  class Actor
19  : public EnableSharedFromThis<Actor>,
21  public detail::ActorState {
23  public:
24 
25  explicit Actor(ActorInitializer init)
27  Super(std::move(init)) {}
28 
29  using ActorState::GetBoundingBox;
30 
31  virtual ~Actor() = default;
32 
33  /// Return the current location of the actor.
34  ///
35  /// @note This function does not call the simulator, it returns the location
36  /// received in the last tick.
38 
39  /// Return the current transform of the actor.
40  ///
41  /// @note This function does not call the simulator, it returns the
42  /// transform received in the last tick.
44 
45  /// Return the current 3D velocity of the actor.
46  ///
47  /// @note This function does not call the simulator, it returns the
48  /// velocity received in the last tick.
50 
51  /// Return the current 3D angular velocity of the actor.
52  ///
53  /// @note This function does not call the simulator, it returns the
54  /// angular velocity received in the last tick.
56 
57  /// Return the current 3D acceleration of the actor.
58  ///
59  /// @note This function does not call the simulator, it returns the
60  /// acceleration calculated after the actor's velocity.
62 
63  /// Teleport the actor to @a location.
64  void SetLocation(const geom::Location &location);
65 
66  /// Teleport and rotate the actor to @a transform.
67  void SetTransform(const geom::Transform &transform);
68 
69  /// Set the actor velocity before applying physics.
70  void SetTargetVelocity(const geom::Vector3D &vector);
71 
72  /// Set the angular velocity of the actor before applying physics.
73  void SetTargetAngularVelocity(const geom::Vector3D &vector);
74 
75  /// Enable a constant velocity mode
76  void EnableConstantVelocity(const geom::Vector3D &vector);
77 
78  /// Disable the constant velocity mode
80 
81  /// Add impulse to the actor at its center of mass.
82  void AddImpulse(const geom::Vector3D &vector);
83 
84  /// Add impulse to the actor at certain location.
85  void AddImpulse(const geom::Vector3D &impulse, const geom::Vector3D &location);
86 
87  /// Add force to the actor at its center of mass.
88  void AddForce(const geom::Vector3D &force);
89 
90  /// Add force to the actor at certain location.
91  void AddForce(const geom::Vector3D &force, const geom::Vector3D &location);
92 
93  /// Add angular impulse to the actor.
94  void AddAngularImpulse(const geom::Vector3D &vector);
95 
96  /// Add a torque to the actor.
97  void AddTorque(const geom::Vector3D &vector);
98 
99  /// Enable or disable physics simulation on this actor.
100  void SetSimulatePhysics(bool enabled = true);
101 
102  /// Enable or disable gravity on this actor.
103  void SetEnableGravity(bool enabled = true);
104 
105  /// @warning This method only checks whether this instance of Actor has
106  /// called the Destroy() method, it does not check whether the actor is
107  /// actually alive in the simulator.
108  bool IsAlive() const {
109  return _is_alive && GetEpisode().IsValid();
110  }
111 
112  /// Tell the simulator to destroy this Actor, and return whether the actor
113  /// was successfully destroyed.
114  ///
115  /// @note It has no effect if the Actor was already successfully destroyed.
116  ///
117  /// @warning This function blocks until the destruction operation is
118  /// completed by the simulator.
119  virtual bool Destroy();
120 
121  const auto &Serialize() const {
122  return Super::GetActorDescription();
123  }
124 
125  private:
126 
127  bool _is_alive = true;
128  };
129 
130 } // namespace client
131 } // namespace carla
void SetSimulatePhysics(bool enabled=true)
Enable or disable physics simulation on this actor.
Definition: Actor.cpp:83
geom::Vector3D GetAcceleration() const
Return the current 3D acceleration of the actor.
Definition: Actor.cpp:31
const auto & Serialize() const
Definition: client/Actor.h:121
void AddForce(const geom::Vector3D &force)
Add force to the actor at its center of mass.
Definition: Actor.cpp:67
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
void SetTransform(const geom::Transform &transform)
Teleport and rotate the actor to transform.
Definition: Actor.cpp:39
void AddAngularImpulse(const geom::Vector3D &vector)
Add angular impulse to the actor.
Definition: Actor.cpp:75
const std::string & GetDisplayId() const
Definition: ActorState.h:33
void AddImpulse(const geom::Vector3D &vector)
Add impulse to the actor at its center of mass.
Definition: Actor.cpp:59
virtual ~Actor()=default
Used to initialize Actor classes.
Definition: ActorState.h:93
#define LIBCARLA_INITIALIZE_LIFETIME_PROFILER(display_name)
virtual bool Destroy()
Tell the simulator to destroy this Actor, and return whether the actor was successfully destroyed...
Definition: Actor.cpp:91
geom::Vector3D GetAngularVelocity() const
Return the current 3D angular velocity of the actor.
Definition: Actor.cpp:27
geom::Transform GetTransform() const
Return the current transform of the actor.
Definition: Actor.cpp:19
void SetTargetAngularVelocity(const geom::Vector3D &vector)
Set the angular velocity of the actor before applying physics.
Definition: Actor.cpp:47
geom::Location GetLocation() const
Return the current location of the actor.
Definition: Actor.cpp:15
void SetLocation(const geom::Location &location)
Teleport the actor to location.
Definition: Actor.cpp:35
void SetTargetVelocity(const geom::Vector3D &vector)
Set the actor velocity before applying physics.
Definition: Actor.cpp:43
Represents an actor in the simulation.
Definition: client/Actor.h:18
geom::Vector3D GetVelocity() const
Return the current 3D velocity of the actor.
Definition: Actor.cpp:23
void EnableConstantVelocity(const geom::Vector3D &vector)
Enable a constant velocity mode.
Definition: Actor.cpp:51
Actor(ActorInitializer init)
Definition: client/Actor.h:25
void SetEnableGravity(bool enabled=true)
Enable or disable gravity on this actor.
Definition: Actor.cpp:87
bool IsAlive() const
Definition: client/Actor.h:108
void AddTorque(const geom::Vector3D &vector)
Add a torque to the actor.
Definition: Actor.cpp:79
Internal state of an Actor.
Definition: ActorState.h:22
void DisableConstantVelocity()
Disable the constant velocity mode.
Definition: Actor.cpp:55