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"
20 
21 #ifdef _MSC_VER
22 #pragma warning(push)
23 #pragma warning(disable:4583)
24 #pragma warning(disable:4582)
25 #include <boost/variant2/variant.hpp>
26 #pragma warning(pop)
27 #else
28 #include <boost/variant2/variant.hpp>
29 #endif
30 
31 namespace carla {
32 
33 namespace traffic_manager {
34  class TrafficManager;
35 }
36 
37 namespace ctm = carla::traffic_manager;
38 
39 namespace rpc {
40 
41  class Command {
42  private:
43 
44  template <typename T>
45  struct CommandBase {
46  operator Command() const {
47  return Command{*static_cast<const T *>(this)};
48  }
49  };
50 
51  public:
52 
53  struct SpawnActor : CommandBase<SpawnActor> {
54  SpawnActor() = default;
55  SpawnActor(ActorDescription description, const geom::Transform &transform)
56  : description(std::move(description)),
57  transform(transform) {}
58  SpawnActor(ActorDescription description, const geom::Transform &transform, ActorId parent)
59  : description(std::move(description)),
60  transform(transform),
61  parent(parent) {}
64  boost::optional<ActorId> parent;
65  std::vector<Command> do_after;
66  MSGPACK_DEFINE_ARRAY(description, transform, parent, do_after);
67  };
68 
69  struct DestroyActor : CommandBase<DestroyActor> {
70  DestroyActor() = default;
72  : actor(id) {}
74  MSGPACK_DEFINE_ARRAY(actor);
75  };
76 
77  struct ApplyVehicleControl : CommandBase<ApplyVehicleControl> {
78  ApplyVehicleControl() = default;
80  : actor(id),
81  control(value) {}
84  MSGPACK_DEFINE_ARRAY(actor, control);
85  };
86 
87  struct ApplyVehicleAckermannControl : CommandBase<ApplyVehicleAckermannControl> {
88  ApplyVehicleAckermannControl() = default;
90  : actor(id),
91  control(value) {}
94  MSGPACK_DEFINE_ARRAY(actor, control);
95  };
96 
97  struct ApplyWalkerControl : CommandBase<ApplyWalkerControl> {
98  ApplyWalkerControl() = default;
100  : actor(id),
101  control(value) {}
104  MSGPACK_DEFINE_ARRAY(actor, control);
105  };
106 
107  struct ApplyVehiclePhysicsControl : CommandBase<ApplyVehiclePhysicsControl> {
108  ApplyVehiclePhysicsControl() = default;
110  : actor(id),
111  physics_control(value) {}
114  MSGPACK_DEFINE_ARRAY(actor, physics_control);
115  };
116 
117  struct ApplyTransform : CommandBase<ApplyTransform> {
118  ApplyTransform() = default;
120  : actor(id),
121  transform(value) {}
124  MSGPACK_DEFINE_ARRAY(actor, transform);
125  };
126 
127  struct ApplyLocation : CommandBase<ApplyLocation> {
128  ApplyLocation() = default;
130  : actor(id),
131  location(value) {}
134  MSGPACK_DEFINE_ARRAY(actor, location);
135  };
136 
137  struct ApplyWalkerState : CommandBase<ApplyWalkerState> {
138  ApplyWalkerState() = default;
139  ApplyWalkerState(ActorId id, const geom::Transform &value, const float speed) : actor(id), transform(value), speed(speed) {}
142  float speed;
143  MSGPACK_DEFINE_ARRAY(actor, transform, speed);
144  };
145 
146  struct ApplyTargetVelocity : CommandBase<ApplyTargetVelocity> {
147  ApplyTargetVelocity() = default;
149  : actor(id),
150  velocity(value) {}
153  MSGPACK_DEFINE_ARRAY(actor, velocity);
154  };
155 
156  struct ApplyTargetAngularVelocity : CommandBase<ApplyTargetAngularVelocity> {
157  ApplyTargetAngularVelocity() = default;
159  : actor(id),
160  angular_velocity(value) {}
163  MSGPACK_DEFINE_ARRAY(actor, angular_velocity);
164  };
165 
166  struct ApplyImpulse : CommandBase<ApplyImpulse> {
167  ApplyImpulse() = default;
169  : actor(id),
170  impulse(value) {}
173  MSGPACK_DEFINE_ARRAY(actor, impulse);
174  };
175 
176  struct ApplyForce : CommandBase<ApplyForce> {
177  ApplyForce() = default;
179  : actor(id),
180  force(value) {}
183  MSGPACK_DEFINE_ARRAY(actor, force);
184  };
185 
186  struct ApplyAngularImpulse : CommandBase<ApplyAngularImpulse> {
187  ApplyAngularImpulse() = default;
189  : actor(id),
190  impulse(value) {}
193  MSGPACK_DEFINE_ARRAY(actor, impulse);
194  };
195 
196  struct ApplyTorque : CommandBase<ApplyTorque> {
197  ApplyTorque() = default;
199  : actor(id),
200  torque(value) {}
203  MSGPACK_DEFINE_ARRAY(actor, torque);
204  };
205 
206  struct SetSimulatePhysics : CommandBase<SetSimulatePhysics> {
207  SetSimulatePhysics() = default;
208  SetSimulatePhysics(ActorId id, bool value)
209  : actor(id),
210  enabled(value) {}
212  bool enabled;
213  MSGPACK_DEFINE_ARRAY(actor, enabled);
214  };
215 
216  struct SetEnableGravity : CommandBase<SetEnableGravity> {
217  SetEnableGravity() = default;
218  SetEnableGravity(ActorId id, bool value)
219  : actor(id),
220  enabled(value) {}
222  bool enabled;
223  MSGPACK_DEFINE_ARRAY(actor, enabled);
224  };
225 
226  struct SetAutopilot : CommandBase<SetAutopilot> {
227  SetAutopilot() = default;
229  ActorId id,
230  bool value,
231  uint16_t tm_port)
232  : actor(id),
233  enabled(value),
234  tm_port(tm_port) {}
236  bool enabled;
237  uint16_t tm_port;
238  MSGPACK_DEFINE_ARRAY(actor, enabled);
239  };
240 
241  struct ShowDebugTelemetry : CommandBase<ShowDebugTelemetry> {
242  ShowDebugTelemetry() = default;
244  ActorId id,
245  bool value)
246  : actor(id),
247  enabled(value) {}
249  bool enabled;
250  MSGPACK_DEFINE_ARRAY(actor, enabled);
251  };
252 
253  struct SetVehicleLightState : CommandBase<SetVehicleLightState> {
254  SetVehicleLightState() = default;
256  ActorId id,
258  : actor(id),
259  light_state(value) {}
262  MSGPACK_DEFINE_ARRAY(actor, light_state);
263  };
264 
265  struct ConsoleCommand : CommandBase<ConsoleCommand> {
266  ConsoleCommand() = default;
267  ConsoleCommand(std::string cmd) : cmd(cmd) {}
268  std::string cmd;
269  MSGPACK_DEFINE_ARRAY(cmd);
270  };
271 
272  struct SetTrafficLightState : CommandBase<SetTrafficLightState> {
273  SetTrafficLightState() = default;
275  ActorId id,
277  : actor(id),
278  traffic_light_state(state) {}
281  MSGPACK_DEFINE_ARRAY(actor, traffic_light_state);
282  };
283 
284  using CommandType = boost::variant2::variant<
285  SpawnActor,
286  DestroyActor,
295  ApplyImpulse,
296  ApplyForce,
298  ApplyTorque,
301  SetAutopilot,
307 
309 
310  MSGPACK_DEFINE_ARRAY(command);
311  };
312 
313 } // namespace rpc
314 } // namespace carla
VehicleLightState::flag_type light_state
Definition: Command.h:261
SetSimulatePhysics(ActorId id, bool value)
Definition: Command.h:208
ShowDebugTelemetry(ActorId id, bool value)
Definition: Command.h:243
ApplyWalkerControl(ActorId id, const WalkerControl &value)
Definition: Command.h:99
SetEnableGravity(ActorId id, bool value)
Definition: Command.h:218
SetAutopilot(ActorId id, bool value, uint16_t tm_port)
Definition: Command.h:228
ApplyWalkerState(ActorId id, const geom::Transform &value, const float speed)
Definition: Command.h:139
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
ActorDescription description
Definition: Command.h:62
ApplyVehicleControl(ActorId id, const VehicleControl &value)
Definition: Command.h:79
SetTrafficLightState(ActorId id, rpc::TrafficLightState state)
Definition: Command.h:274
SpawnActor(ActorDescription description, const geom::Transform &transform, ActorId parent)
Definition: Command.h:58
SpawnActor(ActorDescription description, const geom::Transform &transform)
Definition: Command.h:55
ApplyImpulse(ActorId id, const geom::Vector3D &value)
Definition: Command.h:168
CommandType command
Definition: Command.h:308
ApplyTargetVelocity(ActorId id, const geom::Vector3D &value)
Definition: Command.h:148
geom::Transform transform
Definition: Command.h:63
ApplyTransform(ActorId id, const geom::Transform &value)
Definition: Command.h:119
uint32_t ActorId
Definition: ActorId.h:14
std::vector< Command > do_after
Definition: Command.h:65
boost::variant2::variant< SpawnActor, DestroyActor, ApplyVehicleControl, ApplyVehicleAckermannControl, ApplyWalkerControl, ApplyVehiclePhysicsControl, ApplyTransform, ApplyWalkerState, ApplyTargetVelocity, ApplyTargetAngularVelocity, ApplyImpulse, ApplyForce, ApplyAngularImpulse, ApplyTorque, SetSimulatePhysics, SetEnableGravity, SetAutopilot, ShowDebugTelemetry, SetVehicleLightState, ApplyLocation, ConsoleCommand, SetTrafficLightState > CommandType
Definition: Command.h:306
SetVehicleLightState(ActorId id, VehicleLightState::flag_type value)
Definition: Command.h:255
ApplyTorque(ActorId id, const geom::Vector3D &value)
Definition: Command.h:198
ConsoleCommand(std::string cmd)
Definition: Command.h:267
ApplyForce(ActorId id, const geom::Vector3D &value)
Definition: Command.h:178
boost::optional< ActorId > parent
Definition: Command.h:64
ApplyVehiclePhysicsControl(ActorId id, const VehiclePhysicsControl &value)
Definition: Command.h:109
ApplyAngularImpulse(ActorId id, const geom::Vector3D &value)
Definition: Command.h:188
ApplyLocation(ActorId id, const geom::Location &value)
Definition: Command.h:129
ApplyTargetAngularVelocity(ActorId id, const geom::Vector3D &value)
Definition: Command.h:158
rpc::TrafficLightState traffic_light_state
Definition: Command.h:280
ApplyVehicleAckermannControl(ActorId id, const VehicleAckermannControl &value)
Definition: Command.h:89