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  const auto a = transform.location.MakeSafeUnitVector(std::numeric_limits<float>::epsilon());
337  const auto z = geom::Vector3D(0.0f, 0.f, 1.0f);
338  constexpr float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
339  if (geom::Math::Dot(a, z) > OneEps) {
340  std::cout << "WARNING: Transformations with translation only in the 'z' axis are ill-formed when \
341  using SprintArm attachment. Please, be careful with that." << std::endl;
342  }
343  }
344 
345  return _pimpl->CallAndWait<rpc::Actor>("spawn_actor_with_parent",
346  description,
347  transform,
348  parent,
349  attachment_type);
350  }
351 
353  try {
354  return _pimpl->CallAndWait<bool>("destroy_actor", actor);
355  } catch (const std::exception &e) {
356  log_error("failed to destroy actor", actor, ':', e.what());
357  return false;
358  }
359  }
360 
361  void Client::SetActorLocation(rpc::ActorId actor, const geom::Location &location) {
362  _pimpl->AsyncCall("set_actor_location", actor, location);
363  }
364 
366  _pimpl->AsyncCall("set_actor_transform", actor, transform);
367  }
368 
370  _pimpl->AsyncCall("set_actor_target_velocity", actor, vector);
371  }
372 
374  _pimpl->AsyncCall("set_actor_target_angular_velocity", actor, vector);
375  }
376 
378  _pimpl->AsyncCall("enable_actor_constant_velocity", actor, vector);
379  }
380 
382  _pimpl->AsyncCall("disable_actor_constant_velocity", actor);
383  }
384 
386  _pimpl->AsyncCall("add_actor_impulse", actor, impulse);
387  }
388 
389  void Client::AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
390  _pimpl->AsyncCall("add_actor_impulse_at_location", actor, impulse, location);
391  }
392 
394  _pimpl->AsyncCall("add_actor_force", actor, force);
395  }
396 
397  void Client::AddActorForce(rpc::ActorId actor, const geom::Vector3D &force, const geom::Vector3D &location) {
398  _pimpl->AsyncCall("add_actor_force_at_location", actor, force, location);
399  }
400 
402  _pimpl->AsyncCall("add_actor_angular_impulse", actor, vector);
403  }
404 
406  _pimpl->AsyncCall("add_actor_torque", actor, vector);
407  }
408 
409  void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
410  _pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
411  }
412 
413  void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
414  _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
415  }
416 
417  void Client::SetActorAutopilot(rpc::ActorId vehicle, const bool enabled) {
418  _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
419  }
420 
421  void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
422  _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
423  }
424 
426  _pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
427  }
428 
430  _pimpl->AsyncCall("apply_ackermann_control_to_vehicle", vehicle, control);
431  }
432 
434  rpc::ActorId vehicle) const {
435  return _pimpl->CallAndWait<carla::rpc::AckermannControllerSettings>("get_ackermann_controller_settings", vehicle);
436  }
437 
439  _pimpl->AsyncCall("apply_ackermann_controller_settings", vehicle, settings);
440  }
441 
442  void Client::EnableCarSim(rpc::ActorId vehicle, std::string simfile_path) {
443  _pimpl->AsyncCall("enable_carsim", vehicle, simfile_path);
444  }
445 
446  void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
447  _pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
448  }
449 
451  rpc::ActorId vehicle,
452  uint64_t MaxSubsteps,
453  float MaxSubstepDeltaTime,
454  std::string VehicleJSON,
455  std::string PowertrainJSON,
456  std::string TireJSON,
457  std::string BaseJSONPath) {
458  _pimpl->AsyncCall("enable_chrono_physics",
459  vehicle,
460  MaxSubsteps,
461  MaxSubstepDeltaTime,
462  VehicleJSON,
463  PowertrainJSON,
464  TireJSON,
465  BaseJSONPath);
466  }
467 
469  _pimpl->AsyncCall("apply_control_to_walker", walker, control);
470  }
471 
473  auto res = _pimpl->CallAndWait<rpc::WalkerBoneControlOut>("get_bones_transform", walker);
474  return res;
475  }
476 
478  _pimpl->AsyncCall("set_bones_transform", walker, bones);
479  }
480 
481  void Client::BlendPose(rpc::ActorId walker, float blend) {
482  _pimpl->AsyncCall("blend_pose", walker, blend);
483  }
484 
486  _pimpl->AsyncCall("get_pose_from_animation", walker);
487  }
488 
490  rpc::ActorId traffic_light,
491  const rpc::TrafficLightState traffic_light_state) {
492  _pimpl->AsyncCall("set_traffic_light_state", traffic_light, traffic_light_state);
493  }
494 
495  void Client::SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time) {
496  _pimpl->AsyncCall("set_traffic_light_green_time", traffic_light, green_time);
497  }
498 
499  void Client::SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time) {
500  _pimpl->AsyncCall("set_traffic_light_yellow_time", traffic_light, yellow_time);
501  }
502 
503  void Client::SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time) {
504  _pimpl->AsyncCall("set_traffic_light_red_time", traffic_light, red_time);
505  }
506 
507  void Client::FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze) {
508  _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
509  }
510 
512  _pimpl->AsyncCall("reset_traffic_light_group", traffic_light);
513  }
514 
516  _pimpl->CallAndWait<void>("reset_all_traffic_lights");
517  }
518 
519  void Client::FreezeAllTrafficLights(bool frozen) {
520  _pimpl->AsyncCall("freeze_all_traffic_lights", frozen);
521  }
522 
523  std::vector<geom::BoundingBox> Client::GetLightBoxes(rpc::ActorId traffic_light) const {
524  using return_t = std::vector<geom::BoundingBox>;
525  return _pimpl->CallAndWait<return_t>("get_light_boxes", traffic_light);
526  }
527 
529  return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
530  }
531 
532  std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
533  using return_t = std::vector<ActorId>;
534  return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);
535  }
536 
537  std::string Client::StartRecorder(std::string name, bool additional_data) {
538  return _pimpl->CallAndWait<std::string>("start_recorder", name, additional_data);
539  }
540 
542  return _pimpl->AsyncCall("stop_recorder");
543  }
544 
545  std::string Client::ShowRecorderFileInfo(std::string name, bool show_all) {
546  return _pimpl->CallAndWait<std::string>("show_recorder_file_info", name, show_all);
547  }
548 
549  std::string Client::ShowRecorderCollisions(std::string name, char type1, char type2) {
550  return _pimpl->CallAndWait<std::string>("show_recorder_collisions", name, type1, type2);
551  }
552 
553  std::string Client::ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
554  return _pimpl->CallAndWait<std::string>("show_recorder_actors_blocked", name, min_time, min_distance);
555  }
556 
557  std::string Client::ReplayFile(std::string name, double start, double duration,
558  uint32_t follow_id, bool replay_sensors) {
559  return _pimpl->CallAndWait<std::string>("replay_file", name, start, duration,
560  follow_id, replay_sensors);
561  }
562 
563  void Client::StopReplayer(bool keep_actors) {
564  _pimpl->AsyncCall("stop_replayer", keep_actors);
565  }
566 
567  void Client::SetReplayerTimeFactor(double time_factor) {
568  _pimpl->AsyncCall("set_replayer_time_factor", time_factor);
569  }
570 
571  void Client::SetReplayerIgnoreHero(bool ignore_hero) {
572  _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
573  }
574 
576  const streaming::Token &token,
577  std::function<void(Buffer)> callback) {
578  _pimpl->streaming_client.Subscribe(token, std::move(callback));
579  }
580 
582  _pimpl->streaming_client.UnSubscribe(token);
583  }
584 
586  _pimpl->AsyncCall("draw_debug_shape", shape);
587  }
588 
589  void Client::ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
590  _pimpl->AsyncCall("apply_batch", std::move(commands), do_tick_cue);
591  }
592 
593  std::vector<rpc::CommandResponse> Client::ApplyBatchSync(
594  std::vector<rpc::Command> commands,
595  bool do_tick_cue) {
596  auto result = _pimpl->RawCall("apply_batch", std::move(commands), do_tick_cue);
597  return result.as<std::vector<rpc::CommandResponse>>();
598  }
599 
600  uint64_t Client::SendTickCue() {
601  return _pimpl->CallAndWait<uint64_t>("tick_cue");
602  }
603 
604  std::vector<rpc::LightState> Client::QueryLightsStateToServer() const {
605  using return_t = std::vector<rpc::LightState>;
606  return _pimpl->CallAndWait<return_t>("query_lights_state", _pimpl->endpoint);
607  }
608 
609  void Client::UpdateServerLightsState(std::vector<rpc::LightState>& lights, bool discard_client) const {
610  _pimpl->AsyncCall("update_lights_state", _pimpl->endpoint, std::move(lights), discard_client);
611  }
612 
613  void Client::UpdateDayNightCycle(const bool active) const {
614  _pimpl->AsyncCall("update_day_night_cycle", _pimpl->endpoint, active);
615  }
616 
617  std::vector<geom::BoundingBox> Client::GetLevelBBs(uint8_t queried_tag) const {
618  using return_t = std::vector<geom::BoundingBox>;
619  return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
620  }
621 
622  std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects(uint8_t queried_tag) const {
623  using return_t = std::vector<rpc::EnvironmentObject>;
624  return _pimpl->CallAndWait<return_t>("get_environment_objects", queried_tag);
625  }
626 
628  std::vector<uint64_t> env_objects_ids,
629  bool enable) const {
630  _pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
631  }
632 
633  std::pair<bool,rpc::LabelledPoint> Client::ProjectPoint(
634  geom::Location location, geom::Vector3D direction, float search_distance) const {
635  using return_t = std::pair<bool,rpc::LabelledPoint>;
636  return _pimpl->CallAndWait<return_t>("project_point", location, direction, search_distance);
637  }
638 
639  std::vector<rpc::LabelledPoint> Client::CastRay(
640  geom::Location start_location, geom::Location end_location) const {
641  using return_t = std::vector<rpc::LabelledPoint>;
642  return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
643  }
644 
645 } // namespace detail
646 } // namespace client
647 } // 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 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)
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)
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)
void UpdateDayNightCycle(const bool active) const
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)