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