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// Forward declarations.
44namespace carla {
45 class Buffer;
46namespace rpc {
47 class AckermannControllerSettings;
48 class ActorDescription;
49 class DebugShape;
50 class VehicleAckermannControl;
51 class VehicleControl;
52 class WalkerControl;
53 class WalkerBoneControlIn;
54 class WalkerBoneControlOut;
55}
56namespace sensor {
57 class SensorData;
58}
59namespace streaming {
60 class Token;
61}
62}
63
64namespace carla {
65namespace client {
66namespace detail {
67
68 /// Provides communication with the rpc and streaming servers of a CARLA
69 /// simulator.
70 class Client : private NonCopyable {
71 public:
72
73 explicit Client(
74 const std::string &host,
75 uint16_t port,
76 size_t worker_threads = 0u);
77
79
80 /// Querry to know if a Traffic Manager is running on port
81 bool IsTrafficManagerRunning(uint16_t port) const;
82
83 /// Gets a pair filled with the <IP, port> of the Trafic Manager running on port.
84 /// If there is no Traffic Manager running the pair will be ("", 0)
85 std::pair<std::string, uint16_t> GetTrafficManagerRunning(uint16_t port) const;
86
87 /// Informs the server that a Traffic Manager is running on <IP, port>
88 bool AddTrafficManagerRunning(std::pair<std::string, uint16_t> trafficManagerInfo) const;
89
90 void DestroyTrafficManager(uint16_t port) const;
91
92 void SetTimeout(time_duration timeout);
93
95
96 const std::string GetEndpoint() const;
97
98 std::string GetClientVersion();
99
100 std::string GetServerVersion();
101
102 void LoadEpisode(std::string map_name, bool reset_settings = true, rpc::MapLayer map_layer = rpc::MapLayer::All);
103
104 void LoadLevelLayer(rpc::MapLayer map_layer) const;
105
106 void UnloadLevelLayer(rpc::MapLayer map_layer) const;
107
109 std::string opendrive, const rpc::OpendriveGenerationParameters & params);
110
112 const std::vector<std::string> &objects_name,
113 const rpc::MaterialParameter& parameter,
114 const rpc::TextureColor& Texture);
115
117 const std::vector<std::string> &objects_name,
118 const rpc::MaterialParameter& parameter,
119 const rpc::TextureFloatColor& Texture);
120
121 std::vector<std::string> GetNamesOfAllObjects() const;
122
124
126
127 std::vector<uint8_t> GetNavigationMesh() const;
128
129 bool SetFilesBaseFolder(const std::string &path);
130
131 std::vector<std::string> GetRequiredFiles(const std::string &folder = "", const bool download = true) const;
132
133 std::string GetMapData() const;
134
135 void RequestFile(const std::string &name) const;
136
137 std::vector<uint8_t> GetCacheFile(const std::string &name, const bool request_otherwise = true) const;
138
139 std::vector<std::string> GetAvailableMaps();
140
141 std::vector<rpc::ActorDefinition> GetActorDefinitions();
142
144
146
147 uint64_t SetEpisodeSettings(const rpc::EpisodeSettings &settings);
148
150
151 void SetWeatherParameters(const rpc::WeatherParameters &weather);
152
153 float GetIMUISensorGravity() const;
154
155 void SetIMUISensorGravity( float NewIMUISensorGravity );
156
157 std::vector<rpc::Actor> GetActorsById(const std::vector<ActorId> &ids);
158
160
162
164 rpc::ActorId vehicle,
165 const rpc::VehiclePhysicsControl &physics_control);
166
168 rpc::ActorId vehicle,
169 const rpc::VehicleLightState &light_state);
170
171 void OpenVehicleDoor(
172 rpc::ActorId vehicle,
173 const rpc::VehicleDoor door_idx);
174
175 void CloseVehicleDoor(
176 rpc::ActorId vehicle,
177 const rpc::VehicleDoor door_idx);
178
180 const rpc::ActorDescription &description,
181 const geom::Transform &transform);
182
184 const rpc::ActorDescription &description,
185 const geom::Transform &transform,
186 rpc::ActorId parent,
187 rpc::AttachmentType attachment_type,
188 const std::string& socket_name = "");
189
190 bool DestroyActor(rpc::ActorId actor);
191
192 void SetActorLocation(
193 rpc::ActorId actor,
194 const geom::Location &location);
195
197 rpc::ActorId actor,
198 const geom::Transform &transform);
199
201 rpc::ActorId actor,
202 const geom::Vector3D &vector);
203
205 rpc::ActorId actor,
206 const geom::Vector3D &vector);
207
209 rpc::ActorId actor,
210 const geom::Vector3D &vector);
211
213 rpc::ActorId actor);
214
215 void AddActorImpulse(
216 rpc::ActorId actor,
217 const geom::Vector3D &impulse);
218
219 void AddActorImpulse(
220 rpc::ActorId actor,
221 const geom::Vector3D &impulse,
222 const geom::Vector3D &location);
223
224 void AddActorForce(
225 rpc::ActorId actor,
226 const geom::Vector3D &force);
227
228 void AddActorForce(
229 rpc::ActorId actor,
230 const geom::Vector3D &force,
231 const geom::Vector3D &location);
232
234 rpc::ActorId actor,
235 const geom::Vector3D &vector);
236
237 void AddActorTorque(
238 rpc::ActorId actor,
239 const geom::Vector3D &vector);
240
242 rpc::ActorId actor,
243 const std::string componentName);
244
246 rpc::ActorId actor,
247 const std::string componentName);
248
249 std::vector<geom::Transform> GetActorBoneWorldTransforms(
250 rpc::ActorId actor);
251
252 std::vector<geom::Transform> GetActorBoneRelativeTransforms(
253 rpc::ActorId actor);
254
255 std::vector<std::string> GetActorComponentNames(
256 rpc::ActorId actor);
257
258 std::vector<std::string> GetActorBoneNames(
259 rpc::ActorId actor);
260
261 std::vector<geom::Transform> GetActorSocketWorldTransforms(
262 rpc::ActorId actor);
263
264 std::vector<geom::Transform> GetActorSocketRelativeTransforms(
265 rpc::ActorId actor);
266
267 std::vector<std::string> GetActorSocketNames(
268 rpc::ActorId actor);
269
271 rpc::ActorId actor,
272 bool enabled);
273
275 rpc::ActorId actor,
276 bool enabled);
277
278 void SetActorDead(
279 rpc::ActorId actor);
280
282 rpc::ActorId actor,
283 bool enabled);
284
286 rpc::ActorId vehicle,
287 bool enabled);
288
290
292 rpc::ActorId vehicle,
293 bool enabled);
294
296 rpc::ActorId vehicle,
297 const rpc::VehicleControl &control);
298
300 rpc::ActorId vehicle,
301 const rpc::VehicleAckermannControl &control);
302
304
306 rpc::ActorId vehicle,
307 const rpc::AckermannControllerSettings &settings);
308
309 void EnableCarSim(
310 rpc::ActorId vehicle,
311 std::string simfile_path);
312
313 void UseCarSimRoad(
314 rpc::ActorId vehicle,
315 bool enabled);
316
318 rpc::ActorId vehicle,
319 rpc::VehicleWheelLocation vehicle_wheel,
320 float angle_in_deg
321 );
322
323 float GetWheelSteerAngle(
324 rpc::ActorId vehicle,
325 rpc::VehicleWheelLocation wheel_location
326 );
327
329 rpc::ActorId vehicle,
330 uint64_t MaxSubsteps,
331 float MaxSubstepDeltaTime,
332 std::string VehicleJSON,
333 std::string PowertrainJSON,
334 std::string TireJSON,
335 std::string BaseJSONPath);
336
337 void RestorePhysXPhysics(rpc::ActorId vehicle);
338
340 rpc::ActorId walker,
341 const rpc::WalkerControl &control);
342
344 rpc::ActorId walker);
345
347 rpc::ActorId walker,
348 const rpc::WalkerBoneControlIn &bones);
349
350 void BlendPose(
351 rpc::ActorId walker,
352 float blend);
353
355 rpc::ActorId walker);
356
358 rpc::ActorId traffic_light,
359 const rpc::TrafficLightState trafficLightState);
360
362 rpc::ActorId traffic_light,
363 float green_time);
364
366 rpc::ActorId traffic_light,
367 float yellow_time);
368
370 rpc::ActorId traffic_light,
371 float red_time);
372
374 rpc::ActorId traffic_light,
375 bool freeze);
376
378 rpc::ActorId traffic_light);
379
381
382 void FreezeAllTrafficLights(bool frozen);
383
384 std::vector<geom::BoundingBox> GetLightBoxes(
385 rpc::ActorId traffic_light) const;
386
387 /// Returns a list of pairs where the firts element is the vehicle ID
388 /// and the second one is the light state
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
Inherit (privately) to suppress copy/move construction and assignment.
Provides communication with the rpc and streaming servers of a CARLA simulator.
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)
Defines the physical appearance of a vehicle whitch is obtained by the sensors.
Base class for all the objects containing data generated by a sensor.
Definition SensorData.h:22
A token that uniquely identify a stream.
Definition Token.h:17
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:14
std::deque< std::shared_ptr< SimpleWaypoint > > Buffer
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
Seting for map generation from opendrive without additional geometry