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