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
7#include "carla/client/detail/Client.h" // 包含当前目录下的Client.h
8
9#include "carla/Exception.h"
10#include "carla/Version.h"
16#include "carla/rpc/Client.h" // 包含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 // 丢弃返回的 future(std::async 是 C++11 引入的异步任务执行工具,它返回一个 std::future 对象,用于获取异步任务的返回值)
83 // 从当前客户端开始rpc模块的异步调用
84 // std::forward 确保参数在传递过程中保持其原始的左值或右值属性(完美转发),保持args的值类别
85 rpc_client.async_call(function, std::forward<Args>(args) ...);
86 }
87
89 auto timeout = rpc_client.get_timeout();
90 DEBUG_ASSERT(timeout.has_value());
91 return time_duration::milliseconds(static_cast<size_t>(*timeout));
92 }
93
94 const std::string endpoint;
95
97
99 };
100
101 // ===========================================================================
102 // -- 客户端 -----------------------------------------------------------------
103 // ===========================================================================
104
106 const std::string &host,
107 const uint16_t port,
108 const size_t worker_threads)
109 : _pimpl(std::make_unique<Pimpl>(host, port, worker_threads)) {}
110
111 bool Client::IsTrafficManagerRunning(uint16_t port) const {
112 return _pimpl->CallAndWait<bool>("is_traffic_manager_running", port);
113 }
114
115 std::pair<std::string, uint16_t> Client::GetTrafficManagerRunning(uint16_t port) const {
116 return _pimpl->CallAndWait<std::pair<std::string, uint16_t>>("get_traffic_manager_running", port);
117 };
118
119 bool Client::AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const {
120 return _pimpl->CallAndWait<bool>("add_traffic_manager_running", trafficManagerInfo);
121 };
122
123 void Client::DestroyTrafficManager(uint16_t port) const {
124 _pimpl->AsyncCall("destroy_traffic_manager", port);
125 }
126
127 Client::~Client() = default;
128
130 _pimpl->rpc_client.set_timeout(static_cast<int64_t>(timeout.milliseconds()));
131 }
132
134 return _pimpl->GetTimeout();
135 }
136
137 const std::string Client::GetEndpoint() const {
138 return _pimpl->endpoint;
139 }
140
142 return ::carla::version();
143 }
144
146 return _pimpl->CallAndWait<std::string>("version");
147 }
148
149 void Client::LoadEpisode(std::string map_name, bool reset_settings, rpc::MapLayer map_layer) {
150 // 等待响应,我们需要确定这一点。
151 _pimpl->CallAndWait<void>("load_new_episode", std::move(map_name), reset_settings, map_layer);
152 }
153
154 void Client::LoadLevelLayer(rpc::MapLayer map_layer) const {
155 // 等待响应,我们需要确定这一点。
156 _pimpl->CallAndWait<void>("load_map_layer", map_layer);
157 }
158
160 // 等待响应,我们需要确定这一点。
161 _pimpl->CallAndWait<void>("unload_map_layer", map_layer);
162 }
163
164 void Client::CopyOpenDriveToServer(std::string opendrive, const rpc::OpendriveGenerationParameters & params) {
165 // 等待响应,我们需要确定这一点。
166 _pimpl->CallAndWait<void>("copy_opendrive_to_file", std::move(opendrive), params);
167 }
168
170 const std::vector<std::string> &objects_name,
171 const rpc::MaterialParameter& parameter,
172 const rpc::TextureColor& Texture) {
173 _pimpl->CallAndWait<void>("apply_color_texture_to_objects", objects_name, parameter, Texture);
174 }
175
177 const std::vector<std::string> &objects_name,
178 const rpc::MaterialParameter& parameter,
179 const rpc::TextureFloatColor& Texture) {
180 _pimpl->CallAndWait<void>("apply_float_color_texture_to_objects", objects_name, parameter, Texture);
181 }
182
183 std::vector<std::string> Client::GetNamesOfAllObjects() const {
184 return _pimpl->CallAndWait<std::vector<std::string>>("get_names_of_all_objects");
185 }
186
188 return _pimpl->CallAndWait<rpc::EpisodeInfo>("get_episode_info");
189 }
190
192 return _pimpl->CallAndWait<rpc::MapInfo>("get_map_info");
193 }
194
195 std::string Client::GetMapData() const{
196 return _pimpl->CallAndWait<std::string>("get_map_data");
197 }
198
199 std::vector<uint8_t> Client::GetNavigationMesh() const {
200 return _pimpl->CallAndWait<std::vector<uint8_t>>("get_navigation_mesh");
201 }
202
203 bool Client::SetFilesBaseFolder(const std::string &path) {
205 }
206
207 std::vector<std::string> Client::GetRequiredFiles(const std::string &folder, const bool download) const {
208 // 获取所需文件列表
209 auto requiredFiles = _pimpl->CallAndWait<std::vector<std::string>>("get_required_files", folder);
210
211 if (download) {
212
213 // 对于每个所需文件,检查它是否存在,否则请求它
214 for (auto requiredFile : requiredFiles) {
215 if (!FileTransfer::FileExists(requiredFile)) {
216 RequestFile(requiredFile);
217 log_info("Could not find the required file in cache, downloading... ", requiredFile);
218 } else {
219 log_info("Found the required file in cache! ", requiredFile);
220 }
221 }
222 }
223 return requiredFiles;
224 }
225
226 void Client::RequestFile(const std::string &name) const {
227 // 从服务器下载文件的二进制内容并写入客户端
228 auto content = _pimpl->CallAndWait<std::vector<uint8_t>>("request_file", name);
229 FileTransfer::WriteFile(name, content);
230 }
231
232 std::vector<uint8_t> Client::GetCacheFile(const std::string &name, const bool request_otherwise) const {
233 // 在文件传输中从缓存中获取文件
234 std::vector<uint8_t> file = FileTransfer::ReadFile(name);
235
236 // 如果缓存中没有,则下载它(如果请求为真)
237 if (file.empty() && request_otherwise) {
238 RequestFile(name);
239 file = FileTransfer::ReadFile(name);
240 }
241 return file;
242 }
243
244 std::vector<std::string> Client::GetAvailableMaps() {
245 return _pimpl->CallAndWait<std::vector<std::string>>("get_available_maps");
246 }
247
248 std::vector<rpc::ActorDefinition> Client::GetActorDefinitions() {
249 return _pimpl->CallAndWait<std::vector<rpc::ActorDefinition>>("get_actor_definitions");
250 }
251
253 return _pimpl->CallAndWait<carla::rpc::Actor>("get_spectator");
254 }
255
257 return _pimpl->CallAndWait<rpc::EpisodeSettings>("get_episode_settings");
258 }
259
261 return _pimpl->CallAndWait<uint64_t>("set_episode_settings", settings);
262 }
263
265 return _pimpl->CallAndWait<rpc::WeatherParameters>("get_weather_parameters");
266 }
267
269 _pimpl->AsyncCall("set_weather_parameters", weather);
270 }
271
273 return _pimpl->CallAndWait<float>("get_imui_gravity");
274 }
275
276 void Client::SetIMUISensorGravity(float NewIMUISensorGravity) {
277 _pimpl->AsyncCall("set_imui_gravity", NewIMUISensorGravity);
278 }
279
280 std::vector<rpc::Actor> Client::GetActorsById(
281 const std::vector<ActorId> &ids) {
282 using return_t = std::vector<rpc::Actor>;
283 return _pimpl->CallAndWait<return_t>("get_actors_by_id", ids);
284 }
285
287 rpc::ActorId vehicle) const {
288 return _pimpl->CallAndWait<carla::rpc::VehiclePhysicsControl>("get_physics_control", vehicle);
289 }
290
292 rpc::ActorId vehicle) const {
293 return _pimpl->CallAndWait<carla::rpc::VehicleLightState>("get_vehicle_light_state", vehicle);
294 }
295
297 rpc::ActorId vehicle,
298 const rpc::VehiclePhysicsControl &physics_control) {
299 return _pimpl->AsyncCall("apply_physics_control", vehicle, physics_control);
300 }
301
303 rpc::ActorId vehicle,
304 const rpc::VehicleLightState &light_state) {
305 return _pimpl->AsyncCall("set_vehicle_light_state", vehicle, light_state);
306 }
307
309 rpc::ActorId vehicle,
310 const rpc::VehicleDoor door_idx) {
311 return _pimpl->AsyncCall("open_vehicle_door", vehicle, door_idx);
312 }
313
315 rpc::ActorId vehicle,
316 const rpc::VehicleDoor door_idx) {
317 return _pimpl->AsyncCall("close_vehicle_door", vehicle, door_idx);
318 }
319
321 rpc::ActorId vehicle,
322 rpc::VehicleWheelLocation vehicle_wheel,
323 float angle_in_deg) {
324 return _pimpl->AsyncCall("set_wheel_steer_direction", vehicle, vehicle_wheel, angle_in_deg);
325 }
326
328 rpc::ActorId vehicle,
329 rpc::VehicleWheelLocation wheel_location){
330 return _pimpl->CallAndWait<float>("get_wheel_steer_angle", vehicle, wheel_location);
331 }
332
334 const rpc::ActorDescription &description,
335 const geom::Transform &transform) {
336 return _pimpl->CallAndWait<rpc::Actor>("spawn_actor", description, transform);
337 }
338
340 const rpc::ActorDescription &description,
341 const geom::Transform &transform,
342 rpc::ActorId parent,
343 rpc::AttachmentType attachment_type,
344 const std::string& socket_name) {
345
346 if (attachment_type == rpc::AttachmentType::SpringArm ||
347 attachment_type == rpc::AttachmentType::SpringArmGhost)
348 {
349 const auto a = transform.location.MakeSafeUnitVector(std::numeric_limits<float>::epsilon());
350 const auto z = geom::Vector3D(0.0f, 0.f, 1.0f);
351 constexpr float OneEps = 1.0f - std::numeric_limits<float>::epsilon();
352 if (geom::Math::Dot(a, z) > OneEps) {
353 std::cout << "WARNING: Transformations with translation only in the 'z' axis are ill-formed when \
354 using SpringArm or SpringArmGhost attachment. Please, be careful with that." << std::endl;
355 }
356 }
357
358 return _pimpl->CallAndWait<rpc::Actor>("spawn_actor_with_parent",
359 description,
360 transform,
361 parent,
362 attachment_type,
363 socket_name);
364 }
365
367 try {
368 return _pimpl->CallAndWait<bool>("destroy_actor", actor);
369 } catch (const std::exception &e) {
370 log_error("failed to destroy actor", actor, ':', e.what());
371 return false;
372 }
373 }
374
376 _pimpl->AsyncCall("set_actor_location", actor, location);
377 }
378
380 _pimpl->AsyncCall("set_actor_transform", actor, transform);
381 }
382
384 _pimpl->AsyncCall("set_actor_target_velocity", actor, vector);
385 }
386
388 _pimpl->AsyncCall("set_actor_target_angular_velocity", actor, vector);
389 }
390
392 _pimpl->AsyncCall("enable_actor_constant_velocity", actor, vector);
393 }
394
396 _pimpl->AsyncCall("disable_actor_constant_velocity", actor);
397 }
398
400 _pimpl->AsyncCall("add_actor_impulse", actor, impulse);
401 }
402
403 void Client::AddActorImpulse(rpc::ActorId actor, const geom::Vector3D &impulse, const geom::Vector3D &location) {
404 _pimpl->AsyncCall("add_actor_impulse_at_location", actor, impulse, location);
405 }
406
408 _pimpl->AsyncCall("add_actor_force", actor, force);
409 }
410
411 void Client::AddActorForce(rpc::ActorId actor, const geom::Vector3D &force, const geom::Vector3D &location) {
412 _pimpl->AsyncCall("add_actor_force_at_location", actor, force, location);
413 }
414
416 _pimpl->AsyncCall("add_actor_angular_impulse", actor, vector);
417 }
418
420 _pimpl->AsyncCall("add_actor_torque", actor, vector);
421 }
422
424 return _pimpl->CallAndWait<geom::Transform>("get_actor_component_world_transform", actor, componentName);
425 }
426
428 return _pimpl->CallAndWait<geom::Transform>("get_actor_component_relative_transform", actor, componentName);
429 }
430
431 std::vector<geom::Transform> Client::GetActorBoneWorldTransforms(rpc::ActorId actor) {
432 using return_t = std::vector<geom::Transform>;
433 return _pimpl->CallAndWait<return_t>("get_actor_bone_world_transforms", actor);
434 }
435
436 std::vector<geom::Transform> Client::GetActorBoneRelativeTransforms(rpc::ActorId actor) {
437 using return_t = std::vector<geom::Transform>;
438 return _pimpl->CallAndWait<return_t>("get_actor_bone_relative_transforms", actor);
439 }
440
441 std::vector<std::string> Client::GetActorComponentNames(rpc::ActorId actor) {
442 using return_t = std::vector<std::string>;
443 return _pimpl->CallAndWait<return_t>("get_actor_component_names", actor);
444 }
445
446 std::vector<std::string> Client::GetActorBoneNames(rpc::ActorId actor) {
447 using return_t = std::vector<std::string>;
448 return _pimpl->CallAndWait<return_t>("get_actor_bone_names", actor);
449 }
450
451 std::vector<geom::Transform> Client::GetActorSocketWorldTransforms(rpc::ActorId actor) {
452 using return_t = std::vector<geom::Transform>;
453 return _pimpl->CallAndWait<return_t>("get_actor_socket_world_transforms", actor);
454 }
455
456 std::vector<geom::Transform> Client::GetActorSocketRelativeTransforms(rpc::ActorId actor) {
457 using return_t = std::vector<geom::Transform>;
458 return _pimpl->CallAndWait<return_t>("get_actor_socket_relative_transforms", actor);
459 }
460
461 std::vector<std::string> Client::GetActorSocketNames(rpc::ActorId actor) {
462 using return_t = std::vector<std::string>;
463 return _pimpl->CallAndWait<return_t>("get_actor_socket_names", actor);
464 }
465
466 void Client::SetActorSimulatePhysics(rpc::ActorId actor, const bool enabled) {
467 _pimpl->CallAndWait<void>("set_actor_simulate_physics", actor, enabled);
468 }
469
470 void Client::SetActorCollisions(rpc::ActorId actor, const bool enabled) {
471 _pimpl->CallAndWait<void>("set_actor_collisions", actor, enabled);
472 }
473
475 _pimpl->AsyncCall("set_actor_dead", actor);
476 }
477
478 void Client::SetActorEnableGravity(rpc::ActorId actor, const bool enabled) {
479 _pimpl->AsyncCall("set_actor_enable_gravity", actor, enabled);
480 }
481
482 void Client::SetActorAutopilot(rpc::ActorId vehicle, const bool enabled) {
483 _pimpl->AsyncCall("set_actor_autopilot", vehicle, enabled);
484 }
485
487 rpc::ActorId vehicle) const {
488 return _pimpl->CallAndWait<carla::rpc::VehicleTelemetryData>("get_telemetry_data", vehicle);
489 }
490
491 void Client::ShowVehicleDebugTelemetry(rpc::ActorId vehicle, const bool enabled) {
492 _pimpl->AsyncCall("show_vehicle_debug_telemetry", vehicle, enabled);
493 }
494
496 _pimpl->AsyncCall("apply_control_to_vehicle", vehicle, control);
497 }
498
500 _pimpl->AsyncCall("apply_ackermann_control_to_vehicle", vehicle, control);
501 }
502
504 rpc::ActorId vehicle) const {
505 return _pimpl->CallAndWait<carla::rpc::AckermannControllerSettings>("get_ackermann_controller_settings", vehicle);
506 }
507
509 _pimpl->AsyncCall("apply_ackermann_controller_settings", vehicle, settings);
510 }
511
512 void Client::EnableCarSim(rpc::ActorId vehicle, std::string simfile_path) {
513 _pimpl->AsyncCall("enable_carsim", vehicle, simfile_path);
514 }
515
516 void Client::UseCarSimRoad(rpc::ActorId vehicle, bool enabled) {
517 _pimpl->AsyncCall("use_carsim_road", vehicle, enabled);
518 }
519
521 rpc::ActorId vehicle,
522 uint64_t MaxSubsteps,
523 float MaxSubstepDeltaTime,
524 std::string VehicleJSON,
525 std::string PowertrainJSON,
526 std::string TireJSON,
527 std::string BaseJSONPath) {
528 _pimpl->AsyncCall("enable_chrono_physics",
529 vehicle,
530 MaxSubsteps,
531 MaxSubstepDeltaTime,
532 VehicleJSON,
533 PowertrainJSON,
534 TireJSON,
535 BaseJSONPath);
536 }
537
539 _pimpl->AsyncCall("restore_physx_physics", vehicle);
540 }
541
543 _pimpl->AsyncCall("apply_control_to_walker", walker, control);
544 }
545
547 auto res = _pimpl->CallAndWait<rpc::WalkerBoneControlOut>("get_bones_transform", walker);
548 return res;
549 }
550
552 _pimpl->AsyncCall("set_bones_transform", walker, bones);
553 }
554
555 void Client::BlendPose(rpc::ActorId walker, float blend) {
556 _pimpl->AsyncCall("blend_pose", walker, blend);
557 }
558
560 _pimpl->AsyncCall("get_pose_from_animation", walker);
561 }
562
564 rpc::ActorId traffic_light,
565 const rpc::TrafficLightState traffic_light_state) {
566 _pimpl->AsyncCall("set_traffic_light_state", traffic_light, traffic_light_state);
567 }
568
569 void Client::SetTrafficLightGreenTime(rpc::ActorId traffic_light, float green_time) {
570 _pimpl->AsyncCall("set_traffic_light_green_time", traffic_light, green_time);
571 }
572
573 void Client::SetTrafficLightYellowTime(rpc::ActorId traffic_light, float yellow_time) {
574 _pimpl->AsyncCall("set_traffic_light_yellow_time", traffic_light, yellow_time);
575 }
576
577 void Client::SetTrafficLightRedTime(rpc::ActorId traffic_light, float red_time) {
578 _pimpl->AsyncCall("set_traffic_light_red_time", traffic_light, red_time);
579 }
580
581 void Client::FreezeTrafficLight(rpc::ActorId traffic_light, bool freeze) {
582 _pimpl->AsyncCall("freeze_traffic_light", traffic_light, freeze);
583 }
584
586 _pimpl->AsyncCall("reset_traffic_light_group", traffic_light);
587 }
588
590 _pimpl->CallAndWait<void>("reset_all_traffic_lights");
591 }
592
594 _pimpl->AsyncCall("freeze_all_traffic_lights", frozen);
595 }
596
597 std::vector<geom::BoundingBox> Client::GetLightBoxes(rpc::ActorId traffic_light) const {
598 using return_t = std::vector<geom::BoundingBox>;
599 return _pimpl->CallAndWait<return_t>("get_light_boxes", traffic_light);
600 }
601
603 return _pimpl->CallAndWait<std::vector<std::pair<carla::ActorId, uint32_t>>>("get_vehicle_light_states");
604 }
605
606 std::vector<ActorId> Client::GetGroupTrafficLights(rpc::ActorId traffic_light) {
607 using return_t = std::vector<ActorId>;
608 return _pimpl->CallAndWait<return_t>("get_group_traffic_lights", traffic_light);
609 }
610
611 std::string Client::StartRecorder(std::string name, bool additional_data) {
612 return _pimpl->CallAndWait<std::string>("start_recorder", name, additional_data);
613 }
614
616 return _pimpl->AsyncCall("stop_recorder");
617 }
618
619 std::string Client::ShowRecorderFileInfo(std::string name, bool show_all) {
620 return _pimpl->CallAndWait<std::string>("show_recorder_file_info", name, show_all);
621 }
622
623 std::string Client::ShowRecorderCollisions(std::string name, char type1, char type2) {
624 return _pimpl->CallAndWait<std::string>("show_recorder_collisions", name, type1, type2);
625 }
626
627 std::string Client::ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance) {
628 return _pimpl->CallAndWait<std::string>("show_recorder_actors_blocked", name, min_time, min_distance);
629 }
630
631 std::string Client::ReplayFile(std::string name, double start, double duration,
632 uint32_t follow_id, bool replay_sensors) {
633 return _pimpl->CallAndWait<std::string>("replay_file", name, start, duration,
634 follow_id, replay_sensors);
635 }
636
637 void Client::StopReplayer(bool keep_actors) {
638 _pimpl->AsyncCall("stop_replayer", keep_actors);
639 }
640
641 void Client::SetReplayerTimeFactor(double time_factor) {
642 _pimpl->AsyncCall("set_replayer_time_factor", time_factor);
643 }
644
645 void Client::SetReplayerIgnoreHero(bool ignore_hero) {
646 _pimpl->AsyncCall("set_replayer_ignore_hero", ignore_hero);
647 }
648
649 void Client::SetReplayerIgnoreSpectator(bool ignore_spectator) {
650 _pimpl->AsyncCall("set_replayer_ignore_spectator", ignore_spectator);
651 }
652
654 const streaming::Token &token,
655 std::function<void(Buffer)> callback) {
657 streaming::Token receivedToken = _pimpl->CallAndWait<streaming::Token>("get_sensor_token", thisToken.get_stream_id());
658 _pimpl->streaming_client.Subscribe(receivedToken, std::move(callback));
659 }
660
662 _pimpl->streaming_client.UnSubscribe(token);
663 }
664
667 _pimpl->AsyncCall("enable_sensor_for_ros", thisToken.get_stream_id());
668 }
669
672 _pimpl->AsyncCall("disable_sensor_for_ros", thisToken.get_stream_id());
673 }
674
677 return _pimpl->CallAndWait<bool>("is_sensor_enabled_for_ros", thisToken.get_stream_id());
678 }
679
680 void Client::Send(rpc::ActorId ActorId, std::string message) {
681 _pimpl->AsyncCall("send", ActorId, message);
682 }
683
686 uint32_t GBufferId,
687 std::function<void(Buffer)> callback)
688 {
689 std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
690 streaming::Token token;
691 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
692 _pimpl->streaming_client.Subscribe(token, std::move(callback));
693 }
694
697 uint32_t GBufferId)
698 {
699 std::vector<unsigned char> token_data = _pimpl->CallAndWait<std::vector<unsigned char>>("get_gbuffer_token", ActorId, GBufferId);
700 streaming::Token token;
701 std::memcpy(&token.data[0u], token_data.data(), token_data.size());
702 _pimpl->streaming_client.UnSubscribe(token);
703 }
704
706 _pimpl->AsyncCall("draw_debug_shape", shape);
707 }
708
709 void Client::ApplyBatch(std::vector<rpc::Command> commands, bool do_tick_cue) {
710 _pimpl->AsyncCall("apply_batch", std::move(commands), do_tick_cue);
711 }
712
713 std::vector<rpc::CommandResponse> Client::ApplyBatchSync(
714 std::vector<rpc::Command> commands,
715 bool do_tick_cue) {
716 auto result = _pimpl->RawCall("apply_batch", std::move(commands), do_tick_cue);
717 return result.as<std::vector<rpc::CommandResponse>>();
718 }
719
721 return _pimpl->CallAndWait<uint64_t>("tick_cue");
722 }
723
724 std::vector<rpc::LightState> Client::QueryLightsStateToServer() const {
725 using return_t = std::vector<rpc::LightState>;
726 return _pimpl->CallAndWait<return_t>("query_lights_state", _pimpl->endpoint);
727 }
728
729 void Client::UpdateServerLightsState(std::vector<rpc::LightState>& lights, bool discard_client) const {
730 _pimpl->AsyncCall("update_lights_state", _pimpl->endpoint, std::move(lights), discard_client);
731 }
732
733 void Client::UpdateDayNightCycle(const bool active) const {
734 _pimpl->AsyncCall("update_day_night_cycle", _pimpl->endpoint, active);
735 }
736
737 std::vector<geom::BoundingBox> Client::GetLevelBBs(uint8_t queried_tag) const {
738 using return_t = std::vector<geom::BoundingBox>;
739 return _pimpl->CallAndWait<return_t>("get_all_level_BBs", queried_tag);
740 }
741
742 std::vector<rpc::EnvironmentObject> Client::GetEnvironmentObjects(uint8_t queried_tag) const {
743 using return_t = std::vector<rpc::EnvironmentObject>;
744 return _pimpl->CallAndWait<return_t>("get_environment_objects", queried_tag);
745 }
746
748 std::vector<uint64_t> env_objects_ids,
749 bool enable) const {
750 _pimpl->AsyncCall("enable_environment_objects", std::move(env_objects_ids), enable);
751 }
752
753 std::pair<bool,rpc::LabelledPoint> Client::ProjectPoint(
754 geom::Location location, geom::Vector3D direction, float search_distance) const {
755 using return_t = std::pair<bool,rpc::LabelledPoint>;
756 return _pimpl->CallAndWait<return_t>("project_point", location, direction, search_distance);
757 }
758
759 std::vector<rpc::LabelledPoint> Client::CastRay(
760 geom::Location start_location, geom::Location end_location) const {
761 using return_t = std::vector<rpc::LabelledPoint>;
762 return _pimpl->CallAndWait<return_t>("cast_ray", start_location, end_location);
763 }
764
765} // namespace detail
766} // namespace client
767} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:68
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()
返回第一个元素表示交通工具ID,第二个元素表示信号灯状态的键值对
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
获取一个填充了在端口上运行的交通管理器的 <IP, 端口> 的对。 如果没有正在运行的交通管理器,则该对将为 ("", 0)
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
通知正在 <IP, 端口> 上运行的交通管理器服务
std::vector< geom::Transform > GetActorBoneWorldTransforms(rpc::ActorId actor)
bool IsTrafficManagerRunning(uint16_t port) const
查询交通管理器是否正在端口上运行
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:70
Vector3D MakeSafeUnitVector(const float epsilon) const
Definition: geom/Vector3D.h:81
void async_call(const std::string &function, Args &&... args)
Definition: rpc/Client.h:69
auto call(const std::string &function, Args &&... args)
Definition: rpc/Client.h:60
auto get_timeout() const
Definition: rpc/Client.h:49
void set_timeout(int64_t value)
Definition: rpc/Client.h:42
value_type & Get()
Definition: Response.h:82
定义车辆的物理外观,通过传感器获取
void AsyncRun(size_t worker_threads)
静态断言,用于确保token_data结构体的大小与Token::data的大小相同。
Definition: detail/Token.h:98
const auto & get_stream_id() const
获取流ID的引用。
Definition: detail/Token.h:199
Positive time duration up to milliseconds resolution.
Definition: Time.h:19
constexpr size_t milliseconds() const noexcept
Definition: Time.h:60
static time_duration milliseconds(size_t timeout)
Definition: Time.h:26
static T Get(carla::rpc::Response< T > &response)
uint32_t ActorId
Definition: ActorId.h:20
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
carla::ActorId ActorId
参与者的智能指针类型
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
CARLA模拟器的主命名空间。
Definition: Carla.cpp:139
void throw_exception(const std::exception &e)
Definition: Carla.cpp:142
static void log_error(Args &&... args)
Definition: Logging.h:115
static void log_info(Args &&... args)
Definition: Logging.h:86
包含CARLA客户端相关类和函数的命名空间。
Seting for map generation from opendrive without additional geometry
令牌数据结构,用于存储流传输的相关信息。 ::::