CARLA
client/detail/Client.cpp
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 
8 
9 #include "carla/Exception.h"
10 #include "carla/Version.h"
15 #include "carla/rpc/Client.h"
16 #include "carla/rpc/DebugShape.h"
17 #include "carla/rpc/Response.h"
23 #include "carla/streaming/Client.h"
24 
25 #include <rpc/rpc_error.h>
26 
27 #include <thread>
28 
29 namespace carla {
30 namespace client {
31 namespace detail {
32 
33  template <typename T>
34  static T Get(carla::rpc::Response<T> &response) {
35  return response.Get();
36  }
37 
39  return true;
40  }
41 
42  // ===========================================================================
43  // -- Client::Pimpl ----------------------------------------------------------
44  // ===========================================================================
45 
46  class Client::Pimpl {
47  public:
48 
49  Pimpl(const std::string &host, uint16_t port, size_t worker_threads)
50  : endpoint(host + ":" + std::to_string(port)),
51  rpc_client(host, port),
52  streaming_client(host) {
53  rpc_client.set_timeout(5000u);
55  worker_threads > 0u ? worker_threads : std::thread::hardware_concurrency());
56  }
57 
58  template <typename ... Args>
59  auto RawCall(const std::string &function, Args && ... args) {
60  try {
61  return rpc_client.call(function, std::forward<Args>(args) ...);
62  } catch (const ::rpc::timeout &) {
64  }
65  }
66 
67  template <typename T, typename ... Args>
68  auto CallAndWait(const std::string &function, Args && ... args) {
69  auto object = RawCall(function, std::forward<Args>(args) ...);
70  using R = typename carla::rpc::Response<T>;
71  auto response = object.template as<R>();
72  if (response.HasError()) {
73  throw_exception(std::runtime_error(response.GetError().What()));
74  }
75  return Get(response);
76  }
77 
78  template <typename ... Args>
79  void AsyncCall(const std::string &function, Args && ... args) {
80  // Discard returned future.
81  rpc_client.async_call(function, std::forward<Args>(args) ...);
82  }
83 
85  auto timeout = rpc_client.get_timeout();
86  DEBUG_ASSERT(timeout.has_value());
87  return time_duration::milliseconds(static_cast<size_t>(*timeout));
88  }
89 
90  const std::string endpoint;
91 
93 
95  };
96 
97  // ===========================================================================
98  // -- Client -----------------------------------------------------------------
99  // ===========================================================================
100 
102  const std::string &host,
103  const uint16_t port,
104  const size_t worker_threads)
105  : _pimpl(std::make_unique<Pimpl>(host, port, worker_threads)) {}
106 
107  bool Client::IsTrafficManagerRunning(uint16_t port) const {
108  return _pimpl->CallAndWait<bool>("is_traffic_manager_running", port);
109  }
110 
111  std::pair<std::string, uint16_t> Client::GetTrafficManagerRunning(uint16_t port) const {
112  return _pimpl->CallAndWait<std::pair<std::string, uint16_t>>("get_traffic_manager_running", port);
113  };
114 
115  bool Client::AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const {
116  return _pimpl->CallAndWait<bool>("add_traffic_manager_running", trafficManagerInfo);
117  };
118 
119  void Client::DestroyTrafficManager(uint16_t port) const {
120  _pimpl->AsyncCall("destroy_traffic_manager", port);
121  }
122 
123  Client::~Client() = default;
124 
126  _pimpl->rpc_client.set_timeout(static_cast<int64_t>(timeout.milliseconds()));
127  }
128 
130  return _pimpl->GetTimeout();
131  }
132 
133  const std::string Client::GetEndpoint() const {
134  return _pimpl->endpoint;
135  }
136 
137  std::string Client::GetClientVersion() {
138  return ::carla::version();
139  }
140 
141  std::string Client::GetServerVersion() {
142  return _pimpl->CallAndWait<std::string>("version");
143  }
144 
145  void Client::LoadEpisode(std::string map_name, bool reset_settings, rpc::MapLayer map_layer) {
146  // Await response, we need to be sure in this one.
147  _pimpl->CallAndWait<void>("load_new_episode", std::move(map_name), reset_settings, map_layer);
148  }
149 
150  void Client::LoadLevelLayer(rpc::MapLayer map_layer) const {
151  // Await response, we need to be sure in this one.
152  _pimpl->CallAndWait<void>("load_map_layer", map_layer);
153  }
154 
155  void Client::UnloadLevelLayer(rpc::MapLayer map_layer) const {
156  // Await response, we need to be sure in this one.
157  _pimpl->CallAndWait<void>("unload_map_layer", map_layer);
158  }
159 
160  void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) {
161  // Await response, we need to be sure in this one.
162  _pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params);
163  }
164 
166  const std::vector<std::string> &objects_name,
167  const rpc::MaterialParameter& parameter,
168  const rpc::TextureColor& Texture) {
169  _pimpl->CallAndWait<void>("apply_color_texture_to_objects", objects_name, parameter, Texture);
170  }
171 
173  const std::vector<std::string> &objects_name,
174  const rpc::MaterialParameter& parameter,
175  const rpc::TextureFloatColor& Texture) {
176  _pimpl->CallAndWait<void>("apply_float_color_texture_to_objects", objects_name, parameter, Texture);
177  }
178 
179  std::vector<std::string> Client::GetNamesOfAllObjects() const {
180  return _pimpl->CallAndWait<std::vector<std::string>>("get_names_of_all_objects");
181  }
182 
184  return _pimpl->CallAndWait<rpc::EpisodeInfo>("get_episode_info");
185  }
186 
188  return _pimpl->CallAndWait<rpc::MapInfo>("get_map_info");
189  }
190 
191  std::string Client::GetMapData() const{
192  return _pimpl->CallAndWait<std::string>("get_map_data");
193  }
194 
195  std::vector<uint8_t> Client::GetNavigationMesh() const {
196  return _pimpl->CallAndWait<std::vector<uint8_t>>("get_navigation_mesh");
197  }
198 
199  bool Client::SetFilesBaseFolder(const std::string &path) {
201  }
202 
203  std::vector<std::string> Client::GetRequiredFiles(const std::string &folder, const bool download) const {
204  // Get the list of required files
205  auto requiredFiles = _pimpl->CallAndWait<std::vector<std::string>>("get_required_files", folder);
206 
207  if (download) {
208 
209  // For each required file, check if it exists and request it otherwise
210  for (auto requiredFile : requiredFiles) {
211  if (!FileTransfer::FileExists(requiredFile)) {
212  RequestFile(requiredFile);
213  log_info("Could not find the required file in cache, downloading... ", requiredFile);
214  } else {
215  log_info("Found the required file in cache! ", requiredFile);
216  }
217  }
218  }
219  return requiredFiles;
220  }
221 
222  void Client::RequestFile(const std::string &name) const {
223  // Download the binary content of the file from the server and write it on the client
224  auto content = _pimpl->CallAndWait<std::vector<uint8_t>>("request_file", name);
225  FileTransfer::WriteFile(name, content);
226  }
227 
228  std::vector<uint8_t> Client::GetCacheFile(const std::string &name, const bool request_otherwise) const {
229  // Get the file from the cache in the file transfer
230  std::vector<uint8_t> file = FileTransfer::ReadFile(name);
231 
232  // If it isn't in the cache, download it if request otherwise is true
233  if (file.empty() && request_otherwise) {
234  RequestFile(name);
235  file = FileTransfer::ReadFile(name);
236  }
237  return file;
238  }
239 
240  std::vector<std::string> Client::GetAvailableMaps() {
241  return _pimpl->CallAndWait<std::vector<std::string>>("get_available_maps");
242  }
243 
244  std::vector<rpc::ActorDefinition> Client::GetActorDefinitions() {
245  return _pimpl->CallAndWait<std::vector<rpc::ActorDefinition>>("get_actor_definitions");
246  }
247 
249  return _pimpl->CallAndWait<carla::rpc::Actor>("get_spectator");
250  }
251 
253  return _pimpl->CallAndWait<rpc::EpisodeSettings>("get_episode_settings");
254  }
255 
257  return _pimpl->CallAndWait<uint64_t>("set_episode_settings", settings);
258  }
259 
261  return _pimpl->CallAndWait<rpc::WeatherParameters>("get_weather_parameters");
262  }
263 
265  _pimpl->AsyncCall("set_weather_parameters", weather);
266  }
267 
268  std::vector<rpc::Actor> Client::GetActorsById(
269  const std::vector<ActorId> &ids) {
270  using return_t = std::vector<rpc::Actor>;
271  return _pimpl->CallAndWait<return_t>("get_actors_by_id", ids);
272  }
273 
275  rpc::ActorId vehicle) const {
276  return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", vehicle);
277  }
278 
280  rpc::ActorId vehicle) const {
281  return _pimpl->CallAndWait<carla::rpc::VehicleLightState>("get_vehicle_light_state", vehicle);
282  }
283 
285  rpc::ActorId vehicle,
286  const rpc::VehiclePhysicsControl &physics_control) {
287  return _pimpl->AsyncCall("apply_physics_control", vehicle, physics_control);
288  }
289 
291  rpc::ActorId vehicle,
292  const rpc::VehicleLightState &light_state) {
293  return _pimpl->AsyncCall("set_vehicle_light_state", vehicle, light_state);
294  }
295 
297  rpc::ActorId vehicle,
298  const rpc::VehicleDoor door_idx) {
299  return _pimpl->AsyncCall("open_vehicle_door", vehicle, door_idx);
300  }
301 
303  rpc::ActorId vehicle,
304  const rpc::VehicleDoor door_idx) {
305  return _pimpl->AsyncCall("close_vehicle_door", vehicle, door_idx);
306  }
307 
309  rpc::ActorId vehicle,
310  rpc::VehicleWheelLocation vehicle_wheel,
311  float angle_in_deg) {
312  return _pimpl->AsyncCall("set_wheel_steer_direction", vehicle, vehicle_wheel, angle_in_deg);
313  }
314 
316  rpc::ActorId vehicle,
317  rpc::VehicleWheelLocation wheel_location){
318  return _pimpl->CallAndWait<float>("get_wheel_steer_angle", vehicle, wheel_location);
319  }
320 
322  const rpc::ActorDescription &description,
323  const geom::Transform &transform) {
324  return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
325  }
326 
328  const rpc::ActorDescription &description,
329  const geom::Transform &transform,
330  rpc::ActorId parent,
331  rpc::AttachmentType attachment_type) {
332 
333  if(attachment_type == rpc::AttachmentType::SpringArm) {
334  const auto a = transform.location.MakeSafeUnitVector(std::numeric_limits<float>::epsilon());
335  const auto z = geom::Vector3D(0.0f, 0.f, 1.0f);
336  constexpr float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
337  if (geom::Math::Dot(a, z) > OneEps) {
338  std::cout << "WARNING: Transformations with translation only in the 'z' axis are ill-formed when \
339  using SprintArm attachment. Please, be careful with that." << std::endl;
340  }
341  }
342 
343  return _pimpl->CallAndWait<rpc::Actor>("spawn_actor_with_parent",
344  description,
345  transform,
346  parent,
347  attachment_type);
348  }
349 
351  try {
352  return _pimpl->CallAndWait<bool>("destroy_actor", actor);
353  } catch (const std::exception &e) {
354  log_error("failed to destroy actor", actor, ':', e.what());
355  return false;
356  }
357  }
358 
359  void Client::SetActorLocation(rpc::ActorId actor, const geom::Location &location) {
360  _pimpl->AsyncCall("set_actor_location", actor, location);
361  }
362 
364  _pimpl->AsyncCall("set_actor_transform", actor, transform);
365  }
366 
368  _pimpl->AsyncCall("set_actor_target_velocity", actor, vector);
369  }
370 
372  _pimpl->AsyncCall("set_actor_target_angular_velocity", actor, vector);
373  }
374 
376  _pimpl->AsyncCall("enable_actor_constant_velocity", actor, vector);
377  }
378 
380  _pimpl->AsyncCall("disable_actor_constant_velocity", actor);
381  }
382 
384  _pimpl->AsyncCall("add_actor_impulse", actor, impulse);
385  }
386 
387  void Client::AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
388  _pimpl->AsyncCall("add_actor_impulse_at_location", actor, impulse, location);
389  }
390 
392  _pimpl->AsyncCall("add_actor_force", actor, force);
393  }
394 
395  void Client::AddActorForce(rpc::ActorId actor, const geom::Vector3D &force, const geom::Vector3D &location) {
396  _pimpl->AsyncCall("add_actor_force_at_location", actor, force, location);
397  }
398 
400  _pimpl->AsyncCall("add_actor_angular_impulse", actor, vector);
401  }
402 
404  _pimpl->AsyncCall("add_actor_torque", actor, vector);
405  }
406 
407  void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
408  _pimpl->AsyncCall("set_actor_simulate_physics", actor, enabled);
409  }
410 
411  void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
412  _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
413  }
414 
415  void Client::SetActorAutopilot(rpc::ActorId vehicle, const bool enabled) {
416  _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
417  }
418 
419  void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
420  _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
421  }
422 
424  _pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
425  }
426 
427  void Client::EnableCarSim(rpc::ActorId vehicle, std::string simfile_path) {
428  _pimpl->AsyncCall("enable_carsim", vehicle, simfile_path);
429  }
430 
431  void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
432  _pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
433  }
434 
436  rpc::ActorId vehicle,
437  uint64_t MaxSubsteps,
438  float MaxSubstepDeltaTime,
439  std::string VehicleJSON,
440  std::string PowertrainJSON,
441  std::string TireJSON,
442  std::string BaseJSONPath) {
443  _pimpl->AsyncCall("enable_chrono_physics",
444  vehicle,
445  MaxSubsteps,
446  MaxSubstepDeltaTime,
447  VehicleJSON,
448  PowertrainJSON,
449  TireJSON,
450  BaseJSONPath);
451  }
452 
454  _pimpl->AsyncCall("apply_control_to_walker", walker, control);
455  }
456 
458  auto res = _pimpl->CallAndWait<rpc::WalkerBoneControlOut>("get_bones_transform", walker);
459  return res;
460  }
461 
463  _pimpl->AsyncCall("set_bones_transform", walker, bones);
464  }
465 
466  void Client::BlendPose(rpc::ActorId walker, float blend) {
467  _pimpl->AsyncCall("blend_pose", walker, blend);
468  }
469 
471  _pimpl->AsyncCall("get_pose_from_animation", walker);
472  }
473 
475  rpc::ActorId traffic_light,
476  const rpc::TrafficLightState traffic_light_state) {
477  _pimpl->AsyncCall("set_traffic_light_state", traffic_light, traffic_light_state);
478  }
479 
480  void Client::SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time) {
481  _pimpl->AsyncCall("set_traffic_light_green_time", traffic_light, green_time);
482  }
483 
484  void Client::SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time) {
485  _pimpl->AsyncCall("set_traffic_light_yellow_time", traffic_light, yellow_time);
486  }
487 
488  void Client::SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time) {
489  _pimpl->AsyncCall("set_traffic_light_red_time", traffic_light, red_time);
490  }
491 
492  void Client::FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze) {
493  _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
494  }
495 
497  _pimpl->AsyncCall("reset_traffic_light_group", traffic_light);
498  }
499 
501  _pimpl->CallAndWait<void>("reset_all_traffic_lights");
502  }
503 
504  void Client::FreezeAllTrafficLights(bool frozen) {
505  _pimpl->AsyncCall("freeze_all_traffic_lights", frozen);
506  }
507 
508  std::vector<geom::BoundingBox> Client::GetLightBoxes(rpc::ActorId traffic_light) const {
509  using return_t = std::vector<geom::BoundingBox>;
510  return _pimpl->CallAndWait<return_t>("get_light_boxes", traffic_light);
511  }
512 
514  return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
515  }
516 
517  std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
518  using return_t = std::vector<ActorId>;
519  return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);
520  }
521 
522  std::string Client::StartRecorder(std::string name, bool additional_data) {
523  return _pimpl->CallAndWait<std::string>("start_recorder", name, additional_data);
524  }
525 
527  return _pimpl->AsyncCall("stop_recorder");
528  }
529 
530  std::string Client::ShowRecorderFileInfo(std::string name, bool show_all) {
531  return _pimpl->CallAndWait<std::string>("show_recorder_file_info", name, show_all);
532  }
533 
534  std::string Client::ShowRecorderCollisions(std::string name, char type1, char type2) {
535  return _pimpl->CallAndWait<std::string>("show_recorder_collisions", name, type1, type2);
536  }
537 
538  std::string Client::ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
539  return _pimpl->CallAndWait<std::string>("show_recorder_actors_blocked", name, min_time, min_distance);
540  }
541 
542  std::string Client::ReplayFile(std::string name, double start, double duration,
543  uint32_t follow_id, bool replay_sensors) {
544  return _pimpl->CallAndWait<std::string>("replay_file", name, start, duration,
545  follow_id, replay_sensors);
546  }
547 
548  void Client::StopReplayer(bool keep_actors) {
549  _pimpl->AsyncCall("stop_replayer", keep_actors);
550  }
551 
552  void Client::SetReplayerTimeFactor(double time_factor) {
553  _pimpl->AsyncCall("set_replayer_time_factor", time_factor);
554  }
555 
556  void Client::SetReplayerIgnoreHero(bool ignore_hero) {
557  _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
558  }
559 
561  const streaming::Token &token,
562  std::function<void(Buffer)> callback) {
563  _pimpl->streaming_client.Subscribe(token, std::move(callback));
564  }
565 
567  _pimpl->streaming_client.UnSubscribe(token);
568  }
569 
571  _pimpl->AsyncCall("draw_debug_shape", shape);
572  }
573 
574  void Client::ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
575  _pimpl->AsyncCall("apply_batch", std::move(commands), do_tick_cue);
576  }
577 
578  std::vector<rpc::CommandResponse> Client::ApplyBatchSync(
579  std::vector<rpc::Command> commands,
580  bool do_tick_cue) {
581  auto result = _pimpl->RawCall("apply_batch", std::move(commands), do_tick_cue);
582  return result.as<std::vector<rpc::CommandResponse>>();
583  }
584 
585  uint64_t Client::SendTickCue() {
586  return _pimpl->CallAndWait<uint64_t>("tick_cue");
587  }
588 
589  std::vector<rpc::LightState> Client::QueryLightsStateToServer() const {
590  using return_t = std::vector<rpc::LightState>;
591  return _pimpl->CallAndWait<return_t>("query_lights_state", _pimpl->endpoint);
592  }
593 
594  void Client::UpdateServerLightsState(std::vector<rpc::LightState>& lights, bool discard_client) const {
595  _pimpl->AsyncCall("update_lights_state", _pimpl->endpoint, std::move(lights), discard_client);
596  }
597 
598  std::vector<geom::BoundingBox> Client::GetLevelBBs(uint8_t queried_tag) const {
599  using return_t = std::vector<geom::BoundingBox>;
600  return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
601  }
602 
603  std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects(uint8_t queried_tag) const {
604  using return_t = std::vector<rpc::EnvironmentObject>;
605  return _pimpl->CallAndWait<return_t>("get_environment_objects", queried_tag);
606  }
607 
609  std::vector<uint64_t> env_objects_ids,
610  bool enable) const {
611  _pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
612  }
613 
614  std::pair<bool,rpc::LabelledPoint> Client::ProjectPoint(
615  geom::Location location, geom::Vector3D direction, float search_distance) const {
616  using return_t = std::pair<bool,rpc::LabelledPoint>;
617  return _pimpl->CallAndWait<return_t>("project_point", location, direction, search_distance);
618  }
619 
620  std::vector<rpc::LabelledPoint> Client::CastRay(
621  geom::Location start_location, geom::Location end_location) const {
622  using return_t = std::vector<rpc::LabelledPoint>;
623  return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
624  }
625 
626 } // namespace detail
627 } // namespace client
628 } // namespace carla
Seting for map generation from opendrive without additional geometry.
static time_duration milliseconds(size_t timeout)
Definition: Time.h:26
void SetLightStateToVehicle(rpc::ActorId vehicle, const rpc::VehicleLightState &light_state)
bool SetFilesBaseFolder(const std::string &path)
void AddActorTorque(rpc::ActorId actor, const geom::Vector3D &vector)
std::vector< uint8_t > GetNavigationMesh() const
void SetActorTargetVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void SetActorLocation(rpc::ActorId actor, const geom::Location &location)
bool AddTrafficManagerRunning(std::pair< std::string, uint16_t > trafficManagerInfo) const
Informs the server that a Traffic Manager is running on <IP, port>
void set_timeout(int64_t value)
Definition: rpc/Client.h:23
void ApplyPhysicsControlToVehicle(rpc::ActorId vehicle, const rpc::VehiclePhysicsControl &physics_control)
void SetBonesTransform(rpc::ActorId walker, const rpc::WalkerBoneControlIn &bones)
std::string ShowRecorderFileInfo(std::string name, bool show_all)
void EnableCarSim(rpc::ActorId vehicle, std::string simfile_path)
std::vector< rpc::ActorDefinition > GetActorDefinitions()
void ShowVehicleDebugTelemetry(rpc::ActorId vehicle, bool enabled)
void CloseVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void SetTrafficLightState(rpc::ActorId traffic_light, const rpc::TrafficLightState trafficLightState)
void SetActorTransform(rpc::ActorId actor, const geom::Transform &transform)
void GetPoseFromAnimation(rpc::ActorId walker)
std::string ReplayFile(std::string name, double start, double duration, uint32_t follow_id, bool replay_sensors)
void throw_exception(const std::exception &e)
Definition: Carla.cpp:135
std::vector< std::string > GetNamesOfAllObjects() const
std::vector< ActorId > GetGroupTrafficLights(rpc::ActorId traffic_light)
void CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters &params)
void SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time)
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise=true) const
void OpenVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void EnableActorConstantVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void async_call(const std::string &function, Args &&... args)
Definition: rpc/Client.h:37
static void log_error(Args &&... args)
Definition: Logging.h:110
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
rpc::EpisodeSettings GetEpisodeSettings()
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
void DrawDebugShape(const rpc::DebugShape &shape)
auto call(const std::string &function, Args &&... args)
Definition: rpc/Client.h:32
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
void RequestFile(const std::string &name) const
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
void AddActorAngularImpulse(rpc::ActorId actor, const geom::Vector3D &vector)
void FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze)
void SubscribeToStream(const streaming::Token &token, std::function< void(Buffer)> callback)
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
void SetReplayerIgnoreHero(bool ignore_hero)
void ResetTrafficLightGroup(rpc::ActorId traffic_light)
bool IsTrafficManagerRunning(uint16_t port) const
Querry to know if a Traffic Manager is running on port.
void AsyncCall(const std::string &function, Args &&... args)
void ApplyControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleControl &control)
static T Get(carla::rpc::Response< T > &response)
void LoadLevelLayer(rpc::MapLayer map_layer) const
static std::vector< uint8_t > ReadFile(std::string path)
geom::Vector3D Vector3D
Definition: rpc/Vector3D.h:14
const std::unique_ptr< Pimpl > _pimpl
static bool WriteFile(std::string path, std::vector< uint8_t > content)
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
std::vector< rpc::LabelledPoint > CastRay(geom::Location start_location, geom::Location end_location) const
void SetReplayerTimeFactor(double time_factor)
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
void SetActorAutopilot(rpc::ActorId vehicle, bool enabled)
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(rpc::ActorId vehicle) const
auto CallAndWait(const std::string &function, Args &&... args)
std::string StartRecorder(std::string name, bool additional_data)
value_type & Get()
Definition: Response.h:74
rpc::WeatherParameters GetWeatherParameters()
void AsyncRun(size_t worker_threads)
void BlendPose(rpc::ActorId walker, float blend)
void LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layer=rpc::MapLayer::All)
std::pair< std::string, uint16_t > GetTrafficManagerRunning(uint16_t port) const
Gets a pair filled with the <IP, port> of the Trafic Manager running on port.
void EnableChronoPhysics(rpc::ActorId vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON, std::string PowertrainJSON, std::string TireJSON, std::string BaseJSONPath)
void ApplyBatch(std::vector< rpc::Command > commands, bool do_tick_cue)
std::vector< geom::BoundingBox > GetLevelBBs(uint8_t queried_tag) const
Returns all the BBs of all the elements of the level.
float GetWheelSteerAngle(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location)
void DestroyTrafficManager(uint16_t port) const
void AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse)
A token that uniquely identify a stream.
Definition: Token.h:17
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &ids)
std::vector< rpc::CommandResponse > ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue)
void SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time)
rpc::VehicleLightState GetVehicleLightState(rpc::ActorId vehicle) const
constexpr size_t milliseconds() const noexcept
Definition: Time.h:58
Pimpl(const std::string &host, uint16_t port, size_t worker_threads)
void UpdateServerLightsState(std::vector< rpc::LightState > &lights, bool discard_client=false) const
auto get_timeout() const
Definition: rpc/Client.h:27
void SetTimeout(time_duration timeout)
uint32_t ActorId
Definition: ActorId.h:14
void SetActorTargetAngularVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
auto RawCall(const std::string &function, Args &&... args)
static void log_info(Args &&... args)
Definition: Logging.h:82
rpc::Actor SpawnActorWithParent(const rpc::ActorDescription &description, const geom::Transform &transform, rpc::ActorId parent, rpc::AttachmentType attachment_type)
A client able to subscribe to multiple streams.
void UnloadLevelLayer(rpc::MapLayer map_layer) const
void SetActorSimulatePhysics(rpc::ActorId actor, bool enabled)
std::vector< rpc::LightState > QueryLightsStateToServer() const
void UseCarSimRoad(rpc::ActorId vehicle, bool enabled)
rpc::Actor SpawnActor(const rpc::ActorDescription &description, const geom::Transform &transform)
bool DestroyActor(rpc::ActorId actor)
void SetWeatherParameters(const rpc::WeatherParameters &weather)
static auto Dot(const Vector3D &a, const Vector3D &b)
Definition: Math.h:62
Client(const std::string &host, uint16_t port, size_t worker_threads=0u)
rpc::WalkerBoneControlOut GetBonesTransform(rpc::ActorId walker)
Positive time duration up to milliseconds resolution.
Definition: Time.h:19
std::vector< geom::BoundingBox > GetLightBoxes(rpc::ActorId traffic_light) const
void SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time)
void UnSubscribeFromStream(const streaming::Token &token)
std::string ShowRecorderCollisions(std::string name, char type1, char type2)
std::vector< rpc::EnvironmentObject > GetEnvironmentObjects(uint8_t queried_tag) const
void SetActorEnableGravity(rpc::ActorId actor, bool enabled)
std::pair< bool, rpc::LabelledPoint > ProjectPoint(geom::Location location, geom::Vector3D direction, float search_distance) const
void AddActorForce(rpc::ActorId actor, const geom::Vector3D &force)
void SetWheelSteerDirection(rpc::ActorId vehicle, rpc::VehicleWheelLocation vehicle_wheel, float angle_in_deg)
Vector3D MakeSafeUnitVector(const float epsilon) const
Definition: geom/Vector3D.h:64
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
void ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control)
const std::string GetEndpoint() const
static bool FileExists(std::string file)
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
static bool SetFilesBaseFolder(const std::string &path)
void DisableActorConstantVelocity(rpc::ActorId actor)
std::vector< std::string > GetAvailableMaps()
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)