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"
16 #include "carla/rpc/Client.h"
17 #include "carla/rpc/DebugShape.h"
18 #include "carla/rpc/Response.h"
25 #include "carla/streaming/Client.h"
26 
27 #include <rpc/rpc_error.h>
28 
29 #include <thread>
30 
31 namespace carla {
32 namespace client {
33 namespace detail {
34 
35  template <typename T>
36  static T Get(carla::rpc::Response<T> &response) {
37  return response.Get();
38  }
39 
41  return true;
42  }
43 
44  // ===========================================================================
45  // -- Client::Pimpl ----------------------------------------------------------
46  // ===========================================================================
47 
48  class Client::Pimpl {
49  public:
50 
51  Pimpl(const std::string &host, uint16_t port, size_t worker_threads)
52  : endpoint(host + ":" + std::to_string(port)),
53  rpc_client(host, port),
54  streaming_client(host) {
55  rpc_client.set_timeout(5000u);
57  worker_threads > 0u ? worker_threads : std::thread::hardware_concurrency());
58  }
59 
60  template <typename ... Args>
61  auto RawCall(const std::string &function, Args && ... args) {
62  try {
63  return rpc_client.call(function, std::forward<Args>(args) ...);
64  } catch (const ::rpc::timeout &) {
66  }
67  }
68 
69  template <typename T, typename ... Args>
70  auto CallAndWait(const std::string &function, Args && ... args) {
71  auto object = RawCall(function, std::forward<Args>(args) ...);
72  using R = typename carla::rpc::Response<T>;
73  auto response = object.template as<R>();
74  if (response.HasError()) {
75  throw_exception(std::runtime_error(response.GetError().What()));
76  }
77  return Get(response);
78  }
79 
80  template <typename ... Args>
81  void AsyncCall(const std::string &function, Args && ... args) {
82  // Discard returned future.
83  rpc_client.async_call(function, std::forward<Args>(args) ...);
84  }
85 
87  auto timeout = rpc_client.get_timeout();
88  DEBUG_ASSERT(timeout.has_value());
89  return time_duration::milliseconds(static_cast<size_t>(*timeout));
90  }
91 
92  const std::string endpoint;
93 
95 
97  };
98 
99  // ===========================================================================
100  // -- Client -----------------------------------------------------------------
101  // ===========================================================================
102 
104  const std::string &host,
105  const uint16_t port,
106  const size_t worker_threads)
107  : _pimpl(std::make_unique<Pimpl>(host, port, worker_threads)) {}
108 
109  bool Client::IsTrafficManagerRunning(uint16_t port) const {
110  return _pimpl->CallAndWait<bool>("is_traffic_manager_running", port);
111  }
112 
113  std::pair<std::string, uint16_t> Client::GetTrafficManagerRunning(uint16_t port) const {
114  return _pimpl->CallAndWait<std::pair<std::string, uint16_t>>("get_traffic_manager_running", port);
115  };
116 
117  bool Client::AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const {
118  return _pimpl->CallAndWait<bool>("add_traffic_manager_running", trafficManagerInfo);
119  };
120 
121  void Client::DestroyTrafficManager(uint16_t port) const {
122  _pimpl->AsyncCall("destroy_traffic_manager", port);
123  }
124 
125  Client::~Client() = default;
126 
128  _pimpl->rpc_client.set_timeout(static_cast<int64_t>(timeout.milliseconds()));
129  }
130 
132  return _pimpl->GetTimeout();
133  }
134 
135  const std::string Client::GetEndpoint() const {
136  return _pimpl->endpoint;
137  }
138 
139  std::string Client::GetClientVersion() {
140  return ::carla::version();
141  }
142 
143  std::string Client::GetServerVersion() {
144  return _pimpl->CallAndWait<std::string>("version");
145  }
146 
147  void Client::LoadEpisode(std::string map_name, bool reset_settings, rpc::MapLayer map_layer) {
148  // Await response, we need to be sure in this one.
149  _pimpl->CallAndWait<void>("load_new_episode", std::move(map_name), reset_settings, map_layer);
150  }
151 
152  void Client::LoadLevelLayer(rpc::MapLayer map_layer) const {
153  // Await response, we need to be sure in this one.
154  _pimpl->CallAndWait<void>("load_map_layer", map_layer);
155  }
156 
157  void Client::UnloadLevelLayer(rpc::MapLayer map_layer) const {
158  // Await response, we need to be sure in this one.
159  _pimpl->CallAndWait<void>("unload_map_layer", map_layer);
160  }
161 
162  void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) {
163  // Await response, we need to be sure in this one.
164  _pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params);
165  }
166 
168  const std::vector<std::string> &objects_name,
169  const rpc::MaterialParameter& parameter,
170  const rpc::TextureColor& Texture) {
171  _pimpl->CallAndWait<void>("apply_color_texture_to_objects", objects_name, parameter, Texture);
172  }
173 
175  const std::vector<std::string> &objects_name,
176  const rpc::MaterialParameter& parameter,
177  const rpc::TextureFloatColor& Texture) {
178  _pimpl->CallAndWait<void>("apply_float_color_texture_to_objects", objects_name, parameter, Texture);
179  }
180 
181  std::vector<std::string> Client::GetNamesOfAllObjects() const {
182  return _pimpl->CallAndWait<std::vector<std::string>>("get_names_of_all_objects");
183  }
184 
186  return _pimpl->CallAndWait<rpc::EpisodeInfo>("get_episode_info");
187  }
188 
190  return _pimpl->CallAndWait<rpc::MapInfo>("get_map_info");
191  }
192 
193  std::string Client::GetMapData() const{
194  return _pimpl->CallAndWait<std::string>("get_map_data");
195  }
196 
197  std::vector<uint8_t> Client::GetNavigationMesh() const {
198  return _pimpl->CallAndWait<std::vector<uint8_t>>("get_navigation_mesh");
199  }
200 
201  bool Client::SetFilesBaseFolder(const std::string &path) {
203  }
204 
205  std::vector<std::string> Client::GetRequiredFiles(const std::string &folder, const bool download) const {
206  // Get the list of required files
207  auto requiredFiles = _pimpl->CallAndWait<std::vector<std::string>>("get_required_files", folder);
208 
209  if (download) {
210 
211  // For each required file, check if it exists and request it otherwise
212  for (auto requiredFile : requiredFiles) {
213  if (!FileTransfer::FileExists(requiredFile)) {
214  RequestFile(requiredFile);
215  log_info("Could not find the required file in cache, downloading... ", requiredFile);
216  } else {
217  log_info("Found the required file in cache! ", requiredFile);
218  }
219  }
220  }
221  return requiredFiles;
222  }
223 
224  void Client::RequestFile(const std::string &name) const {
225  // Download the binary content of the file from the server and write it on the client
226  auto content = _pimpl->CallAndWait<std::vector<uint8_t>>("request_file", name);
227  FileTransfer::WriteFile(name, content);
228  }
229 
230  std::vector<uint8_t> Client::GetCacheFile(const std::string &name, const bool request_otherwise) const {
231  // Get the file from the cache in the file transfer
232  std::vector<uint8_t> file = FileTransfer::ReadFile(name);
233 
234  // If it isn't in the cache, download it if request otherwise is true
235  if (file.empty() && request_otherwise) {
236  RequestFile(name);
237  file = FileTransfer::ReadFile(name);
238  }
239  return file;
240  }
241 
242  std::vector<std::string> Client::GetAvailableMaps() {
243  return _pimpl->CallAndWait<std::vector<std::string>>("get_available_maps");
244  }
245 
246  std::vector<rpc::ActorDefinition> Client::GetActorDefinitions() {
247  return _pimpl->CallAndWait<std::vector<rpc::ActorDefinition>>("get_actor_definitions");
248  }
249 
251  return _pimpl->CallAndWait<carla::rpc::Actor>("get_spectator");
252  }
253 
255  return _pimpl->CallAndWait<rpc::EpisodeSettings>("get_episode_settings");
256  }
257 
259  return _pimpl->CallAndWait<uint64_t>("set_episode_settings", settings);
260  }
261 
263  return _pimpl->CallAndWait<rpc::WeatherParameters>("get_weather_parameters");
264  }
265 
267  _pimpl->AsyncCall("set_weather_parameters", weather);
268  }
269 
270  std::vector<rpc::Actor> Client::GetActorsById(
271  const std::vector<ActorId> &ids) {
272  using return_t = std::vector<rpc::Actor>;
273  return _pimpl->CallAndWait<return_t>("get_actors_by_id", ids);
274  }
275 
277  rpc::ActorId vehicle) const {
278  return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", vehicle);
279  }
280 
282  rpc::ActorId vehicle) const {
283  return _pimpl->CallAndWait<carla::rpc::VehicleLightState>("get_vehicle_light_state", vehicle);
284  }
285 
287  rpc::ActorId vehicle,
288  const rpc::VehiclePhysicsControl &physics_control) {
289  return _pimpl->AsyncCall("apply_physics_control", vehicle, physics_control);
290  }
291 
293  rpc::ActorId vehicle,
294  const rpc::VehicleLightState &light_state) {
295  return _pimpl->AsyncCall("set_vehicle_light_state", vehicle, light_state);
296  }
297 
299  rpc::ActorId vehicle,
300  const rpc::VehicleDoor door_idx) {
301  return _pimpl->AsyncCall("open_vehicle_door", vehicle, door_idx);
302  }
303 
305  rpc::ActorId vehicle,
306  const rpc::VehicleDoor door_idx) {
307  return _pimpl->AsyncCall("close_vehicle_door", vehicle, door_idx);
308  }
309 
311  rpc::ActorId vehicle,
312  rpc::VehicleWheelLocation vehicle_wheel,
313  float angle_in_deg) {
314  return _pimpl->AsyncCall("set_wheel_steer_direction", vehicle, vehicle_wheel, angle_in_deg);
315  }
316 
318  rpc::ActorId vehicle,
319  rpc::VehicleWheelLocation wheel_location){
320  return _pimpl->CallAndWait<float>("get_wheel_steer_angle", vehicle, wheel_location);
321  }
322 
324  const rpc::ActorDescription &description,
325  const geom::Transform &transform) {
326  return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
327  }
328 
330  const rpc::ActorDescription &description,
331  const geom::Transform &transform,
332  rpc::ActorId parent,
333  rpc::AttachmentType attachment_type) {
334 
335  if (attachment_type == rpc::AttachmentType::SpringArm ||
336  attachment_type == rpc::AttachmentType::SpringArmGhost)
337  {
338  const auto a = transform.location.MakeSafeUnitVector(std::numeric_limits<float>::epsilon());
339  const auto z = geom::Vector3D(0.0f, 0.f, 1.0f);
340  constexpr float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
341  if (geom::Math::Dot(a, z) > OneEps) {
342  std::cout << "WARNING: Transformations with translation only in the 'z' axis are ill-formed when \
343  using SpringArm or SpringArmGhost attachment. Please, be careful with that." << std::endl;
344  }
345  }
346 
347  return _pimpl->CallAndWait<rpc::Actor>("spawn_actor_with_parent",
348  description,
349  transform,
350  parent,
351  attachment_type);
352  }
353 
355  try {
356  return _pimpl->CallAndWait<bool>("destroy_actor", actor);
357  } catch (const std::exception &e) {
358  log_error("failed to destroy actor", actor, ':', e.what());
359  return false;
360  }
361  }
362 
363  void Client::SetActorLocation(rpc::ActorId actor, const geom::Location &location) {
364  _pimpl->AsyncCall("set_actor_location", actor, location);
365  }
366 
368  _pimpl->AsyncCall("set_actor_transform", actor, transform);
369  }
370 
372  _pimpl->AsyncCall("set_actor_target_velocity", actor, vector);
373  }
374 
376  _pimpl->AsyncCall("set_actor_target_angular_velocity", actor, vector);
377  }
378 
380  _pimpl->AsyncCall("enable_actor_constant_velocity", actor, vector);
381  }
382 
384  _pimpl->AsyncCall("disable_actor_constant_velocity", actor);
385  }
386 
388  _pimpl->AsyncCall("add_actor_impulse", actor, impulse);
389  }
390 
391  void Client::AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
392  _pimpl->AsyncCall("add_actor_impulse_at_location", actor, impulse, location);
393  }
394 
396  _pimpl->AsyncCall("add_actor_force", actor, force);
397  }
398 
399  void Client::AddActorForce(rpc::ActorId actor, const geom::Vector3D &force, const geom::Vector3D &location) {
400  _pimpl->AsyncCall("add_actor_force_at_location", actor, force, location);
401  }
402 
404  _pimpl->AsyncCall("add_actor_angular_impulse", actor, vector);
405  }
406 
408  _pimpl->AsyncCall("add_actor_torque", actor, vector);
409  }
410 
411  void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
412  _pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
413  }
414 
415  void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
416  _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
417  }
418 
419  void Client::SetActorAutopilot(rpc::ActorId vehicle, const bool enabled) {
420  _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
421  }
422 
423  void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
424  _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
425  }
426 
428  _pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
429  }
430 
432  _pimpl->AsyncCall("apply_ackermann_control_to_vehicle", vehicle, control);
433  }
434 
436  rpc::ActorId vehicle) const {
437  return _pimpl->CallAndWait<carla::rpc::AckermannControllerSettings>("get_ackermann_controller_settings", vehicle);
438  }
439 
441  _pimpl->AsyncCall("apply_ackermann_controller_settings", vehicle, settings);
442  }
443 
444  void Client::EnableCarSim(rpc::ActorId vehicle, std::string simfile_path) {
445  _pimpl->AsyncCall("enable_carsim", vehicle, simfile_path);
446  }
447 
448  void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
449  _pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
450  }
451 
453  rpc::ActorId vehicle,
454  uint64_t MaxSubsteps,
455  float MaxSubstepDeltaTime,
456  std::string VehicleJSON,
457  std::string PowertrainJSON,
458  std::string TireJSON,
459  std::string BaseJSONPath) {
460  _pimpl->AsyncCall("enable_chrono_physics",
461  vehicle,
462  MaxSubsteps,
463  MaxSubstepDeltaTime,
464  VehicleJSON,
465  PowertrainJSON,
466  TireJSON,
467  BaseJSONPath);
468  }
469 
471  _pimpl->AsyncCall("apply_control_to_walker", walker, control);
472  }
473 
475  auto res = _pimpl->CallAndWait<rpc::WalkerBoneControlOut>("get_bones_transform", walker);
476  return res;
477  }
478 
480  _pimpl->AsyncCall("set_bones_transform", walker, bones);
481  }
482 
483  void Client::BlendPose(rpc::ActorId walker, float blend) {
484  _pimpl->AsyncCall("blend_pose", walker, blend);
485  }
486 
488  _pimpl->AsyncCall("get_pose_from_animation", walker);
489  }
490 
492  rpc::ActorId traffic_light,
493  const rpc::TrafficLightState traffic_light_state) {
494  _pimpl->AsyncCall("set_traffic_light_state", traffic_light, traffic_light_state);
495  }
496 
497  void Client::SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time) {
498  _pimpl->AsyncCall("set_traffic_light_green_time", traffic_light, green_time);
499  }
500 
501  void Client::SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time) {
502  _pimpl->AsyncCall("set_traffic_light_yellow_time", traffic_light, yellow_time);
503  }
504 
505  void Client::SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time) {
506  _pimpl->AsyncCall("set_traffic_light_red_time", traffic_light, red_time);
507  }
508 
509  void Client::FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze) {
510  _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
511  }
512 
514  _pimpl->AsyncCall("reset_traffic_light_group", traffic_light);
515  }
516 
518  _pimpl->CallAndWait<void>("reset_all_traffic_lights");
519  }
520 
521  void Client::FreezeAllTrafficLights(bool frozen) {
522  _pimpl->AsyncCall("freeze_all_traffic_lights", frozen);
523  }
524 
525  std::vector<geom::BoundingBox> Client::GetLightBoxes(rpc::ActorId traffic_light) const {
526  using return_t = std::vector<geom::BoundingBox>;
527  return _pimpl->CallAndWait<return_t>("get_light_boxes", traffic_light);
528  }
529 
531  return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
532  }
533 
534  std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
535  using return_t = std::vector<ActorId>;
536  return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);
537  }
538 
539  std::string Client::StartRecorder(std::string name, bool additional_data) {
540  return _pimpl->CallAndWait<std::string>("start_recorder", name, additional_data);
541  }
542 
544  return _pimpl->AsyncCall("stop_recorder");
545  }
546 
547  std::string Client::ShowRecorderFileInfo(std::string name, bool show_all) {
548  return _pimpl->CallAndWait<std::string>("show_recorder_file_info", name, show_all);
549  }
550 
551  std::string Client::ShowRecorderCollisions(std::string name, char type1, char type2) {
552  return _pimpl->CallAndWait<std::string>("show_recorder_collisions", name, type1, type2);
553  }
554 
555  std::string Client::ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
556  return _pimpl->CallAndWait<std::string>("show_recorder_actors_blocked", name, min_time, min_distance);
557  }
558 
559  std::string Client::ReplayFile(std::string name, double start, double duration,
560  uint32_t follow_id, bool replay_sensors) {
561  return _pimpl->CallAndWait<std::string>("replay_file", name, start, duration,
562  follow_id, replay_sensors);
563  }
564 
565  void Client::StopReplayer(bool keep_actors) {
566  _pimpl->AsyncCall("stop_replayer", keep_actors);
567  }
568 
569  void Client::SetReplayerTimeFactor(double time_factor) {
570  _pimpl->AsyncCall("set_replayer_time_factor", time_factor);
571  }
572 
573  void Client::SetReplayerIgnoreHero(bool ignore_hero) {
574  _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
575  }
576 
578  const streaming::Token &token,
579  std::function<void(Buffer)> callback) {
580  carla::streaming::detail::token_type thisToken(token);
581  streaming::Token receivedToken = _pimpl->CallAndWait<streaming::Token>("get_sensor_token", thisToken.get_stream_id());
582  _pimpl->streaming_client.Subscribe(receivedToken, std::move(callback));
583  }
584 
586  _pimpl->streaming_client.UnSubscribe(token);
587  }
588 
591  uint32_t GBufferId,
592  std::function<void(Buffer)> callback)
593  {
594  std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
595  streaming::Token token;
596  std::memcpy(&token.data[0u], token_data.data(), token_data.size());
597  _pimpl->streaming_client.Subscribe(token, std::move(callback));
598  }
599 
601  rpc::ActorId ActorId,
602  uint32_t GBufferId)
603  {
604  std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
605  streaming::Token token;
606  std::memcpy(&token.data[0u], token_data.data(), token_data.size());
607  _pimpl->streaming_client.UnSubscribe(token);
608  }
609 
611  _pimpl->AsyncCall("draw_debug_shape", shape);
612  }
613 
614  void Client::ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
615  _pimpl->AsyncCall("apply_batch", std::move(commands), do_tick_cue);
616  }
617 
618  std::vector<rpc::CommandResponse> Client::ApplyBatchSync(
619  std::vector<rpc::Command> commands,
620  bool do_tick_cue) {
621  auto result = _pimpl->RawCall("apply_batch", std::move(commands), do_tick_cue);
622  return result.as<std::vector<rpc::CommandResponse>>();
623  }
624 
625  uint64_t Client::SendTickCue() {
626  return _pimpl->CallAndWait<uint64_t>("tick_cue");
627  }
628 
629  std::vector<rpc::LightState> Client::QueryLightsStateToServer() const {
630  using return_t = std::vector<rpc::LightState>;
631  return _pimpl->CallAndWait<return_t>("query_lights_state", _pimpl->endpoint);
632  }
633 
634  void Client::UpdateServerLightsState(std::vector<rpc::LightState>& lights, bool discard_client) const {
635  _pimpl->AsyncCall("update_lights_state", _pimpl->endpoint, std::move(lights), discard_client);
636  }
637 
638  void Client::UpdateDayNightCycle(const bool active) const {
639  _pimpl->AsyncCall("update_day_night_cycle", _pimpl->endpoint, active);
640  }
641 
642  std::vector<geom::BoundingBox> Client::GetLevelBBs(uint8_t queried_tag) const {
643  using return_t = std::vector<geom::BoundingBox>;
644  return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
645  }
646 
647  std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects(uint8_t queried_tag) const {
648  using return_t = std::vector<rpc::EnvironmentObject>;
649  return _pimpl->CallAndWait<return_t>("get_environment_objects", queried_tag);
650  }
651 
653  std::vector<uint64_t> env_objects_ids,
654  bool enable) const {
655  _pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
656  }
657 
658  std::pair<bool,rpc::LabelledPoint> Client::ProjectPoint(
659  geom::Location location, geom::Vector3D direction, float search_distance) const {
660  using return_t = std::pair<bool,rpc::LabelledPoint>;
661  return _pimpl->CallAndWait<return_t>("project_point", location, direction, search_distance);
662  }
663 
664  std::vector<rpc::LabelledPoint> Client::CastRay(
665  geom::Location start_location, geom::Location end_location) const {
666  using return_t = std::vector<rpc::LabelledPoint>;
667  return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
668  }
669 
670 } // namespace detail
671 } // namespace client
672 } // namespace carla
void ApplyAckermannControllerSettings(rpc::ActorId vehicle, const rpc::AckermannControllerSettings &settings)
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)
void SubscribeToGBuffer(rpc::ActorId ActorId, uint32_t GBufferId, std::function< void(Buffer)> callback)
void ApplyAckermannControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleAckermannControl &control)
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)
rpc::ActorId ActorId
Definition: ActorId.h:18
void CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters &params)
rpc::AckermannControllerSettings GetAckermannControllerSettings(rpc::ActorId vehicle) const
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:83
rpc::WeatherParameters GetWeatherParameters()
void AsyncRun(size_t worker_threads)
Serializes a stream endpoint.
Definition: detail/Token.h:61
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
carla::ActorId ActorId
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)
void UpdateDayNightCycle(const bool active) const
A client able to subscribe to multiple streams.
const auto & get_stream_id() const
Definition: detail/Token.h:116
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)
void UnSubscribeFromGBuffer(rpc::ActorId ActorId, uint32_t GBufferId)
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)