CARLA
 
载入中...
搜索中...
未找到
client/detail/Client.h
浏览该文件的文档.
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#pragma once
8
9#include "carla/Memory.h"
10#include "carla/NonCopyable.h"
11#include "carla/Time.h"
13#include "carla/geom/Location.h"
14#include "carla/rpc/Actor.h"
17#include "carla/rpc/Command.h"
24#include "carla/rpc/MapInfo.h"
25#include "carla/rpc/MapLayer.h"
35#include "carla/rpc/Texture.h"
37
38#include <functional>
39#include <memory>
40#include <string>
41#include <vector>
42
43// 前置声明,用于在声明某个实体(通常是类、函数、变量等)的名称而无需提供其详细定义。
44// 前置声明的目的是为了告诉编译器某个实体的存在,以便在稍后的代码中引用它,而不必在声明的地方提供完整的定义。
45// 这可以提高编译速度和减少编译依赖性。
46namespace carla {
47 class Buffer;
48namespace rpc {
50 class ActorDescription;
51 class DebugShape;
52 class VehicleAckermannControl;
53 class VehicleControl;
54 class WalkerControl;
55 class WalkerBoneControlIn;
56 class WalkerBoneControlOut;
57}
58namespace sensor {
59 class SensorData;
60}
61namespace streaming {
62 class Token;
63}
64}
65
66namespace carla {
67namespace client {
68namespace detail {
69
70 /// 提供与 CARLA 模拟器的 rpc 和流媒体服务器的通信。
71 class Client : private NonCopyable {
72 public:
73
74 explicit Client(
75 const std::string &host,
76 uint16_t port,
77 size_t worker_threads = 0u);
78
80
81 /// 查询交通管理器是否正在端口上运行
82 bool IsTrafficManagerRunning(uint16_t port) const;
83
84 /// 获取一个填充了在端口上运行的交通管理器的 <IP, 端口> 的对。
85 /// 如果没有正在运行的交通管理器,则该对将为 ("", 0)
86 std::pair<std::string, uint16_t> GetTrafficManagerRunning(uint16_t port) const;
87
88 /// 通知正在 <IP, 端口> 上运行的交通管理器服务
89 bool AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const;
90
91 void DestroyTrafficManager(uint16_t port) const;
92
93 void SetTimeout(time_duration timeout);
94
96
97 const std::string GetEndpoint() const;
98
99 std::string GetClientVersion();
100
101 std::string GetServerVersion();
102
103 void LoadEpisode(std::string map_name, bool reset_settings = true, rpc::MapLayer map_layer = rpc::MapLayer::All);
104
105 void LoadLevelLayer(rpc::MapLayer map_layer) const;
106
107 void UnloadLevelLayer(rpc::MapLayer map_layer) const;
108
110 std::string opendrive, const rpc::OpendriveGenerationParameters & params);
111
113 const std::vector<std::string> &objects_name,
114 const rpc::MaterialParameter& parameter,
115 const rpc::TextureColor& Texture);
116
118 const std::vector<std::string> &objects_name,
119 const rpc::MaterialParameter& parameter,
120 const rpc::TextureFloatColor& Texture);
121
122 std::vector<std::string> GetNamesOfAllObjects() const;
123
125
127
128 std::vector<uint8_t> GetNavigationMesh() const;
129
130 bool SetFilesBaseFolder(const std::string &path);
131
132 std::vector<std::string> GetRequiredFiles(const std::string &folder = "", const bool download = true) const;
133
134 std::string GetMapData() const;
135
136 void RequestFile(const std::string &name) const;
137
138 std::vector<uint8_t> GetCacheFile(const std::string &name, const bool request_otherwise = true) const;
139
140 std::vector<std::string> GetAvailableMaps();
141
142 std::vector<rpc::ActorDefinition> GetActorDefinitions();
143
145
147
148 uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings);
149
151
152 void SetWeatherParameters(const rpc::WeatherParameters &weather);
153
154 float GetIMUISensorGravity() const;
155
156 void SetIMUISensorGravity( float NewIMUISensorGravity );
157
158 std::vector<rpc::Actor> GetActorsById(const std::vector<ActorId> &ids);
159
161
163
165 rpc::ActorId vehicle,
166 const rpc::VehiclePhysicsControl &physics_control);
167
169 rpc::ActorId vehicle,
170 const rpc::VehicleLightState &light_state);
171
172 void OpenVehicleDoor(
173 rpc::ActorId vehicle,
174 const rpc::VehicleDoor door_idx);
175
176 void CloseVehicleDoor(
177 rpc::ActorId vehicle,
178 const rpc::VehicleDoor door_idx);
179
181 const rpc::ActorDescription &description,
182 const geom::Transform &transform);
183
185 const rpc::ActorDescription &description,
186 const geom::Transform &transform,
187 rpc::ActorId parent,
188 rpc::AttachmentType attachment_type,
189 const std::string& socket_name = "");
190
191 bool DestroyActor(rpc::ActorId actor);
192
193 void SetActorLocation(
194 rpc::ActorId actor,
195 const geom::Location &location);
196
198 rpc::ActorId actor,
199 const geom::Transform &transform);
200
202 rpc::ActorId actor,
203 const geom::Vector3D &vector);
204
206 rpc::ActorId actor,
207 const geom::Vector3D &vector);
208
210 rpc::ActorId actor,
211 const geom::Vector3D &vector);
212
214 rpc::ActorId actor);
215
216 void AddActorImpulse(
217 rpc::ActorId actor,
218 const geom::Vector3D &impulse);
219
220 void AddActorImpulse(
221 rpc::ActorId actor,
222 const geom::Vector3D &impulse,
223 const geom::Vector3D &location);
224
225 void AddActorForce(
226 rpc::ActorId actor,
227 const geom::Vector3D &force);
228
229 void AddActorForce(
230 rpc::ActorId actor,
231 const geom::Vector3D &force,
232 const geom::Vector3D &location);
233
235 rpc::ActorId actor,
236 const geom::Vector3D &vector);
237
238 void AddActorTorque(
239 rpc::ActorId actor,
240 const geom::Vector3D &vector);
241
243 rpc::ActorId actor,
244 const std::string componentName);
245
247 rpc::ActorId actor,
248 const std::string componentName);
249
250 std::vector<geom::Transform> GetActorBoneWorldTransforms(
251 rpc::ActorId actor);
252
253 std::vector<geom::Transform> GetActorBoneRelativeTransforms(
254 rpc::ActorId actor);
255
256 std::vector<std::string> GetActorComponentNames(
257 rpc::ActorId actor);
258
259 std::vector<std::string> GetActorBoneNames(
260 rpc::ActorId actor);
261
262 std::vector<geom::Transform> GetActorSocketWorldTransforms(
263 rpc::ActorId actor);
264
265 std::vector<geom::Transform> GetActorSocketRelativeTransforms(
266 rpc::ActorId actor);
267
268 std::vector<std::string> GetActorSocketNames(
269 rpc::ActorId actor);
270
272 rpc::ActorId actor,
273 bool enabled);
274
276 rpc::ActorId actor,
277 bool enabled);
278
279 void SetActorDead(
280 rpc::ActorId actor);
281
283 rpc::ActorId actor,
284 bool enabled);
285
287 rpc::ActorId vehicle,
288 bool enabled);
289
291
293 rpc::ActorId vehicle,
294 bool enabled);
295
297 rpc::ActorId vehicle,
298 const rpc::VehicleControl &control);
299
301 rpc::ActorId vehicle,
302 const rpc::VehicleAckermannControl &control);
303
305
307 rpc::ActorId vehicle,
308 const rpc::AckermannControllerSettings &settings);
309
310 void EnableCarSim(
311 rpc::ActorId vehicle,
312 std::string simfile_path);
313
314 void UseCarSimRoad(
315 rpc::ActorId vehicle,
316 bool enabled);
317
319 rpc::ActorId vehicle,
320 rpc::VehicleWheelLocation vehicle_wheel,
321 float angle_in_deg
322 );
323
324 float GetWheelSteerAngle(
325 rpc::ActorId vehicle,
326 rpc::VehicleWheelLocation wheel_location
327 );
328
330 rpc::ActorId vehicle,
331 uint64_t MaxSubsteps,
332 float MaxSubstepDeltaTime,
333 std::string VehicleJSON,
334 std::string PowertrainJSON,
335 std::string TireJSON,
336 std::string BaseJSONPath);
337
338 void RestorePhysXPhysics(rpc::ActorId vehicle);
339
341 rpc::ActorId walker,
342 const rpc::WalkerControl &control);
343
345 rpc::ActorId walker);
346
348 rpc::ActorId walker,
349 const rpc::WalkerBoneControlIn &bones);
350
351 void BlendPose(
352 rpc::ActorId walker,
353 float blend);
354
356 rpc::ActorId walker);
357
359 rpc::ActorId traffic_light,
360 const rpc::TrafficLightState trafficLightState);
361
363 rpc::ActorId traffic_light,
364 float green_time);
365
367 rpc::ActorId traffic_light,
368 float yellow_time);
369
371 rpc::ActorId traffic_light,
372 float red_time);
373
375 rpc::ActorId traffic_light,
376 bool freeze);
377
379 rpc::ActorId traffic_light);
380
382
383 void FreezeAllTrafficLights(bool frozen);
384
385 std::vector<geom::BoundingBox> GetLightBoxes(
386 rpc::ActorId traffic_light) const;
387
388 /// 返回第一个元素表示交通工具ID,第二个元素表示信号灯状态的键值对
390
391 std::vector<ActorId> GetGroupTrafficLights(
392 rpc::ActorId traffic_light);
393
394 std::string StartRecorder(std::string name, bool additional_data);
395
396 void StopRecorder();
397
398 std::string ShowRecorderFileInfo(std::string name, bool show_all);
399
400 std::string ShowRecorderCollisions(std::string name, char type1, char type2);
401
402 std::string ShowRecorderActorsBlocked(std::string name, double min_time, double min_distance);
403
404 std::string ReplayFile(std::string name, double start, double duration,
405 uint32_t follow_id, bool replay_sensors);
406
407 void SetReplayerTimeFactor(double time_factor);
408
409 void SetReplayerIgnoreHero(bool ignore_hero);
410
411 void SetReplayerIgnoreSpectator(bool ignore_spectator);
412
413 void StopReplayer(bool keep_actors);
414
416 const streaming::Token &token,
417 std::function<void(Buffer)> callback);
418
421 uint32_t GBufferId,
422 std::function<void(Buffer)> callback);
423
424 void UnSubscribeFromStream(const streaming::Token &token);
425
426 void EnableForROS(const streaming::Token &token);
427
428 void DisableForROS(const streaming::Token &token);
429
430 bool IsEnabledForROS(const streaming::Token &token);
431
434 uint32_t GBufferId);
435
436 void Send(rpc::ActorId ActorId, std::string message);
437
438 void DrawDebugShape(const rpc::DebugShape &shape);
439
440 void ApplyBatch(
441 std::vector<rpc::Command> commands,
442 bool do_tick_cue);
443
444 std::vector<rpc::CommandResponse> ApplyBatchSync(
445 std::vector<rpc::Command> commands,
446 bool do_tick_cue);
447
448 uint64_t SendTickCue();
449
450 std::vector<rpc::LightState> QueryLightsStateToServer() const;
451
453 std::vector<rpc::LightState>& lights,
454 bool discard_client = false) const;
455
456 void UpdateDayNightCycle(const bool active) const;
457
458 /// Returns all the BBs of all the elements of the level
459 std::vector<geom::BoundingBox> GetLevelBBs(uint8_t queried_tag) const;
460
461 std::vector<rpc::EnvironmentObject> GetEnvironmentObjects(uint8_t queried_tag) const;
462
464 std::vector<uint64_t> env_objects_ids,
465 bool enable) const;
466
467 std::pair<bool,rpc::LabelledPoint> ProjectPoint(
468 geom::Location location, geom::Vector3D direction, float search_distance) const;
469
470 std::vector<rpc::LabelledPoint> CastRay(
471 geom::Location start_location, geom::Location end_location) const;
472
473 private:
474
475 class Pimpl;
476 const std::unique_ptr<Pimpl> _pimpl;
477 };
478
479} // namespace detail
480} // namespace client
481} // namespace carla
FAckermannControllerSettings AckermannControllerSettings
Definition ActorData.h:128
这个类用于禁止拷贝和移动构造函数及赋值操作
提供与 CARLA 模拟器的 rpc 和流媒体服务器的通信。
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)
定义车辆的物理外观,通过传感器获取
所有传感器生成数据的对象的基类
Definition SensorData.h:22
Positive time duration up to milliseconds resolution.
Definition Time.h:19
std::vector< std::pair< ActorId, VehicleLightState::flag_type > > VehicleLightStateList
uint32_t ActorId
Definition ActorId.h:20
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
carla::ActorId ActorId
参与者的智能指针类型
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
包含CARLA客户端相关类和函数的命名空间。
Seting for map generation from opendrive without additional geometry