CARLA
 
载入中...
搜索中...
未找到
client/detail/Client.cpp
浏览该文件的文档.
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"
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
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
271 return _pimpl->CallAndWait<float>("get_imui_gravity");
272 }
273
274 void Client::SetIMUISensorGravity(float NewIMUISensorGravity) {
275 _pimpl->AsyncCall("set_imui_gravity", NewIMUISensorGravity);
276 }
277
278 std::vector<rpc::Actor> Client::GetActorsById(
279 const std::vector<ActorId> &ids) {
280 using return_t = std::vector<rpc::Actor>;
281 return _pimpl->CallAndWait<return_t>("get_actors_by_id", ids);
282 }
283
285 rpc::ActorId vehicle) const {
286 return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", vehicle);
287 }
288
290 rpc::ActorId vehicle) const {
291 return _pimpl->CallAndWait<carla::rpc::VehicleLightState>("get_vehicle_light_state", vehicle);
292 }
293
295 rpc::ActorId vehicle,
296 const rpc::VehiclePhysicsControl &physics_control) {
297 return _pimpl->AsyncCall("apply_physics_control", vehicle, physics_control);
298 }
299
301 rpc::ActorId vehicle,
302 const rpc::VehicleLightState &light_state) {
303 return _pimpl->AsyncCall("set_vehicle_light_state", vehicle, light_state);
304 }
305
307 rpc::ActorId vehicle,
308 const rpc::VehicleDoor door_idx) {
309 return _pimpl->AsyncCall("open_vehicle_door", vehicle, door_idx);
310 }
311
313 rpc::ActorId vehicle,
314 const rpc::VehicleDoor door_idx) {
315 return _pimpl->AsyncCall("close_vehicle_door", vehicle, door_idx);
316 }
317
319 rpc::ActorId vehicle,
320 rpc::VehicleWheelLocation vehicle_wheel,
321 float angle_in_deg) {
322 return _pimpl->AsyncCall("set_wheel_steer_direction", vehicle, vehicle_wheel, angle_in_deg);
323 }
324
326 rpc::ActorId vehicle,
327 rpc::VehicleWheelLocation wheel_location){
328 return _pimpl->CallAndWait<float>("get_wheel_steer_angle", vehicle, wheel_location);
329 }
330
332 const rpc::ActorDescription &description,
333 const geom::Transform &transform) {
334 return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
335 }
336
338 const rpc::ActorDescription &description,
339 const geom::Transform &transform,
340 rpc::ActorId parent,
341 rpc::AttachmentType attachment_type,
342 const std::string& socket_name) {
343
344 if (attachment_type == rpc::AttachmentType::SpringArm ||
345 attachment_type == rpc::AttachmentType::SpringArmGhost)
346 {
347 const auto a = transform.location.MakeSafeUnitVector(std::numeric_limits<float>::epsilon());
348 const auto z = geom::Vector3D(0.0f, 0.f, 1.0f);
349 constexpr float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
350 if (geom::Math::Dot(a, z) > OneEps) {
351 std::cout << "WARNING: Transformations with translation only in the 'z' axis are ill-formed when \
352 using SpringArm or SpringArmGhost attachment. Please, be careful with that." << std::endl;
353 }
354 }
355
356 return _pimpl->CallAndWait<rpc::Actor>("spawn_actor_with_parent",
357 description,
358 transform,
359 parent,
360 attachment_type,
361 socket_name);
362 }
363
365 try {
366 return _pimpl->CallAndWait<bool>("destroy_actor", actor);
367 } catch (const std::exception &e) {
368 log_error("failed to destroy actor", actor, ':', e.what());
369 return false;
370 }
371 }
372
374 _pimpl->AsyncCall("set_actor_location", actor, location);
375 }
376
378 _pimpl->AsyncCall("set_actor_transform", actor, transform);
379 }
380
382 _pimpl->AsyncCall("set_actor_target_velocity", actor, vector);
383 }
384
386 _pimpl->AsyncCall("set_actor_target_angular_velocity", actor, vector);
387 }
388
390 _pimpl->AsyncCall("enable_actor_constant_velocity", actor, vector);
391 }
392
394 _pimpl->AsyncCall("disable_actor_constant_velocity", actor);
395 }
396
398 _pimpl->AsyncCall("add_actor_impulse", actor, impulse);
399 }
400
401 void Client::AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
402 _pimpl->AsyncCall("add_actor_impulse_at_location", actor, impulse, location);
403 }
404
406 _pimpl->AsyncCall("add_actor_force", actor, force);
407 }
408
409 void Client::AddActorForce(rpc::ActorId actor, const geom::Vector3D &force, const geom::Vector3D &location) {
410 _pimpl->AsyncCall("add_actor_force_at_location", actor, force, location);
411 }
412
414 _pimpl->AsyncCall("add_actor_angular_impulse", actor, vector);
415 }
416
418 _pimpl->AsyncCall("add_actor_torque", actor, vector);
419 }
420
422 return _pimpl->CallAndWait<geom::Transform>("get_actor_component_world_transform", actor, componentName);
423 }
424
426 return _pimpl->CallAndWait<geom::Transform>("get_actor_component_relative_transform", actor, componentName);
427 }
428
429 std::vector<geom::Transform> Client::GetActorBoneWorldTransforms(rpc::ActorId actor) {
430 using return_t = std::vector<geom::Transform>;
431 return _pimpl->CallAndWait<return_t>("get_actor_bone_world_transforms", actor);
432 }
433
434 std::vector<geom::Transform> Client::GetActorBoneRelativeTransforms(rpc::ActorId actor) {
435 using return_t = std::vector<geom::Transform>;
436 return _pimpl->CallAndWait<return_t>("get_actor_bone_relative_transforms", actor);
437 }
438
439 std::vector<std::string> Client::GetActorComponentNames(rpc::ActorId actor) {
440 using return_t = std::vector<std::string>;
441 return _pimpl->CallAndWait<return_t>("get_actor_component_names", actor);
442 }
443
444 std::vector<std::string> Client::GetActorBoneNames(rpc::ActorId actor) {
445 using return_t = std::vector<std::string>;
446 return _pimpl->CallAndWait<return_t>("get_actor_bone_names", actor);
447 }
448
449 std::vector<geom::Transform> Client::GetActorSocketWorldTransforms(rpc::ActorId actor) {
450 using return_t = std::vector<geom::Transform>;
451 return _pimpl->CallAndWait<return_t>("get_actor_socket_world_transforms", actor);
452 }
453
454 std::vector<geom::Transform> Client::GetActorSocketRelativeTransforms(rpc::ActorId actor) {
455 using return_t = std::vector<geom::Transform>;
456 return _pimpl->CallAndWait<return_t>("get_actor_socket_relative_transforms", actor);
457 }
458
459 std::vector<std::string> Client::GetActorSocketNames(rpc::ActorId actor) {
460 using return_t = std::vector<std::string>;
461 return _pimpl->CallAndWait<return_t>("get_actor_socket_names", actor);
462 }
463
464 void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
465 _pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
466 }
467
468 void Client::SetActorCollisions(rpc::ActorId actor, const bool enabled) {
469 _pimpl->CallAndWait<void>("set_actor_collisions", actor, enabled);
470 }
471
473 _pimpl->AsyncCall("set_actor_dead", actor);
474 }
475
476 void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
477 _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
478 }
479
480 void Client::SetActorAutopilot(rpc::ActorId vehicle, const bool enabled) {
481 _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
482 }
483
485 rpc::ActorId vehicle) const {
486 return _pimpl->CallAndWait<carla::rpc::VehicleTelemetryData>("get_telemetry_data", vehicle);
487 }
488
489 void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
490 _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
491 }
492
494 _pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
495 }
496
498 _pimpl->AsyncCall("apply_ackermann_control_to_vehicle", vehicle, control);
499 }
500
502 rpc::ActorId vehicle) const {
503 return _pimpl->CallAndWait<carla::rpc::AckermannControllerSettings>("get_ackermann_controller_settings", vehicle);
504 }
505
507 _pimpl->AsyncCall("apply_ackermann_controller_settings", vehicle, settings);
508 }
509
510 void Client::EnableCarSim(rpc::ActorId vehicle, std::string simfile_path) {
511 _pimpl->AsyncCall("enable_carsim", vehicle, simfile_path);
512 }
513
514 void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
515 _pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
516 }
517
519 rpc::ActorId vehicle,
520 uint64_t MaxSubsteps,
521 float MaxSubstepDeltaTime,
522 std::string VehicleJSON,
523 std::string PowertrainJSON,
524 std::string TireJSON,
525 std::string BaseJSONPath) {
526 _pimpl->AsyncCall("enable_chrono_physics",
527 vehicle,
528 MaxSubsteps,
529 MaxSubstepDeltaTime,
530 VehicleJSON,
531 PowertrainJSON,
532 TireJSON,
533 BaseJSONPath);
534 }
535
537 _pimpl->AsyncCall("restore_physx_physics", vehicle);
538 }
539
541 _pimpl->AsyncCall("apply_control_to_walker", walker, control);
542 }
543
545 auto res = _pimpl->CallAndWait<rpc::WalkerBoneControlOut>("get_bones_transform", walker);
546 return res;
547 }
548
550 _pimpl->AsyncCall("set_bones_transform", walker, bones);
551 }
552
553 void Client::BlendPose(rpc::ActorId walker, float blend) {
554 _pimpl->AsyncCall("blend_pose", walker, blend);
555 }
556
558 _pimpl->AsyncCall("get_pose_from_animation", walker);
559 }
560
562 rpc::ActorId traffic_light,
563 const rpc::TrafficLightState traffic_light_state) {
564 _pimpl->AsyncCall("set_traffic_light_state", traffic_light, traffic_light_state);
565 }
566
567 void Client::SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time) {
568 _pimpl->AsyncCall("set_traffic_light_green_time", traffic_light, green_time);
569 }
570
571 void Client::SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time) {
572 _pimpl->AsyncCall("set_traffic_light_yellow_time", traffic_light, yellow_time);
573 }
574
575 void Client::SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time) {
576 _pimpl->AsyncCall("set_traffic_light_red_time", traffic_light, red_time);
577 }
578
579 void Client::FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze) {
580 _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
581 }
582
584 _pimpl->AsyncCall("reset_traffic_light_group", traffic_light);
585 }
586
588 _pimpl->CallAndWait<void>("reset_all_traffic_lights");
589 }
590
592 _pimpl->AsyncCall("freeze_all_traffic_lights", frozen);
593 }
594
595 std::vector<geom::BoundingBox> Client::GetLightBoxes(rpc::ActorId traffic_light) const {
596 using return_t = std::vector<geom::BoundingBox>;
597 return _pimpl->CallAndWait<return_t>("get_light_boxes", traffic_light);
598 }
599
601 return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
602 }
603
604 std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
605 using return_t = std::vector<ActorId>;
606 return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);
607 }
608
609 std::string Client::StartRecorder(std::string name, bool additional_data) {
610 return _pimpl->CallAndWait<std::string>("start_recorder", name, additional_data);
611 }
612
614 return _pimpl->AsyncCall("stop_recorder");
615 }
616
617 std::string Client::ShowRecorderFileInfo(std::string name, bool show_all) {
618 return _pimpl->CallAndWait<std::string>("show_recorder_file_info", name, show_all);
619 }
620
621 std::string Client::ShowRecorderCollisions(std::string name, char type1, char type2) {
622 return _pimpl->CallAndWait<std::string>("show_recorder_collisions", name, type1, type2);
623 }
624
625 std::string Client::ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
626 return _pimpl->CallAndWait<std::string>("show_recorder_actors_blocked", name, min_time, min_distance);
627 }
628
629 std::string Client::ReplayFile(std::string name, double start, double duration,
630 uint32_t follow_id, bool replay_sensors) {
631 return _pimpl->CallAndWait<std::string>("replay_file", name, start, duration,
632 follow_id, replay_sensors);
633 }
634
635 void Client::StopReplayer(bool keep_actors) {
636 _pimpl->AsyncCall("stop_replayer", keep_actors);
637 }
638
639 void Client::SetReplayerTimeFactor(double time_factor) {
640 _pimpl->AsyncCall("set_replayer_time_factor", time_factor);
641 }
642
643 void Client::SetReplayerIgnoreHero(bool ignore_hero) {
644 _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
645 }
646
647 void Client::SetReplayerIgnoreSpectator(bool ignore_spectator) {
648 _pimpl->AsyncCall("set_replayer_ignore_spectator", ignore_spectator);
649 }
650
652 const streaming::Token &token,
653 std::function<void(Buffer)> callback) {
655 streaming::Token receivedToken = _pimpl->CallAndWait<streaming::Token>("get_sensor_token", thisToken.get_stream_id());
656 _pimpl->streaming_client.Subscribe(receivedToken, std::move(callback));
657 }
658
660 _pimpl->streaming_client.UnSubscribe(token);
661 }
662
665 _pimpl->AsyncCall("enable_sensor_for_ros", thisToken.get_stream_id());
666 }
667
670 _pimpl->AsyncCall("disable_sensor_for_ros", thisToken.get_stream_id());
671 }
672
675 return _pimpl->CallAndWait<bool>("is_sensor_enabled_for_ros", thisToken.get_stream_id());
676 }
677
678 void Client::Send(rpc::ActorId ActorId, std::string message) {
679 _pimpl->AsyncCall("send", ActorId, message);
680 }
681
684 uint32_t GBufferId,
685 std::function<void(Buffer)> callback)
686 {
687 std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
688 streaming::Token token;
689 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
690 _pimpl->streaming_client.Subscribe(token, std::move(callback));
691 }
692
695 uint32_t GBufferId)
696 {
697 std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
698 streaming::Token token;
699 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
700 _pimpl->streaming_client.UnSubscribe(token);
701 }
702
704 _pimpl->AsyncCall("draw_debug_shape", shape);
705 }
706
707 void Client::ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
708 _pimpl->AsyncCall("apply_batch", std::move(commands), do_tick_cue);
709 }
710
711 std::vector<rpc::CommandResponse> Client::ApplyBatchSync(
712 std::vector<rpc::Command> commands,
713 bool do_tick_cue) {
714 auto result = _pimpl->RawCall("apply_batch", std::move(commands), do_tick_cue);
715 return result.as<std::vector<rpc::CommandResponse>>();
716 }
717
719 return _pimpl->CallAndWait<uint64_t>("tick_cue");
720 }
721
722 std::vector<rpc::LightState> Client::QueryLightsStateToServer() const {
723 using return_t = std::vector<rpc::LightState>;
724 return _pimpl->CallAndWait<return_t>("query_lights_state", _pimpl->endpoint);
725 }
726
727 void Client::UpdateServerLightsState(std::vector<rpc::LightState>& lights, bool discard_client) const {
728 _pimpl->AsyncCall("update_lights_state", _pimpl->endpoint, std::move(lights), discard_client);
729 }
730
731 void Client::UpdateDayNightCycle(const bool active) const {
732 _pimpl->AsyncCall("update_day_night_cycle", _pimpl->endpoint, active);
733 }
734
735 std::vector<geom::BoundingBox> Client::GetLevelBBs(uint8_t queried_tag) const {
736 using return_t = std::vector<geom::BoundingBox>;
737 return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
738 }
739
740 std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects(uint8_t queried_tag) const {
741 using return_t = std::vector<rpc::EnvironmentObject>;
742 return _pimpl->CallAndWait<return_t>("get_environment_objects", queried_tag);
743 }
744
746 std::vector<uint64_t> env_objects_ids,
747 bool enable) const {
748 _pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
749 }
750
751 std::pair<bool,rpc::LabelledPoint> Client::ProjectPoint(
752 geom::Location location, geom::Vector3D direction, float search_distance) const {
753 using return_t = std::pair<bool,rpc::LabelledPoint>;
754 return _pimpl->CallAndWait<return_t>("project_point", location, direction, search_distance);
755 }
756
757 std::vector<rpc::LabelledPoint> Client::CastRay(
758 geom::Location start_location, geom::Location end_location) const {
759 using return_t = std::vector<rpc::LabelledPoint>;
760 return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
761 }
762
763} // namespace detail
764} // namespace client
765} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:66
static std::vector< uint8_t > ReadFile(std::string path)
static bool FileExists(std::string file)
static bool SetFilesBaseFolder(const std::string &path)
static bool WriteFile(std::string 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)
geom::Transform GetActorComponentRelativeTransform(rpc::ActorId actor, const std::string componentName)
void SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time)
void ApplyControlToWalker(rpc::ActorId walker, const rpc::WalkerControl &control)
void OpenVehicleDoor(rpc::ActorId vehicle, const rpc::VehicleDoor door_idx)
const std::string GetEndpoint() const
rpc::WeatherParameters GetWeatherParameters()
std::vector< std::string > GetActorBoneNames(rpc::ActorId actor)
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)
std::vector< std::string > GetAvailableMaps()
bool IsEnabledForROS(const streaming::Token &token)
void DisableForROS(const streaming::Token &token)
bool SetFilesBaseFolder(const std::string &path)
rpc::VehicleLightState GetVehicleLightState(rpc::ActorId vehicle) const
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)
std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance)
std::vector< rpc::CommandResponse > ApplyBatchSync(std::vector< rpc::Command > commands, bool do_tick_cue)
void Send(rpc::ActorId ActorId, std::string message)
void UnSubscribeFromGBuffer(rpc::ActorId ActorId, uint32_t GBufferId)
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)
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)
rpc::Actor SpawnActorWithParent(const rpc::ActorDescription &description, const geom::Transform &transform, rpc::ActorId parent, rpc::AttachmentType attachment_type, const std::string &socket_name="")
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 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 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 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::string StartRecorder(std::string name, bool additional_data)
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>
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::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 EnableCarSim(rpc::ActorId vehicle, std::string simfile_path)
void SetTimeout(time_duration timeout)
geom::Transform GetActorComponentWorldTransform(rpc::ActorId actor, const std::string componentName)
std::vector< geom::Transform > GetActorBoneRelativeTransforms(rpc::ActorId actor)
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)
void RestorePhysXPhysics(rpc::ActorId vehicle)
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 ReplayFile(std::string name, double start, double duration, uint32_t follow_id, bool replay_sensors)
std::vector< std::string > GetActorSocketNames(rpc::ActorId actor)
rpc::WalkerBoneControlOut GetBonesTransform(rpc::ActorId walker)
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
void AddActorTorque(rpc::ActorId actor, const geom::Vector3D &vector)
void UpdateServerLightsState(std::vector< rpc::LightState > &lights, bool discard_client=false) const
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 ApplyControlToVehicle(rpc::ActorId vehicle, const rpc::VehicleControl &control)
void UpdateDayNightCycle(const bool active) const
void EnableEnvironmentObjects(std::vector< uint64_t > env_objects_ids, bool enable) const
rpc::EpisodeSettings GetEpisodeSettings()
void SetIMUISensorGravity(float NewIMUISensorGravity)
rpc::Actor SpawnActor(const rpc::ActorDescription &description, const geom::Transform &transform)
static auto Dot(const Vector3D &a, const Vector3D &b)
Definition Math.h:62
Vector3D MakeSafeUnitVector(const float epsilon) const
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
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:19
constexpr size_t milliseconds() const noexcept
Definition Time.h:58
static time_duration milliseconds(size_t timeout)
Definition Time.h:26
static T Get(carla::rpc::Response< T > &response)
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
uint32_t ActorId
Definition ActorId.h:14
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
void throw_exception(const std::exception &e)
Definition Carla.cpp:135
static void log_error(Args &&... args)
Definition Logging.h:110
static void log_info(Args &&... args)
Definition Logging.h:82
Seting for map generation from opendrive without additional geometry