CARLA
Loading...
Searching...
No Matches
client/detail/Client.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 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"
18#include "carla/rpc/Response.h"
26
27#include <rpc/rpc_error.h>
28
29#include <thread>
30
31namespace carla {
32namespace client {
33namespace 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
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) {
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
140 return ::carla::version();
141 }
142
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
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
169 const rpc::MaterialParameter& MaterialParameter,
170 const rpc::TextureColor& Texture)
171 {
172 _pimpl->CallAndWait<void>("apply_texture_to_actor", ActorId, MaterialParameter, Texture);
173 }
174
177 const rpc::MaterialParameter& MaterialParameter,
178 const rpc::TextureFloatColor& Texture)
179 {
180 _pimpl->CallAndWait<void>("apply_texture_to_actor_float", ActorId, MaterialParameter, Texture);
181 }
182
184 const std::vector<std::string> &objects_name,
185 const rpc::MaterialParameter& parameter,
186 const rpc::TextureColor& Texture) {
187 _pimpl->CallAndWait<void>("apply_color_texture_to_objects", objects_name, parameter, Texture);
188 }
189
191 const std::vector<std::string> &objects_name,
192 const rpc::MaterialParameter& parameter,
193 const rpc::TextureFloatColor& Texture) {
194 _pimpl->CallAndWait<void>("apply_float_color_texture_to_objects", objects_name, parameter, Texture);
195 }
196
197 void Client::SetSkyLightMap(const rpc::TextureFloatColor& panorama, float intensity, int32_t face_size) {
198 _pimpl->CallAndWait<void>("set_sky_light_map", panorama, intensity, face_size);
199 }
200
202 _pimpl->CallAndWait<void>("clear_sky_light_map");
203 }
204
206 return _pimpl->CallAndWait<bool>("has_sky_light_map");
207 }
208
209 std::vector<std::string> Client::GetNamesOfAllObjects() const {
210 return _pimpl->CallAndWait<std::vector<std::string>>("get_names_of_all_objects");
211 }
212
214 return _pimpl->CallAndWait<rpc::EpisodeInfo>("get_episode_info");
215 }
216
218 return _pimpl->CallAndWait<rpc::MapInfo>("get_map_info");
219 }
220
221 std::string Client::GetMapData() const{
222 return _pimpl->CallAndWait<std::string>("get_map_data");
223 }
224
225 std::vector<uint8_t> Client::GetNavigationMesh() const {
226 return _pimpl->CallAndWait<std::vector<uint8_t>>("get_navigation_mesh");
227 }
228
230 try {
231 return _pimpl->CallAndWait<bool>("is_navigation_server_side");
232 } catch (const ::rpc::rpc_error &) {
233 // Servers that predate server-side navigation don't bind this function;
234 // that means legacy client-side navigation. Timeouts are NOT caught:
235 // a dead server must not masquerade as a legacy one.
236 return false;
237 }
238 }
239
241 return _pimpl->CallAndWait<geom::Location>("get_random_location_from_navigation");
242 }
243
245 return _pimpl->CallAndWait<bool>("walker_start_navigation", walker);
246 }
247
248 bool Client::WalkerGoToLocation(rpc::ActorId walker, const geom::Location &destination) const {
249 return _pimpl->CallAndWait<bool>("walker_go_to_location", walker, destination);
250 }
251
252 bool Client::WalkerSetMaxSpeed(rpc::ActorId walker, float max_speed) const {
253 return _pimpl->CallAndWait<bool>("walker_set_max_speed", walker, max_speed);
254 }
255
257 return _pimpl->CallAndWait<bool>("walker_stop_navigation", walker);
258 }
259
260 bool Client::SetPedestriansCrossFactor(float percentage) const {
261 return _pimpl->CallAndWait<bool>("set_pedestrians_cross_factor", percentage);
262 }
263
264 bool Client::SetPedestriansSeed(uint32_t seed) const {
265 return _pimpl->CallAndWait<bool>("set_pedestrians_seed", seed);
266 }
267
268 bool Client::SetFilesBaseFolder(const std::string &path) {
270 }
271
272 std::vector<std::string> Client::GetRequiredFiles(const std::string &folder, const bool download) const {
273 // Get the list of required files
274 auto requiredFiles = _pimpl->CallAndWait<std::vector<std::string>>("get_required_files", folder);
275
276 if (download) {
277
278 // For each required file, check if it exists and request it otherwise
279 for (auto requiredFile : requiredFiles) {
280 if (!FileTransfer::FileExists(requiredFile)) {
281 RequestFile(requiredFile);
282 log_info("Could not find the required file in cache, downloading... ", requiredFile);
283 } else {
284 log_info("Found the required file in cache! ", requiredFile);
285 }
286 }
287 }
288 return requiredFiles;
289 }
290
291 void Client::RequestFile(const std::string &name) const {
292 // Download the binary content of the file from the server and write it on the client
293 auto content = _pimpl->CallAndWait<std::vector<uint8_t>>("request_file", name);
294 FileTransfer::WriteFile(name, content);
295 }
296
297 std::vector<uint8_t> Client::GetCacheFile(const std::string &name, const bool request_otherwise) const {
298 // Get the file from the cache in the file transfer
299 std::vector<uint8_t> file = FileTransfer::ReadFile(name);
300
301 // If it isn't in the cache, download it if request otherwise is true
302 if (file.empty() && request_otherwise) {
303 RequestFile(name);
304 file = FileTransfer::ReadFile(name);
305 }
306 return file;
307 }
308
309 std::vector<std::string> Client::GetAvailableMaps() {
310 return _pimpl->CallAndWait<std::vector<std::string>>("get_available_maps");
311 }
312
313 std::vector<rpc::ContentPackInfo> Client::GetContentPacks() {
314 return _pimpl->CallAndWait<std::vector<rpc::ContentPackInfo>>("get_content_packs");
315 }
316
318 return _pimpl->CallAndWait<rpc::ContentPackInfo>("mount_content_pack", path);
319 }
320
321 bool Client::UnmountContentPack(const std::string &name) {
322 return _pimpl->CallAndWait<bool>("unmount_content_pack", name);
323 }
324
325 std::vector<rpc::ActorDefinition> Client::GetActorDefinitions() {
326 return _pimpl->CallAndWait<std::vector<rpc::ActorDefinition>>("get_actor_definitions");
327 }
328
330 return _pimpl->CallAndWait<carla::rpc::Actor>("get_spectator");
331 }
332
334 return _pimpl->CallAndWait<rpc::EpisodeSettings>("get_episode_settings");
335 }
336
338 return _pimpl->CallAndWait<uint64_t>("set_episode_settings", settings);
339 }
340
342 return _pimpl->CallAndWait<rpc::WeatherParameters>("get_weather_parameters");
343 }
344
346 _pimpl->AsyncCall("set_weather_parameters", weather);
347 }
348
350 return _pimpl->CallAndWait<float>("get_imu_gravity");
351 }
352
353 void Client::SetIMUSensorGravity(float gravity) {
354 _pimpl->AsyncCall("set_imu_gravity", gravity);
355 }
356
358 return _pimpl->CallAndWait<bool>("is_weather_enabled");
359 }
360
361 void Client::SetPublishTF(bool publish_tf) {
362 _pimpl->AsyncCall("set_publish_tf", publish_tf);
363 }
364
365 bool Client::GetPublishTF() const {
366 return _pimpl->CallAndWait<bool>("get_publish_tf");
367 }
368
369 std::vector<geom::Transform> Client::GetEgoSpawnPoints() const {
370 return _pimpl->CallAndWait<std::vector<carla::geom::Transform>>("get_ego_spawn_points");
371 }
372
373 std::vector<rpc::Actor> Client::GetActorsById(
374 const std::vector<ActorId> &ids) {
375 using return_t = std::vector<rpc::Actor>;
376 return _pimpl->CallAndWait<return_t>("get_actors_by_id", ids);
377 }
378
380 rpc::ActorId vehicle) const {
381 return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", vehicle);
382 }
383
385 rpc::ActorId vehicle) const {
386 return _pimpl->CallAndWait<carla::rpc::VehicleTelemetryData>("get_telemetry_data", vehicle);
387 }
388
390 rpc::ActorId vehicle) const {
391 return _pimpl->CallAndWait<carla::rpc::VehicleLightState>("get_vehicle_light_state", vehicle);
392 }
393
395 rpc::ActorId vehicle,
396 const rpc::VehiclePhysicsControl &physics_control) {
397 return _pimpl->AsyncCall("apply_physics_control", vehicle, physics_control);
398 }
399
401 rpc::ActorId vehicle,
402 const rpc::VehicleLightState &light_state) {
403 return _pimpl->AsyncCall("set_vehicle_light_state", vehicle, light_state);
404 }
405
407 rpc::ActorId vehicle,
408 const rpc::VehicleDoor door_idx) {
409 return _pimpl->AsyncCall("open_vehicle_door", vehicle, door_idx);
410 }
411
413 rpc::ActorId vehicle,
414 const rpc::VehicleDoor door_idx) {
415 return _pimpl->AsyncCall("close_vehicle_door", vehicle, door_idx);
416 }
417
419 rpc::ActorId vehicle,
420 rpc::VehicleWheelLocation vehicle_wheel,
421 float angle_in_deg) {
422 _pimpl->CallAndWait<void>("set_wheel_steer_direction", vehicle, vehicle_wheel, angle_in_deg);
423 }
424
426 rpc::ActorId vehicle,
427 rpc::VehicleWheelLocation wheel_location){
428 return _pimpl->CallAndWait<float>("get_wheel_steer_angle", vehicle, wheel_location);
429 }
430
432 rpc::ActorId vehicle,
433 rpc::VehicleWheelLocation wheel_location,
434 float angle_in_deg) {
435 _pimpl->CallAndWait<void>("set_wheel_pitch_angle", vehicle, wheel_location, angle_in_deg);
436 }
437
439 rpc::ActorId vehicle,
440 rpc::VehicleWheelLocation wheel_location) {
441 return _pimpl->CallAndWait<float>("get_wheel_pitch_angle", vehicle, wheel_location);
442 }
443
445 rpc::ActorId vehicle,
446 rpc::VehicleWheelLocation wheel_location,
447 float offset) {
448 _pimpl->CallAndWait<void>("set_wheel_suspension_offset", vehicle, wheel_location, offset);
449 }
450
452 rpc::ActorId vehicle,
453 rpc::VehicleWheelLocation wheel_location) {
454 return _pimpl->CallAndWait<float>("get_wheel_suspension_offset", vehicle, wheel_location);
455 }
456
458 _pimpl->CallAndWait<void>("set_wheel_animation_override", vehicle, enabled);
459 }
460
462 const rpc::ActorDescription &description,
463 const geom::Transform &transform) {
464 return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
465 }
466
468 const rpc::ActorDescription &description,
469 const geom::Transform &transform,
470 rpc::ActorId parent,
471 rpc::AttachmentType attachment_type) {
472
473 if (attachment_type == rpc::AttachmentType::SpringArm ||
474 attachment_type == rpc::AttachmentType::SpringArmGhost)
475 {
476 const auto a = transform.location.MakeUnitVector(std::numeric_limits<float>::epsilon());
477 const auto z = geom::Vector3D(0.0f, 0.f, 1.0f);
478 constexpr float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
479 if (geom::Math::Dot(a, z) > OneEps) {
480 std::cout << "WARNING: Transformations with translation only in the 'z' axis are ill-formed when \
481 using SpringArm or SpringArmGhost attachment. Please, be careful with that." << std::endl;
482 }
483 }
484
485 return _pimpl->CallAndWait<rpc::Actor>("spawn_actor_with_parent",
486 description,
487 transform,
488 parent,
489 attachment_type);
490 }
491
493 try {
494 return _pimpl->CallAndWait<bool>("destroy_actor", actor);
495 } catch (const std::exception &e) {
496 log_error("failed to destroy actor", actor, ':', e.what());
497 return false;
498 }
499 }
500
502 _pimpl->AsyncCall("set_actor_location", actor, location);
503 }
504
506 _pimpl->AsyncCall("set_actor_transform", actor, transform);
507 }
508
510 _pimpl->AsyncCall("set_actor_target_velocity", actor, vector);
511 }
512
514 _pimpl->AsyncCall("set_actor_target_angular_velocity", actor, vector);
515 }
516
518 _pimpl->AsyncCall("enable_actor_constant_velocity", actor, vector);
519 }
520
522 _pimpl->AsyncCall("disable_actor_constant_velocity", actor);
523 }
524
526 _pimpl->AsyncCall("enable_actor_constant_acceleration", actor, vector);
527 }
528
530 _pimpl->AsyncCall("disable_actor_constant_acceleration", actor);
531 }
532
534 _pimpl->AsyncCall("add_actor_impulse", actor, impulse);
535 }
536
537 void Client::AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
538 _pimpl->AsyncCall("add_actor_impulse_at_location", actor, impulse, location);
539 }
540
542 _pimpl->AsyncCall("add_actor_force", actor, force);
543 }
544
545 void Client::AddActorForce(rpc::ActorId actor, const geom::Vector3D &force, const geom::Vector3D &location) {
546 _pimpl->AsyncCall("add_actor_force_at_location", actor, force, location);
547 }
548
550 _pimpl->AsyncCall("add_actor_angular_impulse", actor, vector);
551 }
552
554 _pimpl->AsyncCall("add_actor_torque", actor, vector);
555 }
556
558 rpc::ActorId actor,
559 const std::string &component_name) {
560 return _pimpl->CallAndWait<geom::Transform>(
561 "get_actor_component_world_transform", actor, component_name);
562 }
563
565 rpc::ActorId actor,
566 const std::string &component_name) {
567 return _pimpl->CallAndWait<geom::Transform>(
568 "get_actor_component_relative_transform", actor, component_name);
569 }
570
571 std::vector<geom::Transform> Client::GetActorBoneWorldTransforms(rpc::ActorId actor) {
572 using return_t = std::vector<geom::Transform>;
573 return _pimpl->CallAndWait<return_t>("get_actor_bone_world_transforms", actor);
574 }
575
576 std::vector<geom::Transform> Client::GetActorBoneRelativeTransforms(rpc::ActorId actor) {
577 using return_t = std::vector<geom::Transform>;
578 return _pimpl->CallAndWait<return_t>("get_actor_bone_relative_transforms", actor);
579 }
580
581 std::vector<std::string> Client::GetActorComponentNames(rpc::ActorId actor) {
582 using return_t = std::vector<std::string>;
583 return _pimpl->CallAndWait<return_t>("get_actor_component_names", actor);
584 }
585
586 std::vector<std::string> Client::GetActorBoneNames(rpc::ActorId actor) {
587 using return_t = std::vector<std::string>;
588 return _pimpl->CallAndWait<return_t>("get_actor_bone_names", actor);
589 }
590
591 std::vector<geom::Transform> Client::GetActorSocketWorldTransforms(rpc::ActorId actor) {
592 using return_t = std::vector<geom::Transform>;
593 return _pimpl->CallAndWait<return_t>("get_actor_socket_world_transforms", actor);
594 }
595
596 std::vector<geom::Transform> Client::GetActorSocketRelativeTransforms(rpc::ActorId actor) {
597 using return_t = std::vector<geom::Transform>;
598 return _pimpl->CallAndWait<return_t>("get_actor_socket_relative_transforms", actor);
599 }
600
601 std::vector<std::string> Client::GetActorSocketNames(rpc::ActorId actor) {
602 using return_t = std::vector<std::string>;
603 return _pimpl->CallAndWait<return_t>("get_actor_socket_names", actor);
604 }
605
606 void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
607 _pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
608 }
609
610 void Client::SetActorCollisions(rpc::ActorId actor, const bool enabled) {
611 _pimpl->CallAndWait<void>("set_actor_collisions", actor, enabled);
612 }
613
615 _pimpl->AsyncCall("set_actor_dead", actor);
616 }
617
618 void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
619 _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
620 }
621
622 void Client::SetActorAutopilot(rpc::ActorId vehicle, const bool enabled) {
623 _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
624 }
625
626 void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
627 _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
628 }
629
631 _pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
632 }
633
635 _pimpl->AsyncCall("apply_ackermann_control_to_vehicle", vehicle, control);
636 }
637
639 rpc::ActorId vehicle) const {
640 return _pimpl->CallAndWait<carla::rpc::AckermannControllerSettings>("get_ackermann_controller_settings", vehicle);
641 }
642
644 _pimpl->AsyncCall("apply_ackermann_controller_settings", vehicle, settings);
645 }
646
647 void Client::EnableCarSim(rpc::ActorId vehicle, std::string simfile_path) {
648 _pimpl->AsyncCall("enable_carsim", vehicle, simfile_path);
649 }
650
651 void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
652 _pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
653 }
654
656 rpc::ActorId vehicle,
657 uint64_t MaxSubsteps,
658 float MaxSubstepDeltaTime,
659 std::string VehicleJSON,
660 std::string PowertrainJSON,
661 std::string TireJSON,
662 std::string BaseJSONPath) {
663 _pimpl->AsyncCall("enable_chrono_physics",
664 vehicle,
665 MaxSubsteps,
666 MaxSubstepDeltaTime,
667 VehicleJSON,
668 PowertrainJSON,
669 TireJSON,
670 BaseJSONPath);
671 }
672
674 _pimpl->AsyncCall("apply_control_to_walker", walker, control);
675 }
676
678 auto res = _pimpl->CallAndWait<rpc::WalkerBoneControlOut>("get_bones_transform", walker);
679 return res;
680 }
681
683 _pimpl->AsyncCall("set_bones_transform", walker, bones);
684 }
685
686 void Client::BlendPose(rpc::ActorId walker, float blend) {
687 _pimpl->AsyncCall("blend_pose", walker, blend);
688 }
689
691 _pimpl->AsyncCall("get_pose_from_animation", walker);
692 }
693
695 rpc::ActorId traffic_light,
696 const rpc::TrafficLightState traffic_light_state) {
697 _pimpl->AsyncCall("set_traffic_light_state", traffic_light, traffic_light_state);
698 }
699
700 void Client::SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time) {
701 _pimpl->AsyncCall("set_traffic_light_green_time", traffic_light, green_time);
702 }
703
704 void Client::SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time) {
705 _pimpl->AsyncCall("set_traffic_light_yellow_time", traffic_light, yellow_time);
706 }
707
708 void Client::SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time) {
709 _pimpl->AsyncCall("set_traffic_light_red_time", traffic_light, red_time);
710 }
711
712 void Client::FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze) {
713 _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
714 }
715
717 _pimpl->AsyncCall("reset_traffic_light_group", traffic_light);
718 }
719
721 _pimpl->CallAndWait<void>("reset_all_traffic_lights");
722 }
723
725 _pimpl->AsyncCall("freeze_all_traffic_lights", frozen);
726 }
727
728 std::vector<geom::BoundingBox> Client::GetLightBoxes(rpc::ActorId traffic_light) const {
729 using return_t = std::vector<geom::BoundingBox>;
730 return _pimpl->CallAndWait<return_t>("get_light_boxes", traffic_light);
731 }
732
734 return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
735 }
736
737 std::vector<geom::Transform> Client::GetVehicleBoneWorldTransforms(rpc::ActorId actor) {
738 using return_t = std::vector<geom::Transform>;
739 return _pimpl->CallAndWait<return_t>("get_vehicle_bone_world_transforms", actor);
740 }
741
742 std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
743 using return_t = std::vector<ActorId>;
744 return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);
745 }
746
747 std::string Client::StartRecorder(std::string name, bool additional_data, bool stop_replayer) {
748 return _pimpl->CallAndWait<std::string>("start_recorder", name, additional_data, stop_replayer);
749 }
750
752 return _pimpl->AsyncCall("stop_recorder");
753 }
754
755 std::string Client::ShowRecorderFileInfo(std::string name, bool show_all) {
756 return _pimpl->CallAndWait<std::string>("show_recorder_file_info", name, show_all);
757 }
758
759 std::string Client::ShowRecorderCollisions(std::string name, char type1, char type2) {
760 return _pimpl->CallAndWait<std::string>("show_recorder_collisions", name, type1, type2);
761 }
762
763 std::string Client::ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
764 return _pimpl->CallAndWait<std::string>("show_recorder_actors_blocked", name, min_time, min_distance);
765 }
766
768 std::string name, double start, double duration,
769 uint32_t follow_id, bool replay_sensors, bool replay_weather, const geom::Transform& offset,
770 std::string map_override) {
771 return _pimpl->CallAndWait<std::string>("replay_file", name, start, duration,
772 follow_id, replay_sensors, replay_weather, offset, map_override);
773 }
774
775 void Client::StopReplayer(bool keep_actors) {
776 _pimpl->AsyncCall("stop_replayer", keep_actors);
777 }
778
779 void Client::SetReplayerTimeFactor(double time_factor) {
780 _pimpl->AsyncCall("set_replayer_time_factor", time_factor);
781 }
782
783 void Client::SetReplayerIgnoreHero(bool ignore_hero) {
784 _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
785 }
786
787 void Client::SetReplayerIgnoreSpectator(bool ignore_spectator) {
788 _pimpl->AsyncCall("set_replayer_ignore_spectator", ignore_spectator);
789 }
790
792 const streaming::Token &token,
793 std::function<void(Buffer)> callback) {
795 streaming::Token receivedToken = _pimpl->CallAndWait<streaming::Token>("get_sensor_token", thisToken.get_stream_id());
796 _pimpl->streaming_client.Subscribe(receivedToken, std::move(callback));
797 }
798
800 _pimpl->streaming_client.UnSubscribe(token);
801 }
802
804 _pimpl->streaming_client.Stop();
805 }
806
809 _pimpl->AsyncCall("enable_sensor_for_ros", thisToken.get_stream_id());
810 }
811
814 _pimpl->AsyncCall("disable_sensor_for_ros", thisToken.get_stream_id());
815 }
816
819 return _pimpl->CallAndWait<bool>("is_sensor_enabled_for_ros", thisToken.get_stream_id());
820 }
821
824 uint32_t GBufferId,
825 std::function<void(Buffer)> callback)
826 {
827 std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
828 streaming::Token token;
829 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
830 _pimpl->streaming_client.Subscribe(token, std::move(callback));
831 }
832
835 uint32_t GBufferId)
836 {
837 std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
838 streaming::Token token;
839 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
840 _pimpl->streaming_client.UnSubscribe(token);
841 }
842
844 _pimpl->AsyncCall("send", ActorId, data);
845 }
846
848 _pimpl->AsyncCall("draw_debug_shape", shape);
849 }
850
852 _pimpl->AsyncCall("clear_debug_shape");
853 }
854
856 _pimpl->AsyncCall("clear_debug_string");
857 }
858
860 const std::vector<float> &vertices,
861 const std::vector<uint32_t> &triangles,
862 const std::string &material) {
863 _pimpl->CallAndWait<void>("spawn_custom_mesh", vertices, triangles, material);
864 }
865
866 void Client::ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
867 _pimpl->AsyncCall("apply_batch", std::move(commands), do_tick_cue);
868 }
869
870 std::vector<rpc::CommandResponse> Client::ApplyBatchSync(
871 std::vector<rpc::Command> commands,
872 bool do_tick_cue) {
873 auto result = _pimpl->RawCall("apply_batch", std::move(commands), do_tick_cue);
874 return result.as<std::vector<rpc::CommandResponse>>();
875 }
876
878 return _pimpl->CallAndWait<uint64_t>("tick_cue");
879 }
880
881 std::vector<rpc::LightState> Client::QueryLightsStateToServer() const {
882 using return_t = std::vector<rpc::LightState>;
883 return _pimpl->CallAndWait<return_t>("query_lights_state", _pimpl->endpoint);
884 }
885
886 void Client::UpdateServerLightsState(std::vector<rpc::LightState>& lights, bool discard_client) const {
887 _pimpl->AsyncCall("update_lights_state", _pimpl->endpoint, std::move(lights), discard_client);
888 }
889
890 void Client::UpdateDayNightCycle(const bool active) const {
891 _pimpl->AsyncCall("update_day_night_cycle", _pimpl->endpoint, active);
892 }
893
894 std::vector<geom::BoundingBox> Client::GetLevelBBs(uint8_t queried_tag) const {
895 using return_t = std::vector<geom::BoundingBox>;
896 return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
897 }
898
899 std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects(uint8_t queried_tag) const {
900 using return_t = std::vector<rpc::EnvironmentObject>;
901 return _pimpl->CallAndWait<return_t>("get_environment_objects", queried_tag);
902 }
903
905 std::vector<uint64_t> env_objects_ids,
906 bool enable) const {
907 _pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
908 }
909
910 std::pair<bool,rpc::LabelledPoint> Client::ProjectPoint(
911 geom::Location location, geom::Vector3D direction, float search_distance) const {
912 using return_t = std::pair<bool,rpc::LabelledPoint>;
913 return _pimpl->CallAndWait<return_t>("project_point", location, direction, search_distance);
914 }
915
916 std::vector<rpc::LabelledPoint> Client::CastRay(
917 geom::Location start_location, geom::Location end_location) const {
918 using return_t = std::vector<rpc::LabelledPoint>;
919 return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
920 }
921
922 std::string Client::GetActorName(rpc::ActorId actor) const
923 {
924 return _pimpl->CallAndWait<std::string>("get_actor_name", actor);
925 }
926
928 {
929 return _pimpl->CallAndWait<std::string>("get_actor_class_name", actor);
930 }
931
932} // namespace detail
933} // namespace client
934} // namespace carla
float intensity
float z
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
static std::vector< uint8_t > ReadFile(std::string_view path)
static bool FileExists(std::string_view file)
static bool SetFilesBaseFolder(std::string_view path)
static bool WriteFile(std::string_view path, std::vector< uint8_t > content)
void AsyncCall(const std::string &function, Args &&... args)
auto RawCall(const std::string &function, Args &&... args)
Pimpl(const std::string &host, uint16_t port, size_t worker_threads)
auto CallAndWait(const std::string &function, Args &&... args)
void SetReplayerIgnoreHero(bool ignore_hero)
void SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time)
void ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control)
bool WalkerGoToLocation(rpc::ActorId walker, const geom::Location &destination) const
bool SetPedestriansSeed(uint32_t seed) const
Seed for the server-side navigation RNG (crosser draw); applies to walkers whose navigation starts af...
std::vector< geom::Transform > GetVehicleBoneWorldTransforms(rpc::ActorId actor)
void OpenVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
const std::string GetEndpoint() const
float GetWheelSuspensionOffset(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location)
std::string ReplayFile(std::string name, double start, double duration, uint32_t follow_id, bool replay_sensors, bool replay_weather, const geom::Transform &offset, std::string map_override)
std::vector< geom::Transform > GetEgoSpawnPoints() const
rpc::WeatherParameters GetWeatherParameters()
std::vector< std::string > GetActorBoneNames(rpc::ActorId actor)
void ApplyTextureToActor(rpc::ActorId ActorId, const rpc::MaterialParameter &MaterialParameter, const rpc::TextureColor &Texture)
void ApplyPhysicsControlToVehicle(rpc::ActorId vehicle, const rpc::VehiclePhysicsControl &physics_control)
void CloseVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
void LoadLevelLayer(rpc::MapLayer map_layer) const
void SetActorTargetVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
geom::Transform GetActorComponentWorldTransform(rpc::ActorId actor, const std::string &component_name)
std::vector< std::string > GetAvailableMaps()
bool IsEnabledForROS(const streaming::Token &token)
void DisableForROS(const streaming::Token &token)
std::vector< rpc::ContentPackInfo > GetContentPacks()
bool SetFilesBaseFolder(const std::string &path)
void Send(rpc::ActorId ActorId, const rpc::CustomV2XBytes &data)
rpc::VehicleLightState GetVehicleLightState(rpc::ActorId vehicle) const
void SetWheelAnimationOverride(rpc::ActorId vehicle, bool enabled)
std::vector< rpc::Actor > GetActorsById(const std::vector< ActorId > &ids)
rpc::VehicleTelemetryData GetVehicleTelemetryData(rpc::ActorId vehicle) const
void DisableActorConstantVelocity(rpc::ActorId actor)
void EnableActorConstantVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void RequestFile(const std::string &name) const
const std::unique_ptr< Pimpl > _pimpl
rpc::AckermannControllerSettings GetAckermannControllerSettings(rpc::ActorId vehicle) const
void EnableChronoPhysics(rpc::ActorId vehicle, uint64_t MaxSubsteps, float MaxSubstepDeltaTime, std::string VehicleJSON, std::string PowertrainJSON, std::string TireJSON, std::string BaseJSONPath)
bool WalkerStartNavigation(rpc::ActorId walker) const
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
geom::Transform GetActorComponentRelativeTransform(rpc::ActorId actor, const std::string &component_name)
std::vector< rpc::CommandResponse > ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue)
void UnSubscribeFromGBuffer(rpc::ActorId ActorId, uint32_t GBufferId)
bool IsNavigationServerSide() const
True when the server hosts the pedestrian navigation (a World-Partitioned navmesh exists in the curre...
std::vector< ActorId > GetGroupTrafficLights(rpc::ActorId traffic_light)
void SetActorCollisions(rpc::ActorId actor, bool enabled)
void ApplyAckermannControllerSettings(rpc::ActorId vehicle, const rpc::AckermannControllerSettings &settings)
void SetActorAutopilot(rpc::ActorId vehicle, bool enabled)
float GetWheelPitchAngle(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location)
void UnSubscribeFromStream(const streaming::Token &token)
rpc::VehicleLightStateList GetVehiclesLightStates()
Returns a list of pairs where the firts element is the vehicle ID and the second one is the light sta...
std::vector< std::string > GetRequiredFiles(const std::string &folder="", const bool download=true) const
void LoadEpisode(std::string map_name, bool reset_settings=true, rpc::MapLayer map_layer=rpc::MapLayer::All)
void ResetTrafficLightGroup(rpc::ActorId traffic_light)
std::vector< std::string > GetActorComponentNames(rpc::ActorId actor)
void SetActorLocation(rpc::ActorId actor, const geom::Location &location)
uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings)
void ShowVehicleDebugTelemetry(rpc::ActorId vehicle, bool enabled)
void SubscribeToStream(const streaming::Token &token, std::function< void(Buffer)> callback)
void SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time)
void BlendPose(rpc::ActorId walker, float blend)
std::vector< std::string > GetNamesOfAllObjects() const
void SpawnCustomMesh(const std::vector< float > &vertices, const std::vector< uint32_t > &triangles, const std::string &material)
void CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters &params)
rpc::VehiclePhysicsControl GetVehiclePhysicsControl(rpc::ActorId vehicle) const
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.
std::vector< uint8_t > GetNavigationMesh() const
void EnableActorConstantAcceleration(rpc::ActorId actor, const geom::Vector3D &vector)
void AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse)
void DrawDebugShape(const rpc::DebugShape &shape)
void SetActorTransform(rpc::ActorId actor, const geom::Transform &transform)
void SetActorDead(rpc::ActorId actor)
void ApplyBatch(std::vector< rpc::Command > commands, bool do_tick_cue)
void StopStreaming()
Join the streaming threads; no stream callback runs afterwards.
void SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time)
void SetWeatherParameters(const rpc::WeatherParameters &weather)
void FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze)
void AddActorAngularImpulse(rpc::ActorId actor, const geom::Vector3D &vector)
std::vector< geom::Transform > GetActorSocketWorldTransforms(rpc::ActorId actor)
bool DestroyActor(rpc::ActorId actor)
bool AddTrafficManagerRunning(std::pair< std::string, uint16_t > trafficManagerInfo) const
Informs the server that a Traffic Manager is running on <IP, port>
bool SetPedestriansCrossFactor(float percentage) const
Probability that a walker whose navigation starts after this call may cross roads (server-side naviga...
std::vector< geom::Transform > GetActorBoneWorldTransforms(rpc::ActorId actor)
bool IsTrafficManagerRunning(uint16_t port) const
Querry to know if a Traffic Manager is running on port.
void SetReplayerIgnoreSpectator(bool ignore_spectator)
std::string StartRecorder(std::string name, bool additional_data, bool stop_replayer)
std::vector< geom::BoundingBox > GetLightBoxes(rpc::ActorId traffic_light) const
float GetWheelSteerAngle(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location)
void AddActorForce(rpc::ActorId actor, const geom::Vector3D &force)
std::string ShowRecorderCollisions(std::string name, char type1, char type2)
void SetLightStateToVehicle(rpc::ActorId vehicle, const rpc::VehicleLightState &light_state)
std::vector< geom::BoundingBox > GetLevelBBs(uint8_t queried_tag) const
Returns all the BBs of all the elements of the level.
std::vector< uint8_t > GetCacheFile(const std::string &name, const bool request_otherwise=true) const
std::vector< rpc::LabelledPoint > CastRay(geom::Location start_location, geom::Location end_location) const
void EnableForROS(const streaming::Token &token)
void SetSkyLightMap(const rpc::TextureFloatColor &panorama, float intensity, int32_t face_size)
void EnableCarSim(rpc::ActorId vehicle, std::string simfile_path)
std::string GetActorClassName(rpc::ActorId actor) const
void SetTimeout(time_duration timeout)
std::vector< geom::Transform > GetActorBoneRelativeTransforms(rpc::ActorId actor)
bool WalkerStopNavigation(rpc::ActorId walker) const
Client(const std::string &host, uint16_t port, size_t worker_threads=0u)
void SetActorEnableGravity(rpc::ActorId actor, bool enabled)
void SetActorSimulatePhysics(rpc::ActorId actor, bool enabled)
bool UnmountContentPack(const std::string &name)
void ApplyAckermannControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleAckermannControl &control)
std::string ShowRecorderFileInfo(std::string name, bool show_all)
std::vector< rpc::ActorDefinition > GetActorDefinitions()
void SubscribeToGBuffer(rpc::ActorId ActorId, uint32_t GBufferId, std::function< void(Buffer)> callback)
void SetReplayerTimeFactor(double time_factor)
void SetTrafficLightState(rpc::ActorId traffic_light, const rpc::TrafficLightState trafficLightState)
std::string GetActorName(rpc::ActorId actor) const
std::vector< std::string > GetActorSocketNames(rpc::ActorId actor)
rpc::WalkerBoneControlOut GetBonesTransform(rpc::ActorId walker)
void SetWheelSuspensionOffset(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location, float offset)
void UnloadLevelLayer(rpc::MapLayer map_layer) const
void SetWheelSteerDirection(rpc::ActorId vehicle, rpc::VehicleWheelLocation vehicle_wheel, float angle_in_deg)
void SetBonesTransform(rpc::ActorId walker, const rpc::WalkerBoneControlIn &bones)
void SetActorTargetAngularVelocity(rpc::ActorId actor, const geom::Vector3D &vector)
void UseCarSimRoad(rpc::ActorId vehicle, bool enabled)
std::pair< bool, rpc::LabelledPoint > ProjectPoint(geom::Location location, geom::Vector3D direction, float search_distance) const
std::vector< rpc::EnvironmentObject > GetEnvironmentObjects(uint8_t queried_tag) const
bool WalkerSetMaxSpeed(rpc::ActorId walker, float max_speed) const
void AddActorTorque(rpc::ActorId actor, const geom::Vector3D &vector)
void UpdateServerLightsState(std::vector< rpc::LightState > &lights, bool discard_client=false) const
geom::Location GetRandomLocationFromNavigation() const
Server-side random point on the loaded navmesh.
std::vector< geom::Transform > GetActorSocketRelativeTransforms(rpc::ActorId actor)
std::vector< rpc::LightState > QueryLightsStateToServer() const
void ApplyColorTextureToObjects(const std::vector< std::string > &objects_name, const rpc::MaterialParameter &parameter, const rpc::TextureColor &Texture)
void GetPoseFromAnimation(rpc::ActorId walker)
void DestroyTrafficManager(uint16_t port) const
void DisableActorConstantAcceleration(rpc::ActorId actor)
void ApplyControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleControl &control)
rpc::Actor SpawnActorWithParent(const rpc::ActorDescription &description, const geom::Transform &transform, rpc::ActorId parent, rpc::AttachmentType attachment_type)
void UpdateDayNightCycle(const bool active) const
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
rpc::EpisodeSettings GetEpisodeSettings()
void SetWheelPitchAngle(rpc::ActorId vehicle, rpc::VehicleWheelLocation wheel_location, float angle_in_deg)
rpc::ContentPackInfo MountContentPack(const std::string &path)
rpc::Actor SpawnActor(const rpc::ActorDescription &description, const geom::Transform &transform)
static constexpr auto Dot(const Vector3D &a, const Vector3D &b)
Definition Math.h:62
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
void async_call(const std::string &function, Args &&... args)
Definition rpc/Client.h:37
auto call(const std::string &function, Args &&... args)
Definition rpc/Client.h:32
auto get_timeout() const
Definition rpc/Client.h:27
void set_timeout(int64_t value)
Definition rpc/Client.h:23
Description of a CARLA content pack known to the server (see UCarlaContentPackManager).
Fixed-size binary payload carried by the custom V2X sensor (sensor.other.v2x_custom).
value_type & Get()
Definition Response.h:83
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
A client able to subscribe to multiple streams.
void AsyncRun(size_t worker_threads)
A token that uniquely identify a stream.
Definition Token.h:17
Serializes a stream endpoint.
Positive time duration up to milliseconds resolution.
Definition Time.h:20
constexpr size_t milliseconds() const noexcept
Definition Time.h:62
static time_duration milliseconds(size_t timeout)
Definition Time.h:27
static T Get(carla::rpc::Response< T > &response)
uint32_t ActorId
Definition ActorId.h:14
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
Definition Logging.h:110
static void log_info(Args &&... args)
Definition Logging.h:82
void throw_exception(const ExceptionT &e)
Templated on the static type so the thrown object keeps its dynamic type: taking a const std::excepti...
Definition Exception.h:44
Vector3D MakeUnitVector(const float epsilon=2.0f *std::numeric_limits< float >::epsilon()) const
Return a unit-length copy of this vector.
Seting for map generation from opendrive without additional geometry.