CARLA
Command.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/MsgPack.h"
10 #include "carla/MsgPackAdaptors.h"
11 #include "carla/geom/Transform.h"
13 #include "carla/rpc/ActorId.h"
18 
19 #include <boost/variant.hpp>
20 
21 namespace carla {
22 
23 namespace traffic_manager {
24  class TrafficManager;
25 }
26 
27 namespace ctm = carla::traffic_manager;
28 
29 namespace rpc {
30 
31  class Command {
32  private:
33 
34  template <typename T>
35  struct CommandBase {
36  operator Command() const {
37  return Command{*static_cast<const T *>(this)};
38  }
39  };
40 
41  public:
42 
43  struct SpawnActor : CommandBase<SpawnActor> {
44  SpawnActor() = default;
45  SpawnActor(ActorDescription description, const geom::Transform &transform)
46  : description(std::move(description)),
47  transform(transform) {}
48  SpawnActor(ActorDescription description, const geom::Transform &transform, ActorId parent)
49  : description(std::move(description)),
50  transform(transform),
51  parent(parent) {}
54  boost::optional<ActorId> parent;
55  std::vector<Command> do_after;
56  MSGPACK_DEFINE_ARRAY(description, transform, parent, do_after);
57  };
58 
59  struct DestroyActor : CommandBase<DestroyActor> {
60  DestroyActor() = default;
62  : actor(id) {}
64  MSGPACK_DEFINE_ARRAY(actor);
65  };
66 
67  struct ApplyVehicleControl : CommandBase<ApplyVehicleControl> {
68  ApplyVehicleControl() = default;
70  : actor(id),
71  control(value) {}
74  MSGPACK_DEFINE_ARRAY(actor, control);
75  };
76 
77  struct ApplyWalkerControl : CommandBase<ApplyWalkerControl> {
78  ApplyWalkerControl() = default;
80  : actor(id),
81  control(value) {}
84  MSGPACK_DEFINE_ARRAY(actor, control);
85  };
86 
87  struct ApplyVehiclePhysicsControl : CommandBase<ApplyVehiclePhysicsControl> {
88  ApplyVehiclePhysicsControl() = default;
90  : actor(id),
91  physics_control(value) {}
94  MSGPACK_DEFINE_ARRAY(actor, physics_control);
95  };
96 
97  struct ApplyTransform : CommandBase<ApplyTransform> {
98  ApplyTransform() = default;
100  : actor(id),
101  transform(value) {}
104  MSGPACK_DEFINE_ARRAY(actor, transform);
105  };
106 
107  struct ApplyWalkerState : CommandBase<ApplyWalkerState> {
108  ApplyWalkerState() = default;
109  ApplyWalkerState(ActorId id, const geom::Transform &value, const float speed) : actor(id), transform(value), speed(speed) {}
112  float speed;
113  MSGPACK_DEFINE_ARRAY(actor, transform, speed);
114  };
115 
116  struct ApplyTargetVelocity : CommandBase<ApplyTargetVelocity> {
117  ApplyTargetVelocity() = default;
119  : actor(id),
120  velocity(value) {}
123  MSGPACK_DEFINE_ARRAY(actor, velocity);
124  };
125 
126  struct ApplyTargetAngularVelocity : CommandBase<ApplyTargetAngularVelocity> {
127  ApplyTargetAngularVelocity() = default;
129  : actor(id),
130  angular_velocity(value) {}
133  MSGPACK_DEFINE_ARRAY(actor, angular_velocity);
134  };
135 
136  struct ApplyImpulse : CommandBase<ApplyImpulse> {
137  ApplyImpulse() = default;
139  : actor(id),
140  impulse(value) {}
143  MSGPACK_DEFINE_ARRAY(actor, impulse);
144  };
145 
146  struct ApplyForce : CommandBase<ApplyForce> {
147  ApplyForce() = default;
149  : actor(id),
150  force(value) {}
153  MSGPACK_DEFINE_ARRAY(actor, force);
154  };
155 
156  struct ApplyAngularImpulse : CommandBase<ApplyAngularImpulse> {
157  ApplyAngularImpulse() = default;
159  : actor(id),
160  impulse(value) {}
163  MSGPACK_DEFINE_ARRAY(actor, impulse);
164  };
165 
166  struct ApplyTorque : CommandBase<ApplyTorque> {
167  ApplyTorque() = default;
169  : actor(id),
170  torque(value) {}
173  MSGPACK_DEFINE_ARRAY(actor, torque);
174  };
175 
176  struct SetSimulatePhysics : CommandBase<SetSimulatePhysics> {
177  SetSimulatePhysics() = default;
178  SetSimulatePhysics(ActorId id, bool value)
179  : actor(id),
180  enabled(value) {}
182  bool enabled;
183  MSGPACK_DEFINE_ARRAY(actor, enabled);
184  };
185 
186  struct SetEnableGravity : CommandBase<SetEnableGravity> {
187  SetEnableGravity() = default;
188  SetEnableGravity(ActorId id, bool value)
189  : actor(id),
190  enabled(value) {}
192  bool enabled;
193  MSGPACK_DEFINE_ARRAY(actor, enabled);
194  };
195 
196  struct SetAutopilot : CommandBase<SetAutopilot> {
197  SetAutopilot() = default;
199  ActorId id,
200  bool value,
201  uint16_t tm_port)
202  : actor(id),
203  enabled(value),
204  tm_port(tm_port) {}
206  bool enabled;
207  uint16_t tm_port;
208  MSGPACK_DEFINE_ARRAY(actor, enabled);
209  };
210 
211  struct ShowDebugTelemetry : CommandBase<ShowDebugTelemetry> {
212  ShowDebugTelemetry() = default;
214  ActorId id,
215  bool value)
216  : actor(id),
217  enabled(value) {}
219  bool enabled;
220  MSGPACK_DEFINE_ARRAY(actor, enabled);
221  };
222 
223  struct SetVehicleLightState : CommandBase<SetVehicleLightState> {
224  SetVehicleLightState() = default;
226  ActorId id,
228  : actor(id),
229  light_state(value) {}
232  MSGPACK_DEFINE_ARRAY(actor, light_state);
233  };
234 
235  using CommandType = boost::variant<
236  SpawnActor,
237  DestroyActor,
245  ApplyImpulse,
246  ApplyForce,
248  ApplyTorque,
251  SetAutopilot,
254 
256 
257  MSGPACK_DEFINE_ARRAY(command);
258  };
259 
260 } // namespace rpc
261 } // namespace carla
VehicleLightState::flag_type light_state
Definition: Command.h:231
SetSimulatePhysics(ActorId id, bool value)
Definition: Command.h:178
ShowDebugTelemetry(ActorId id, bool value)
Definition: Command.h:213
ApplyWalkerControl(ActorId id, const WalkerControl &value)
Definition: Command.h:79
SetEnableGravity(ActorId id, bool value)
Definition: Command.h:188
SetAutopilot(ActorId id, bool value, uint16_t tm_port)
Definition: Command.h:198
ApplyWalkerState(ActorId id, const geom::Transform &value, const float speed)
Definition: Command.h:109
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
ActorDescription description
Definition: Command.h:52
ApplyVehicleControl(ActorId id, const VehicleControl &value)
Definition: Command.h:69
SpawnActor(ActorDescription description, const geom::Transform &transform, ActorId parent)
Definition: Command.h:48
boost::variant< SpawnActor, DestroyActor, ApplyVehicleControl, ApplyWalkerControl, ApplyVehiclePhysicsControl, ApplyTransform, ApplyWalkerState, ApplyTargetVelocity, ApplyTargetAngularVelocity, ApplyImpulse, ApplyForce, ApplyAngularImpulse, ApplyTorque, SetSimulatePhysics, SetEnableGravity, SetAutopilot, ShowDebugTelemetry, SetVehicleLightState > CommandType
Definition: Command.h:253
SpawnActor(ActorDescription description, const geom::Transform &transform)
Definition: Command.h:45
ApplyImpulse(ActorId id, const geom::Vector3D &value)
Definition: Command.h:138
CommandType command
Definition: Command.h:255
ApplyTargetVelocity(ActorId id, const geom::Vector3D &value)
Definition: Command.h:118
geom::Transform transform
Definition: Command.h:53
ApplyTransform(ActorId id, const geom::Transform &value)
Definition: Command.h:99
uint32_t ActorId
Definition: ActorId.h:14
std::vector< Command > do_after
Definition: Command.h:55
SetVehicleLightState(ActorId id, VehicleLightState::flag_type value)
Definition: Command.h:225
ApplyTorque(ActorId id, const geom::Vector3D &value)
Definition: Command.h:168
ApplyForce(ActorId id, const geom::Vector3D &value)
Definition: Command.h:148
boost::optional< ActorId > parent
Definition: Command.h:54
ApplyVehiclePhysicsControl(ActorId id, const VehiclePhysicsControl &value)
Definition: Command.h:89
ApplyAngularImpulse(ActorId id, const geom::Vector3D &value)
Definition: Command.h:158
ApplyTargetAngularVelocity(ActorId id, const geom::Vector3D &value)
Definition: Command.h:128