CARLA
client/detail/Client.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/Memory.h"
10 #include "carla/NonCopyable.h"
11 #include "carla/Time.h"
12 #include "carla/geom/Transform.h"
13 #include "carla/geom/Location.h"
14 #include "carla/rpc/Actor.h"
17 #include "carla/rpc/Command.h"
20 #include "carla/rpc/EpisodeInfo.h"
23 #include "carla/rpc/LightState.h"
24 #include "carla/rpc/MapInfo.h"
25 #include "carla/rpc/MapLayer.h"
28 #include "carla/rpc/VehicleDoor.h"
34 #include "carla/rpc/Texture.h"
36 
37 #include <functional>
38 #include <memory>
39 #include <string>
40 #include <vector>
41 
42 // Forward declarations.
43 namespace carla {
44  class Buffer;
45 namespace rpc {
46  class AckermannControllerSettings;
47  class ActorDescription;
48  class DebugShape;
49  class VehicleAckermannControl;
50  class VehicleControl;
51  class WalkerControl;
52  class WalkerBoneControlIn;
53  class WalkerBoneControlOut;
54 }
55 namespace sensor {
56  class SensorData;
57 }
58 namespace streaming {
59  class Token;
60 }
61 }
62 
63 namespace carla {
64 namespace client {
65 namespace detail {
66 
67  /// Provides communication with the rpc and streaming servers of a CARLA
68  /// simulator.
69  class Client : private NonCopyable {
70  public:
71 
72  explicit Client(
73  const std::string &host,
74  uint16_t port,
75  size_t worker_threads = 0u);
76 
77  ~Client();
78 
79  /// Querry to know if a Traffic Manager is running on port
80  bool IsTrafficManagerRunning(uint16_t port) const;
81 
82  /// Gets a pair filled with the <IP, port> of the Trafic Manager running on port.
83  /// If there is no Traffic Manager running the pair will be ("", 0)
84  std::pair<std::string, uint16_t> GetTrafficManagerRunning(uint16_t port) const;
85 
86  /// Informs the server that a Traffic Manager is running on <IP, port>
87  bool AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const;
88 
89  void DestroyTrafficManager(uint16_t port) const;
90 
91  void SetTimeout(time_duration timeout);
92 
93  time_duration GetTimeout() const;
94 
95  const std::string GetEndpoint() const;
96 
97  std::string GetClientVersion();
98 
99  std::string GetServerVersion();
100 
101  void LoadEpisode(std::string map_name, bool reset_settings = true, rpc::MapLayer map_layer = rpc::MapLayer::All);
102 
103  void LoadLevelLayer(rpc::MapLayer map_layer) const;
104 
105  void UnloadLevelLayer(rpc::MapLayer map_layer) const;
106 
107  void CopyOpenDriveToServer(
108  std::string opendrive, const rpc::OpendriveGenerationParameters & params);
109 
110  void ApplyColorTextureToObjects(
111  const std::vector<std::string> &objects_name,
112  const rpc::MaterialParameter& parameter,
113  const rpc::TextureColor& Texture);
114 
115  void ApplyColorTextureToObjects(
116  const std::vector<std::string> &objects_name,
117  const rpc::MaterialParameter& parameter,
118  const rpc::TextureFloatColor& Texture);
119 
120  std::vector<std::string> GetNamesOfAllObjects() const;
121 
122  rpc::EpisodeInfo GetEpisodeInfo();
123 
124  rpc::MapInfo GetMapInfo();
125 
126  std::vector<uint8_t> GetNavigationMesh() const;
127 
128  bool SetFilesBaseFolder(const std::string &path);
129 
130  std::vector<std::string> GetRequiredFiles(const std::string &folder = "", const bool download = true) const;
131 
132  std::string GetMapData() const;
133 
134  void RequestFile(const std::string &name) const;
135 
136  std::vector<uint8_t> GetCacheFile(const std::string &name, const bool request_otherwise = true) const;
137 
138  std::vector<std::string> GetAvailableMaps();
139 
140  std::vector<rpc::ActorDefinition> GetActorDefinitions();
141 
142  rpc::Actor GetSpectator();
143 
144  rpc::EpisodeSettings GetEpisodeSettings();
145 
146  uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings);
147 
148  rpc::WeatherParameters GetWeatherParameters();
149 
150  void SetWeatherParameters(const rpc::WeatherParameters &weather);
151 
152  std::vector<rpc::Actor> GetActorsById(const std::vector<ActorId> &ids);
153 
154  rpc::VehiclePhysicsControl GetVehiclePhysicsControl(rpc::ActorId vehicle) const;
155 
156  rpc::VehicleLightState GetVehicleLightState(rpc::ActorId vehicle) const;
157 
158  void ApplyPhysicsControlToVehicle(
159  rpc::ActorId vehicle,
160  const rpc::VehiclePhysicsControl &physics_control);
161 
162  void SetLightStateToVehicle(
163  rpc::ActorId vehicle,
164  const rpc::VehicleLightState &light_state);
165 
166  void OpenVehicleDoor(
167  rpc::ActorId vehicle,
168  const rpc::VehicleDoor door_idx);
169 
170  void CloseVehicleDoor(
171  rpc::ActorId vehicle,
172  const rpc::VehicleDoor door_idx);
173 
174  rpc::Actor SpawnActor(
175  const rpc::ActorDescription &description,
176  const geom::Transform &transform);
177 
178  rpc::Actor SpawnActorWithParent(
179  const rpc::ActorDescription &description,
180  const geom::Transform &transform,
181  rpc::ActorId parent,
182  rpc::AttachmentType attachment_type);
183 
184  bool DestroyActor(rpc::ActorId actor);
185 
186  void SetActorLocation(
187  rpc::ActorId actor,
188  const geom::Location &location);
189 
190  void SetActorTransform(
191  rpc::ActorId actor,
192  const geom::Transform &transform);
193 
194  void SetActorTargetVelocity(
195  rpc::ActorId actor,
196  const geom::Vector3D &vector);
197 
198  void SetActorTargetAngularVelocity(
199  rpc::ActorId actor,
200  const geom::Vector3D &vector);
201 
202  void EnableActorConstantVelocity(
203  rpc::ActorId actor,
204  const geom::Vector3D &vector);
205 
206  void DisableActorConstantVelocity(
207  rpc::ActorId actor);
208 
209  void AddActorImpulse(
210  rpc::ActorId actor,
211  const geom::Vector3D &impulse);
212 
213  void AddActorImpulse(
214  rpc::ActorId actor,
215  const geom::Vector3D &impulse,
216  const geom::Vector3D &location);
217 
218  void AddActorForce(
219  rpc::ActorId actor,
220  const geom::Vector3D &force);
221 
222  void AddActorForce(
223  rpc::ActorId actor,
224  const geom::Vector3D &force,
225  const geom::Vector3D &location);
226 
227  void AddActorAngularImpulse(
228  rpc::ActorId actor,
229  const geom::Vector3D &vector);
230 
231  void AddActorTorque(
232  rpc::ActorId actor,
233  const geom::Vector3D &vector);
234 
235  void SetActorSimulatePhysics(
236  rpc::ActorId actor,
237  bool enabled);
238 
239  void SetActorEnableGravity(
240  rpc::ActorId actor,
241  bool enabled);
242 
243  void SetActorAutopilot(
244  rpc::ActorId vehicle,
245  bool enabled);
246 
247  void ShowVehicleDebugTelemetry(
248  rpc::ActorId vehicle,
249  bool enabled);
250 
251  void ApplyControlToVehicle(
252  rpc::ActorId vehicle,
253  const rpc::VehicleControl &control);
254 
255  void ApplyAckermannControlToVehicle(
256  rpc::ActorId vehicle,
257  const rpc::VehicleAckermannControl &control);
258 
259  rpc::AckermannControllerSettings GetAckermannControllerSettings(rpc::ActorId vehicle) const;
260 
261  void ApplyAckermannControllerSettings(
262  rpc::ActorId vehicle,
263  const rpc::AckermannControllerSettings &settings);
264 
265  void EnableCarSim(
266  rpc::ActorId vehicle,
267  std::string simfile_path);
268 
269  void UseCarSimRoad(
270  rpc::ActorId vehicle,
271  bool enabled);
272 
273  void SetWheelSteerDirection(
274  rpc::ActorId vehicle,
275  rpc::VehicleWheelLocation vehicle_wheel,
276  float angle_in_deg
277  );
278 
279  float GetWheelSteerAngle(
280  rpc::ActorId vehicle,
281  rpc::VehicleWheelLocation wheel_location
282  );
283 
284  void EnableChronoPhysics(
285  rpc::ActorId vehicle,
286  uint64_t MaxSubsteps,
287  float MaxSubstepDeltaTime,
288  std::string VehicleJSON,
289  std::string PowertrainJSON,
290  std::string TireJSON,
291  std::string BaseJSONPath);
292 
293  void ApplyControlToWalker(
294  rpc::ActorId walker,
295  const rpc::WalkerControl &control);
296 
297  rpc::WalkerBoneControlOut GetBonesTransform(
298  rpc::ActorId walker);
299 
300  void SetBonesTransform(
301  rpc::ActorId walker,
302  const rpc::WalkerBoneControlIn &bones);
303 
304  void BlendPose(
305  rpc::ActorId walker,
306  float blend);
307 
308  void GetPoseFromAnimation(
309  rpc::ActorId walker);
310 
311  void SetTrafficLightState(
312  rpc::ActorId traffic_light,
313  const rpc::TrafficLightState trafficLightState);
314 
315  void SetTrafficLightGreenTime(
316  rpc::ActorId traffic_light,
317  float green_time);
318 
319  void SetTrafficLightYellowTime(
320  rpc::ActorId traffic_light,
321  float yellow_time);
322 
323  void SetTrafficLightRedTime(
324  rpc::ActorId traffic_light,
325  float red_time);
326 
327  void FreezeTrafficLight(
328  rpc::ActorId traffic_light,
329  bool freeze);
330 
331  void ResetTrafficLightGroup(
332  rpc::ActorId traffic_light);
333 
334  void ResetAllTrafficLights();
335 
336  void FreezeAllTrafficLights(bool frozen);
337 
338  std::vector<geom::BoundingBox> GetLightBoxes(
339  rpc::ActorId traffic_light) const;
340 
341  /// Returns a list of pairs where the firts element is the vehicle ID
342  /// and the second one is the light state
343  rpc::VehicleLightStateList GetVehiclesLightStates();
344 
345  std::vector<ActorId> GetGroupTrafficLights(
346  rpc::ActorId traffic_light);
347 
348  std::string StartRecorder(std::string name, bool additional_data);
349 
350  void StopRecorder();
351 
352  std::string ShowRecorderFileInfo(std::string name, bool show_all);
353 
354  std::string ShowRecorderCollisions(std::string name, char type1, char type2);
355 
356  std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance);
357 
358  std::string ReplayFile(std::string name, double start, double duration,
359  uint32_t follow_id, bool replay_sensors);
360 
361  void SetReplayerTimeFactor(double time_factor);
362 
363  void SetReplayerIgnoreHero(bool ignore_hero);
364 
365  void StopReplayer(bool keep_actors);
366 
367  void SubscribeToStream(
368  const streaming::Token &token,
369  std::function<void(Buffer)> callback);
370 
371  void SubscribeToGBuffer(
373  uint32_t GBufferId,
374  std::function<void(Buffer)> callback);
375 
376  void UnSubscribeFromStream(const streaming::Token &token);
377 
378  void UnSubscribeFromGBuffer(
379  rpc::ActorId ActorId,
380  uint32_t GBufferId);
381 
382  void DrawDebugShape(const rpc::DebugShape &shape);
383 
384  void ApplyBatch(
385  std::vector<rpc::Command> commands,
386  bool do_tick_cue);
387 
388  std::vector<rpc::CommandResponse> ApplyBatchSync(
389  std::vector<rpc::Command> commands,
390  bool do_tick_cue);
391 
392  uint64_t SendTickCue();
393 
394  std::vector<rpc::LightState> QueryLightsStateToServer() const;
395 
396  void UpdateServerLightsState(
397  std::vector<rpc::LightState>& lights,
398  bool discard_client = false) const;
399 
400  void UpdateDayNightCycle(const bool active) const;
401 
402  /// Returns all the BBs of all the elements of the level
403  std::vector<geom::BoundingBox> GetLevelBBs(uint8_t queried_tag) const;
404 
405  std::vector<rpc::EnvironmentObject> GetEnvironmentObjects(uint8_t queried_tag) const;
406 
407  void EnableEnvironmentObjects(
408  std::vector<uint64_t> env_objects_ids,
409  bool enable) const;
410 
411  std::pair<bool,rpc::LabelledPoint> ProjectPoint(
412  geom::Location location, geom::Vector3D direction, float search_distance) const;
413 
414  std::vector<rpc::LabelledPoint> CastRay(
415  geom::Location start_location, geom::Location end_location) const;
416 
417  private:
418 
419  class Pimpl;
420  const std::unique_ptr<Pimpl> _pimpl;
421  };
422 
423 } // namespace detail
424 } // namespace client
425 } // namespace carla
Seting for map generation from opendrive without additional geometry.
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
const std::unique_ptr< Pimpl > _pimpl
Base class for all the objects containing data generated by a sensor.
Definition: SensorData.h:20
carla::ActorId ActorId
A token that uniquely identify a stream.
Definition: Token.h:17
uint32_t ActorId
Definition: ActorId.h:14
Provides communication with the rpc and streaming servers of a CARLA simulator.
Positive time duration up to milliseconds resolution.
Definition: Time.h:19
Inherit (privately) to suppress copy/move construction and assignment.
Defines the physical appearance of a vehicle whitch is obtained by the sensors.